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.HybsSystem;
019import org.opengion.hayabusa.common.HybsSystemException;
020import org.opengion.hayabusa.html.TabData;
021
022import static org.opengion.fukurou.util.StringUtil.nval ;
023
024import java.util.List;
025import java.util.ArrayList;
026import java.util.Locale ;
027
028/**
029 * 【廃止】タブペインで、項目を分割して表示するタブテーブルを作成します。
030 *
031 * ※ このタグは廃止予定です。tabLink、tabList の使用をご検討ください。
032 *
033 * 一つの大きなHTMLを、タブを使用することで複数の塊に分割表示できます。
034 * 分割された各タブは、一つのHTMLのため、タブ間の移動による情報の消失はありません。
035 * また、一つのHTMLのため、タブにまたがって入力した値は、すべて 一括送信することも
036 * 可能です。(Formタグで、全てのタブをまとめて記述していれば)
037 * タブテーブルは、orientation 属性で、横(horizontal)と縦(vertical)を指定できます。
038 * これは、タブの位置が異なるだけで、機能は同一です。初期値は、横(horizontal)です。
039 * 個々のタブの指定は、tab タグを使用します。
040 * 必ず一つ以上のtab タグを BODY要素に記述する必要があります。
041 * selectedIndex を指定すると、初期表示させるタブを指定できます。番号は0から始まります。
042 *
043 * @og.formSample
044 * ●形式:<og:tabTable
045 *                    orientation = "[horizontal/vertical]"     タブの方向(横/縦)
046 *                    height      = "[100px / 100%]"            テーブルの高さ(px OR %)
047 *                    width       = "[100px / 100%]"            テーブルの幅(px OR %)
048 *                    selectedIndex = "[0..]"                   初期表示するタブ番号
049 *         >
050 *             <og:tab lbl="・・・" > ... </og:tab >  タブそのもの
051 *             <og:tab lbl="・・・" > ... </og:tab >  タブそのもの
052 *         </og:tabTable >
053 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します)
054 *
055 * ●Tag定義:
056 *   <og:tabTable
057 *       orientation        【廃止】タブの方向、横型(horizontal)か縦型(vertical)を指定します(初期値:横型)
058 *       height             【廃止】タブの高さを、% 、px 、または "auto" で指定します
059 *       width              【廃止】タブの幅を % 、px 、または "auto" で指定します
060 *       selectedIndex      【廃止】初期表示するページ番号を指定します(初期値:0)
061 *       style              【廃止】初期表示時のタブに与える style 属性を指定します
062 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
063 *   >   ... Body ...
064 *   </og:tabTable>
065 *
066 * ●使用例
067 *  横型(horizontal)の場合。横型が初期値のため、無指定で使用できます。
068 *  <og:tabTable>
069 *      <og:tab lbl="page 1"><jsp:directive.include file="paGE1.jsp" /></og:tab>
070 *      <og:tab lbl="page 2"><jsp:directive.include file="page2.jsp" /></og:tab>
071 *      <og:tab lbl="page 3"><jsp:directive.include file="page3.jsp" /></og:tab>
072 *  </og:tabTable>
073 *
074 *  縦型(vertical)の場合。テーブルの高さを指定する必要があります。(px OR %)
075 *  <og:tabTable orientation="vertical" height="100px" >
076 *      <og:tab lbl="page 1"><jsp:directive.include file="paGE1.jsp" /></og:tab>
077 *      <og:tab lbl="page 2"><jsp:directive.include file="page2.jsp" /></og:tab>
078 *      <og:tab lbl="page 3"><jsp:directive.include file="page3.jsp" /></og:tab>
079 *  </og:tabTable>
080 *
081 * @og.rev 3.5.6.5 (2004/08/09) 新規作成
082 * @og.group (廃止)画面部品
083 *
084 * @version  4.0
085 * @author       Kazuhiko Hasegawa
086 * @since    JDK5.0,
087 * @deprecated マイクロソフトのスクリプトに依存するため、廃止します。tabLink、tabList の使用をご検討ください。
088 */
089@Deprecated public class TabTableTag extends CommonTagSupport {
090        //* このプログラムのVERSION文字列を設定します。   {@value} */
091        private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
092
093        private static final long serialVersionUID = 400020050831L ;
094
095        private static final String CR = HybsSystem.CR ;
096        private static final String JSV = "<script type=\"text/javascript\">ots.style.height = otab.offsetHeight ;</script>";
097
098        private transient List<TabData> tabList = null;
099        private boolean orientation = true;             // true:horizontal false:vertical
100
101        // 3.5.6.6 (2004/08/23) height と width の初期値変更。
102        private String  height  = null;
103        private String  width   = null;
104        private String  style   = null; // 3.8.6.1 (2006/10/24)
105        private int             selectedIndex = -1 ;    // 3.7.1.1 (2005/05/31) 初期選択されるページ番号
106        private int             realIndex     = -1 ;    // 3.8.6.2 (2006/11/01) 実際の選択タブのページ番号
107        private int             realTabCount  = -1 ;    // 3.8.6.2 (2006/11/01) 実際のタブのページ番号
108
109        /**
110         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
111         *
112         * @return      後続処理の指示( EVAL_BODY_BUFFERED )
113         */
114        @Override
115        public int doStartTag() {
116                return EVAL_BODY_BUFFERED ;     // Body を評価する。( extends BodyTagSupport 時)
117        }
118
119        /**
120         * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。
121         *
122         * @return      後続処理の指示
123         */
124        @Override
125        public int doEndTag() {
126                debugPrint();           // 4.0.0 (2005/02/28)
127                if( tabList == null ) {
128                        String errMsg = "BODY部に TabTag が必ず必要です。";
129                        throw new HybsSystemException( errMsg );
130                }
131
132                jspPrint( makeTag() );
133                return EVAL_PAGE ;
134        }
135
136        /**
137         * タグリブオブジェクトをリリースします。
138         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
139         *
140         * @og.rev 3.5.6.6 (2004/08/23) height と width の初期値変更。
141         * @og.rev 3.8.6.1 (2006/10/24) style属性を追加
142         * @og.rev 3.8.6.2 (2006/11/01) selectedIndex の初期値変更(0 ⇒ -1)。
143         */
144        @Override
145        protected void release2() {
146                super.release2();
147                tabList                 = null;
148                orientation     = true;         // true:horizontal false:vertical
149                height                  = null;
150                width                   = null;
151                selectedIndex   = -1 ;  // 3.7.1.1 (2005/05/31) 初期選択されるページ番号
152                realIndex               = -1 ;  // 3.8.6.2 (2006/11/01) 実際の選択タブのページ番号
153                realTabCount    = -1 ;  // 3.8.6.2 (2006/11/01) 実際のタブのページ番号
154                style                   = null;
155        }
156
157        /**
158         * 出力するタグ文字列を作成します。
159         *
160         * @og.rev 3.5.6.6 (2004/08/23) メソッドを HorizontalとVerticalに分割。
161         *
162         * @return      タグ文字列
163         */
164        private String makeTag() {
165                if( orientation ) {
166                        if( height == null ) { height = "auto"; }
167                        if( width  == null ) { width  = "auto"; }
168                        return makeHorizontalTag();
169                }
170                else {
171                        if( height == null ) { height = "200px"; }
172                        if( width  == null ) { width  = "100%" ; }
173                        return makeVerticalTag();
174                }
175        }
176
177        /**
178         * 出力する horizontal タグ文字列を作成します。
179         *
180         * @og.rev 3.5.6.6 (2004/08/23) メソッドを HorizontalとVerticalに分割。
181         * @og.rev 3.7.1.1 (2005/05/23) 初期表示するページ番号を指定
182         * @og.rev 3.8.6.0 (2006/08/23) IE7対応。mp:multipage の width:100%; を削除
183         * @og.rev 3.8.6.1 (2006/10/20) action属性を追加
184         * @og.rev 3.8.6.2 (2006/11/01) selectedIndex は、初めての OPENタブとします。
185         *
186         * @return      タグ文字列
187         */
188        private String makeHorizontalTag() {
189                // 注意:/**/ でマーカー付けされている行は、縦横で異なる記述が書かれています。
190                if( realIndex < 0 ) { realIndex = 0; }  // 3.8.6.2 (2006/11/01)
191
192                StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE );
193
194                buf.append( "<table cellpadding=\"0px\" cellspacing=\"0px\"" ).append( CR );
195                buf.append( " style=\"width:" ).append( width ).append( ";" );
196
197                buf.append( "\">" ).append( CR );
198                buf.append( "  <tr valign=\"top\">" ).append( CR );
199                buf.append( "    <td id=\"otab\">" ).append( CR );
200                buf.append( "      <ts:tabstrip id=\"ots\" targetid=\"omp\" style=\"height:100%\"" ).append( CR );
201                buf.append( "                tabdefaultstyle=\"border:solid 1px black;padding:3px;\"" ).append( CR );
202                buf.append( "                tabhoverstyle=\"color:blue;\"" ).append( CR );
203/**/    buf.append( "                tabselectedstyle=\"border:solid 1px black;border-bottom:none\"" ).append( CR );
204/**/    buf.append( "                sepdefaultstyle=\"border-bottom:solid 1px black;\"" ).append( CR );
205                // 3.7.1.1 (2005/05/23) 追加
206                buf.append( "                selectedIndex=\"" ).append( realIndex ).append( "\"" ).append( CR );
207/**/    buf.append( "                orientation=\"horizontal\">" ).append( CR );
208
209                int size = tabList.size();
210                TabData tab ;
211                for( int i=0; i<size; i++ ) {
212                        tab = tabList.get(i);
213                        if( tab.isOpen() ) {
214                                buf.append( tab.getTab( style ) ).append( CR );
215                        }
216                        else {
217                                buf.append( tab.getTab( null ) ).append( CR );
218                        }
219
220                        if( orientation && i != size-1 ) {
221                                buf.append( "<ts:tabseparator />" ).append( CR );
222                        }
223                }
224                buf.append( "<ts:tabseparator defaultstyle=\"width:100%;height:100%\" />" ).append( CR );
225
226                buf.append( "        </ts:tabstrip>" ).append( CR );
227                buf.append( "    </td>" ).append( CR );
228
229/**/    buf.append( "</tr><tr style=\"height:" ).append( height ).append( "\" >" ).append( CR );
230
231                buf.append( "    <td width=\"100%\">" ).append( CR );
232                buf.append( "      <mp:multipage id=\"omp\"" ).append( CR );
233/**/ // buf.append( "            style=\"border:solid 1px black;border-top:none;padding:5px;height:100%;width:100%;\">" ).append( CR );
234/**/    buf.append( "            style=\"border:solid 1px black;border-top:none;padding:5px;height:100%;\">" ).append( CR );
235
236                for( int i=0; i<size; i++ ) {
237                        tab = tabList.get(i);
238                        buf.append( tab.getTabBody() ).append( CR );
239                }
240                buf.append( "      </mp:multipage>" ).append( CR );
241                buf.append( "    </td>" ).append( CR );
242                buf.append( "  </tr>" ).append( CR );
243                buf.append( "</table>" ).append( CR );
244
245                return buf.toString();
246        }
247
248        /**
249         * 出力する vertical タグ文字列を作成します。
250         *
251         * @og.rev 3.5.6.6 (2004/08/23) メソッドを HorizontalとVerticalに分割。
252         * @og.rev 3.7.1.1 (2005/05/23) 初期表示するページ番号を指定
253         * @og.rev 3.8.6.0 (2006/08/23) IE7対応。mp:multipage の height:100%; を削除
254         * @og.rev 3.8.6.1 (2006/10/20) action属性を追加
255         * @og.rev 3.8.6.2 (2006/11/01) selectedIndex は、初めての OPENタブとします。
256         *
257         * @return      タグ文字列
258         */
259        private String makeVerticalTag() {
260                // 注意:/**/ でマーカー付けされている行は、縦横で異なる記述が書かれています。
261                if( realIndex < 0 ) { realIndex = 0; }  // 3.8.6.2 (2006/11/01)
262
263                StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE );
264
265                buf.append( "<table cellpadding=\"0px\" cellspacing=\"0px\"" ).append( CR );
266                buf.append( " style=\"width:" ).append( width ).append( ";" );
267/**/    buf.append( "height:" ).append( height ).append( ";" );
268
269                buf.append( "\">" ).append( CR );
270                buf.append( "  <tr valign=\"top\">" ).append( CR );
271                buf.append( "    <td id=\"otab\">" ).append( CR );
272                buf.append( "      <ts:tabstrip id=\"ots\" targetid=\"omp\" style=\"height:100%\"" ).append( CR );
273                buf.append( "                tabdefaultstyle=\"border:solid 1px black;padding:3px;\"" ).append( CR );
274                buf.append( "                tabhoverstyle=\"color:blue;\"" ).append( CR );
275/**/    buf.append( "                tabselectedstyle=\"border:solid 1px black;border-right:none\"" ).append( CR );
276/**/    buf.append( "                sepdefaultstyle=\"border-right:solid 1px black;\"" ).append( CR );
277                // 3.7.1.1 (2005/05/23) 追加
278                buf.append( "                selectedIndex=\"" ).append( realIndex ).append( "\"" ).append( CR );
279/**/    buf.append( "                orientation=\"vertical\">" ).append( CR );
280
281                int size = tabList.size();
282                TabData tab ;
283                for( int i=0; i<size; i++ ) {
284                        tab = tabList.get(i);
285                        if( tab.isOpen() ) {
286                                buf.append( tab.getTab( style ) ).append( CR );
287                        }
288                        else {
289                                buf.append( tab.getTab( null ) ).append( CR );
290                        }
291
292                        if( orientation && i != size-1 ) {
293                                buf.append( "<ts:tabseparator />" ).append( CR );
294                        }
295                }
296                buf.append( "<ts:tabseparator defaultstyle=\"width:100%;height:100%\" />" ).append( CR );
297
298                buf.append( "        </ts:tabstrip>" ).append( CR );
299                buf.append( "    </td>" ).append( CR );
300
301                buf.append( "    <td style=\"width:100%;height:100%;\">" ).append( CR );
302                buf.append( "      <mp:multipage id=\"omp\"" ).append( CR );
303/**/ // buf.append( "            style=\"border:solid 1px black;border-left:none;padding:5px;height:100%;width:100%;\">" ).append( CR );
304/**/    buf.append( "            style=\"border:solid 1px black;border-left:none;padding:5px;height:100%;\">" ).append( CR );
305
306                for( int i=0; i<size; i++ ) {
307                        tab = tabList.get(i);
308                        buf.append( tab.getTabBody() ).append( CR );
309                }
310                buf.append( "      </mp:multipage>" ).append( CR );
311                buf.append( "    </td>" ).append( CR );
312                buf.append( "  </tr>" ).append( CR );
313                buf.append( "</table>" ).append( CR );
314                buf.append( JSV ).append( CR );         // vertical 時に IE7でサイズの取り方が異なる為の対策。
315
316                return buf.toString();
317        }
318
319        /**
320         * 設定する タブオブジェクトを、内部変数(List)に追加します。
321         *
322         * BODY 部に記述された タブオブジェクトを順番に追加します。
323         * タブペインのタグを出力する場合も、この順番で作成します。
324         *
325         * @og.rev 3.8.6.1 (2006/10/20) action属性を追加
326         * @og.rev 3.8.6.2 (2006/11/01) realIndex は、初めての OPENタブとします。
327         *
328         * @param       data    タブオブジェクト
329         */
330        protected void addTabData( final TabData data ) {
331                if( tabList == null ) { tabList = new ArrayList<TabData>(); }
332                tabList.add( data );
333
334                // タブが選択されていれば、その値を選択番号とする。
335                if( realIndex < 0 && data.isOpen() ) {
336                        realIndex = tabList.size()-1 ;
337                }
338        }
339
340        /**
341         * selectedIndex で設定されたタブかどうかを判断して返します。
342         *
343         * このメソッド呼び出しは、各タブから1回のみ有効とします。
344         * 呼び出すたびに、内部変数 realTabCount をカウントアップします。
345         * つまり、その数が、タブの個数に対応します。
346         * タブは、DELETE と判断されるケースがあるため、実際の数より少なく登録されます。
347         * そのときに、ここで自分自身が選択されていることを判断して、実際の選択タブを
348         * JavaScript に指定するときに使用します。
349         *
350         * @og.rev 3.8.6.2 (2006/11/01) 新規作成
351         *
352         * @return      選択タブかどうか
353         */
354        protected boolean isSelected() {
355                realTabCount ++ ;
356                return selectedIndex == realTabCount ;
357        }
358
359        /**
360         * 【廃止】タブの方向、横型(horizontal)か縦型(vertical)を指定します(初期値:横型)。
361         *
362         * @og.tag
363         * タブは、上にタブが並ぶ横型と左にタブが並ぶ縦型があります。
364         * この属性では、横型は、horizontal 、縦型は、vertical を指定します。
365         * 指定は、文字列の最初の一文字を見ているだけですので、HかVでも構いません。
366         * 初期値は、横型(horizontal) です。
367         *
368         * @param       ori タブの方向、横型(horizontal)か縦型(vertical)を指定
369         * @deprecated クラスが廃止されました。
370         */
371        @Deprecated public void setOrientation( final String ori ) {
372                String ori2 = nval( getRequestParameter( ori ),null );
373                if( ori2 != null && ori2.length() > 0 ) {
374                        char ch = ori2.toUpperCase(Locale.JAPAN).charAt( 0 );
375                        if( ch == 'H' ) { orientation = true; }
376                        else if( ch == 'V' ) { orientation = false; }
377                        else {
378                                String errMsg = "orientation の指定は、H(orizontal) または、V(ertical) です。"
379                                                        + " orientation=" + ori2 ;                      // 5.1.8.0 (2010/07/01) errMsg 修正
380                                throw new HybsSystemException( errMsg );
381                        }
382                }
383        }
384
385        /**
386         * 【廃止】タブの高さを、% 、px 、または "auto" で指定します。
387         *
388         * @og.tag
389         * 縦型(orientation="vertical")の初期値は、"auto" です。
390         * 横型(orientation="horizontal")の初期値は、"200px"です。
391         * 横型の場合は、"auto" に設定すると、高さが "0" になってしまいます。
392         * 必ず、なにかの値(px)で指定する必要があります。
393         * 縦型 で "auto" に設定すると、各タブ毎に中の記述情報によって、タブの
394         * 大きさが替わります。タブを切り替えた時に、違和感がない様にするには、
395         * 高さを固定(px 指定)するとよいです。
396         *
397         * @param       ht      高さ (% 、px 、または "auto" )
398         * @deprecated クラスが廃止されました。
399         */
400        @Deprecated public void setHeight( final String ht ) {
401                height = nval( getRequestParameter( ht ),height );
402        }
403
404        /**
405         * 【廃止】タブの幅を % 、px 、または "auto" で指定します。
406         *
407         * @og.tag
408         * 縦型(orientation="vertical")の初期値は、"auto" です。
409         * 横型(orientation="horizontal")の初期値は、"100%"です。
410         * ※ 縦型の場合、幅に px で数字を設定しても、有効に作用しません。
411         *
412         * @param       wh      幅 (% 、px 、または "auto" )
413         * @deprecated クラスが廃止されました。
414         */
415        @Deprecated public void setWidth( final String wh ) {
416                width = nval( getRequestParameter( wh ),width );
417        }
418
419        /**
420         * 【廃止】初期表示するページ番号を指定します(初期値:0)。
421         *
422         * @og.tag
423         * タブテーブルには、複数のタブを含みます。初期表示時にどのタブを
424         * 表示するかを指定します。
425         * ページ番号は、0から始まる数字です。
426         * 初期値は、0です。
427         *
428         * @og.rev 3.7.1.1 (2005/05/23) 新規作成
429         *
430         * @param       no      初期表示するページ番号(0..)
431         * @deprecated クラスが廃止されました。
432         */
433        @Deprecated public void setSelectedIndex( final String no ) {
434                selectedIndex = nval( getRequestParameter( no ),selectedIndex );
435        }
436
437        /**
438         * 【廃止】初期表示時のタブに与える style 属性を指定します。
439         *
440         * @og.tag
441         * ts:tab 本体では、初期選択時のスタイルシートを、defaultStyle と
442         * selectedStyle で与える必要があります。これは、id 属性を設定して、
443         * 外部でスタイルシートを定義する形式で指定できません。
444         * ここで指定した style 属性 は、個別の tabTag に与える style 属性 より優先度は
445         * 低くなります。
446         *
447         * @og.rev 3.8.6.1 (2006/10/24) 新規追加
448         *
449         * @param       st タブに与える 初期 style 属性
450         * @deprecated クラスが廃止されました。
451         */
452        @Deprecated public void setStyle( final String st ) {
453                style = nval( getRequestParameter( st ),style );
454        }
455
456        /**
457         * このオブジェクトの文字列表現を返します。
458         * 基本的にデバッグ目的に使用します。
459         *
460         * @return このクラスの文字列表現
461         */
462        @Override
463        public String toString() {
464                return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
465                                .println( "VERSION"                     ,VERSION                )
466                                .println( "height"                      ,height                 )
467                                .println( "width"                       ,width                  )
468                                .println( "selectedIndex"       ,selectedIndex  )
469                                .println( "Other..."    ,getAttributes().getAttribute() )
470                                .fixForm().toString() ;
471        }
472}