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 */
016 package org.opengion.hayabusa.taglib;
017
018 import static org.opengion.fukurou.util.StringUtil.nval;
019
020 import java.io.IOException;
021 import java.io.ObjectInputStream;
022 import java.io.ObjectOutputStream;
023 import java.util.ArrayList;
024 import java.util.HashMap;
025 import java.util.List;
026 import java.util.Locale;
027 import java.util.Map;
028
029 import javax.script.ScriptEngine;
030 import javax.script.ScriptEngineManager;
031 import javax.script.ScriptException;
032 import javax.servlet.ServletException;
033
034 import org.opengion.fukurou.db.DBUtil;
035 import org.opengion.fukurou.db.Transaction;
036 import org.opengion.fukurou.db.TransactionReal;
037 import org.opengion.fukurou.model.Formatter;
038 import org.opengion.fukurou.util.ErrorMessage;
039 import org.opengion.fukurou.util.StringUtil;
040 import org.opengion.hayabusa.common.HybsSystem;
041 import org.opengion.hayabusa.common.HybsSystemException;
042 import org.opengion.hayabusa.db.DBTableModel;
043 import org.opengion.hayabusa.resource.ResourceManager;
044
045 /**
046 * 画面で入力された??タのチェ?を行うためのタグです?
047 *
048 * commandがNEWの場合?検索条件等?リクエストパラメータに対してチェ?を行います?
049 * commandがENTRYの場合?、登録時?DB??ブルモ?に対するチェ?を行います?
050 * (値の取得?、?に選択された行?みにつ?、実行されます?)
051 *
052 * チェ?を行うための定義は、SQL?又? JavaScriptの式が記述可能です?
053 * これら?式?タグのボディー部?記述します?
054 *
055 * SQL?よりチェ?を行う場合?、?件数が返されるように記述して下さ?select count(*) ??? ?
056 * こ?SQL?取得された件数とexistの属?値とを?合しチェ?を行います?
057 * ?れ?場合も、?立時は、正常とみなします?
058 * (?true:存在する? には、データが存在した場合に??で、なければエラーです?)
059 *
060 * JavaScript式を記述する場合?、?true or falseを返す式を?して下さ??
061 * こ?式を評価した結果falseが返される場合?、エラーとみなします?
062 * 式に不等号等を使用する場合?、CDATAセクションで囲??して下さ??
063 *
064 * また??れ?チェ?方法?場合でも?引数部に[カラ?]を用?Hybs拡張SQL?
065 * ?することが可能です?
066 * メ?ージIDの{0},{1}にはそれぞれ[カラ?]?されたカラ?及???タがカンマ区?で
067 * 自動的に設定されます?
068 *
069 * ※ こ?タグは、Transaction タグの対象です?
070 *
071 * @og.formSample
072 * <pre>
073 * ●形式?
074 * ・<og:dataCheck
075 * command = "{@command}"
076 * exist = "[auto|true|false|one|notuse]"
077 * errRemove = "[true|false]"
078 * lbl = "{@lbl}"
079 * msgParamKeys = "ZY03" : メ?ージリソースのキーをカンマ区?で??{2} 以降にセ?
080 * sqlType = "{@sqlType}"
081 * execType = "INSERT|COPY|UPDATE|MODIFY|DELETE" : sqlType を含??合?実?
082 * conditionKey = "FGJ" : 条件判定するカラ??を指?初期値は columnId )
083 * conditionList = "0|1|8|9" : 条件判定する?のリストを?|"で区?て登録(初期値は、無条件)
084 * uniqCheckKeys = "CLM,LANG" : DBTableModel?のユニ?クキーチェ?を行うためのカラ?
085 * >
086 *
087 * ●body?あ?EVAL_BODY_BUFFERED:BODYを評価し?{@XXXX} を解析しま?
088 * (SQL?又? JavaScript?
089 *
090 * ●Tag定義??
091 * <og:dataCheck
092 * command 【TAG】コマン?NEW or ENTRY)をセ?しま?
093 * exist 【TAG】データベ?スのチェ?方法[auto/true/false/one/notuse]を指定しま?初期値:auto[自動])
094 * tableId 【TAG?通常は使?せん)結果をDBTableModelに書き込んで、sessionに登録するとき?キーを指定しま?
095 * dbid 【TAG?通常は使?せん)Queryオブジェクトを作?する時?DB接続IDを指定しま?
096 * lbl 【TAG】ラベルリソースIDを指定しま?
097 * lblParamKeys 【TAG】ラベルリソースの引数をカンマ区?で?しま?
098 * errRemove 【TAG】エラー時?選択行を取り除?継続??行うかど?[true/false]を指定しま?初期値:false)
099 * sqlType 【TAG】このチェ?を行う、SQLタイ?を指定しま?
100 * execType 【TAG】このチェ?を行う、実行タイ?を指定しま?
101 * conditionKey 【TAG】条件判定するカラ??を指定しま?
102 * conditionList 【TAG】条件判定する?のリストを?|"で区?て登録しま?初期値:無条件)
103 * uniqCheckClms 【TAG】指定されたキーに従って、メモリ上???ブルに対してユニ?クキーチェ?を行いま?
104 * beforeErrorJsp 【TAG】エラーが発生した際に、エラーメ?ージの表示前にincludeするJSPを指定しま?
105 * afterErrorJsp 【TAG】エラーが発生した際に、エラーメ?ージの表示後にincludeするJSPを指定しま?
106 * selectedAll 【TAG】データを?件選択済みとして処?るかど?[true/false]を指定しま?初期値:false)
107 * msg 【?】メ?ージIDを指定しま?lbl 属?を使用してください)
108 * msgParamKeys 【?】メ?ージリソースの引数をカンマ区?で?しま?lblParamKeys 属?を使用してください)
109 * debug 【TAG】デバッグ??を?力するかど?[true/false]を指定しま?初期値:false)
110 * > ... Body ...
111 * </og:dataCheck>
112 *
113 * ●使用?
114 * ・<og:dataCheck
115 * command = "ENTRY"
116 * exist = "true"
117 * msg = "MSG0001"
118 * >
119 * select count(*) from GEA03 where clm = [CLM]
120 * </og:dataCheck>
121 *
122 * ・exist 属?の値に応じて、チェ?方法が異なります?
123 * [ auto , true , false , one , notuse が指定できます?]
124 *
125 * ・<og:dataCheck
126 * command = "ENTRY"
127 * msg = "MSG0001"
128 * >
129 * <![CDATA[
130 * [DYSTART] < [DY] && [DY] < [DYEND]
131 * ]]>
132 * </og:dataCheck>
133 *
134 * ・<og:dataCheck
135 * command = "ENTRY"
136 * msg = "MSG0001"
137 * >
138 * <![CDATA[
139 * [GOKEI] < [TANKA] * [RITU]
140 * ]]>
141 * </og:dataCheck>
142 * </pre>
143 *
144 * @og.rev 4.1.1.1 (2008/02/22) 新規作?
145 * @og.group ??登録
146 *
147 * @version 4.0
148 * @author Hiroki Nakamura
149 * @since JDK5.0,
150 */
151 public class DataCheckTag extends CommonTagSupport {
152 //* こ?プログラ??VERSION??を設定します? {@value} */
153 private static final String VERSION = "5.6.1.1 (2013/02/08)";
154
155 private static final long serialVersionUID = 561120130208L;
156
157 /** command 引数に渡す事?出来?コマン?{@value} */
158 public static final String CMD_NEW = "NEW";
159
160 /** command 引数に渡す事?出来?コマン?{@value} */
161 public static final String CMD_ENTRY = "ENTRY";
162
163 /** command 引数に渡す事?出来?コマン?リス? */
164 private static final String[] COMMAND_LIST = { CMD_ENTRY, CMD_NEW };
165
166 /** ?変数 */
167 private transient DBTableModel table = null;
168 // private transient ErrorMessage errMessage = null;
169 private transient boolean isSql = false;
170 private transient boolean isUniqCheck = false; // 4.3.4.0 (2008/12/01) 追?
171 private transient ScriptEngine jsEngine = null;
172 private transient String bodyStr = null; // 4.3.4.0 (2008/12/01) 追?
173
174 /** タグで設定する属? */
175 private String command = CMD_ENTRY;
176 private String exist = "auto";
177 private String tableId = HybsSystem.TBL_MDL_KEY;
178 private String dbid = null;
179 private String msg = null;
180 private String[] msgParamKeys = null; // 4.2.0.1 (2008/03/27)
181 private boolean errRemove = false;
182 private String sqlType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE
183 private String execType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE
184 private boolean isExec = true; // 4.1.2.0 (2008/03/12)
185
186 private String conditionKey = null; // 4.2.0.1 (2008/03/27)
187 private String conditionList = null; // 4.2.0.1 (2008/03/27)
188 private String from = null; // 4.2.0.1 (2008/03/27)
189 private String[] uniqCheckClms = null; // 4.3.4.0 (2008/12/01)
190
191 private String beforeErrorJsp = null; // 5.1.9.0 (2010/08/01)
192 private String afterErrorJsp = null; // 5.1.9.0 (2010/08/01)
193 private boolean selectedAll = false; // 5.1.9.0 (2010/08/01)
194
195 /**
196 * Taglibの開始タグが見つかったときに処??doStartTag() ?オーバ?ライドします?
197 *
198 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
199 * @og.rev 4.1.2.0 (2008/03/12) sqlType,execType 判?
200 *
201 * @return 後続????
202 */
203 @Override
204 public int doStartTag() {
205 isExec = (sqlType == null || execType == null || execType.indexOf( sqlType ) >= 0 );
206
207 if( isExec ) {
208 return( EVAL_BODY_BUFFERED ); // Body を評価する
209 }
210 else {
211 return(SKIP_BODY); // Body を評価しな?
212 }
213 }
214
215 /**
216 * Taglibのタグ本体を処??doAfterBody() ?オーバ?ライドします?
217 *
218 * @og.rev 4.3.4.0 (2008/12/01) 新規追?
219 *
220 * @return 後続????(SKIP_BODY)
221 */
222 @Override
223 public int doAfterBody() {
224 bodyStr = getBodyString().trim();
225 return(SKIP_BODY);
226 }
227
228 /**
229 * Taglibの終?グが見つかったときに処??doEndTag() ?オーバ?ライドします?
230 *
231 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
232 * @og.rev 4.1.2.0 (2008/03/12) sqlType,execType 判?
233 * @og.rev 4.2.0.1 (2008/03/27) from を取?
234 * @og.rev 4.2.1.0 (2008/04/11) ErrMessageManager対?
235 * @og.rev 4.3.4.0 (2008/12/01) ユニ?クキーチェ?対応?bodyContentの取得を#doAfterBody()で行う?
236 * @og.rev 5.1.9.0 (2010/08/01) エラーメ?ージの表示前後にincludeするJSPを指定できるようにする?
237 * @og.rev 5.1.9.0 (2010/08/01) Transaction 対応します?
238 * @og.rev 5.3.7.0 (2011/07/01) TransactionReal の引数変更 、Transaction対応で、close処?入れる?
239 *
240 * @return 後続????
241 */
242 @Override
243 public int doEndTag() {
244 debugPrint();
245 int rtnCode = EVAL_PAGE;
246
247 // 4.1.2.0 (2008/03/12) 実行条件 isExec を評価
248 if( isExec && check( command, COMMAND_LIST ) ) {
249 // exist="notuse"の場合?チェ?しな?
250 if( exist.equalsIgnoreCase( "notuse" ) ) { return rtnCode; }
251
252 // パラメーターから処??タイプを判別
253 checkParam();
254
255 // エラーメ?ージを管?るクラスを作?します?
256 ErrMessageManager manager = new ErrMessageManager();
257 manager.setTitle( "Data Check Error!" );
258 manager.setParamKeys( msgParamKeys );
259 manager.setResourceManager( getResource() );
260 manager.setFrom( from );
261
262 // 5.1.9.0 (2010/08/01) TransactionTag 対?
263 Transaction tran = null ;
264 // 5.3.7.0 (2011/07/01) Transaction対応で、close処?入れる?
265 try {
266 if( isSql ) {
267 TransactionTag tranTag = (TransactionTag)findAncestorWithClass( this,TransactionTag.class );
268 if( tranTag == null ) {
269 // tran = new TransactionReal( dbid,getApplicationInfo() );
270 tran = new TransactionReal( getApplicationInfo() ); // 5.3.7.0 (2011/07/01) 引数変更
271 }
272 else {
273 tran = tranTag.getTransaction();
274 }
275 }
276
277 // command="NEW"の場?
278 if( CMD_NEW.equals( command ) ) {
279 if( isSql ) {
280 // checkSql( str, null, null, DBTableModel.UPDATE_TYPE, 0 );
281 // checkSql( bodyStr, manager, null, 0, DBTableModel.UPDATE_TYPE );
282 checkSql( bodyStr, manager, null, 0, DBTableModel.UPDATE_TYPE, tran ); // 5.1.9.0 (2010/08/01)
283 }
284 else {
285 // checkJs( str, null, null, 0, jsEngine );
286 checkJs( bodyStr, manager, null, 0, jsEngine );
287 }
288 }
289 // command="ENTRY"の場???ブルモ?が存在しな??合?処?な?
290 else if( CMD_ENTRY.equals( command ) ) {
291 table = (DBTableModel) getObject( tableId );
292 if( table != null && table.getRowCount() > 0 ) {
293 manager.setDBTableModel( table );
294 if( isUniqCheck ) {
295 checkUnique( manager );
296 }
297 else {
298 // checkRows( bodyStr, manager );
299 checkRows( bodyStr, manager, tran ); // 5.1.9.0 (2010/08/01)
300 }
301 }
302 else {
303 System.out.println( "DBTableModel doesn't exist!! need this when command=\"ENTRY\"" );
304 }
305 }
306 }
307 finally {
308 if( tran != null ) { tran.close(); }
309 }
310
311 // エラーが発生した?合?、エラーメ?ージを表示して以降?処?行わな??
312 ErrorMessage errMessage = manager.getErrMessage() ;
313 if( errMessage != null && !errMessage.isOK() && !errRemove ) {
314 rtnCode = SKIP_PAGE;
315
316 // 5.1.9.0 (2010/08/01) エラーメ?ージの表示前にincludeするJSPを指?
317 if( beforeErrorJsp != null && beforeErrorJsp.length() > 0 ) {
318 includeJsp( beforeErrorJsp );
319 }
320
321 jspPrint( TaglibUtil.makeHTMLErrorTable( errMessage, getResource() ) );
322
323 // 5.1.9.0 (2010/08/01) エラーメ?ージの表示後にincludeするJSPを指?
324 if( afterErrorJsp != null && afterErrorJsp.length() > 0 ) {
325 includeJsp( afterErrorJsp );
326 }
327 }
328 }
329
330 return( rtnCode );
331 }
332
333 /**
334 * タグリブオブジェクトをリリースします?
335 * キャ?ュされて再利用される?で、フィールド?初期設定を行います?
336 *
337 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
338 * @og.rev 4.1.2.0 (2008/03/12) sqlType , execType , isExec 追?
339 * @og.rev 4.2.0.1 (2008/03/27) conditionKey , conditionList , msgParamKeys 追?
340 * @og.rev 5.1.9.0 (2010/08/01) beforeErrorJsp , afterErrorJsp, selectedAll 追?
341 */
342 @Override
343 protected void release2() {
344 super.release2();
345 tableId = HybsSystem.TBL_MDL_KEY;
346 dbid = null;
347 command = CMD_ENTRY;
348 table = null;
349 // errMessage = null;
350 exist = "auto";
351 errRemove = false;
352 msg = null;
353 msgParamKeys = null; // 4.2.0.1 (2008/03/27)
354 isSql = false;
355 isUniqCheck = false; // 4.3.4.0 (2008/12/01)
356 jsEngine = null;
357 sqlType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE
358 execType = null; // INSERT,COPY,UPDATE,MODIFY,DELETE
359 isExec = true; // 4.1.2.0 (2008/03/12)
360 conditionKey = null; // 4.2.0.1 (2008/03/27)
361 conditionList = null; // 4.2.0.1 (2008/03/27)
362 from = null; // 4.2.0.1 (2008/03/27)
363 bodyStr = null; // 4.3.4.0 (2008/12/01))
364 uniqCheckClms = null; // 4.3.4.0 (2008/12/01)
365 beforeErrorJsp = null; // 5.1.9.0 (2010/08/01)
366 afterErrorJsp = null; // 5.1.9.0 (2010/08/01)
367 selectedAll = false; // 5.1.9.0 (2010/08/01)
368 }
369
370 /**
371 * 引数及?ボディー部??チェ?を行い、???タイプを判別します?
372 * @og.rev 5.5.8.0 (2012/11/01) タイプ判別変更
373 * @og.rev 5.6.1.1 (2013/02/08) FROM 部の?出し位置修正
374 *
375 */
376 private void checkParam() {
377 isUniqCheck = ( uniqCheckClms != null && uniqCheckClms.length > 0 ) ? true : false;
378 if( isUniqCheck ) {
379 if( !CMD_ENTRY.equals( command ) ) {
380 String errMsg = "ユニ?クキーチェ?は、command=\"ENTRY\"の場合?み使用可能です?"
381 + " command=" + command ; // 5.1.8.0 (2010/07/01) errMsg 修正
382 throw new HybsSystemException( errMsg );
383 }
384 }
385 else {
386 if( bodyStr == null || bodyStr.length() == 0 ) {
387 String errMsg = "Body部?チェ?定義を記述して下さ??";
388 throw new HybsSystemException( errMsg );
389 }
390 else {
391 // SQLチェ?かJavaScriptによるチェ?か?判?
392 String query = bodyStr.toUpperCase( Locale.JAPAN ); // 4.2.0.1 (2008/03/27)
393 // if( query.indexOf( "SELECT" ) >= 0 ) {
394 if( query.indexOf( "SELECT" ) == 0 ) { // 5.5.8.0 (2012/11/01) 先?に限定する?(trim済?ため)
395 isSql = true;
396 int st = query.indexOf( "FROM" ) ;
397 int ed = query.indexOf( "WHERE" ) ;
398 if( st > 0 && st < ed ) {
399 // from = query.substring( st,ed ).trim();
400 from = query.substring( st+"FROM".length(),ed ).trim(); // 5.6.1.1 (2013/02/08)
401 }
402 }
403 else {
404 jsEngine = new ScriptEngineManager().getEngineByName( "JavaScript" );
405 }
406 }
407 }
408 }
409
410 /**
411 * SQLによる??タチェ?を行います?
412 * チェ?方法?、exist属?の?に依存します?
413 * autoの場合?、テーブルモ?の改廃Cから自動でチェ?方法が決定されます?
414 *
415 * @param str 実行するSQL?
416 * @param manager ErrMessageManager オブジェク?
417 * @param values SQL??パラメータ
418 * @param row 行番号
419 * @param modifyType 改廃C
420 * @param tran トランザクションオブジェク?
421 *
422 * @return 処??成否
423 *
424 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
425 * @og.rev 4.2.1.0 (2008/04/11) ErrMessageManager対?
426 * @og.rev 5.1.9.0 (2010/08/01) Transaction 対応します?
427 */
428 // private boolean checkSql( final String str, final String names, final String[] values
429 // , final String modifyType, final int row ) {
430 // private boolean checkSql( final String str, final ErrMessageManager manager, final String[] values
431 // , final int row, final String modifyType ) {
432 private boolean checkSql( final String str, final ErrMessageManager manager, final String[] values
433 , final int row, final String modifyType, final Transaction tran ) {
434
435 // int cnt = DBUtil.dbExist( str, values, getApplicationInfo(), dbid );
436 int cnt = DBUtil.dbExist( str, values, tran, dbid ); // 5.1.9.0 (2010/08/01)
437
438 boolean okFlag = true;
439 String id = null;
440 if( ( exist.equalsIgnoreCase( "true" ) || ( exist.equalsIgnoreCase( "auto" )
441 && ( DBTableModel.UPDATE_TYPE.equals( modifyType ) || DBTableModel.DELETE_TYPE.equals( modifyType ) ) ) ) && cnt <= 0 ) {
442 // ERR0025=??タ未登録エラー。キー={0}、?={1} の??タは、存在して?せん?
443 id = ( msg == null ? "ERR0025" : msg );
444 okFlag = false;
445 }
446 else if( ( exist.equalsIgnoreCase( "false" ) || ( exist.equalsIgnoreCase( "auto" )
447 && DBTableModel.INSERT_TYPE.equals( modifyType ) ) ) && cnt > 0 ) {
448 // ERR0026=??タ登録済みエラー。キー={0}、?={1} の??タは、すでに存在して?す?
449 id = ( msg == null ? "ERR0026" : msg );
450 okFlag = false;
451 }
452 else if( exist.equalsIgnoreCase( "one" ) && cnt > 1 ) {
453 // ERR0027=??タ?重登録エラー。キー={0}、?={1} の??タは??て存在して?す?
454 id = ( msg == null ? "ERR0027" : msg );
455 okFlag = false;
456 }
457
458 if( !okFlag ) {
459 manager.addMessage( row, id, values );
460
461 // String vals = StringUtil.array2csv( values );
462 // ResourceManager resource = getResource();
463 // String fromLbl = resource.getLabel( from );
464 // if( msgParamKeys == null || msgParamKeys.length == 0 ) {
465 // errMessage.addMessage( row, ErrorMessage.NG, id, names, vals, fromLbl );
466 // }
467 // else {
468 // int size = msgParamKeys.length;
469 // String[] args = new String[size] ;
470 // for( int i=0; i<size; i++ ) {
471 // String key = msgParamKeys[i] ;
472 // if( "@KEY".equals( key ) ) { args[i] = names; }
473 // else if( "@VAL".equals( key ) ) { args[i] = vals; }
474 // else if( "@TBL".equals( key ) ) { args[i] = fromLbl;}
475 // // 4.2.1.0 (2008/04/11) リクエスト変数対?
476 // else if( "[".startsWith( key ) && "]".endsWith( key ) ) {
477 // if( table != null ) {
478 // args[i] = table.getValue( row,key.substrng( 1,key.length()-1 ) );
479 // }
480 // }
481 // // 4.2.1.0 (2008/04/11) リクエスト変数対?
482 // else if( "{#".startsWith( key ) && "}".endsWith( key ) ) {
483 // args[i] = resource.getLabel( key.substrng( 2,key.length()-1 ));
484 // }
485 // else {
486 // args[i] = key;
487 // }
488 // }
489 // errMessage.addMessage( row, ErrorMessage.NG, id, args );
490 // }
491 }
492 return okFlag;
493 }
494
495 /**
496 * JavaScriptの式を実行します?
497 * 実行した結果がboolean型でな??合?エラーとなります?
498 *
499 * @param str 実行するSQL?
500 * @param manager オブジェク?
501 * @param values 値配?
502 * @param row 行番号
503 * @param engine JavaScriptエンジン
504 *
505 * @return 処??成否
506 *
507 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
508 * @og.rev 4.2.0.1 (2008/03/27) getClass().getName() から、instanceof に変更
509 * @og.rev 4.2.1.0 (2008/04/11) ErrMessageManager対?
510 */
511 // private boolean checkJs( final String str, final String names, final String[] values
512 // , final int row, final ScriptEngine engine ) {
513 private boolean checkJs( final String str, final ErrMessageManager manager, final String[] values
514 , final int row, final ScriptEngine engine ) {
515 // JavaScriptエンジンによる評価
516 Object obj = null;
517 try {
518 obj = engine.eval( str );
519 }
520 catch( ScriptException ex ) {
521 String errMsg = "JavaScript式?パ?スに失敗しました?" + str + "]";
522 throw new HybsSystemException( errMsg , ex );
523 }
524
525 // 返り値がBoolean型かチェ?
526 boolean okFlag = false;
527 // 4.2.0.1 (2008/03/27) instanceof に変更
528 // if( obj != null && "java.lang.Boolean".equals( obj.getClass().getName() ) ) {
529 // if( obj != null && obj instanceof Boolean ) {
530 if( obj instanceof Boolean ) { // 4.3.1.1 (2008/08/23) instanceof チェ?は、nullチェ?不?
531 okFlag = ((Boolean)obj).booleanValue();
532 }
533 else {
534 String errMsg = "JavaScript式には true 若しくは false が返るように設定して下さ?
535 + " Object=" + obj ; // 5.1.8.0 (2010/07/01) errMsg 修正
536 throw new HybsSystemException( errMsg );
537 }
538
539 if( !okFlag ) {
540 // ERR0030=入力したデータが不正です?key={0} value={1} 形?{2}
541 String id = ( msg == null ? "ERR0030" : msg );
542
543 manager.addMessage( row, id, values );
544
545 // String vals = StringUtil.array2csv( values );
546 // // ERR0030=入力したデータが不正です?key={0} value={1} 形?{2}
547 // String id = ( msg == null ? "ERR0030" : msg );
548 // // 4.2.1.0 (2008/04/11) リクエスト変数対?
549 // if( msgParamKeys == null || msgParamKeys.length == 0 ) {
550 // errMessage.addMessage( row, ErrorMessage.NG, id, names, vals, str );
551 // }
552 // else {
553 // int size = msgParamKeys.length;
554 // String[] args = new String[size] ;
555 // for( int i=0; i<size; i++ ) {
556 // ResourceManager resource = getResource();
557 // String key = msgParamKeys[i] ;
558 // // 4.2.1.0 (2008/04/11) リクエスト変数対?
559 // if( "{#".startsWith( key ) && "}".endsWith( key ) ) {
560 // args[i] = resource.getLabel( key.substrng( 2,key.length()-1 ));
561 // }
562 // else {
563 // args[i] = key;
564 // }
565 // }
566 // errMessage.addMessage( row, ErrorMessage.NG, id, args );
567 // }
568 }
569
570 return okFlag;
571 }
572
573 /**
574 * DB??ブルモ?の?に対して??タチェ?を行います?
575 *
576 * @param str チェ?対象の??
577 * @param manager ErrMessageManagerオブジェク?
578 * @param tran Transactionトランザクションオブジェク?
579 *
580 * @og.rev 4.1.1.0 (2008/02/22) 新規作?
581 * @og.rev 4.2.0.1 (2008/03/27) conditionKey,conditionList 対?
582 * @og.rev 4.2.1.0 (2008/04/11) ErrMessageManager対?
583 * @og.rev 5.1.9.0 (2010/08/01) Transaction 対応します?
584 */
585 // private void checkRows( final String str ) {
586 // private void checkRows( final String str, final ErrMessageManager manager ) {
587 private void checkRows( final String str, final ErrMessageManager manager, final Transaction tran ) {
588
589 int[] rowNo = getParameterRows(); // 4.0.0 (2005/01/31)
590 if( rowNo.length == 0 ) { return; }
591
592 Formatter format = new Formatter( table );
593 format.setFormat( str );
594 int[] clmNo = format.getClmNos();
595 // 4.2.0.1 (2008/03/27) カラ?のメ?ージリソース??を作?します?
596 // String names = getKeysLabel( clmNo );
597
598 manager.setClmNos( clmNo );
599
600 // SQL??場合?み[xxx]?に変換したSQL?取?JavaScriptの場合?ループ?で?毎に取?
601 String query = null;
602 if( isSql ) {
603 query = format.getQueryFormatString();
604 }
605
606 // 4.2.0.1 (2008/03/27) conditionKey,conditionList 対?
607 int cndKeyNo = -1;
608 if( conditionKey != null && conditionList != null ) {
609 cndKeyNo = table.getColumnNo( conditionKey ); // 不正??エラー
610 }
611
612 List<Integer> list = new ArrayList<Integer>();
613 boolean okFlag = false;
614 for( int i = 0; i < rowNo.length; i++ ) {
615 int row = rowNo[i] ;
616 String[] values = getTableModelData( row, clmNo );
617 // 4.2.0.1 (2008/03/27) 条件?がされて?場合に?
618 // Listに含まれな??合?、実行されな??
619 // 4.2.1.0 (2008/04/11) 厳?処?ます?
620 if( cndKeyNo >= 0 && conditionList.indexOf( table.getValue( row,cndKeyNo ) ) < 0 ) {
621 String conVal = "|" + table.getValue( row,cndKeyNo ) + "|" ;
622 if( conditionList.indexOf( conVal ) < 0 ) { continue; }
623 }
624
625 if( isSql ) {
626 // okFlag = checkSql( query, names, values, table.getModifyType( row ), row );
627 // okFlag = checkSql( query, manager, values, row, table.getModifyType( row ) );
628 okFlag = checkSql( query, manager, values, row, table.getModifyType( row ), tran );
629 }
630 else {
631 String jsStr = format.getFormatString( row, "\"" );
632 // okFlag = checkJs( jsStr, names, values, row, jsEngine );
633 okFlag = checkJs( jsStr, manager, values, row, jsEngine );
634 }
635
636 if( errRemove && okFlag ) {
637 list.add( row );
638 }
639 }
640
641 if( errRemove ) {
642 Integer[] in = list.toArray( new Integer[list.size()] );
643 int[] newRowNo = new int[in.length];
644 for( int i = 0; i < in.length; i++ ) {
645 newRowNo[i] = in[i].intValue();
646 }
647 setParameterRows( newRowNo );
648 }
649 }
650
651 /**
652 * DB??ブルモ?の?にユニ?クキーのチェ?を行います?
653 *
654 * @og.rev 4.3.4.0 (2008/12/01) 新規作?
655 *
656 * @param manager ErrMessageManagerオブジェク?
657 */
658 private void checkUnique( final ErrMessageManager manager ) {
659 int[] rowNo = getParameterRows();
660 if( rowNo.length == 0 ) { return; }
661
662 int[] clmNo = new int[uniqCheckClms.length];
663 for( int i=0; i<clmNo.length; i++ ) {
664 clmNo[i] = table.getColumnNo( uniqCheckClms[i] );
665 }
666
667 manager.setClmNos( clmNo );
668
669 List<Integer> list = new ArrayList<Integer>();
670 Map<String,Integer> map = new HashMap<String,Integer>();
671 for( int i = 0; i < rowNo.length; i++ ) {
672 int row = rowNo[i] ;
673 String[] values = getTableModelData( row, clmNo );
674 String key = StringUtil.array2line( values, " + " );
675
676 if( map.get( key ) == null ) {
677 map.put( key, 1 );
678 if( errRemove ) {
679 list.add( row );
680 }
681 }
682 else {
683 // ERR0027=??タ?重登録エラー。キー={0}、?={1} の??タは??て存在して?す?
684 id = ( msg == null ? "ERR0027" : msg );
685 manager.addMessage( row, id, values );
686 }
687 }
688
689 if( errRemove ) {
690 Integer[] in = list.toArray( new Integer[list.size()] );
691 int[] newRowNo = new int[in.length];
692 for( int i = 0; i < in.length; i++ ) {
693 newRowNo[i] = in[i].intValue();
694 }
695 setParameterRows( newRowNo );
696 }
697 }
698
699 /**
700 * msgParamKeys 属?に対して、実際の値を割り当てます?
701 *
702 * ここでは?#064;KEY ?#064;TBL 、{#XX} 、{@XX} に対して、実際の値と置き換えられます?
703 * @VAL と、[XX] は、DBTableModel の行番号が?なので、?別処?判断します?
704 * msgParamKeys が?未??null) の場合?、null を返します?
705 *
706 * @param names カラ?
707 * @param fromLbl ??ブル?
708 *
709 * @og.rev 4.2.0.1 (2008/03/27) 新規作?
710 */
711 // private String[] makeMsgParamVals( final String names,final String fromLbl ) {
712 // if( msgParamKeys == null ) { return null; }
713 //
714 // int size = msgParamKeys.length;
715 // String[] args = new String[size] ;
716 // ResourceManager resource = getResource();
717 //
718 // for( int i=0; i<size; i++ ) {
719 // String key = msgParamKeys[i] ;
720 // if( "@KEY".equals( key ) ) { args[i] = names; }
721 // else if( "@VAL".equals( key ) ) { args[i] = key; } // そ?まま返す
722 // else if( "@TBL".equals( key ) ) { args[i] = fromLbl;}
723 // // 4.2.1.0 (2008/04/11) リクエスト変数対?
724 // else if( "[".startsWith( key ) && "]".endsWith( key ) ) {
725 // args[i] = key; // そ?まま返す
726 // }
727 // else if( "{#".startsWith( key ) && "}".endsWith( key ) ) {
728 // args[i] = resource.getLabel( key.substrng( 2,key.length()-1 ));
729 // }
730 // else {
731 // args[i] = getRequestParameter( key );
732 // }
733 // }
734 //
735 // return args ;
736 // }
737
738 /**
739 * 【TAG?通常は使?せん)結果のDBTableModelを?sessionに登録するとき?キーを指定しま?
740 * (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])?
741 *
742 * @og.tag
743 * 検索結果より、DBTableModelオブジェクトを作?します?これを?下流?viewタグ等に
744 * 渡す?合に??常は、session を利用します?そ?場合?登録キーです?
745 * query タグを同時に実行して、結果を求める?合?同?モリに配置される為?
746 * こ? tableId 属?を利用して、メモリ空間を?ます?
747 * (初期値:HybsSystem#TBL_MDL_KEY[={@og.value org.opengion.hayabusa.common.HybsSystem#TBL_MDL_KEY}])?
748 *
749 * @param id sessionに登録する時? ID
750 */
751 public void setTableId( final String id ) {
752 tableId = nval( getRequestParameter( id ), tableId );
753 }
754
755 /**
756 * 【TAG?通常は使?せん)Queryオブジェクトを作?する時?DB接続IDを指定します?
757 *
758 * @og.tag Queryオブジェクトを作?する時?DB接続IDを指定します?
759 *
760 * @param id ??タベ?ス接続ID
761 */
762 public void setDbid( final String id ) {
763 dbid = nval( getRequestParameter( id ), dbid );
764 }
765
766 /**
767 * 【TAG】コマン?NEW or ENTRY)をセ?します?
768 *
769 * @og.tag
770 * コマンド?,HTMLから(get/post)?されます?で,CMD_xxx で設定される
771 * フィールド定数値の?れかを??できます?
772 *
773 * @param cmd コマン?public static final 宣?れて???)
774 * @see <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.DataCheckTag.CMD_NEW">コマンド定数</a>
775 */
776 public void setCommand( final String cmd ) {
777 String cmd2 = getRequestParameter( cmd );
778 if( cmd2 != null && cmd2.length() > 0 ) {
779 command = cmd2.toUpperCase( Locale.JAPAN );
780 }
781 }
782
783 /**
784 * 【TAG】データベ?スのチェ?方法[auto/true/false/one/notuse]を指定しま?初期値:auto[自動])?
785 *
786 * @og.tag
787 * exist 属?に?された ?true:存在する??false:存在しな??one:ひとつ以下」?
788 * の値は、いずれの場合も、?立時は、正常とみなします?
789 * ?auto:自動」は、DBTableModeleのmodifyType(A,C,D)に応じて、チェ?します?
790 * A,C,D は、entryタグにコマンドを渡して??タを作?したときに、?部で作?されます?
791 * (command="NEW"の場合?、trueと同じ動きになります?)
792 * notuse は、チェ?を行いません。これ?、このタグを?有使用する場合に、外部で
793 * チェ?を行うかど?を指定できるようにするために使用します?
794 * (?true:存在する? には、データが存在した場合に??で、なければエラーです?)
795 * 初期値は?auto:自動」です?
796 *
797 * @param ext チェ?方??auto:自動」?true:存在する??false:存在しな??one:ひとつ以下」?notuse:チェ?しな?)
798 */
799 public void setExist( final String ext ) {
800 exist = nval( getRequestParameter( ext ), exist );
801 if( !"auto".equalsIgnoreCase( exist )
802 && !"true".equalsIgnoreCase( exist )
803 && !"false".equalsIgnoreCase( exist )
804 && !"one".equalsIgnoreCase( exist )
805 && !"notuse".equalsIgnoreCase( exist ) ) {
806 String errMsg = "exist 属?は?auto,true,false,one,notuse)を指定してください?[" + exist + "]" + HybsSystem.CR;
807 throw new HybsSystemException( errMsg );
808 }
809 }
810
811 /**
812 * 【TAG】エラー時?選択行を取り除?継続??行うかど?[true/false]を指定しま?初期値:false)?
813 *
814 * @og.tag
815 * exist 属?に?された ?true:存在する??false:存在しな??one:ひとつ以下」?
816 * に対して、エラーが発生した選択行番号を?取り除?以下?処?継続するかど??
817 * ?します?
818 * true に設定した?合?、エラー??タを削除し?継続??行うことができます?
819 * flase の場合?、エラー??タを表示して、継続??停止します?
820 * 初期値は?false:エラー時停止?です?
821 *
822 * @param flag エラー時?継続??[true:エラー行番号を取り除き継続??false:エラー時停止]
823 */
824 public void setErrRemove( final String flag ) {
825 errRemove = nval( getRequestParameter( flag ), errRemove );
826 }
827
828 /**
829 * 【?】メ?ージIDを指定しま?lbl 属?を使用してください)?
830 *
831 * @og.tag メ?ージIDを指定します?
832 * ???応じた?期設定?メ?ージIDは、以下?通りです?
833 * exist="true" ERR0025=??タ未登録エラー。キー={0}、?={1} の??タは、存在して?せん?
834 * exist="false" ERR0026=??タ登録済みエラー。キー={0}、?={1} の??タは、すでに存在して?す?
835 * exist="one" ERR0027=??タ?重登録エラー。キー={0}、?={1} の??タは??て存在して?す?
836 * JavaScript ERR0030=入力したデータが不正です?key={0} value={1} 形?{2}
837 * 引数のパラメータには??常、チェ?に使用した実データが?DBTableModel から取得されます?
838 * 引数を変更する場合?、msgParamKeys を使用してください?
839 *
840 * @og.rev 5.2.2.0 (2010/11/01) ?します?lbl 属?を使用してください?
841 *
842 * @param id メ?ージID
843 * @see #setMsgParamKeys( String )
844 * @deprecated lbl 属?を使用してください?
845 */
846 @Deprecated public void setMsg( final String id ) {
847 msg = nval( getRequestParameter( id ), msg );
848 }
849
850 /**
851 * 【TAG】ラベルリソースIDを指定します?
852 *
853 * @og.tag ラベルリソースIDを指定します?
854 * ???応じた?期設定?ラベルリソースIDは、以下?通りです?
855 * exist="true" ERR0025=??タ未登録エラー。キー={0}、?={1} の??タは、存在して?せん?
856 * exist="false" ERR0026=??タ登録済みエラー。キー={0}、?={1} の??タは、すでに存在して?す?
857 * exist="one" ERR0027=??タ?重登録エラー。キー={0}、?={1} の??タは??て存在して?す?
858 * JavaScript ERR0030=入力したデータが不正です?key={0} value={1} 形?{2}
859 * 引数のパラメータには??常、チェ?に使用した実データが?DBTableModel から取得されます?
860 * 引数を変更する場合?、msgParamKeys を使用してください?
861 *
862 * @param id メ?ージID
863 * @see #setLblParamKeys( String )
864 */
865 @Override
866 public void setLbl( final String id ) {
867 // 継承親のメソ?を使わな??
868 msg = nval( getRequestParameter( id ), msg );
869 }
870
871 /**
872 * 【?】メ?ージリソースの引数をカンマ区?で?しま?lblParamKeys 属?を使用してください)?
873 *
874 * @og.tag
875 * メ?ージリソースのキーをカンマ区?で?することで、設定します?
876 * メ?ージに引数( {0},{1} など ) がある?合?ここで?した??
877 * ?に、{0},{1},{2}・・・ に当てはめて?ます?
878 * キーワード?、カンマ区?で?し、それを?後?ラベルリソースで
879 * リソース変換を行います?(つまり?記述された?そ?も?では在りません)
880 * PL/SQL では?{#PN}" などと?して???、同様に "PN" と?しです?
881 * ??、where 条件に?されたキーと値は、@KEY と @VAL に?
882 * from と where の間???は?#064;TBL に対応付けられます?
883 * {@XXXX} 変数も使用できます?実データの値を取出した??合?、[PN]と
884 * すれば、DBTableModel の PN の値を取出します?
885 * なにも指定しな??合?、キー={0} 、?={1}、from={2} です?
886 *
887 * @og.rev 4.2.0.1 (2008/03/27) 新規追?
888 *
889 * @param keys メ?ージリソースのキー(CSV)
890 * @see #setLbl( String )
891 * @deprecated lblParamKeys 属?を使用してください?
892 */
893 @Deprecated public void setMsgParamKeys( final String keys ) {
894 msgParamKeys = getCSVParameter( keys );
895 }
896
897 /**
898 * 【TAG】ラベルリソースの引数をカンマ区?で?します?
899 *
900 * @og.tag
901 * ラベルリソースのキーをカンマ区?で?することで、設定します?
902 * ラベルに引数( {0},{1} など ) がある?合?ここで?した??
903 * ?に、{0},{1},{2}・・・ に当てはめて?ます?
904 * キーワード?、カンマ区?で?し、それを?後?ラベルリソースで
905 * リソース変換を行います?(つまり?記述された?そ?も?では在りません)
906 * PL/SQL では?{#PN}" などと?して???、同様に "PN" と?しです?
907 * ??、where 条件に?されたキーと値は?#064;KEY と @VAL に?
908 * from と where の間???は?#064;TBL に対応付けられます?
909 * {@XXXX} 変数も使用できます?実データの値を取出した??合?、[PN]と
910 * すれば、DBTableModel の PN の値を取出します?
911 * なにも指定しな??合?、キー={0} 、?={1}、from={2} です?
912 *
913 * @og.rev 4.2.0.1 (2008/03/27) 新規追?
914 *
915 * @param keys メ?ージリソースのキー(CSV)
916 * @see #setMsg( String )
917 */
918 public void setLblParamKeys( final String keys ) {
919 msgParamKeys = getCSVParameter( keys );
920 }
921
922 /**
923 * 【TAG】このチェ?を行う、SQLタイ?を指定します?
924 *
925 * @og.tag
926 * SQLタイプ?、INSERT,COPY,UPDATE,MODIFY,DELETE などの記号を指定します?
927 * ?には、result 画面から update 画面へ遷移するとき?、command と
928 * 同じにしておけばよいでしょ??
929 * これは、execType とマッチした?合?み、このチェ?が??れます?
930 * 簡?equals タグの代役に使用できます?
931 * なにも指定しな??合?、チェ?は実行されます?
932 *
933 * @og.rev 4.1.2.0 (2008/03/12) 新規追?
934 *
935 * @param type こ?チェ?を行う、SQLタイ?
936 */
937 public void setSqlType( final String type ) {
938 sqlType = nval( getRequestParameter( type ),sqlType );
939 }
940
941 /**
942 * 【TAG】このチェ?を行う、実行タイ?を指定します?
943 *
944 * @og.tag
945 * 実行タイプ?、sqlType とマッチした?合?み、このチェ?が??れます?
946 * 簡?equals タグの代役に使用できます?
947 * execType は、??が可能です?単純な??マッチで、sqlType ?
948 * 含め?、実行されます?
949 * 例えば、sqlType={@sqlType} execType="INSERT|COPY" とすれば?
950 * sqlType に、INSERT また?、COPY が登録された?合にチェ?が掛かります?
951 * なにも指定しな??合?、チェ?は実行されます?
952 *
953 * @og.rev 4.1.2.0 (2008/03/12) 新規追?
954 *
955 * @param type こ?チェ?を行う、実行タイ?
956 */
957 public void setExecType( final String type ) {
958 execType = nval( getRequestParameter( type ),execType );
959 }
960
961 /**
962 * 【TAG】条件判定するカラ??を指定します?
963 *
964 * @og.tag
965 * ??カラ??の値と、conditionList の値を比?て?
966 * 存在する場合?、check処?実行します?
967 * こ?処?有効なのは、command="ENTRY" の場合?みです?
968 *
969 * @og.rev 4.2.0.1 (2008/03/27) 新規追?
970 *
971 * @param key カラ??
972 * @see #setConditionList( String )
973 */
974 public void setConditionKey( final String key ) {
975 conditionKey = nval( getRequestParameter( key ),null ) ;
976 }
977
978 /**
979 * 【TAG】条件判定する?のリストを?|"で区?て登録しま?初期値:無条件)?
980 *
981 * @og.tag
982 * conditionKey とペアで?します?ここには、カラ??設定?のリストを
983 * ?することで、?条件(??結合)での比?行い、リストにカラ???
984 * 存在する場合?み、check処?実行します?
985 * こ?処?有効なのは、command="ENTRY" の場合?みです?
986 * 設定しな??合?、無条件に実行します?
987 *
988 * @og.rev 4.2.0.1 (2008/03/27) 新規追?
989 *
990 * @param list 条件判定する?("|"で区?
991 * @see #setConditionKey( String )
992 */
993 public void setConditionList( final String list ) {
994 conditionList = nval( getRequestParameter( list ),null ) ;
995 if( conditionList != null ) {
996 conditionList = "|" + conditionList + "|" ;
997 }
998 }
999
1000 /**
1001 * 【TAG】指定されたキーに従って、メモリ上???ブルに対してユニ?クキーチェ?を行います?
1002 *
1003 * @og.tag
1004 * ユニ?クキーチェ?を行うキーを指定します?ここで、指定されたキーに対して?
1005 * DBTableModelの値をチェ?し?全てのキーに同じ値となって?行が存在すればエラーとなります?
1006 * こ?チェ?は、command="ENTRY"の場合?み有効です?
1007 * また?こ?チェ?は他?チェ?(DB存在チェ?など)と同時に処?ることはできません?
1008 * キーが指定され手?場合?、??部?記述されて?定義は無視されます?
1009 * errRemoveの属?がtrueに?されて?場合?重??、DBTableModelの並び?ら見て?
1010 * ??の行?み処?れ?2つめ以降?重??無視されます?
1011 * なお?キーはカンマ区?(CSV形?で??が可能です?
1012 *
1013 * @og.rev 4.3.4.0 (2008/12/01) 新規追?
1014 *
1015 * @param clm チェ?キー(CSV形?
1016 */
1017 public void setUniqCheckClms( final String clm ) {
1018 String tmp = nval( getRequestParameter( clm ),null );
1019 uniqCheckClms = StringUtil.csv2Array( tmp );
1020 }
1021
1022 /**
1023 * 【TAG】エラーが発生した際に、エラーメ?ージの表示前にincludeするJSPを指定します?
1024 *
1025 * @og.tag
1026 * エラーが発生した際に、エラーメ?ージの表示前にincludeするJSPを指定します?
1027 * エラーが発生して???合?、ここで?されたJSPが??れることはありません?
1028 * 通常は、戻るリンクなどを指定します?
1029 *
1030 * ??方法?、相対パス、絶対パスの両方で?することができます?
1031 * ?、絶対パスで?した?合?そ?基点は、コン?スト?ルートディレクトリになります?
1032 * ? beforeErrorJsp = "/jsp/common/history_back.jsp"
1033 *
1034 * @og.rev 5.1.9.0 (2010/08/01) 新規追?
1035 *
1036 * @param jsp 表示前にincludeするJSPファイル?
1037 */
1038 public void setBeforeErrorJsp( final String jsp ) {
1039 beforeErrorJsp = nval( getRequestParameter( jsp ),beforeErrorJsp );
1040 }
1041
1042 /**
1043 * 【TAG】エラーが発生した際に、エラーメ?ージの表示後にincludeするJSPを指定します?
1044 *
1045 * @og.tag
1046 * エラーが発生した際に、エラーメ?ージの表示前にincludeするJSPを指定します?
1047 * エラーが発生して???合?、ここで?されたJSPが??れることはありません?
1048 *
1049 * ??方法?、相対パス、絶対パスの両方で?することができます?
1050 * ?、絶対パスで?した?合?そ?基点は、コン?スト?ルートディレクトリになります?
1051 * ? afterErrorJsp = "/jsp/common/history_back.jsp"
1052 *
1053 * @og.rev 5.1.9.0 (2010/08/01) 新規追?
1054 *
1055 * @param jsp 表示後にincludeするJSPファイル?
1056 */
1057 public void setAfterErrorJsp( final String jsp ) {
1058 afterErrorJsp = nval( getRequestParameter( jsp ),afterErrorJsp );
1059 }
1060
1061 /**
1062 * 【TAG】データを?件選択済みとして処?るかど?[true/false]を指定しま?初期値:false)?
1063 *
1064 * @og.tag
1065 * 全ての??タを選択済み??タとして扱って処?ます?
1066 * 全件処?る?合に?true/false)を指定します?
1067 * 初期値は false です?
1068 *
1069 * @og.rev 5.1.9.0 (2010/08/01) 新規追?
1070 *
1071 * @param all 選択済みとして処?るかど?[true:全件選択済み/false:通常]
1072 */
1073 public void setSelectedAll( final String all ) {
1074 selectedAll = nval( getRequestParameter( all ),selectedAll );
1075 }
1076
1077 /**
1078 * ??行番号の、カラ?o配?(int[])に対応した?の配?を返します?
1079 *
1080 * 表示??タの HybsSystem.ROW_SEL_KEY を?に?ばれた 行を
1081 * 処??対象とします?
1082 *
1083 * @og.rev 4.2.0.1 (2008/03/27) row と clm を?れ替えます?(他とあわせま?
1084 *
1085 * @param row 行番号
1086 * @param clmNo カラ?o配?
1087 *
1088 * @return 行番号とカラ?o配?に対応した?値の配?
1089 */
1090 // private String[] getTableModelData( final int[] clmNo, final int row ) {
1091 private String[] getTableModelData( final int row, final int[] clmNo ) {
1092 String[] values = new String[clmNo.length];
1093 for( int i = 0; i < values.length; i++ ) {
1094 values[i] = table.getValue( row, clmNo[i] );
1095 }
1096 return values;
1097 }
1098
1099 /**
1100 * ??行番号の、カラ?o配?(int[])に対応したカラ?の配?を返します?
1101 *
1102 * @og.rev 4.3.1.1 (2008/08/23) ?
1103 *
1104 * @param clmNo カラ?o配?
1105 *
1106 * @return String[] カラ?o配?に対応した?カラ?の配?
1107 */
1108 // private String[] getTableModelClm( final int[] clmNo ) {
1109 // String[] clm = new String[clmNo.length];
1110 // for( int i = 0; i < clm.length; i++ ) {
1111 // clm[i] = table.getColumnName( clmNo[i] );
1112 // }
1113 // return clm;
1114 // }
1115
1116 /**
1117 * カラ?o配?(int[])に対応したカラ?のメ?ージリソース??を返します?
1118 *
1119 * @og.rev 4.3.1.1 (2008/08/23) ErrMessageManager ?クラスへ移?
1120 *
1121 * @param clmNo カラ?o配?
1122 *
1123 * @return カラ?o配?に対応した?カラ?のメ?ージリソース
1124 */
1125 // private String getKeysLabel( final int[] clmNo ) {
1126 // ResourceManager resource = getResource();
1127 //
1128 // StringBuilder buf = new StringBuilder();
1129 // if( clmNo.length > 0 ) {
1130 // String key = table.getColumnName( clmNo[0] );
1131 // buf.append( resource.getLabel( key ) );
1132 // for( int i=1; i<clmNo.length; i++ ) {
1133 // key = table.getColumnName( clmNo[i] );
1134 // buf.append( "," ).append( resource.getLabel( key ) );
1135 // }
1136 // }
1137 //
1138 // return buf.toString();
1139 // }
1140
1141 /**
1142 * エラーメ?ージの前後に処?るJSPをインクルードします?
1143 *
1144 * @og.rev 5.1.9.0 (2010/08/01) 新規作?
1145 *
1146 * @param jsp JSP?
1147 */
1148 private void includeJsp( final String jsp ) {
1149 try {
1150 pageContext.include( jsp, false );
1151 } catch ( IOException ex ) {
1152 String errMsg = jsp + " の include に失敗しました?";
1153 throw new HybsSystemException( errMsg,ex );
1154 } catch ( ServletException ex ) {
1155 String errMsg = jsp + " の include に失敗しました?";
1156 throw new HybsSystemException( errMsg,ex );
1157 }
1158 }
1159
1160 /**
1161 * 表示??タの HybsSystem.ROW_SEL_KEY を?に?ばれた 行を処??対象とします?
1162 *
1163 * @og.rev 5.1.9.0 (2010/08/01) 新規追?
1164 *
1165 * @return 選択行?配?
1166 */
1167 @Override
1168 protected int[] getParameterRows() {
1169 final int[] rowNo ;
1170 if( selectedAll ) {
1171 int rowCnt = table.getRowCount();
1172 rowNo = new int[ rowCnt ];
1173 for( int i=0; i<rowCnt; i++ ) {
1174 rowNo[i] = i;
1175 }
1176 } else {
1177 rowNo = super.getParameterRows();
1178 }
1179 return rowNo ;
1180 }
1181
1182 /**
1183 * ErrMessage を管?て? メソ????クラス
1184 *
1185 * 繰返し処?と、固定部が混在したエラーメ?ージで、固定部を?に処??
1186 * 繰返し部は、?時に処?るよ?しました?
1187 * また?実際にエラーが発生して?になるまで、実行遅延させます?
1188 *
1189 * @og.rev 4.2.1.0 (2008/04/11) 新規追?
1190 * @og.rev 4.3.0.0 (2008/07/24) クラス宣?static?
1191 */
1192 private static final class ErrMessageManager {
1193 // 引数として初期設定される変数
1194 private String title = null;
1195 private String from = null;
1196 private String[] msgKeys = null;
1197 private ResourceManager resource = null;
1198 private DBTableModel table = null;
1199 private int[] clmNo = null;
1200
1201 // ?引数として処?れたキャ?ュ値
1202 private ErrorMessage errMessage = null;
1203 private String names = null;
1204 private String fromLbl = null;
1205 private String[] msgVals = null;
1206
1207 private boolean isFirst = true; // 初期化されて??true
1208
1209 /**
1210 * ErrMessage のタイトルを設定します?
1211 *
1212 * @param title タイトル
1213 */
1214 public void setTitle( final String title ) { this.title = title; }
1215
1216 /**
1217 * 処?象の??ブル名を設定します?
1218 *
1219 * @param from ??ブル?
1220 */
1221 public void setFrom( final String from ) { this.from = from; }
1222
1223 /**
1224 * 処?象の??ブルオブジェクトを設定します?
1225 *
1226 * @param table DBTableModelオブジェク?
1227 */
1228 public void setDBTableModel( final DBTableModel table ) { this.table = table; }
1229
1230 /**
1231 * ResourceManagerオブジェクトを設定します?
1232 *
1233 * @param resource ResourceManagerオブジェク?
1234 */
1235 public void setResourceManager( final ResourceManager resource ) { this.resource = resource; }
1236
1237 /**
1238 * msgParamKeys 属?の配?を設定します?
1239 *
1240 * @param msgKeys 属?の配?
1241 */
1242 public void setParamKeys( final String[] msgKeys ) { this.msgKeys = msgKeys; }
1243
1244 /**
1245 * カラ?列を設定します?
1246 *
1247 * @param clmNo カラ?
1248 */
1249 public void setClmNos( final int[] clmNo ) { this.clmNo = clmNo ; }
1250
1251 /**
1252 * 初期処?行います?
1253 * エラー処??、エラー時?み実行する為、??な??合?、??不要です?
1254 * ??のエラー出力までは、?部オブジェクト?構築??行いません?
1255 * ?回目以降?、?部変数にキャ?ュされた変換値を利用して??化します?
1256 *
1257 * @og.rev 4.2.3.2 (2008/06/20) from が?null なら?なにもしな??
1258 */
1259 private void firstExecute() {
1260 errMessage = new ErrorMessage( title );
1261
1262 // ??ブル(from) をキーにラベルリソースから値を取得します?
1263 // 4.2.3.2 (2008/06/20) from が?null なら?なにもしな??
1264 if( from != null ) {
1265 fromLbl = resource.getLabel( from );
1266 }
1267
1268 // カラ?号配?から、カラ?のラベルリソース??のCSV??を作?します?
1269 names = getKeysLabel( clmNo );
1270
1271 if( msgKeys != null && msgKeys.length > 0 ) {
1272 int size = msgKeys.length;
1273 msgVals = new String[size] ;
1274
1275 for( int i=0; i<size; i++ ) {
1276 String key = msgKeys[i] ;
1277 if( key != null ) {
1278 if( "@KEY".equals( key ) ) { msgVals[i] = names; }
1279 else if( "@TBL".equals( key ) ) { msgVals[i] = fromLbl;}
1280 else if( key.startsWith( "{#" ) && key.endsWith( "}" ) ) {
1281 msgVals[i] = resource.getLabel( key.substring( 2,key.length()-1 ));
1282 }
1283 else {
1284 msgVals[i] = key;
1285 }
1286 }
1287 }
1288 }
1289 }
1290
1291 /**
1292 * カラ?o配?(int[])に対応したカラ?のメ?ージリソース??を返します?
1293 *
1294 * @param clmNo カラ?o配?
1295 * @return カラ?o配?に対応した?カラ?のメ?ージリソース
1296 */
1297 private String getKeysLabel( final int[] clmNo ) {
1298 StringBuilder buf = new StringBuilder();
1299 if( table != null && clmNo.length > 0 ) {
1300 String key = table.getColumnName( clmNo[0] );
1301 buf.append( resource.getLabel( key ) );
1302 for( int i=1; i<clmNo.length; i++ ) {
1303 key = table.getColumnName( clmNo[i] );
1304 buf.append( "," ).append( resource.getLabel( key ) );
1305 }
1306 }
1307
1308 return buf.toString();
1309 }
1310
1311 /**
1312 * カラ?列を設定します?
1313 *
1314 * @og.rev 4.3.5.7 (2008/03/22) エラーメ?ージの行番号を実際の行番号と??させる?
1315 *
1316 * @param row カラ?
1317 * @param id カラ?
1318 * @param values ??行に対する値
1319 */
1320 public void addMessage( final int row, final String id, final String[] values ) {
1321 if( isFirst ) { firstExecute(); isFirst = false; }
1322
1323 String vals = StringUtil.array2csv( values );
1324 if( msgVals == null ) {
1325 // errMessage.addMessage( row, ErrorMessage.NG, id, names, vals, fromLbl );
1326 errMessage.addMessage( row + 1, ErrorMessage.NG, id, names, vals, fromLbl );
1327 }
1328 else {
1329 int size = msgKeys.length;
1330 String[] args = new String[size] ;
1331
1332 for( int i=0; i<size; i++ ) {
1333 String key = msgVals[i] ;
1334 if( key != null ) {
1335 if( "@VAL".equals( key ) ) { args[i] = vals; }
1336 else if( key.startsWith( "[" ) && key.endsWith( "]" ) ) {
1337 if( table != null ) {
1338 args[i] = table.getValue( row,key.substring( 1,key.length()-1 ) );
1339 }
1340 }
1341 else {
1342 args[i] = key;
1343 }
1344 }
1345 }
1346 // errMessage.addMessage( row, ErrorMessage.NG, id, args );
1347 errMessage.addMessage( row + 1, ErrorMessage.NG, id, args );
1348 }
1349 }
1350
1351 /**
1352 * ErrorMessageオブジェクトを返します?
1353 *
1354 * @return ErrorMessage オブジェク?
1355 */
1356 public ErrorMessage getErrMessage() { return errMessage; }
1357 }
1358
1359 /**
1360 * シリアライズ用のカスタ?リアライズ書き込みメソ?
1361 *
1362 * @og.rev 4.0.0.0 (2006/09/31) 新規追?
1363 * @serialData ?のオブジェクト?、シリアライズされません?
1364 *
1365 * @param strm ObjectOutputStreamオブジェク?
1366 * @throws IOException シリアライズに関する入出力エラーが発生した??
1367 */
1368 private void writeObject( final ObjectOutputStream strm ) throws IOException {
1369 strm.defaultWriteObject();
1370 }
1371
1372 /**
1373 * シリアライズ用のカスタ?リアライズ読み込みメソ?
1374 *
1375 * ここでは、transient 宣?れた?変数の??初期化が?なフィールド?み設定します?
1376 *
1377 * @og.rev 4.0.0.0 (2006/09/31) 新規追?
1378 * @serialData ?のオブジェクト?、シリアライズされません?
1379 *
1380 * @param strm ObjectInputStreamオブジェク?
1381 * @see #release2()
1382 * @throws IOException シリアライズに関する入出力エラーが発生した??
1383 * @throws ClassNotFoundException クラスを見つけることができなかった??
1384 */
1385 private void readObject( final ObjectInputStream strm ) throws IOException, ClassNotFoundException {
1386 strm.defaultReadObject();
1387 }
1388
1389 /**
1390 * こ?オブジェクト???表現を返します?
1391 * 基本???目?使用します?
1392 *
1393 * @return こ?クラスの??表現
1394 */
1395 @Override
1396 public String toString() {
1397 return org.opengion.fukurou.util.ToString.title(this.getClass().getName() )
1398 .println( "VERSION", VERSION )
1399 .println( "tableId", tableId )
1400 .println( "dbid", dbid )
1401 .println( "command", command )
1402 .println( "exist", exist )
1403 .println( "msg", msg )
1404 .println( "Other...", getAttributes().getAttribute() ).fixForm().toString();
1405 }
1406 }