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.JspConvertEntity;
022import org.opengion.fukurou.xml.OGElement;
023
024/**
025 * query.jspの <og:hideMenu>タグ 内の <og:column>タグを作成します。
026 * column タグは、部分置換ではなく、hideMenu内の、table 部分からの全面置換です。(部分置換は難しかったので)
027 * hideMenu は、通常の column タグの出力制限以上のカラムを書き出します。
028 * 具体的には、TD_COUNT(初期値=3)* TR_COUNT(初期値=2)を超える検索条件の時のみ行います。
029 * それ以下の場合は、hideMenu タグは書き出しません。
030 * 
031 * これと、JspCreate_COLUMN クラスは、密接に関連していますので、ご注意ください。
032 *
033 * ●使用例
034 *      <table summary = "layout" >
035 *          <tr><og:column ・・・ /> ・・・TD_COUNT(初期値=3)</tr>
036 *                  ・・・・ TR_COUNT(初期値=2)
037 *      </table>
038 *   <og:hideMenu>
039 *      <table summary = "layout" >
040 *          <tr>
041 *              <og:column
042 *                  name       = column.getColumnName() 
043 *                  defaultVal = column.getDefaultValue()
044 *                  must       = "true"         ("1".equals( column.getMust() ))
045 *                  clazz      = "aimai"        (ope.startsWith( "lk" ))
046 *              />
047 *              <og:column
048 *                  ・・・・
049 *              />
050 *          </tr>
051 *          <tr>
052 *                  ・・・・
053 *          </tr>
054 *      </table>
055 *   </og:hideMenu>
056 *
057 * @og.rev 5.6.4.4 (2013/05/31) 新規作成。hideMenu の対応
058 *
059 * @version  5.0
060 * @author       Kazuhiko Hasegawa
061 * @since    JDK7.0,
062 */
063public class JspCreate_HIDEMENU extends JspCreate_COLUMN {
064        /** このプログラムのVERSION文字列を設定します。   {@value} */
065        private static final String VERSION = "6.3.9.1 (2015/11/27)" ;
066
067        // 6.3.9.1 (2015/11/27) Variables should start with a lowercase character(PMD)
068        private List<JspConvertEntity> queryROWS ;
069        private boolean isNULL ;
070
071        /**
072         * コンストラクター
073         *
074         * インスタンス構築時に、タグ名(key)とファイル名(names)を指定します。
075         *
076         * @og.rev 6.3.9.1 (2015/11/27) コンストラクタを用意して、KEY,NAME をセットするように変更します。
077         */
078        public JspCreate_HIDEMENU() {
079                super( ":hideMenu" , "query" );
080        }
081
082        /**
083         * 初期化メソッド
084         *
085         * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。
086         *
087         * @param       master  JspConvertEntityのリストのマップ
088         */
089        @Override
090        protected void init( final Map<String,List<JspConvertEntity>> master ) {
091                queryROWS = master.get("QUERY");                                                // 6.3.9.1 (2015/11/27)
092                isNULL = !isNotEmpty( queryROWS );                                              // 6.3.9.1 (2015/11/27)
093        }
094
095        /**
096         * JSPに出力するタグの内容を作成します。
097         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
098         *
099         * @param ele OGElementエレメントオブジェクト
100         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
101         *
102         * @return      変換された文字列
103         * @og.rtnNotNull
104         * @throws Throwable 変換時のエラー
105         */
106        @Override
107        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
108                if( isNULL ) { return ""; }                                                                             // 6.3.9.1 (2015/11/27)
109
110                if( queryROWS.size() <= TD_COUNT*TR_COUNT ) { return ""; }              // 指定以上のカラムがないと、hideMenu を作成しません。
111
112                // 既存の設定値をすべて削除します。ホントは自動登録した分だけを削除すべき。
113                final OGElement newEle  = new OGElement( "og:hideMenu" );
114
115                final OGElement tblEle  = new OGElement( "table" );
116                newEle.addNode( tblEle );
117
118                OGElement tr = null;
119                        for( int i=TD_COUNT*TR_COUNT; i<queryROWS.size(); i++ ) {               // 6.3.9.1 (2015/11/27)
120                                final JspConvertEntity column = queryROWS.get(i);                       // 6.3.9.1 (2015/11/27)
121                                if( i%TD_COUNT == 0 ) {
122                                        tr = new OGElement( "tr" );
123                                        tblEle.addNode( tr );
124                                }
125                                tr = trElement( tr,column );
126                        }
127
128                return newEle.getText( 0 );
129        }
130}