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 * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。 083 * 084 * @og.rev 3.5.6.0 (2004/06/18) setItdBody メソッドによる itdBody の登録処理追加 085 * @og.rev 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。 086 * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 087 * @og.rev 5.7.6.3 (2014/05/23) useKeyBreak 属性の追加 088 * 089 * @return 後続処理の指示(EVAL_PAGE) 090 */ 091 @Override 092 public int doEndTag() { 093 debugPrint(); // 4.0.0 (2005/02/28) 094 // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応 095 if( useTag() ) { 096 final ViewFormTag viewform = (ViewFormTag)findAncestorWithClass( this,ViewFormTag.class ); 097 if( viewform == null ) { 098 final String errMsg = "<b>" + getTagName() + "タグは、ViewFormTagの内側(要素)に記述してください。</b>"; 099 throw new HybsSystemException( errMsg ); 100 } 101 // 5.1.7.0 (2010/06/01) フォーマットの{@XXXX}の値に[が含まれる場合は、サイニタイズ("\\]\\"に変換)する。 102 // String bodyFormat = getBodyString(); 103 final String bodyFormat = getSanitizedBodyString(); 104 105 final TableFormatter format = new TableFormatter(); 106 format.setFormatType( getType() ); 107 format.setFormat( bodyFormat, useTrCut ); // 5.5.0.3 (2012/03/13) 108 format.setRowspan( rowspan ); 109 format.setNoClass( noClass ); 110 format.setUsableKey( usableKey ); 111 format.setUsableList( usableList ); 112 format.setItdBody( itdBody ); // 3.5.6.0 (2004/06/18) 113 format.setKeyBreakClm( keyBreakClm ); // 5.7.6.3 (2014/05/23) 114 viewform.addFormatter( format ); 115 } 116 return EVAL_PAGE ; // ページの残りを評価する。 117 } 118 119 /** 120 * タグリブオブジェクトをリリースします。 121 * キャッシュされて再利用されるので、フィールドの初期設定を行います。 122 * 123 * @og.rev 3.5.6.0 (2004/06/18) itdBody 属性の追加 124 * @og.rev 5.7.6.3 (2014/05/23) useTrCut,useKeyBreak 属性の追加 125 * 126 */ 127 @Override 128 protected void release2() { 129 super.release2(); 130 rowspan = "2"; 131 noClass = "false"; 132 usableKey = null; 133 usableList = "1" ; 134 itdBody = ""; // 3.5.6.0 (2004/06/18) 135 useTrCut = true; // 5.7.6.3 (2014/05/23) 136 keyBreakClm = null; // 5.7.6.3 (2014/05/23) 137 } 138 139 /** 140 * 【TAG】表示データを作成する場合のフォーマットの行数(rowspan)をセットします(初期値:2)。 141 * 142 * @og.tag 143 * 表示データを作成する場合のフォーマットの行数をセットします。 144 * 上位の viewFormタグより、こちらが優先されます。 145 * 146 * @param span フォーマットの行数 147 */ 148 public void setRowspan( final String span ) { 149 rowspan = span; 150 } 151 152 /** 153 * 【TAG】カラムのクラス名(VERCHAR2,NUMBER など)を使用しないかどうか[true:未使用/false:使用]を指定します(初期値:false)。 154 * 155 * @og.tag 156 * "true" で、クラス属性を設定しません。これは、CSSファイルに書かれている属性を 157 * 使用しないことを意味します。 158 * 初期値は、"false" です。 159 * 160 * @param flag クラス名未使用可否 [true:未使用/false:使用] 161 */ 162 public void setNoClass( final String flag ) { 163 this.noClass = flag; 164 } 165 166 /** 167 * このフォーマットのタイプを返します。 168 * 169 * タイプは、"head/body/foot" の中から、指定します。 170 * 171 * @og.rev 3.5.5.8 (2004/05/20) abstract します。 172 * 173 * @return このフォーマットのタイプを返します。 174 */ 175 protected FormatterType getType() { 176 final String errMsg = "このメソッドは、THead/TBody/TFoot の各サブクラスで実装してください。"; 177 throw new UnsupportedOperationException( errMsg ); 178 } 179 180 /** 181 * 【TAG】フォーマットの使用可否を判断するキーとなるカラム名を指定します。 182 * 183 * @og.tag 184 * キーが、usableList に含まれる場合は、このフォームを使用できます。 185 * キー(カラム名)が指定されない場合は、常に使用されます。 186 * ※ 現時点では、BODYタイプのみ使用しています。 187 * ※ この属性は、リクエスト変数処理を行いません。 188 * 189 * @param key 使用可否判定カラム 190 */ 191 public void setUsableKey( final String key ) { 192 usableKey = key; 193 } 194 195 /** 196 * 【TAG】フォーマットの使用可否を判断する文字列リストを指定します(初期値:"1")。 197 * 198 * @og.tag 199 * キーが、この文字列リスト中に存在する場合は、このフォームを使用できます。 200 * この文字列リストは、固定な文字列です。{@XXXX}は使用できますが、[XXXX]は 201 * 使用できません。 202 * 初期値は、"1" です。 203 * ※ 現時点では、BODYタイプのみ使用しています。 204 * 205 * @param list 使用可否判定リスト 206 */ 207 public void setUsableList( final String list ) { 208 usableList = nval( getRequestParameter(list),usableList ); 209 } 210 211 /** 212 * itdフォーマット文字列を設定します。 213 * 214 * itd ボディ部の文字列を指定します。 215 * itd ボディは、繰り返し処理を行います。これを、上位のボディ文字列の中の 216 * HYBS_ITD_MARKER 文字列 と置き換えます。 217 * ※ この属性は、リクエスト変数処理を行いません。 218 * 219 * @og.rev 3.5.6.0 (2004/06/18) itdフォーマット文字列の取り込み 220 * 221 * @param itd itdフォーマットの文字列 222 */ 223 public void setItdBody( final String itd ) { 224 if( itd != null ) { 225 itdBody = itd; 226 } 227 } 228 229 /** 230 * 【TAG】ここで指定したカラムの値が、キーブレイクした場合、このタグを使用します(初期値:null)。 231 * 232 * @og.tag 233 * usableKey,usableList の様に、予め決められた値の時に、適用されるのではなく、 234 * キーブレイクで 使用可否を指定する為の機能です。 235 * この設定値は、usableKey,usableList とは、独立しているため、それぞれで 236 * 有効になれば、使用されると判断されます。 237 * キーブレイク判定では、最初の1件目は、必ず使用されると判断されます。 238 * 239 * @og.rev 5.7.6.3 (2014/05/23) 新規追加 240 * 241 * @param kclm キーブレイクカラム 242 */ 243 public void setKeyBreakClm( final String kclm ) { 244 keyBreakClm = nval( getRequestParameter( kclm ),keyBreakClm ); 245 } 246 247 /** 248 * 【TAG】 先頭trタグを削除するかどうか[true/false]を指定します(初期値:true)。 249 * 250 * @og.tag 251 * フォーマットの先頭がtrタグの場合は削除する処理がありますが、 252 * CustomDataのような場合では削除したくありません。 253 * falseを指定すると削除処理を行わないようになります。 254 * 255 * @og.rev 5.5.0.3 (2012/03/13) 新規追加 256 * 257 * @param useFlg TRタグの削除 [true:削除する/false:削除しない] 258 */ 259 public void setUseTrCut( final String useFlg ) { 260 useTrCut = nval( getRequestParameter( useFlg ),useTrCut ); 261 } 262 263 /** 264 * このオブジェクトの文字列表現を返します。 265 * 基本的にデバッグ目的に使用します。 266 * 267 * @return このクラスの文字列表現 268 * @og.rtnNotNull 269 */ 270 @Override 271 public String toString() { 272 return ToString.title( this.getClass().getName() ) 273 // .println( "VERSION" ,VERSION ) 274 .println( "rowspan" ,rowspan ) 275 .println( "noClass" ,noClass ) 276 .println( "usableKey" ,usableKey ) 277 .println( "usableList" ,usableList ) 278 .println( "itdBody" ,itdBody ) 279 .println( "keyBreakClm" ,keyBreakClm) 280 .println( "Other..." ,getAttributes().getAttribute() ) 281 .fixForm().toString() ; 282 } 283}