001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016package org.opengion.plugin.develop; 017 018import java.util.List; 019import java.util.Map; 020 021import org.opengion.hayabusa.develop.AbstractJspCreate; 022import org.opengion.hayabusa.develop.JspConvertEntity; 023import org.opengion.fukurou.xml.OGElement; 024 025/** 026 * query.jspの<og:select>タグを利用した ORDER BYパラメータを作成します。 027 * 028 * 検索条件のプルダウンは、通常、queryButtonタグ内に記載します。 029 * ただし、場合によっては、表に出すこともある為、name="ORDER_BY" で置き換えを実行します。 030 * 031 * ●使用例 032 * <og:select name="ORDER_BY"> 033 * <option value = column.getRemarks() lbls = column.getRemarks() selected = "selected" /> 034 * <option value = column.getRemarks() lbls = column.getRemarks() /> 035 * ・・・・ 036 * </og:select> 037 * 038 * @og.rev 5.6.1.2 (2013/02/22) 文字列連結から、XML処理するように変更します。 039 * @author Takeshi.Takada 040 * 041 */ 042public class JspCreate_ORDER_BY extends AbstractJspCreate { 043 //* このプログラムのVERSION文字列を設定します。 {@value} */ 044 private static final String VERSION = "5.6.1.2 (2013/02/22)" ; 045 046 private List<JspConvertEntity> ORDER_ROWS ; 047 private boolean IS_NULL ; 048 049 /** 050 * 初期化メソッド 051 * 052 * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。 053 * 054 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。 055 * 056 * @param master JspConvertEntityのリストのマップ 057 */ 058 @Override 059 protected void init( final Map<String,List<JspConvertEntity>> master ) { 060 ORDER_ROWS = master.get("ORDER"); 061 IS_NULL = !isNotEmpty( ORDER_ROWS ); 062 KEY = ":select"; // 5.2.1.0 (2010/10/01) 名前空間指定無し 063 NAME = "query"; 064 } 065 066 /** 067 * JSPに出力するタグの内容を作成します。 068 * 引数より作成前のタグの属性内容を確認するする事が出来ます。 069 * 070 * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。 071 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。 072 * 073 * @param ele OGElementエレメントオブジェクト 074 * @param nameSpace このドキュメントのnameSpace( og とか mis とか ) 075 * 076 * @return 変換された文字列 077 * @throws Throwable 変換時のエラー 078 */ 079 @Override 080 protected String execute( final OGElement ele , final String nameSpace ) throws Throwable { 081 if( IS_NULL ) { return ""; } 082 083 // name="ORDER_BY" 以外は、そのまま返す。 084 if( !"ORDER_BY".equalsIgnoreCase( ele.getVal( "name" ) ) ) { 085 return ele.toString(); 086 } 087 088 String ns = (nameSpace.length() == 0) ? "" : nameSpace + ":" ; // 名前空間 089 090 ele.clearNode(); // 一旦すべてのノードを削除します。 091 092 boolean isFirst = true; 093 for ( JspConvertEntity column : ORDER_ROWS ){ 094 OGElement opt = new OGElement( ns + "option" ); 095 String remks = column.getRemarks(); // 属性。ここに、A1.AA,A1.BB,A1.CC,B1.DD desc などのカラム列が入る。 096 String[] clms = remks.split( "," ); // カンマで分解 097 StringBuilder buf = new StringBuilder(); // ラベル用に、別名を取り除く 098 for( int i=0; i<clms.length; i++ ) { 099 if( i>0 ) { buf.append( ',' ); } // 最初以外は、カンマを追加していく。 100 101 String clm = clms[i].trim(); 102 int idx = clm.indexOf( '.' ); 103 if( idx >= 0 ) { buf.append( clm.substring( idx+1 ) ); } 104 else { buf.append( clm ); } 105 } 106 107 opt.addAttr( "value" , remks ); 108 opt.addAttr( "lbls" , buf.toString() ); 109 if ( isFirst ){ 110 opt.addAttr( "selected" , "selected" ); 111 isFirst = false; 112 } 113 ele.addNode( opt ); 114 } 115 116 return ele.getText( 1 ); 117 } 118}