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.hayabusa.taglib;
017
018import org.opengion.hayabusa.common.HybsSystemException;
019import org.opengion.hayabusa.html.TableFormatter;
020import org.opengion.hayabusa.html.FormatterType;
021import org.opengion.fukurou.util.ToString;                                              // 6.1.1.0 (2015/01/17)
022
023import static org.opengion.fukurou.util.StringUtil.nval ;
024
025/**
026 * ヘッダ、フッター、ボディー部のフォーマットを汎用的に定義するタグです。
027 *
028 * thead,tfoot,tbody に代わる表示フォーマットをカスタマイズするときに使用する親クラスです。
029 * このクラス自身がタグとしては表に現れません。
030 *
031 * @og.formSample
032 * ●形式:(タグとしては使われません)
033 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します)
034 *
035 * @og.rev 3.5.4.0 (2003/11/25) 新規追加
036 * @og.rev 3.5.4.2 (2003/12/15) カスタムタグクラスから削除します。(abstract化)
037 * @og.rev 4.0.0.0 (2006/01/31) カスタムタグクラスに復活させます。(public化)
038 * @og.rev 6.3.4.0 (2015/08/01) TFormatTag.java → TFormatImpl.java
039 * @og.group 画面部品
040 *
041 * @version  4.0
042 * @author       Kazuhiko Hasegawa
043 * @since    JDK5.0,
044 */
045class TFormatImpl extends CommonTagSupport {
046        /** このプログラムのVERSION文字列を設定します。   {@value} */
047        private static final String VERSION = "7.3.1.0 (2021/02/02)" ;
048        private static final long serialVersionUID = 731020210202L ;
049
050        private String rowspan          = "2";
051        private String noClass          = "false";
052        private String usableKey        ;
053        private String usableList       = "1" ;
054        private String itdBody          = "";                   // 3.5.6.0 (2004/06/18)
055        private String keyBreakClm      ;                               // 5.7.6.3 (2014/05/23)
056        private boolean useTrCut        = true;                 // 5.5.0.3 (2012/03/13)
057
058        /**
059         * デフォルトコンストラクター
060         *
061         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
062         */
063        public TFormatImpl() { super(); }               // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
064
065        /**
066         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
067         *
068         * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
069         *
070         * @return      後続処理の指示( EVAL_BODY_BUFFERED )
071         */
072        @Override
073        public int doStartTag() {
074                // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
075                // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method
076                return useTag()
077                                        ? EVAL_BODY_BUFFERED            // Body を評価する。( extends BodyTagSupport 時)
078                                        : SKIP_BODY ;                           // Body を評価しない
079        }
080
081        /**
082         * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。
083         *
084         * @og.rev 3.5.6.0 (2004/06/18) setItdBody メソッドによる itdBody の登録処理追加
085         * @og.rev 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。
086         * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
087         * @og.rev 5.7.6.3 (2014/05/23) useKeyBreak 属性の追加
088         *
089         * @return      後続処理の指示(EVAL_PAGE)
090         */
091        @Override
092        public int doEndTag() {
093                debugPrint();           // 4.0.0 (2005/02/28)
094                // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
095                if( useTag() ) {
096                        final ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class );
097                        if( viewform == null ) {
098                                final String errMsg = "<b>" + getTagName() + "タグは、ViewFormTagの内側(要素)に記述してください。</b>";
099                                throw new HybsSystemException( errMsg );
100                        }
101                        // 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。
102        //              String bodyFormat = getBodyString();
103                        final String bodyFormat = getSanitizedBodyString();
104
105                        final TableFormatter format = new TableFormatter();
106                        format.setFormatType( getType() );
107                        format.setFormat( bodyFormat, useTrCut );       // 5.5.0.3 (2012/03/13)
108                        format.setRowspan( rowspan );
109                        format.setNoClass( noClass );
110                        format.setUsableKey( usableKey );
111                        format.setUsableList( usableList );
112                        format.setItdBody( itdBody );                           // 3.5.6.0 (2004/06/18)
113                        format.setKeyBreakClm( keyBreakClm );           // 5.7.6.3 (2014/05/23)
114                        viewform.addFormatter( format );
115                }
116                return EVAL_PAGE ;              // ページの残りを評価する。
117        }
118
119        /**
120         * タグリブオブジェクトをリリースします。
121         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
122         *
123         * @og.rev 3.5.6.0 (2004/06/18) itdBody 属性の追加
124         * @og.rev 5.7.6.3 (2014/05/23) useTrCut,useKeyBreak 属性の追加
125         *
126         */
127        @Override
128        protected void release2() {
129                super.release2();
130                rowspan         = "2";
131                noClass         = "false";
132                usableKey       = null;
133                usableList      = "1" ;
134                itdBody         = "";                   // 3.5.6.0 (2004/06/18)
135                useTrCut        = true;                 // 5.7.6.3 (2014/05/23)
136                keyBreakClm     = null;                 // 5.7.6.3 (2014/05/23)
137        }
138
139        /**
140         * 【TAG】表示データを作成する場合のフォーマットの行数(rowspan)をセットします(初期値:2)。
141         *
142         * @og.tag
143         * 表示データを作成する場合のフォーマットの行数をセットします。
144         * 上位の viewFormタグより、こちらが優先されます。
145         *
146         * @og.rev 7.3.1.0 (2021/02/02) リクエスト変数処理を行います。
147         *
148         * @param       span フォーマットの行数
149         */
150        public void setRowspan( final String span ) {
151//              rowspan = span;
152                rowspan = nval( getRequestParameter(span),rowspan );
153        }
154
155        /**
156         * 【TAG】カラムのクラス名(VERCHAR2,NUMBER など)を使用しないかどうか[true:未使用/false:使用]を指定します(初期値:false)。
157         *
158         * @og.tag
159         * "true" で、クラス属性を設定しません。これは、CSSファイルに書かれている属性を
160         * 使用しないことを意味します。
161         * 初期値は、"false" です。
162         *
163         * @og.rev 7.3.1.0 (2021/02/02) リクエスト変数処理を行います。
164         *
165         * @param       flag クラス名未使用可否 [true:未使用/false:使用]
166         */
167        public void setNoClass( final String flag ) {
168//              this.noClass = flag;
169                noClass = nval( getRequestParameter(flag),noClass );
170        }
171
172        /**
173         * このフォーマットのタイプを返します。
174         *
175         * タイプは、"head/body/foot" の中から、指定します。
176         *
177         * @og.rev 3.5.5.8 (2004/05/20) abstract します。
178         *
179         * @return      このフォーマットのタイプを返します。
180         */
181        protected FormatterType getType() {
182                final String errMsg = "このメソッドは、THead/TBody/TFoot の各サブクラスで実装してください。";
183                throw new UnsupportedOperationException( errMsg );
184        }
185
186        /**
187         * 【TAG】フォーマットの使用可否を判断するキーとなるカラム名を指定します。
188         *
189         * @og.tag
190         * キーが、usableList に含まれる場合は、このフォームを使用できます。
191         * キー(カラム名)が指定されない場合は、常に使用されます。
192         * ※ 現時点では、BODYタイプのみ使用しています。
193         * ※ この属性は、リクエスト変数処理を行いません。
194         *
195         * @param  key 使用可否判定カラム
196         */
197        public void setUsableKey( final String key ) {
198                usableKey = key;
199        }
200
201        /**
202         * 【TAG】フォーマットの使用可否を判断する文字列リストを指定します(初期値:"1")。
203         *
204         * @og.tag
205         * キーが、この文字列リスト中に存在する場合は、このフォームを使用できます。
206         * この文字列リストは、固定な文字列です。{&#064;XXXX}は使用できますが、[XXXX]は
207         * 使用できません。
208         * 初期値は、"1" です。
209         * ※ 現時点では、BODYタイプのみ使用しています。
210         *
211         * @param  list 使用可否判定リスト
212         */
213        public void setUsableList( final String list ) {
214                usableList = nval( getRequestParameter(list),usableList );
215        }
216
217        /**
218         *  itdフォーマット文字列を設定します。
219         *
220         * itd ボディ部の文字列を指定します。
221         * itd ボディは、繰り返し処理を行います。これを、上位のボディ文字列の中の
222         * HYBS_ITD_MARKER 文字列 と置き換えます。
223         * ※ この属性は、リクエスト変数処理を行いません。
224         *
225         * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字列の取り込み
226         *
227         * @param  itd itdフォーマットの文字列
228         */
229        public void setItdBody( final String itd ) {
230                if( itd != null ) {
231                        itdBody = itd;
232                }
233        }
234
235        /**
236         * 【TAG】ここで指定したカラムの値が、キーブレイクした場合、このタグを使用します(初期値:null)。
237         *
238         * @og.tag
239         * usableKey,usableList の様に、予め決められた値の時に、適用されるのではなく、
240         * キーブレイクで 使用可否を指定する為の機能です。
241         * この設定値は、usableKey,usableList とは、独立しているため、それぞれで
242         * 有効になれば、使用されると判断されます。
243         * キーブレイク判定では、最初の1件目は、必ず使用されると判断されます。
244         *
245         * @og.rev 5.7.6.3 (2014/05/23) 新規追加
246         *
247         * @param  kclm  キーブレイクカラム
248         */
249        public void setKeyBreakClm( final String kclm ) {
250                keyBreakClm = nval( getRequestParameter( kclm ),keyBreakClm );
251        }
252
253        /**
254         * 【TAG】先頭trタグを削除するかどうか[true/false]を指定します(初期値:true)。
255         *
256         * @og.tag
257         * フォーマットの先頭がtrタグの場合は削除する処理がありますが、
258         * CustomDataのような場合では削除したくありません。
259         * falseを指定すると削除処理を行わないようになります。
260         *
261         * @og.rev 5.5.0.3 (2012/03/13) 新規追加
262         *
263         * @param  useFlg  TRタグの削除 [true:削除する/false:削除しない]
264         */
265        public void setUseTrCut( final String useFlg ) {
266                useTrCut = nval( getRequestParameter( useFlg ),useTrCut );
267        }
268
269        /**
270         * このオブジェクトの文字列表現を返します。
271         * 基本的にデバッグ目的に使用します。
272         *
273         * @return このクラスの文字列表現
274         * @og.rtnNotNull
275         */
276        @Override
277        public String toString() {
278                return ToString.title( this.getClass().getName() )
279        //                      .println( "VERSION"             ,VERSION        )
280                                .println( "rowspan"             ,rowspan        )
281                                .println( "noClass"             ,noClass        )
282                                .println( "usableKey"   ,usableKey      )
283                                .println( "usableList"  ,usableList     )
284                                .println( "itdBody"             ,itdBody        )
285                                .println( "keyBreakClm" ,keyBreakClm)
286                                .println( "Other..."    ,getAttributes().getAttribute() )
287                                .fixForm().toString() ;
288        }
289}