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