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>タグを作成します。
027 *
028 * ●使用例
029 *      JspConvertEntity e = new JspConvertEntity();
030 *      e.setTableName("GF92");
031 *      e.setColumnName("CLM");
032 *      List< JspConvertEntity> a = new List< JspConvertEntity>();
033 *      a.add( e );
034 *      Map< String , List< JspConvertEntity> > m = new Map< String , List<JspConvertEntity> >();
035 *      m.put( "ORDER", a );
036 *      JspCreate  j = JspCreateFactory.newInstance( "SELECT",m );
037 *      j.execute("&ltog:select /&gt");
038 *
039 * @author Takeshi.Takada
040 *
041 */
042public class JspCreate_SELECT extends AbstractJspCreate {
043        private List<JspConvertEntity> ORDER_ROWS ;
044        private boolean IS_NULL ;
045
046        /**
047         * 初期化メソッド
048         *
049         * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。
050         *
051         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、名前空間指定無しに変更します。
052         *
053         * @param       master  JspConvertEntityのリストのマップ
054         */
055        @Override
056        protected void init( final Map<String,List<JspConvertEntity>> master ) {
057                ORDER_ROWS = master.get("ORDER");
058//              IS_NULL = (ORDER_ROWS == null || ORDER_ROWS.isEmpty() );
059                IS_NULL = !isNotEmpty( ORDER_ROWS );
060//              KEY  = "og:select";
061                KEY  = ":select";               // 5.2.1.0 (2010/10/01) 名前空間指定無し
062                NAME = "query";
063        }
064
065        /**
066         * JSPに出力するタグの内容を作成します。
067         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
068         *
069         * @og.rev 5.2.1.0 (2010/10/01) メソッドの引数を、OGAttributes から OGElement に変更します。
070         * @og.rev 5.2.1.0 (2010/10/01) 名前空間を、og 決め打ちから、引数を使用するように変更します。
071         *
072         * @param ele OGElementエレメントオブジェクト
073         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
074         *
075         * @return      変換された文字列
076         * @throws Throwable 変換時のエラー
077         */
078        @Override
079        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
080                if( IS_NULL ) { return ""; }
081
082                String ns = (nameSpace.length() == 0) ? "" : nameSpace + ":" ;  // 5.2.1.0 (2010/10/01) 名前空間
083
084                // TODO Auto-generated method stub
085                //書き出す文字列を作成開始。
086                StringBuilder sbTub = new StringBuilder();
087
088                //JOIN情報から<og:select>タグの検索句を生成する準備をします。
089//              sbTub.append( "\t\t<og:select name=\"ORDER_BY\" lbl=\"ORDER_BY\">").append( CR );
090                sbTub.append( "\t\t<" ).append( ns ).append( "select name=\"ORDER_BY\" lbl=\"ORDER_BY\">").append( CR );
091                boolean isFirst = true;
092
093                for ( JspConvertEntity column : ORDER_ROWS ){
094//                      sbTub.append( "\t\t\t<og:option value=\"" );
095                        sbTub.append( "\t\t\t<" ).append( ns ).append( "option value=\"" );
096                        sbTub.append( column.getRemarks() );
097                        sbTub.append( "\"\t\t" );
098                        sbTub.append( " lbls=\"");
099                        sbTub.append( column.getRemarks() );
100                        sbTub.append( "\" ");
101                        if ( isFirst ){
102                                sbTub.append( "selected=\"selected\"");
103                                isFirst = false;
104                        }
105                        sbTub.append( " />" ).append( CR );
106                }
107//              sbTub.append( "\t\t</og:select>").append( CR );
108                sbTub.append( "\t\t</" ).append( ns ).append( "select>").append( CR );
109
110                return sbTub.toString();
111        }
112
113}