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