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.plugin.view; 017 018import java.util.List; 019 020import org.opengion.hayabusa.common.HybsSystemException; 021import org.opengion.hayabusa.html.TableFormatter; 022 023/** 024 * ヘッダã€ãƒ•ãƒƒã‚¿ã€ãƒœãƒ‡ã‚£ã‚’指定ã—ã¦ä½œæˆã™ã‚‹ã€è‡ªç”±ãƒ¬ã‚¤ã‚¢ã‚¦ãƒˆãŒå¯èƒ½ãªã€ã‚«ã‚¹ã‚¿ãƒ テーブル表示クラスã§ã™ã€‚ 025 * 従æ¥ã¯ã€å†…部ãƒã‚°ã®ãŸã‚ã€thead,tbody,tfoot タグを使ã‚ãªã„ã¨å‡¦ç†ã§ãã¾ã›ã‚“ã§ã—ãŸãŒã€ 026 * viewã‚¿ã‚°ã® BODY 部ã«ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆã‚’記述ã™ã‚‹ã ã‘ã§å‡¦ç†ã™ã‚‹ã‚ˆã†ã«æ”¹å–„ã—ã¾ã—ãŸã€‚(5.6.3.3 (2013/04/19)) 027 * 028 * ã“ã®ã‚¿ã‚°ã§ã¯ã€BODY部ã€ã¾ãŸã¯ã€bodyFormats ã‚’ç¹°ã‚Šè¿”ã™å‡¦ç†ã‚’è¡Œã„ã¾ã™ã€‚ 029 * ヘッダ ãŒã‚ã‚Œã°ã€æœ€åˆã«ã€ï¼‘度ã®ã¿å®Ÿè¡Œã—ã€ãƒ•ãƒƒã‚¿ãŒã‚ã‚Œã°ã€æœ€å¾Œã«å®Ÿè¡Œã—ã¾ã™ã€‚ 030 * ã“ã®ã‚¯ãƒ©ã‚¹ãŒä»–ã¨ç•°ãªã‚‹ã®ã¯ã€ãƒ˜ãƒƒãƒ€ã®ã¿è¨˜è¿°ã—ãŸå ´åˆã€ãƒ˜ãƒƒãƒ€ã¨ã—ã¦ä½¿ã‚ã‚Œãšã€ãƒœãƒ‡ã‚£ã¨ã—ã¦ã®ã¿ç¹°è¿”ã— 031 * 使ã‚ã‚Œã¾ã™ã€‚ã¾ãŸã€bodyFormats ã®ã¿ã®è¨˜è¿°ã‚‚å¯èƒ½ã§ã™ã€‚ 032 * 033 * ã“ã®ã‚¯ãƒ©ã‚¹ã¯ã€ViewForm_HTMLFormatTable クラスã®ä»£æ›¿ãˆã¨ã—ã¦ã‚‚使用ã§ãã¾ã™ã€‚ 034 * ãã®å ´åˆã¯ã€thead ã®ã¿æŒ‡å®šã™ã‚Œã°ã€åŒã˜ãƒ•ã‚©ãƒ¼ãƒ ㌠tbody ã«ã‚‚é©ç”¨ã•ã‚Œã¾ã™ã€‚ 035 * ã“ã‚Œã¯ã€ã¾ã•ã«ã€ViewForm_HTMLFormatTable ã¨åŒã˜ã§ã™ã€‚ 036 * (※ 上記仕様ãŒã€æœªå®Ÿè£…ã§ã—ãŸã®ã§ã€å¯¾å¿œã—ã¾ã—ãŸã€‚ 5.6.3.3 (2013/04/19) ) 037 * 038 * AbstractViewForm ã«ã‚ˆã‚Šã€setter/getterメソッドã®ãƒ‡ãƒ•ã‚©ãƒ«ãƒˆå®Ÿè£…ã‚’æä¾›ã—ã¦ã„ã¾ã™ã€‚ 039 * å„HTMLã®ã‚¿ã‚°ã«å¿…è¦ãª setter/getterメソッドã®ã¿ã€è¿½åŠ 定義ã—ã¦ã„ã¾ã™ã€‚ 040 * 041 * AbstractViewForm を継承ã—ã¦ã„る為ã€ãƒã‚±ãƒ¼ãƒ«ã«å¿œã˜ãŸãƒ©ãƒ™ãƒ«ã‚’出力ã•ã›ã‚‹äº‹ãŒå‡ºæ¥ã¾ã™ã€‚ 042 * 043 * <table class="plain"> 044 * <caption>ヘッダ 㨠ボディ ã®çµ„ã¿åˆã‚ã›</caption> 045 * <tr><th>番å·</th><th>headerFormat</th><th>bodyFormats</th><th>ç¾çŠ¶å‹•ä½œ </th><th>変更後(5.6.3.3以é™) </th></tr> 046 * <tr><td>â‘ </td><td>ã‚ã‚Š </td><td>ãªã— </td><td>headerã®ã¿ </td><td>body ã®ç¹°ã‚Šè¿”ã— </td></tr> 047 * <tr><td>â‘¡ </td><td>ãªã— </td><td>ã‚ã‚Š </td><td>エラー </td><td>bodyFormats ã®ã¿ç¹°ã‚Šè¿”ã™ </td></tr> 048 * <tr><td>â‘¢ </td><td>ã‚ã‚Š </td><td>ã‚ã‚Š </td><td>ãã‚Œãžã‚Œå‹•ä½œ</td><td>↠åŒã˜ </td></tr> 049 * <tr><td>â‘£ </td><td>ãªã— </td><td>ãªã— </td><td>エラー </td><td>↠åŒã˜ </td></tr> 050 * </table> 051 * 052 * @og.rev 3.7.1.1 (2005/05/23) æ–°è¦ä½œæˆ 053 * @og.rev 5.6.3.3 (2013/04/19) 処ç†å¤‰æ›´ 054 * @og.group ç”»é¢è¡¨ç¤º 055 * 056 * @version 4.0 057 * @author Kazuhiko Hasegawa 058 * @since JDK5.0, 059 */ 060public class ViewForm_CustomData extends ViewForm_HTMLTable { 061 /** ã“ã®ãƒ—ãƒã‚°ãƒ©ãƒ ã®VERSIONæ–‡å—列をè¨å®šã—ã¾ã™ã€‚ {@value} */ 062 private static final String VERSION = "8.5.5.1 (2024/02/29)" ; 063 064 private static final int BODYFORMAT_MAX_COUNT = 10; 065 066 private TableFormatter headerFormat ; 067 private TableFormatter[] bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; // 7.3.0.0 (2021/01/06) 068 private TableFormatter footerFormat ; 069 private int bodyFormatsCount; 070 071 /** 072 * デフォルトコンストラクター 073 * 074 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 075 */ 076 public ViewForm_CustomData() { super(); } // ã“れもã€è‡ªå‹•çš„ã«å‘¼ã°ã‚Œã‚‹ãŒã€ç©ºã®ãƒ¡ã‚½ãƒƒãƒ‰ã‚’作æˆã™ã‚‹ã¨è¦å‘Šã•ã‚Œã‚‹ã®ã§ã€æ˜Žç¤ºçš„ã«ã—ã¦ãŠãã¾ã™ã€‚ 077 078 /** 079 * DBTableModel ã‹ã‚‰ HTMLæ–‡å—列を作æˆã—ã¦è¿”ã—ã¾ã™ã€‚ 080 * startNo(表示開始ä½ç½®)ã‹ã‚‰ã€pageSize(表示件数)ã¾ã§ã®Viewæ–‡å—列を作æˆã—ã¾ã™ã€‚ 081 * 表示残りデータ㌠pageSize 以下ã®å ´åˆã¯ã€æ®‹ã‚Šã®ãƒ‡ãƒ¼ã‚¿ã‚’ã™ã¹ã¦å‡ºåŠ›ã—ã¾ã™ã€‚ 082 * 083 * @og.rev 4.3.1.0 (2008/09/08) フォーマットãŒè¨å®šã•ã‚Œã¦ã„ãªã„å ´åˆã®ã‚¨ãƒ©ãƒ¼è¿½åŠ ・編集行ã®ã¿ã‚’表示ã™ã‚‹å±žæ€§(isSkipNoEdit)è¿½åŠ 084 * @og.rev 5.6.3.3 (2013/04/19) headerFormatã®ã¿ã€bodyFormatsã®ã¿å¯¾å¿œ 085 * @og.rev 6.2.0.0 (2015/02/27) フォーマット系㮠noDisplay 対応 086 * @og.rev 6.3.9.0 (2015/11/06) 引数ã«TableFormatterを渡ã—ã¦ã€å‡¦ç†ã®å…±æœ‰åŒ–を図る。 087 * @og.rev 6.4.4.2 (2016/04/01) TableFormatterã®ã‚¿ã‚¤ãƒ—別値å–得処ç†ã®å…±é€šéƒ¨ã‚’ã¾ã¨ã‚る。 088 * 089 * @param startNo 表示開始ä½ç½® 090 * @param pageSize 表示件数 091 * 092 * @return DBTableModelã‹ã‚‰ä½œæˆã•ã‚ŒãŸ HTMLæ–‡å—列 093 * @og.rtnNotNull 094 */ 095 @Override 096 public String create( final int startNo, final int pageSize ) { 097 if( getRowCount() == 0 ) { return ""; } // 暫定処置 098 099 // 5.6.3.3 (2013/04/19) headerFormatã®ã¿ã€bodyFormatsã®ã¿å¯¾å¿œ 100 headerLine = null; // 3.5.3.1 (2003/10/31) ã‚ャッシュクリア 101 102 final int lastNo = getLastNo( startNo, pageSize ); 103 104 // 5.6.3.3 (2013/04/19) headerFormatã®ã¿ã€bodyFormatsã®ã¿å¯¾å¿œ 105 if( headerFormat != null ) { 106 headerFormat.makeFormat( getDBTableModel() ); // 3.5.6.2 (2004/07/05) 移動 107 // 6.2.0.0 (2015/02/27) フォーマット系㮠noDisplay 対応 108 setFormatNoDisplay( headerFormat ); 109 } 110 111 // 6.9.8.0 (2018/05/28) FindBugs:コンストラクタã§åˆæœŸåŒ–ã•ã‚Œã¦ã„ãªã„フィールドを null ãƒã‚§ãƒƒã‚¯ãªã—㧠null 値を利用ã—ã¦ã„ã‚‹ 112 // bodyFormatsCount ãŒã€0 ã§ãªã„å ´åˆã¯ã€bodyFormats ã¯ã€è¨å®šæ¸ˆã¿ãªã®ã§ã€null ãƒã‚§ãƒƒã‚¯ä¸è¦ 113// if( bodyFormatsCount != 0 ) { 114 if( bodyFormatsCount > 0 ) { 115 for( int i=0; i<bodyFormatsCount; i++ ) { 116 bodyFormats[i].makeFormat( getDBTableModel() ); 117 // 6.2.0.0 (2015/02/27) フォーマット系㮠noDisplay 対応 118 setFormatNoDisplay( bodyFormats[i] ); 119 } 120 } 121 122 final StringBuilder out = new StringBuilder( BUFFER_LARGE ); 123 out.append( getHeader() ); 124 for( int row=startNo; row<lastNo; row++ ) { 125 if( isSkip( row ) || isSkipNoEdit( row ) ) { continue; } // 4.3.1.0 (2008/09/08) 126 for( int i=0; i<bodyFormatsCount; i++ ) { 127 final TableFormatter bodyFormat = bodyFormats[i]; 128 if( ! bodyFormat.isUse( row,getDBTableModel() ) ) { continue; } // 3.5.4.0 (2003/11/25) 129 130 int cl = 0; 131 for( ; cl<bodyFormat.getLocationSize(); cl++ ) { 132 final String fmt = bodyFormat.getFormat(cl); 133 out.append( fmt ); // 3.5.0.0 134 135 final int loc = bodyFormat.getLocation(cl); // 3.5.5.0 136 if( loc >= 0 ) { 137 // 6.4.4.2 (2016/04/01) 処ç†ã®å…±é€šéƒ¨ã‚’ã¾ã¨ã‚る。 138 out.append( getTypeCaseValue( bodyFormat.getType(cl),row,loc ) ); 139 } 140 else { 141 out.append( bodyFormat.getSystemFormat(row,loc) ); 142 } 143 } 144 out.append( bodyFormat.getFormat(cl) ); 145 } 146 } 147 148 if( footerFormat != null ) { 149 // 6.3.9.0 (2015/11/06) 引数ã«TableFormatterを渡ã—ã¦ã€å‡¦ç†ã®å…±æœ‰åŒ–を図る。 150 out.append( getTableFoot( footerFormat ) ); 151 } 152 153 return out.toString(); 154 } 155 156 /** 157 * 内容をクリア(åˆæœŸåŒ–)ã—ã¾ã™ã€‚ 158 * 159 */ 160 @Override 161 public void clear() { 162 super.clear(); 163 headerFormat = null; 164// bodyFormats = null; 165 bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; // 7.3.0.0 (2021/01/06) SpotBugs:null ãƒã‚§ãƒƒã‚¯ãªã—㧠null 値を利用 166 footerFormat = null; 167 bodyFormatsCount = 0; 168 } 169 170 /** 171 * DBTableModel ã‹ã‚‰ テーブルã®ãƒ˜ãƒƒãƒ€ãƒ¼ã‚¿ã‚°æ–‡å—列を作æˆã—ã¦è¿”ã—ã¾ã™ã€‚ 172 * 173 * @og.rev 6.4.4.2 (2016/04/01) TableFormatterã®ã‚¿ã‚¤ãƒ—別値å–得処ç†ã®å…±é€šéƒ¨ã‚’ã¾ã¨ã‚る。 174 * 175 * @return テーブルã®ãƒ˜ãƒƒãƒ€ãƒ¼ã‚¿ã‚°æ–‡å—列 176 * @og.rtnNotNull 177 */ 178 @Override 179 protected String getHeader() { 180 // 6.3.9.1 (2015/11/27) A method should have only one exit point, and that should be the last statement in the method.(PMD) 181 182 if( headerLine == null ) { 183 if( headerFormat == null ) { headerLine = ""; } 184 else { 185 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 186 187 int cl = 0; 188 for( ; cl<headerFormat.getLocationSize(); cl++ ) { 189 buf.append( headerFormat.getFormat(cl) ); 190 final int loc = headerFormat.getLocation(cl); 191 // 6.4.4.2 (2016/04/01) 192 if( loc >= 0 ) { 193 buf.append( getTypeCaseValue( headerFormat.getType(cl),-1,loc ) ); 194 } 195 } 196 buf.append( headerFormat.getFormat(cl) ).append( CR ); 197 198 headerLine = buf.toString(); 199 } 200 } 201 return headerLine ; 202 } 203 204 /** 205 * DBTableModel ã‹ã‚‰ テーブルã®ã‚¿ã‚°æ–‡å—列を作æˆã—ã¦è¿”ã—ã¾ã™ã€‚ 206 * 207 * @og.rev 6.2.0.0 (2015/02/27) フォーマット系㮠noDisplay 対応 208 * @og.rev 6.3.9.0 (2015/11/06) 引数ã«TableFormatterを渡ã—ã¦ã€å‡¦ç†ã®å…±æœ‰åŒ–を図る。 209 * @og.rev 6.4.4.2 (2016/04/01) TableFormatterã®ã‚¿ã‚¤ãƒ—別値å–得処ç†ã®å…±é€šéƒ¨ã‚’ã¾ã¨ã‚る。 210 * 211 * @param footerFormat TableFormatterオブジェクト 212 * @return テーブルã®ã‚¿ã‚°æ–‡å—列 213 * @og.rtnNotNull 214 */ 215 @Override 216 protected String getTableFoot( final TableFormatter footerFormat ) { 217 footerFormat.makeFormat( getDBTableModel() ); 218 // 6.2.0.0 (2015/02/27) フォーマット系㮠noDisplay 対応 219 setFormatNoDisplay( footerFormat ); 220 221 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 222 223 int cl = 0; 224 for( ; cl<footerFormat.getLocationSize(); cl++ ) { 225 final int loc = footerFormat.getLocation(cl); 226 // 6.4.4.2 (2016/04/01) 227 if( loc >= 0 ) { 228 buf.append( getTypeCaseValue( footerFormat.getType(cl),-1,loc ) ); 229 } 230 } 231 buf.append( footerFormat.getFormat(cl) ).append( CR ); 232 233 return buf.toString(); 234 } 235 236 /** 237 * フォーマットをè¨å®šã—ã¾ã™ã€‚ 238 * 239 * @og.rev 5.6.3.3 (2013/04/19) headerFormatã®ã¿ã®å ´åˆã€bodyFormats ã¨ã—ã¦ä½¿ã†ã€‚ 240 * @og.rev 7.3.0.0 (2021/01/06) SpotBugs:null ãƒã‚§ãƒƒã‚¯ãªã—㧠null å€¤ã‚’åˆ©ç”¨å¯¾ç– 241 * @og.rev 8.5.5.1 (2024/02/29) switchæ–‡ã«ã‚¢ãƒãƒ¼æ§‹æ–‡ã‚’使用 242 * 243 * @param list TableFormatterã®ãƒªã‚¹ãƒˆ 244 */ 245 @Override 246 public void setFormatterList( final List<TableFormatter> list ) { // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿œ 247// bodyFormats = new TableFormatter[BODYFORMAT_MAX_COUNT]; // 7.3.0.0 (2021/01/06) 248 249 bodyFormatsCount = 0; 250 // 7.2.9.4 (2020/11/20) PMD:This for loop can be replaced by a foreach loop 251 for( final TableFormatter format : list ) { 252// for( int i=0; i<list.size(); i++ ) { 253// final TableFormatter format = list.get( i ); // 4.3.3.6 (2008/11/15) Genericsè¦å‘Šå¯¾å¿œ 254 255 // 8.5.5.1 (2024/02/29) switchæ–‡ã«ã‚¢ãƒãƒ¼æ§‹æ–‡ã‚’使用 256// switch( format.getFormatType() ) { 257// case TYPE_HEAD : headerFormat = format; break; 258// case TYPE_BODY : bodyFormats[bodyFormatsCount++] = format; break; 259// case TYPE_FOOT : footerFormat = format; break; 260// default : final String errMsg = "FormatterType ã®å®šç¾©å¤–ã®å€¤ãŒæŒ‡å®šã•ã‚Œã¾ã—ãŸã€‚"; 261// // 4.3.4.4 (2009/01/01) 262// throw new HybsSystemException( errMsg ); 263// } 264 switch( format.getFormatType() ) { 265 case TYPE_HEAD -> headerFormat = format; 266 case TYPE_BODY -> bodyFormats[bodyFormatsCount++] = format; 267 case TYPE_FOOT -> footerFormat = format; 268 default -> { 269 final String errMsg = "FormatterType ã®å®šç¾©å¤–ã®å€¤ãŒæŒ‡å®šã•ã‚Œã¾ã—ãŸã€‚"; 270 // 4.3.4.4 (2009/01/01) 271 throw new HybsSystemException( errMsg ); 272 } 273 } 274 } 275 276 // 5.6.3.3 (2013/04/19) headerFormatã®ã¿ã®å ´åˆã€bodyFormats ã¨ã—ã¦ä½¿ã†ã€‚ 277 if( bodyFormatsCount == 0 ) { // bodyFormats ãŒãªã„å ´åˆã¯ã€headerFormatをコピーã™ã‚‹ã€‚ 278 if( headerFormat == null ) { 279 final String errMsg = "thead ã‚¿ã‚°ã‹ã€ã¾ãŸã¯ã€tbody ã‚¿ã‚°ã«ã‚ˆã‚‹ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆã®æŒ‡å®šã¯å¿…é ˆã§ã™ã€‚"; 280 throw new HybsSystemException( errMsg ); 281 } 282 else { 283 bodyFormats[bodyFormatsCount++] = headerFormat; 284 headerFormat = null; 285 } 286 } 287 } 288 289 /** 290 * フォーマットメソッドを使用ã§ãã‚‹ã‹ã©ã†ã‹ã‚’å•ã„åˆã‚ã›ã¾ã™ã€‚ 291 * 292 * @return 使用å¯èƒ½(true)/ 使用ä¸å¯èƒ½ (false) 293 */ 294 @Override 295 public boolean canUseFormat() { 296 return true; 297 } 298 299 /** 300 * è¡¨ç¤ºé …ç›®ã®ç·¨é›†(並ã³æ›¿ãˆ)ãŒå¯èƒ½ã‹ã©ã†ã‹ã‚’è¿”ã—ã¾ã™ã€‚ 301 * 302 * @og.rev 5.1.6.0 (2010/05/01) æ–°è¦è¿½åŠ 303 * 304 * @return è¡¨ç¤ºé …ç›®ã®ç·¨é›†(並ã³æ›¿ãˆ)ãŒå¯èƒ½ã‹ã©ã†ã‹(false:ä¸å¯èƒ½) 305 */ 306 @Override 307 public boolean isEditable() { 308 return false; 309 } 310}