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.hayabusa.taglib;
017    
018    import org.opengion.hayabusa.common.HybsSystemException;
019    import org.opengion.hayabusa.html.TableFormatter;
020    import org.opengion.hayabusa.html.FormatterType;
021    
022    import static org.opengion.fukurou.util.StringUtil.nval ;
023    
024    /**
025     * ヘッãƒ??フッター、ã?ãƒ?‚£ー部のフォーマットを汎用çš?�«定義するタグですã?
026     *
027     * thead,tfoot,tbody に代わる表示フォーマットをカスタマイズするときに使用する親クラスですã?
028     *
029     * @og.rev 3.5.4.0 (2003/11/25) 新規追åŠ?
030     * @og.rev 3.5.4.2 (2003/12/15) カスタãƒ?‚¿グクラスから削除しますã?(abstractåŒ?
031     * @og.rev 4.0.0.0 (2006/01/31) カスタãƒ?‚¿グクラスに復活させますã?(publicåŒ?
032     * @og.group 画面部å“?
033     *
034     * @version  4.0
035     * @author       Kazuhiko Hasegawa
036     * @since    JDK5.0,
037     */
038    public class TFormatTag extends CommonTagSupport {
039            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
040            private static final String VERSION = "5.5.0.3 (2012/03/13)" ;
041    
042            private static final long serialVersionUID = 550320120313L ;
043    
044            private String rowspan          = "2";
045            private String noClass          = "false";
046            private String usableKey        = null;
047            private String usableList       = "1" ;
048            private String itdBody          = "";                   // 3.5.6.0 (2004/06/18)
049            private boolean useTrCut        = true;                 // 5.5.0.3 (2012/03/13 )
050    
051            /**
052             * Taglibの開始タグが見つかったときに処ç�?�™ã‚?doStartTag() ã‚?オーバã?ライドしますã?
053             *
054             * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属æ?対å¿?
055             *
056             * @return      後続å?ç�??æŒ?¤º( EVAL_BODY_BUFFERED )
057             */
058            @Override
059            public int doStartTag() {
060                    // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属æ?対å¿?
061                    if( useTag() ) {
062                            return( EVAL_BODY_BUFFERED );   // Body を評価するã€? extends BodyTagSupport æ™?
063                    }
064                    return ( SKIP_BODY );                           // Body を評価しなã�?
065            }
066    
067            /**
068             * Taglibの終äº?‚¿グが見つかったときに処ç�?�™ã‚?doEndTag() ã‚?オーバã?ライドしますã?
069             *
070             * @og.rev 3.5.6.0 (2004/06/18) setItdBody メソãƒ?ƒ‰による itdBody の登録処ç�?¿½åŠ?
071             * @og.rev 5.1.7.0 (2010/06/01) フォーマットã?{@XXXX}の値に[が含まれる場合ã?、サイニタイズ("\\]\\"に変換)するã€?
072             * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属æ?対å¿?
073             *
074             * @return      後続å?ç�??æŒ?¤º(EVAL_PAGE)
075             */
076            @Override
077            public int doEndTag() {
078                    debugPrint();           // 4.0.0 (2005/02/28)
079                    // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属æ?対å¿?
080                    if( useTag() ) {
081                            ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class );
082                            if( viewform == null ) {
083                                    String errMsg = "<b>こã?タグは、ViewFormTagのå†??(要ç´?に記述してくださいã€?/b>";
084                                    throw new HybsSystemException( errMsg );
085                            }
086                            // 5.1.7.0 (2010/06/01) フォーマットã?{@XXXX}の値に[が含まれる場合ã?、サイニタイズ("\\]\\"に変換)するã€?
087            //              String bodyFormat = getBodyString();
088                            String bodyFormat = getSanitizedBodyString();
089    
090                            TableFormatter format = new TableFormatter();
091                            format.setFormatType( getType() );
092    //                      format.setFormat( bodyFormat );
093                            format.setFormat( bodyFormat, useTrCut ); // 5.5.0.3 (2012/03/13)
094                            format.setRowspan( rowspan );
095                            format.setNoClass( noClass );
096                            format.setUsableKey( usableKey );
097                            format.setUsableList( usableList );
098                            format.setItdBody( itdBody );           // 3.5.6.0 (2004/06/18)
099                            viewform.addFormatter( format );
100                    }
101                    return(EVAL_PAGE);              // ペã?ジの残りを評価するã€?
102            }
103    
104            /**
105             * タグリブオブジェクトをリリースしますã?
106             * キャãƒ?‚·ュされて再利用されるã?で、フィールドã?初期設定を行いますã?
107             *
108             * @og.rev 3.5.6.0 (2004/06/18) itdBody 属æ?の追åŠ?
109             *
110             */
111            @Override
112            protected void release2() {
113                    super.release2();
114                    rowspan         = "2";
115                    noClass         = "false";
116                    usableKey       = null;
117                    usableList      = "1" ;
118                    itdBody         = "";                   // 3.5.6.0 (2004/06/18)
119            }
120    
121            /**
122             * 【TAG】表示ãƒ??タを作æ?する場合ã?フォーマットã?行数(rowspan)をセãƒ?ƒˆしまã�?初期値:2)ã€?
123             *
124             * @og.tag
125             * 表示ãƒ??タを作æ?する場合ã?フォーマットã?行数をセãƒ?ƒˆしますã?
126             * 上位ã? viewFormタグより、こちらが優先されますã?
127             *
128             * @param       span フォーマットã?行数
129             */
130            public void setRowspan( final String span ) {
131                    rowspan = span;
132            }
133    
134            /**
135             * 【TAG】カラãƒ??クラスå�?VERCHAR2,NUMBER など)を使用するかどã�?�‹[true/false]を指定しまã�?初期値:false)ã€?
136             *
137             * @og.tag
138             * "true" で、クラス属æ?を設定しません。これã?ã€?¼£?³?³ファイルに書かれてã�?‚‹属æ?ã‚?
139             * 使用しなã�?�“とを意味しますã?
140             * 初期値はã€?false" ですã?
141             *
142             * @param       flag クラス名使用の有無(true:使用しなã�?false:使用するã€?
143             */
144            public void setNoClass( final String flag ) {
145                    this.noClass = flag;
146            }
147    
148            /**
149             * こã?フォーマットã?タイプを返しますã?
150             *
151             * タイプã?ã€?head/body/foot" の中から、指定しますã?
152             *
153             * @og.rev 3.5.5.8 (2004/05/20) abstract しますã?
154             *
155             * @return      こã?フォーマットã?タイプを返しますã?
156             */
157            protected FormatterType getType() {
158                    String errMsg = "こã?メソãƒ?ƒ‰は、THead/TBody/TFoot のå�?‚µブクラスで実è£?�—てくださいã€?;
159                    throw new UnsupportedOperationException( errMsg );
160            }
161    
162    //      protected String getType() {
163    //              String errMsg = "こã?メソãƒ?ƒ‰は、THead/TBody/TFoot のå�?‚µブクラスで実è£?�—てくださいã€?;
164    //              throw new UnsupportedOperationException( errMsg );
165    //      }
166    
167            /**
168             * 【TAG】フォーマットã?使用可否を判断するキーとなるカラãƒ?��を指定しますã?
169             *
170             * @og.tag
171             * キーがã?usableList に含まれる場合ã?、このフォーãƒ?‚’使用できますã?
172             * キー(カラãƒ?��)が指定されなã�??合ã?、常に使用されますã?
173             * ※ 現時点では、BODYタイプã?み使用してã�?�¾すã?
174             *
175             * @param  key フォーマットã?使用可否を判断するカラãƒ?��
176             */
177            public void setUsableKey( final String key ) {
178                    usableKey = key;
179            }
180    
181            /**
182             * 【TAG】フォーマットã?使用可否を判断するæ–?­—å?リストをæŒ?®šしまã�?初期値:"1")ã€?
183             *
184             * @og.tag
185             * キーがã?こã?æ–?­—å?リスト中に存在する場合ã?、このフォーãƒ?‚’使用できますã?
186             * こã?æ–?­—å?リストã?、固定なæ–?­—å?ですã?{&#064;XXXX}は使用できますが、[XXXX]は
187             * 使用できませんã€?
188             * 初期値はã€?1" ですã?
189             * ※ 現時点では、BODYタイプã?み使用してã�?�¾すã?
190             *
191             * @param  list フォーマットã?使用可否を判断するæ–?­—å?リスãƒ?
192             */
193            public void setUsableList( final String list ) {
194                    usableList = nval( getRequestParameter(list),usableList );
195            }
196    
197            /**
198             *  itdフォーマット文字å?を設定しますã?
199             *
200             * itd ボディ部のæ–?­—å?を指定しますã?
201             * itd ボディは、繰り返し処ç�?‚’行いますã?これをã?上位ã?ボディæ–?­—å?の中の
202             * HYBS_ITD_MARKER æ–?­—å? と置き換えますã?
203             *
204             * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字å?の取り込み
205             *
206             * @param  itd itdフォーマットã?æ–?­—å?
207             */
208            public void setItdBody( final String itd ) {
209                    if( itd != null ) {
210                            itdBody = itd;
211                    }
212            }
213    
214            /**
215             * 【TAGã€?先é?trタグを削除するかどã�?�‹[true/false]を指定しまã�?初期値:true)ã€?
216             *
217             * @og.tag
218             * フォーマットã?先é?がtrタグの場合ã?削除する処ç�?�Œありますがã€?
219             * CustomDataのような場合では削除したくありませんã€?
220             * falseを指定すると削除処ç�?‚’行わなã�?‚ˆã�?�«なりますã?
221             *
222             * @og.rev 5.5.0.3 (2012/03/13) 新規追åŠ?
223             *
224             * @param  useFlg  æƒ??出力をæŒ?®?[true:有効/false:無効]
225             */
226            public void setUseTrCut( final String useFlg ) {
227                    useTrCut = nval( getRequestParameter( useFlg ),useTrCut );
228            }
229    
230            /**
231             * こã?オブジェクトã?æ–?­—å?表現を返しますã?
232             * 基本çš?�«ãƒ?ƒ�ãƒ?‚°目çš?�«使用しますã?
233             *
234             * @return こã?クラスのæ–?­—å?表現
235             */
236            @Override
237            public String toString() {
238                    return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
239            //                      .println( "VERSION"             ,VERSION        )
240                                    .println( "rowspan"             ,rowspan        )
241                                    .println( "noClass"             ,noClass        )
242                                    .println( "usableKey"   ,usableKey      )
243                                    .println( "usableList"  ,usableList     )
244                                    .println( "itdBody"             ,itdBody        )
245                                    .println( "Other..."    ,getAttributes().getAttribute() )
246                                    .fixForm().toString() ;
247            }
248    }