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.HybsSystemException; 019import org.opengion.hayabusa.html.TableFormatter; 020import org.opengion.hayabusa.html.FormatterType; 021import org.opengion.fukurou.util.ToString; // 6.1.1.0 (2015/01/17) 022 023import static org.opengion.fukurou.util.StringUtil.nval ; 024 025/** 026 * ヘッダ、フッター、ボディー部のフォーマットを汎用的に定義するタグです。 027 * 028 * thead,tfoot,tbody に代わる表示フォーマットをカスタマイズするときに使用する親クラスです。 029 * このクラス自身がタグとしては表に現れません。 030 * 031 * @og.formSample 032 * ●形式:(タグとしては使われません) 033 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します) 034 * 035 * @og.rev 3.5.4.0 (2003/11/25) 新規追加 036 * @og.rev 3.5.4.2 (2003/12/15) カスタムタグクラスから削除します。(abstract化) 037 * @og.rev 4.0.0.0 (2006/01/31) カスタムタグクラスに復活させます。(public化) 038 * @og.rev 6.3.4.0 (2015/08/01) TFormatTag.java → TFormatImpl.java 039 * @og.group 画面部品 040 * 041 * @version 4.0 042 * @author Kazuhiko Hasegawa 043 * @since JDK5.0, 044 */ 045class TFormatImpl extends CommonTagSupport { 046 /** このプログラムのVERSION文字列を設定します。 {@value} */ 047 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 048 private static final long serialVersionUID = 642020160129L ; 049 050 private String rowspan = "2"; 051 private String noClass = "false"; 052 private String usableKey ; 053 private String usableList = "1" ; 054 private String itdBody = ""; // 3.5.6.0 (2004/06/18) 055 private String keyBreakClm ; // 5.7.6.3 (2014/05/23) 056 private boolean useTrCut = true; // 5.5.0.3 (2012/03/13) 057 058 /** 059 * デフォルトコンストラクター 060 * 061 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 062 */ 063 public TFormatImpl() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 064 065 /** 066 * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。 067 * 068 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 069 * 070 * @return 後続処理の指示( EVAL_BODY_BUFFERED ) 071 */ 072 @Override 073 public int doStartTag() { 074 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 075 // 6.4.1.1 (2016/01/16) PMD refactoring. A method should have only one exit point, and that should be the last statement in the method 076 return useTag() 077 ? EVAL_BODY_BUFFERED // Body を評価する。( extends BodyTagSupport 時) 078 : SKIP_BODY ; // Body を評価しない 079 080 } 081 082 /** 083 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 084 * 085 * @og.rev 3.5.6.0 (2004/06/18) setItdBody メソッドによる itdBody の登録処理追加 086 * @og.rev 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。 087 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 088 * @og.rev 5.7.6.3 (2014/05/23) useKeyBreak 属性の追加 089 * 090 * @return 後続処理の指示(EVAL_PAGE) 091 */ 092 @Override 093 public int doEndTag() { 094 debugPrint(); // 4.0.0 (2005/02/28) 095 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 096 if( useTag() ) { 097 final ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class ); 098 if( viewform == null ) { 099 final String errMsg = "<b>" + getTagName() + "タグは、ViewFormTagの内側(要素)に記述してください。</b>"; 100 throw new HybsSystemException( errMsg ); 101 } 102 // 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。 103 // String bodyFormat = getBodyString(); 104 final String bodyFormat = getSanitizedBodyString(); 105 106 final TableFormatter format = new TableFormatter(); 107 format.setFormatType( getType() ); 108 format.setFormat( bodyFormat, useTrCut ); // 5.5.0.3 (2012/03/13) 109 format.setRowspan( rowspan ); 110 format.setNoClass( noClass ); 111 format.setUsableKey( usableKey ); 112 format.setUsableList( usableList ); 113 format.setItdBody( itdBody ); // 3.5.6.0 (2004/06/18) 114 format.setKeyBreakClm( keyBreakClm ); // 5.7.6.3 (2014/05/23) 115 viewform.addFormatter( format ); 116 } 117 return EVAL_PAGE ; // ページの残りを評価する。 118 } 119 120 /** 121 * タグリブオブジェクトをリリースします。 122 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 123 * 124 * @og.rev 3.5.6.0 (2004/06/18) itdBody 属性の追加 125 * @og.rev 5.7.6.3 (2014/05/23) useTrCut,useKeyBreak 属性の追加 126 * 127 */ 128 @Override 129 protected void release2() { 130 super.release2(); 131 rowspan = "2"; 132 noClass = "false"; 133 usableKey = null; 134 usableList = "1" ; 135 itdBody = ""; // 3.5.6.0 (2004/06/18) 136 useTrCut = true; // 5.7.6.3 (2014/05/23) 137 keyBreakClm = null; // 5.7.6.3 (2014/05/23) 138 } 139 140 /** 141 * 【TAG】表示データを作成する場合のフォーマットの行数(rowspan)をセットします(初期値:2)。 142 * 143 * @og.tag 144 * 表示データを作成する場合のフォーマットの行数をセットします。 145 * 上位の viewFormタグより、こちらが優先されます。 146 * 147 * @param span フォーマットの行数 148 */ 149 public void setRowspan( final String span ) { 150 rowspan = span; 151 } 152 153 /** 154 * 【TAG】カラムのクラス名(VERCHAR2,NUMBER など)を使用しないかどうか[true:未使用/false:使用]を指定します(初期値:false)。 155 * 156 * @og.tag 157 * "true" で、クラス属性を設定しません。これは、CSSファイルに書かれている属性を 158 * 使用しないことを意味します。 159 * 初期値は、"false" です。 160 * 161 * @param flag クラス名未使用可否 [true:未使用/false:使用] 162 */ 163 public void setNoClass( final String flag ) { 164 this.noClass = flag; 165 } 166 167 /** 168 * このフォーマットのタイプを返します。 169 * 170 * タイプは、"head/body/foot" の中から、指定します。 171 * 172 * @og.rev 3.5.5.8 (2004/05/20) abstract します。 173 * 174 * @return このフォーマットのタイプを返します。 175 */ 176 protected FormatterType getType() { 177 final String errMsg = "このメソッドは、THead/TBody/TFoot の各サブクラスで実装してください。"; 178 throw new UnsupportedOperationException( errMsg ); 179 } 180 181 /** 182 * 【TAG】フォーマットの使用可否を判断するキーとなるカラム名を指定します。 183 * 184 * @og.tag 185 * キーが、usableList に含まれる場合は、このフォームを使用できます。 186 * キー(カラム名)が指定されない場合は、常に使用されます。 187 * ※ 現時点では、BODYタイプのみ使用しています。 188 * ※ この属性は、リクエスト変数処理を行いません。 189 * 190 * @param key 使用可否判定カラム 191 */ 192 public void setUsableKey( final String key ) { 193 usableKey = key; 194 } 195 196 /** 197 * 【TAG】フォーマットの使用可否を判断する文字列リストを指定します(初期値:"1")。 198 * 199 * @og.tag 200 * キーが、この文字列リスト中に存在する場合は、このフォームを使用できます。 201 * この文字列リストは、固定な文字列です。{@XXXX}は使用できますが、[XXXX]は 202 * 使用できません。 203 * 初期値は、"1" です。 204 * ※ 現時点では、BODYタイプのみ使用しています。 205 * 206 * @param list 使用可否判定リスト 207 */ 208 public void setUsableList( final String list ) { 209 usableList = nval( getRequestParameter(list),usableList ); 210 } 211 212 /** 213 * itdフォーマット文字列を設定します。 214 * 215 * itd ボディ部の文字列を指定します。 216 * itd ボディは、繰り返し処理を行います。これを、上位のボディ文字列の中の 217 * HYBS_ITD_MARKER 文字列 と置き換えます。 218 * ※ この属性は、リクエスト変数処理を行いません。 219 * 220 * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字列の取り込み 221 * 222 * @param itd itdフォーマットの文字列 223 */ 224 public void setItdBody( final String itd ) { 225 if( itd != null ) { 226 itdBody = itd; 227 } 228 } 229 230 /** 231 * 【TAG】ここで指定したカラムの値が、キーブレイクした場合、このタグを使用します(初期値:null)。 232 * 233 * @og.tag 234 * usableKey,usableList の様に、予め決められた値の時に、適用されるのではなく、 235 * キーブレイクで 使用可否を指定する為の機能です。 236 * この設定値は、usableKey,usableList とは、独立しているため、それぞれで 237 * 有効になれば、使用されると判断されます。 238 * キーブレイク判定では、最初の1件目は、必ず使用されると判断されます。 239 * 240 * @og.rev 5.7.6.3 (2014/05/23) 新規追加 241 * 242 * @param kclm キーブレイクカラム 243 */ 244 public void setKeyBreakClm( final String kclm ) { 245 keyBreakClm = nval( getRequestParameter( kclm ),keyBreakClm ); 246 } 247 248 /** 249 * 【TAG】 先頭trタグを削除するかどうか[true/false]を指定します(初期値:true)。 250 * 251 * @og.tag 252 * フォーマットの先頭がtrタグの場合は削除する処理がありますが、 253 * CustomDataのような場合では削除したくありません。 254 * falseを指定すると削除処理を行わないようになります。 255 * 256 * @og.rev 5.5.0.3 (2012/03/13) 新規追加 257 * 258 * @param useFlg TRタグの削除 [true:削除する/false:削除しない] 259 */ 260 public void setUseTrCut( final String useFlg ) { 261 useTrCut = nval( getRequestParameter( useFlg ),useTrCut ); 262 } 263 264 /** 265 * このオブジェクトの文字列表現を返します。 266 * 基本的にデバッグ目的に使用します。 267 * 268 * @return このクラスの文字列表現 269 * @og.rtnNotNull 270 */ 271 @Override 272 public String toString() { 273 return ToString.title( this.getClass().getName() ) 274 // .println( "VERSION" ,VERSION ) 275 .println( "rowspan" ,rowspan ) 276 .println( "noClass" ,noClass ) 277 .println( "usableKey" ,usableKey ) 278 .println( "usableList" ,usableList ) 279 .println( "itdBody" ,itdBody ) 280 .println( "keyBreakClm" ,keyBreakClm) 281 .println( "Other..." ,getAttributes().getAttribute() ) 282 .fixForm().toString() ; 283 } 284}