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    /**
019     * ãƒ??ブルレイアウト㧠column ã‚¿ã‚°ç­‰ã?存在ã—ãªã?©ºæ¬?®?‰€ã«æŒ¿å…¥ã—ã¦ã€?
020     * ãƒ??ブルã®è¡Œå?ã®å€‹æ•°ã‚’åˆã‚ã›ã‚‹ã‚¿ã‚°ã§ã™ã?
021     *
022     * 通常ã®ç©ºæ¬??ã€ãƒ©ãƒ™ãƒ«ã¨å€¤ã¨ã?†?’ã¤ã®é ?›®ã‚’別ã€??カラãƒ?«ç™»éŒ²ã™ã‚‹ã‚ˆã†ã«
023     * <td></td>ã‚¿ã‚°ãŒã??’ã¤ç¶šã„ãŸå½¢å¼ã‚’ã—ã¦ã?¾ã™ãŒã€ä¸?ˆ¬ã«ã€?
024     * 個数ã¯è¡¨ç¤ºä¸Šã?都åˆã§ä»»æ„ã?個数ã®<td>タグを使用ã—ãŸã?‚±ãƒ¼ã‚¹ã?
025     * ã‚りã¾ã™ã?
026     * ãã?å ´åˆã?ã“ã?SpaceTag を使ã£ã¦ãŠã‘ã°,大é‡ã?作æ?済ã¿ç”»é¢ã‚’修正ã—ãªãã¦ã‚?
027     * ã“ã?クラスを修正ã™ã‚‹ã?‘ã§,ã™ã¹ã¦ã®ç©ºæ¬??ãƒ?‚¶ã‚¤ãƒ³ãŒã‚­ãƒ¼ãƒ—ã§ãã¾ã™ã?
028     *
029     * @og.formSample
030     * â—å½¢å¼ï¼?lt;og:space />
031     * â—body?šãªã?
032     *
033     * â—Tag定義??
034     *   <og:space
035     *       width              ã€TAG】å?体ã?大ãã•(width 属æ?)を指定ã—ã¾ã?
036     *       colspan            ã€TAG】å?体ã?大ãã•(width 属æ?)を指定ã—ã¾ã?
037     *       labelWidth         ã€TAG】ラベル部åˆ?å‰åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã?
038     *       valueWidth         ã€TAG】å?部åˆ?後åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã?
039     *       debug              ã€TAG】デãƒãƒƒã‚°æƒ??ã‚’å?力ã™ã‚‹ã‹ã©ã?‹[true/false]を指定ã—ã¾ã?åˆæœŸå€¤:false)
040     *   />
041     *
042     * â—使用ä¾?
043     *      通常ã®ã€ãƒ©ãƒ™ãƒ«éƒ¨ã€ãƒ•ィールド部ãŒç©ºã® td タグを生æˆã—ã¾ã™ã?
044     *      <og:space />
045     *
046     *      td ã‚¿ã‚°ã®å¤§ãã•を指定ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™ã?
047     *      <og:space
048     *         labelWidth = "ラベル部åˆ?å‰åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã™ã?"
049     *         valueWidth = "値部åˆ?後åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã™ã?"
050     *      />
051     *
052     * @og.group ç”»é¢éƒ¨å“?
053     *
054     * @version  4.0
055     * @author   Kazuhiko Hasegawa
056     * @since    JDK5.0,
057     */
058    public class SpaceTag extends CommonTagSupport {
059            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
060            private static final String VERSION = "5.1.9.0 (2010/08/01)" ;
061    
062            private static final long serialVersionUID = 519020100801L ;
063    
064            private String labelWidth = null ;
065            private String valueWidth = null ;
066            private String width      = null ;              // 5.1.9.0 (2010/08/01) 追�
067            private String colspan    = null ;              // 5.1.9.0 (2010/08/01) 追�
068    
069            /**
070             * Taglibã®é–‹å§‹ã‚¿ã‚°ãŒè¦‹ã¤ã‹ã£ãŸã¨ãã«å‡¦ç?™ã‚?doStartTag() ã‚?オーãƒã?ライドã—ã¾ã™ã?
071             *
072             * @return      後続å?ç??æŒ?¤º( SKIP_BODY )
073             */
074            @Override
075            public int doStartTag() {
076                    jspPrint( makeTag() );
077                    return( SKIP_BODY );
078            }
079    
080            /**
081             * タグリブオブジェクトをリリースã—ã¾ã™ã?
082             * キャãƒ?‚·ãƒ¥ã•れã¦å†åˆ©ç”¨ã•れるã?ã§ã€ãƒ•ィールドã?åˆæœŸè¨­å®šã‚’行ã„ã¾ã™ã?
083             *
084             * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応ã?release2() ã‚?doEndTag()ã§å‘¼ã¶ã€?
085             * @og.rev 5.1.9.0 (2010/08/01) width , colspan 属æ?追åŠ?
086             */
087            @Override
088            protected void release2() {
089                    super.release2();
090                    labelWidth = null ;
091                    valueWidth = null ;
092                    width      = null ;             // 5.1.9.0 (2010/08/01) 追�
093                    colspan    = null ;             // 5.1.9.0 (2010/08/01) 追�
094            }
095    
096            /**
097             * 検索æ¡ä»¶ã®å…¥åŠ›ç”¨ã®ãƒ?‚­ã‚¹ãƒˆãƒ•ィールドを作æ?ã—ã¾ã™ã?
098             *
099             * ãƒ??ブルタグã«ã‚ˆã‚Šãƒ•ィールドã?åˆ?‰²ã•れã¾ã™ã?
100             * 使用時ã?ã€ãƒ†ãƒ¼ãƒ–ルタグをå‰å¾Œã«ä½¿ç”¨ã—ã¦ä¸‹ã•ã??
101             *
102             * @og.rev 5.1.9.0 (2010/08/01) width , colspan 属æ?追åŠ?
103             *
104             * @return  入力用ã®ãƒ?‚­ã‚¹ãƒˆãƒ•ィールドタグ
105             */
106            private String makeTag() {
107                    StringBuilder rtn = new StringBuilder();
108    
109                    // width æŒ?®?
110                    if( width != null && width.length() > 0  ) {
111                            // width ãŒæŒ‡å®šã•れるã¨ã€å¼·åˆ¶çš?« colspan を設定ã™ã‚‹ã?
112                            if( colspan == null || colspan.length() == 0  ) {
113                                    colspan = "2";
114                            }
115                            rtn.append( "<td width=\"" );
116                            rtn.append( width );
117                            rtn.append( "\" colspan=\"" );
118                            rtn.append( colspan );
119                            rtn.append( "\"></td>" );
120                    }
121                    // ã™ã§ã«ã€width ã¯æœªæŒ?®šãªã®ã§ã€colspan ã®ã¿å‡ºåŠ?
122                    else if( colspan != null && colspan.length() > 0  ) {
123                            rtn.append( "<td colspan=\"" );
124                            rtn.append( colspan );
125                            rtn.append( "\"></td>" );
126                    }
127                    // width ã‚?colspan も未æŒ?®šã?å ´åˆã?ã¿ã€labelWidthã€valueWidth ã‚’å?åŠ?
128                    else {
129                            if( labelWidth == null || labelWidth.length() == 0  ) {
130                                    rtn.append( "<td></td>" );
131                            }
132                            else {
133                                    rtn.append( "<td width=\"" );
134                                    rtn.append( labelWidth );
135                                    rtn.append( "\"></td>" );
136                            }
137    
138                            if( valueWidth == null || valueWidth.length() == 0  ) {
139                                    rtn.append( "<td></td>" );
140                            }
141                            else {
142                                    rtn.append( "<td width=\"" );
143                                    rtn.append( valueWidth );
144                                    rtn.append( "\"></td>" );
145                            }
146                    }
147                    return rtn.toString() ;
148            }
149    
150            /**
151             * ã€TAG】å?体ã?大ãã•(width 属æ?)を指定ã—ã¾ã™ã?
152             *
153             * @og.tag
154             * 通常㮠space ã‚¿ã‚°ã¯ã€td ?’å?åˆ??ã‚¿ã‚°ã‚’å?力ã—ã¾ã™ãŒã€width 属æ?ã‚?
155             * æŒ?®šã—ãŸå?åˆã?ã€colspan="2" ã‚’ã‚»ãƒ?ƒˆä¸‹ä¸Šã§ã€width 属æ?ã«è¨­å®šã•れã¾ã™ã?
156             *
157             * @og.rev 5.1.9.0 (2010/08/01) æ–°è¦è¿½åŠ?
158             *
159             * @param   width 属æ?
160             */
161            public void setWidth( final String width ) {
162                    this.width = getRequestParameter( width );
163            }
164    
165            /**
166             * ã€TAG】å?体ã?大ãã•(width 属æ?)を指定ã—ã¾ã™ã?
167             *
168             * @og.tag
169             * 属æ?㯠td ã‚¿ã‚°ã® colspan 属æ?ã«è¨­å®šã•れã¾ã™ã?
170             *
171             * @og.rev 5.1.9.0 (2010/08/01) æ–°è¦è¿½åŠ?
172             *
173             * @param   colspan 属æ?
174             */
175            public void setColspan( final String colspan ) {
176                    this.colspan = getRequestParameter( colspan );
177            }
178    
179            /**
180             * ã€TAG】ラベル部åˆ?å‰åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã™ã?
181             *
182             * @og.tag
183             * 属æ?㯠td ã‚¿ã‚°ã® width 属æ?ã«è¨­å®šã•れã¾ã™ã?
184             *
185             * @param   width 属æ?
186             */
187            public void setLabelWidth( final String width ) {
188                    labelWidth = getRequestParameter( width );
189            }
190    
191            /**
192             * ã€TAG】å?部åˆ?後åŠéƒ¨åˆ?ã®å¤§ãã•(width 属æ?)を指定ã—ã¾ã™ã?
193             *
194             * @og.tag
195             * 属æ?㯠td ã‚¿ã‚°ã® width 属æ?ã«è¨­å®šã•れã¾ã™ã?
196             *
197             * @param   width 属æ?
198             */
199            public void setValueWidth( final String width ) {
200                    valueWidth = getRequestParameter( width );
201            }
202    
203            /**
204             * ã“ã?オブジェクトã?æ–?­—å?表ç¾ã‚’è¿”ã—ã¾ã™ã?
205             * 基本çš?«ãƒ?ƒãƒ?‚°ç›®çš?«ä½¿ç”¨ã—ã¾ã™ã?
206             *
207             * @return ã“ã?ã‚¯ãƒ©ã‚¹ã®æ–?­—å?表ç¾
208             */
209            @Override
210            public String toString() {
211                    return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
212                                    .println( "VERSION"                     ,VERSION        )
213                                    .println( "width"                       ,width          )
214                                    .println( "colspan"                     ,colspan        )
215                                    .println( "labelWidth"          ,labelWidth     )
216                                    .println( "valueWidth"          ,valueWidth     )
217                                    .println( "Other..."    ,getAttributes().getAttribute() )
218                                    .fixForm().toString() ;
219            }
220    }