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     *
030     * @og.formSample
031     * â—å½¢å¼ï¼?ã‚¿ã‚°ã¨ã—ã¦ã¯ä½¿ã‚れã¾ã›ã‚“)
032     * â—body?šã‚ã‚?EVAL_BODY_BUFFERED:BODYを評価ã—ã?{@XXXX} ã‚’è§£æžã—ã¾ã?
033     *
034     * @og.rev 3.5.4.0 (2003/11/25) æ–°è¦è¿½åŠ?
035     * @og.rev 3.5.4.2 (2003/12/15) カスタãƒ?‚¿ã‚°ã‚¯ãƒ©ã‚¹ã‹ã‚‰å‰Šé™¤ã—ã¾ã™ã?(abstractåŒ?
036     * @og.rev 4.0.0.0 (2006/01/31) カスタãƒ?‚¿ã‚°ã‚¯ãƒ©ã‚¹ã«å¾©æ´»ã•ã›ã¾ã™ã?(publicåŒ?
037     * @og.group ç”»é¢éƒ¨å“?
038     *
039     * @version  4.0
040     * @author       Kazuhiko Hasegawa
041     * @since    JDK5.0,
042     */
043    public class TFormatTag extends CommonTagSupport {
044            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
045            private static final String VERSION = "5.5.0.3 (2012/03/13)" ;
046    
047            private static final long serialVersionUID = 550320120313L ;
048    
049            private String rowspan          = "2";
050            private String noClass          = "false";
051            private String usableKey        = null;
052            private String usableList       = "1" ;
053            private String itdBody          = "";                   // 3.5.6.0 (2004/06/18)
054            private boolean useTrCut        = true;                 // 5.5.0.3 (2012/03/13 )
055    
056            /**
057             * Taglibã®é–‹å§‹ã‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doStartTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
058             *
059             * @og.rev 5.2.2.0 (2010/11/01) caseKey ã€caseVal 属æ?対å¿?
060             *
061             * @return      後続å?ç??æŒ?¤º( EVAL_BODY_BUFFERED )
062             */
063            @Override
064            public int doStartTag() {
065                    // 5.2.2.0 (2010/11/01) caseKey ã€caseVal 属æ?対å¿?
066                    if( useTag() ) {
067                            return( EVAL_BODY_BUFFERED );   // Body を評価ã™ã‚‹ã€? extends BodyTagSupport æ™?
068                    }
069                    return ( SKIP_BODY );                           // Body を評価ã—ãªã?
070            }
071    
072            /**
073             * Taglibã®çµ‚äº?‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doEndTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
074             *
075             * @og.rev 3.5.6.0 (2004/06/18) setItdBody メソãƒ?ƒ‰ã«ã‚ˆã‚‹ itdBody ã®ç™»éŒ²å‡¦ç?¿½åŠ?
076             * @og.rev 5.1.7.0 (2010/06/01) フォーマットã?{@XXXX}ã®å€¤ã«[ãŒå«ã¾ã‚Œã‚‹å ´åˆã?ã€ã‚µã‚¤ãƒ‹ã‚¿ã‚¤ã‚º("\\]\\"ã«å¤‰æ›)ã™ã‚‹ã€?
077             * @og.rev 5.2.2.0 (2010/11/01) caseKey ã€caseVal 属æ?対å¿?
078             *
079             * @return      後続å?ç??æŒ?¤º(EVAL_PAGE)
080             */
081            @Override
082            public int doEndTag() {
083                    debugPrint();           // 4.0.0 (2005/02/28)
084                    // 5.2.2.0 (2010/11/01) caseKey ã€caseVal 属æ?対å¿?
085                    if( useTag() ) {
086                            ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class );
087                            if( viewform == null ) {
088                                    String errMsg = "<b>ã“ã?ã‚¿ã‚°ã¯ã€ViewFormTagã®å†??(è¦ç´?ã«è¨˜è¿°ã—ã¦ãã ã•ã„ã€?/b>";
089                                    throw new HybsSystemException( errMsg );
090                            }
091                            // 5.1.7.0 (2010/06/01) フォーマットã?{@XXXX}ã®å€¤ã«[ãŒå«ã¾ã‚Œã‚‹å ´åˆã?ã€ã‚µã‚¤ãƒ‹ã‚¿ã‚¤ã‚º("\\]\\"ã«å¤‰æ›)ã™ã‚‹ã€?
092            //              String bodyFormat = getBodyString();
093                            String bodyFormat = getSanitizedBodyString();
094    
095                            TableFormatter format = new TableFormatter();
096                            format.setFormatType( getType() );
097    //                      format.setFormat( bodyFormat );
098                            format.setFormat( bodyFormat, useTrCut ); // 5.5.0.3 (2012/03/13)
099                            format.setRowspan( rowspan );
100                            format.setNoClass( noClass );
101                            format.setUsableKey( usableKey );
102                            format.setUsableList( usableList );
103                            format.setItdBody( itdBody );           // 3.5.6.0 (2004/06/18)
104                            viewform.addFormatter( format );
105                    }
106                    return(EVAL_PAGE);              // ペã?ã‚¸ã®æ®‹ã‚Šã‚’評価ã™ã‚‹ã€?
107            }
108    
109            /**
110             * タグリブオブジェクトをリリースã—ã¾ã™ã?
111             * キャãƒ?‚·ãƒ¥ã•れã¦å†åˆ©ç”¨ã•れるã?ã§ã€ãƒ•ィールドã?åˆæœŸè¨­å®šã‚’行ã„ã¾ã™ã?
112             *
113             * @og.rev 3.5.6.0 (2004/06/18) itdBody 属æ?ã®è¿½åŠ?
114             *
115             */
116            @Override
117            protected void release2() {
118                    super.release2();
119                    rowspan         = "2";
120                    noClass         = "false";
121                    usableKey       = null;
122                    usableList      = "1" ;
123                    itdBody         = "";                   // 3.5.6.0 (2004/06/18)
124            }
125    
126            /**
127             * ã€TAG】表示ãƒ??タを作æ?ã™ã‚‹å ´åˆã?フォーマットã?行数(rowspan)ã‚’ã‚»ãƒ?ƒˆã—ã¾ã?åˆæœŸå€¤:2)ã€?
128             *
129             * @og.tag
130             * 表示ãƒ??タを作æ?ã™ã‚‹å ´åˆã?フォーマットã?行数をセãƒ?ƒˆã—ã¾ã™ã?
131             * 上ä½ã? viewFormタグよりã€ã“ã¡ã‚‰ãŒå„ªå…ˆã•れã¾ã™ã?
132             *
133             * @param       span フォーマットã?行数
134             */
135            public void setRowspan( final String span ) {
136                    rowspan = span;
137            }
138    
139            /**
140             * ã€TAG】カラãƒ??クラスå?VERCHAR2,NUMBER ãªã©)を使用ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)ã€?
141             *
142             * @og.tag
143             * "true" ã§ã€ã‚¯ãƒ©ã‚¹å±žæ?を設定ã—ã¾ã›ã‚“。ã“れã?ã€?¼£?³?³ãƒ•ã‚¡ã‚¤ãƒ«ã«æ›¸ã‹ã‚Œã¦ã?‚‹å±žæ?ã‚?
144             * 使用ã—ãªã?“ã¨ã‚’æ„味ã—ã¾ã™ã?
145             * åˆæœŸå€¤ã¯ã€?false" ã§ã™ã?
146             *
147             * @param       flag クラスåä½¿ç”¨ã®æœ‰ç„¡(true:使用ã—ãªã?false:使用ã™ã‚‹ã€?
148             */
149            public void setNoClass( final String flag ) {
150                    this.noClass = flag;
151            }
152    
153            /**
154             * ã“ã?フォーマットã?タイプを返ã—ã¾ã™ã?
155             *
156             * タイプã?ã€?head/body/foot" ã®ä¸­ã‹ã‚‰ã€æŒ‡å®šã—ã¾ã™ã?
157             *
158             * @og.rev 3.5.5.8 (2004/05/20) abstract ã—ã¾ã™ã?
159             *
160             * @return      ã“ã?フォーマットã?タイプを返ã—ã¾ã™ã?
161             */
162            protected FormatterType getType() {
163                    String errMsg = "ã“ã?メソãƒ?ƒ‰ã¯ã€THead/TBody/TFoot ã®å?‚µãƒ–クラスã§å®Ÿè£?—ã¦ãã ã•ã„ã€?;
164                    throw new UnsupportedOperationException( errMsg );
165            }
166    
167    //      protected String getType() {
168    //              String errMsg = "ã“ã?メソãƒ?ƒ‰ã¯ã€THead/TBody/TFoot ã®å?‚µãƒ–クラスã§å®Ÿè£?—ã¦ãã ã•ã„ã€?;
169    //              throw new UnsupportedOperationException( errMsg );
170    //      }
171    
172            /**
173             * ã€TAG】フォーマットã?使用å¯å¦ã‚’判断ã™ã‚‹ã‚­ãƒ¼ã¨ãªã‚‹ã‚«ãƒ©ãƒ?を指定ã—ã¾ã™ã?
174             *
175             * @og.tag
176             * キーãŒã?usableList ã«å«ã¾ã‚Œã‚‹å ´åˆã?ã€ã“ã®ãƒ•ォーãƒ?‚’使用ã§ãã¾ã™ã?
177             * キー(カラãƒ?)ãŒæŒ‡å®šã•れãªã??åˆã?ã€å¸¸ã«ä½¿ç”¨ã•れã¾ã™ã?
178             * ※ ç¾æ™‚点ã§ã¯ã€BODYタイプã?ã¿ä½¿ç”¨ã—ã¦ã?¾ã™ã?
179             *
180             * @param  key フォーマットã?使用å¯å¦ã‚’判断ã™ã‚‹ã‚«ãƒ©ãƒ?
181             */
182            public void setUsableKey( final String key ) {
183                    usableKey = key;
184            }
185    
186            /**
187             * ã€TAG】フォーマットã?使用å¯å¦ã‚’判断ã™ã‚‹æ–?­—å?リストをæŒ?®šã—ã¾ã?åˆæœŸå€¤:"1")ã€?
188             *
189             * @og.tag
190             * キーãŒã?ã“ã?æ–?­—å?リスト中ã«å­˜åœ¨ã™ã‚‹å ´åˆã?ã€ã“ã®ãƒ•ォーãƒ?‚’使用ã§ãã¾ã™ã?
191             * ã“ã?æ–?­—å?リストã?ã€å›ºå®šãªæ–?­—å?ã§ã™ã?{&#064;XXXX}ã¯ä½¿ç”¨ã§ãã¾ã™ãŒã€[XXXX]ã¯
192             * 使用ã§ãã¾ã›ã‚“ã€?
193             * åˆæœŸå€¤ã¯ã€?1" ã§ã™ã?
194             * ※ ç¾æ™‚点ã§ã¯ã€BODYタイプã?ã¿ä½¿ç”¨ã—ã¦ã?¾ã™ã?
195             *
196             * @param  list フォーマットã?使用å¯å¦ã‚’判断ã™ã‚‹æ–?­—å?リスãƒ?
197             */
198            public void setUsableList( final String list ) {
199                    usableList = nval( getRequestParameter(list),usableList );
200            }
201    
202            /**
203             *  itdフォーマット文字å?を設定ã—ã¾ã™ã?
204             *
205             * itd ãƒœãƒ‡ã‚£éƒ¨ã®æ–?­—å?を指定ã—ã¾ã™ã?
206             * itd ボディã¯ã€ç¹°ã‚Šè¿”ã—処ç?‚’行ã„ã¾ã™ã?ã“れをã?上ä½ã?ボディæ–?­—å?ã®ä¸­ã®
207             * HYBS_ITD_MARKER æ–?­—å? ã¨ç½®ãæ›ãˆã¾ã™ã?
208             *
209             * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字å?ã®å–り込ã¿
210             *
211             * @param  itd itdフォーマットã?æ–?­—å?
212             */
213            public void setItdBody( final String itd ) {
214                    if( itd != null ) {
215                            itdBody = itd;
216                    }
217            }
218    
219            /**
220             * ã€TAGã€?å…ˆé?trタグを削除ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:true)ã€?
221             *
222             * @og.tag
223             * フォーマットã?å…ˆé?ãŒtrã‚¿ã‚°ã®å ´åˆã?削除ã™ã‚‹å‡¦ç?Œã‚りã¾ã™ãŒã€?
224             * CustomDataã®ã‚ˆã†ãªå ´åˆã§ã¯å‰Šé™¤ã—ãŸãã‚りã¾ã›ã‚“ã€?
225             * falseを指定ã™ã‚‹ã¨å‰Šé™¤å‡¦ç?‚’行ã‚ãªã?‚ˆã?«ãªã‚Šã¾ã™ã?
226             *
227             * @og.rev 5.5.0.3 (2012/03/13) æ–°è¦è¿½åŠ?
228             *
229             * @param  useFlg  æƒ??出力をæŒ?®?[true:有効/false:無効]
230             */
231            public void setUseTrCut( final String useFlg ) {
232                    useTrCut = nval( getRequestParameter( useFlg ),useTrCut );
233            }
234    
235            /**
236             * ã“ã?オブジェクトã?æ–?­—å?表ç¾ã‚’è¿”ã—ã¾ã™ã?
237             * 基本çš?«ãƒ?ƒãƒ?‚°ç›®çš?«ä½¿ç”¨ã—ã¾ã™ã?
238             *
239             * @return ã“ã?ã‚¯ãƒ©ã‚¹ã®æ–?­—å?表ç¾
240             */
241            @Override
242            public String toString() {
243                    return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
244            //                      .println( "VERSION"             ,VERSION        )
245                                    .println( "rowspan"             ,rowspan        )
246                                    .println( "noClass"             ,noClass        )
247                                    .println( "usableKey"   ,usableKey      )
248                                    .println( "usableList"  ,usableList     )
249                                    .println( "itdBody"             ,itdBody        )
250                                    .println( "Other..."    ,getAttributes().getAttribute() )
251                                    .fixForm().toString() ;
252            }
253    }