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 */ 016 package org.opengion.plugin.develop; 017 018 import java.util.List; 019 import java.util.Map; 020 021 import org.opengion.hayabusa.develop.AbstractJspCreate; 022 import org.opengion.hayabusa.develop.JspConvertEntity; 023 import org.opengion.fukurou.xml.OGElement; 024 import 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 */ 043 public 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 }