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; 024import org.opengion.fukurou.xml.OGNode; 025 026/** 027 * query.jspの<og:select>タグを利用した ORDER BYパラメータを作成します。 028 * 029 * 検索条件のプルダウンは、通常、queryButtonタグ内に記載します。 030 * ただし、場合によっては、表に出すこともある為、name="ORDER_BY" で置き換えを実行します。 031 * 032 * ●使用例 033 * <og:select name="ORDER_BY"> 034 * <option value = column.getRemarks() lbls = column.getRemarks() selected = "selected" /> 035 * <option value = column.getRemarks() lbls = column.getRemarks() /> 036 * ・・・・ 037 * </og:select> 038 * 039 * @og.rev 5.6.1.2 (2013/02/22) 文字列連結から、XML処理するように変更します。 040 * @author Takeshi.Takada 041 * 042 */ 043public class JspCreate_ORDER_BY extends AbstractJspCreate { 044 //* このプログラムのVERSION文字列を設定します。 {@value} */ 045 private static final String VERSION = "5.6.1.2 (2013/02/22)" ; 046 047 private List<JspConvertEntity> ORDER_ROWS ; 048 private boolean IS_NULL ; 049 050 /** 051 * 初期化メソッド 052 * 053 * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。 054 * 055 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。 056 * 057 * @param master JspConvertEntityのリストのマップ 058 */ 059 @Override 060 protected void init( final Map<String,List<JspConvertEntity>> master ) { 061 ORDER_ROWS = master.get("ORDER"); 062// IS_NULL = (ORDER_ROWS == null || ORDER_ROWS.isEmpty() ); 063 IS_NULL = !isNotEmpty( ORDER_ROWS ); 064// KEY = "og:select"; 065 KEY = ":select"; // 5.2.1.0 (2010/10/01) 名前空間指定無し 066 NAME = "query"; 067 } 068 069 /** 070 * JSPに出力するタグの内容を作成します。 071 * 引数より作成前のタグの属性内容を確認するする事が出来ます。 072 * 073 * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。 074 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。 075 * 076 * @param ele OGElementエレメントオブジェクト 077 * @param nameSpace このドキュメントのnameSpace( og とか mis とか ) 078 * 079 * @return 変換された文字列 080 * @throws Throwable 変換時のエラー 081 */ 082 @Override 083 protected String execute( final OGElement ele , final String nameSpace ) throws Throwable { 084 if( IS_NULL ) { return ""; } 085 086 // name="ORDER_BY" 以外は、そのまま返す。 087 if( !"ORDER_BY".equalsIgnoreCase( ele.getVal( "name" ) ) ) { 088 return ele.toString(); 089 } 090 091 String ns = (nameSpace.length() == 0) ? "" : nameSpace + ":" ; // 名前空間 092 093 ele.clearNode(); // 一旦すべてのノードを削除します。 094 095 boolean isFirst = true; 096 for ( JspConvertEntity column : ORDER_ROWS ){ 097 OGElement opt = new OGElement( ns + "option" ); 098 String remks = column.getRemarks(); // 属性。ここに、A1.AA,A1.BB,A1.CC,B1.DD desc などのカラム列が入る。 099 String[] clms = remks.split( "," ); // カンマで分解 100 StringBuilder buf = new StringBuilder(); // ラベル用に、別名を取り除く 101 for( int i=0; i<clms.length; i++ ) { 102 if( i>0 ) { buf.append( ',' ); } // 最初以外は、カンマを追加していく。 103 104 String clm = clms[i].trim(); 105 int idx = clm.indexOf( '.' ); 106 if( idx >= 0 ) { buf.append( clm.substring( idx+1 ) ); } 107 else { buf.append( clm ); } 108 } 109 110// opt.addAttr( "value" , column.getRemarks() ); 111// opt.addAttr( "lbls" , column.getRemarks() ); 112 opt.addAttr( "value" , remks ); 113 opt.addAttr( "lbls" , buf.toString() ); 114 if ( isFirst ){ 115 opt.addAttr( "selected" , "selected" ); 116 isFirst = false; 117 } 118 ele.addNode( opt ); 119 } 120 121 return ele.getText( 1 ); 122 } 123 124 /** 125 * JSPに出力するタグの内容を作成します。 126 * 引数より作成前のタグの属性内容を確認するする事が出来ます。 127 * 128 * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。 129 * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。 130 * 131 * @param ele OGElementエレメントオブジェクト 132 * @param nameSpace このドキュメントのnameSpace( og とか mis とか ) 133 * 134 * @return 変換された文字列 135 * @throws Throwable 変換時のエラー 136 */ 137// @Override 138// protected String execute( final OGElement ele , final String nameSpace ) throws Throwable { 139// if( IS_NULL ) { return ""; } 140// 141// String ns = (nameSpace.length() == 0) ? "" : nameSpace + ":" ; // 5.2.1.0 (2010/10/01) 名前空間 142// 143// // TODO Auto-generated method stub 144// //書き出す文字列を作成開始。 145// StringBuilder sbTub = new StringBuilder(); 146// 147// //JOIN情報から<og:select>タグの検索句を生成する準備をします。 148//// sbTub.append( "\t\t<og:select name=\"ORDER_BY\" lbl=\"ORDER_BY\">").append( CR ); 149// sbTub.append( "\t\t<" ).append( ns ).append( "select name=\"ORDER_BY\" lbl=\"ORDER_BY\">").append( CR ); 150// boolean isFirst = true; 151// 152// for ( JspConvertEntity column : ORDER_ROWS ){ 153//// sbTub.append( "\t\t\t<og:option value=\"" ); 154// sbTub.append( "\t\t\t<" ).append( ns ).append( "option value=\"" ); 155// sbTub.append( column.getRemarks() ); 156// sbTub.append( "\"\t\t" ); 157// sbTub.append( " lbls=\""); 158// sbTub.append( column.getRemarks() ); 159// sbTub.append( "\" "); 160// if ( isFirst ){ 161// sbTub.append( "selected=\"selected\""); 162// isFirst = false; 163// } 164// sbTub.append( " />" ).append( CR ); 165// } 166//// sbTub.append( "\t\t</og:select>").append( CR ); 167// sbTub.append( "\t\t</" ).append( ns ).append( "select>").append( CR ); 168// 169// return sbTub.toString(); 170// } 171}