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 = "5.6.4.4 (2013/05/31)" ;
066
067        private List<JspConvertEntity> QUERY_ROWS ;
068        private boolean IS_NULL ;
069
070        /**
071         * 初期化メソッド
072         *
073         * 内部で使用する JspConvertEntity の リスト のマップを受け取り、初期化を行います。
074         *
075         * @param       master  JspConvertEntityのリストのマップ
076         */
077        @Override
078        protected void init( final Map<String,List<JspConvertEntity>> master ) {
079                QUERY_ROWS = master.get("QUERY");
080                IS_NULL = !isNotEmpty( QUERY_ROWS );
081                KEY  = ":hideMenu";
082                NAME = "query";
083        }
084
085        /**
086         * JSPに出力するタグの内容を作成します。
087         * 引数より作成前のタグの属性内容を確認するする事が出来ます。
088         *
089         * @param ele OGElementエレメントオブジェクト
090         * @param       nameSpace       このドキュメントのnameSpace( og とか mis とか )
091         *
092         * @return      変換された文字列
093         * @throws Throwable 変換時のエラー
094         */
095        @Override
096        protected String execute( final OGElement ele , final String nameSpace )  throws Throwable {
097                if( IS_NULL ) { return ""; }
098
099                if( QUERY_ROWS.size() <= TD_COUNT*TR_COUNT ) { return ""; }             // 指定以上のカラムがないと、hideMenu を作成しません。
100
101                // 既存の設定値をすべて削除します。ホントは自動登録した分だけを削除すべき。
102                OGElement newEle  = new OGElement( "og:hideMenu" );
103
104                OGElement tblEle  = new OGElement( "table" );
105                newEle.addNode( tblEle );
106
107                OGElement tr = null;
108                        for( int i=TD_COUNT*TR_COUNT; i<QUERY_ROWS.size(); i++ ) {
109                                JspConvertEntity column = QUERY_ROWS.get(i);
110                                if( i%TD_COUNT == 0 ) {
111                                        tr = new OGElement( "tr" );
112                                        tblEle.addNode( tr );
113                                }
114                                tr = trElement( tr,column );
115                        }
116
117                return newEle.getText( 0 );
118        }
119}