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?šあã‚?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 *
741 * @og.tag 初期値は、HybsSystem.TBL_MDL_KEY ですã?
742 *
743 * @param id sessionに登録する時ã? ID
744 */
745 public void setTableId( final String id ) {
746 tableId = nval( getRequestParameter( id ), tableId );
747 }
748
749 /**
750 * 【TAGã€?通常は使ã�?�¾せん)Queryオブジェクトを作æ?する時ã?DB接続IDを指定しますã?
751 *
752 * @og.tag Queryオブジェクトを作æ?する時ã?DB接続IDを指定しますã?
753 *
754 * @param id ãƒ??タベã?ス接続ID
755 */
756 public void setDbid( final String id ) {
757 dbid = nval( getRequestParameter( id ), dbid );
758 }
759
760 /**
761 * 【TAG】コマンãƒ?NEW or ENTRY)をセãƒ?ƒˆしますã?
762 *
763 * @og.tag
764 * コマンドã?,HTMLから(get/post)æŒ?®šされますã?で,CMD_xxx で設定される
765 * フィールド定数値のã�?�¥れかをã?æŒ?®šできますã?
766 *
767 * @param cmd コマンãƒ?public static final 宣è¨?�•れてã�?‚‹æ–?—å?)
768 * @see <a href="{@docRoot}/constant-values.html#org.opengion.hayabusa.taglib.DataCheckTag.CMD_NEW">コマンド定数</a>
769 */
770 public void setCommand( final String cmd ) {
771 String cmd2 = getRequestParameter( cmd );
772 if( cmd2 != null && cmd2.length() > 0 ) {
773 command = cmd2.toUpperCase( Locale.JAPAN );
774 }
775 }
776
777 /**
778 * 【TAG】データベã?スのチェãƒ?‚¯方法[auto/true/false/one/notuse]を指定しまã�?初期値:auto[自動])ã€?
779 *
780 * @og.tag
781 * exist 属æ?にæŒ?®šされた ã€?½¢true:存在する?£ã€?½¢false:存在しなã�?½£ã€?½¢one:ひとつ以下」ã€?
782 * の値は、いずれの場合も、æ?立時は、正常とみなしますã?
783 * ?¢auto:自動」は、DBTableModeleのmodifyType(A,C,D)に応じて、チェãƒ?‚¯しますã?
784 * A,C,D は、entryタグにコマンドを渡してãƒ??タを作æ?したときに、å?部で作æ?されますã?
785 * (command="NEW"の場合ã?、trueと同じ動きになりますã?)
786 * notuse は、チェãƒ?‚¯を行いません。これã?、このタグをå?有使用する場合に、外部で
787 * チェãƒ?‚¯を行うかどã�?�‹を指定できるようにするために使用しますã?
788 * (?¢true:存在する?£ には、データが存在した場合にã€?¼¯?«で、なければエラーですã?)
789 * 初期値はã€?½¢auto:自動」ですã?
790 *
791 * @param ext チェãƒ?‚¯方æ³??¢auto:自動」ã€?½¢true:存在する?£ã€?½¢false:存在しなã�?½£ã€?½¢one:ひとつ以下」ã€?½¢notuse:チェãƒ?‚¯しなã�?½£)
792 */
793 public void setExist( final String ext ) {
794 exist = nval( getRequestParameter( ext ), exist );
795 if( !"auto".equalsIgnoreCase( exist )
796 && !"true".equalsIgnoreCase( exist )
797 && !"false".equalsIgnoreCase( exist )
798 && !"one".equalsIgnoreCase( exist )
799 && !"notuse".equalsIgnoreCase( exist ) ) {
800 String errMsg = "exist 属æ?はã€?auto,true,false,one,notuse)を指定してくださいã€?[" + exist + "]" + HybsSystem.CR;
801 throw new HybsSystemException( errMsg );
802 }
803 }
804
805 /**
806 * 【TAG】エラー時ã?選択行を取り除ã�?�¦継続å?ç�?‚’行うかどã�?�‹[true/false]を指定しまã�?初期値:false)ã€?
807 *
808 * @og.tag
809 * exist 属æ?にæŒ?®šされた ã€?½¢true:存在する?£ã€?½¢false:存在しなã�?½£ã€?½¢one:ひとつ以下」ã€?
810 * に対して、エラーが発生した選択行番号をã?取り除ã�?�¦以下ã?処ç�?‚’継続するかどã�?�‹ã‚?
811 * æŒ?®šしますã?
812 * true に設定したå?合ã?、エラーãƒ??タを削除しã?継続å?ç�?‚’行うことができますã?
813 * flase の場合ã?、エラーãƒ??タを表示して、継続å?ç�?‚’停止しますã?
814 * 初期値はã€?½¢false:エラー時停止?£ですã?
815 *
816 * @param flag エラー時ã?継続å?ç�?[true:エラー行番号を取り除き継続å?ç�?false:エラー時停止]
817 */
818 public void setErrRemove( final String flag ) {
819 errRemove = nval( getRequestParameter( flag ), errRemove );
820 }
821
822 /**
823 * 【å»?¢】メãƒ?‚»ージIDを指定しまã�?lbl 属æ?を使用してください)ã€?
824 *
825 * @og.tag メãƒ?‚»ージIDを指定しますã?
826 * å�??ç�?�«応じたå?期設定ã?メãƒ?‚»ージIDは、以下ã?通りですã?
827 * exist="true" ERR0025=ãƒ??タ未登録エラー。キー={0}、å?={1} のãƒ??タは、存在してã�?�¾せんã€?
828 * exist="false" ERR0026=ãƒ??タ登録済みエラー。キー={0}、å?={1} のãƒ??タは、すでに存在してã�?�¾すã?
829 * exist="one" ERR0027=ãƒ??タ?’重登録エラー。キー={0}、å?={1} のãƒ??タはã€?‡�è¤?�—て存在してã�?�¾すã?
830 * JavaScript ERR0030=入力したデータが不正ですã?key={0} value={1} 形å¼?{2}
831 * 引数のパラメータにはã€??常、チェãƒ?‚¯に使用した実データがã?DBTableModel から取得されますã?
832 * 引数を変更する場合ã?、msgParamKeys を使用してくださいã€?
833 *
834 * @og.rev 5.2.2.0 (2010/11/01) å»?¢しますã?lbl 属æ?を使用してくださいã€?
835 *
836 * @param id メãƒ?‚»ージID
837 * @see #setMsgParamKeys( String )
838 * @deprecated lbl 属æ?を使用してくださいã€?
839 */
840 @Deprecated public void setMsg( final String id ) {
841 msg = nval( getRequestParameter( id ), msg );
842 }
843
844 /**
845 * 【TAG】ラベルリソースIDを指定しますã?
846 *
847 * @og.tag ラベルリソースIDを指定しますã?
848 * å�??ç�?�«応じたå?期設定ã?ラベルリソースIDは、以下ã?通りですã?
849 * exist="true" ERR0025=ãƒ??タ未登録エラー。キー={0}、å?={1} のãƒ??タは、存在してã�?�¾せんã€?
850 * exist="false" ERR0026=ãƒ??タ登録済みエラー。キー={0}、å?={1} のãƒ??タは、すでに存在してã�?�¾すã?
851 * exist="one" ERR0027=ãƒ??タ?’重登録エラー。キー={0}、å?={1} のãƒ??タはã€?‡�è¤?�—て存在してã�?�¾すã?
852 * JavaScript ERR0030=入力したデータが不正ですã?key={0} value={1} 形å¼?{2}
853 * 引数のパラメータにはã€??常、チェãƒ?‚¯に使用した実データがã?DBTableModel から取得されますã?
854 * 引数を変更する場合ã?、msgParamKeys を使用してくださいã€?
855 *
856 * @param id メãƒ?‚»ージID
857 * @see #setLblParamKeys( String )
858 */
859 @Override
860 public void setLbl( final String id ) {
861 // 継承親のメソãƒ?ƒ‰を使わなã�??
862 msg = nval( getRequestParameter( id ), msg );
863 }
864
865 /**
866 * 【å»?¢】メãƒ?‚»ージリソースの引数をカンマ区åˆ?‚ŠでæŒ?®šしまã�?lblParamKeys 属æ?を使用してください)ã€?
867 *
868 * @og.tag
869 * メãƒ?‚»ージリソースのキーをカンマ区åˆ?‚ŠでæŒ?®šすることで、設定しますã?
870 * メãƒ?‚»ージに引数( {0},{1} など ) があるå?合ã?ここでæŒ?®šしたå?ã‚?
871 * é ?•ªに、{0},{1},{2}・・・ に当てはめてã�?��ますã?
872 * キーワードã?、カンマ区åˆ?‚ŠでæŒ?®šし、それをåˆ?§£後ã?ラベルリソースで
873 * リソース変換を行いますã?(つまりã?記述されたå?そã?もã?では在りません)
874 * PL/SQL ではã€?{#PN}" などとæŒ?®šしてã�?�Ÿåˆ??、同様に "PN" とæŒ?®šしですã?
875 * å†?ƒ¨çš?�«、where 条件にæŒ?®šされたキーと値は、@KEY と @VAL にã€?
876 * from と where の間ã?æ–?—å?はã€?#064;TBL に対応付けられますã?
877 * {@XXXX} 変数も使用できますã?実データの値を取出したã�??合ã?、[PN]と
878 * すれば、DBTableModel の PN の値を取出しますã?
879 * なにも指定しなã�??合ã?、キー={0} 、å?={1}、from={2} ですã?
880 *
881 * @og.rev 4.2.0.1 (2008/03/27) 新規追åŠ?
882 *
883 * @param keys メãƒ?‚»ージリソースのキー(CSV)
884 * @see #setLbl( String )
885 * @deprecated lblParamKeys 属æ?を使用してくださいã€?
886 */
887 @Deprecated public void setMsgParamKeys( final String keys ) {
888 msgParamKeys = getCSVParameter( keys );
889 }
890
891 /**
892 * 【TAG】ラベルリソースの引数をカンマ区åˆ?‚ŠでæŒ?®šしますã?
893 *
894 * @og.tag
895 * ラベルリソースのキーをカンマ区åˆ?‚ŠでæŒ?®šすることで、設定しますã?
896 * ラベルに引数( {0},{1} など ) があるå?合ã?ここでæŒ?®šしたå?ã‚?
897 * é ?•ªに、{0},{1},{2}・・・ に当てはめてã�?��ますã?
898 * キーワードã?、カンマ区åˆ?‚ŠでæŒ?®šし、それをåˆ?§£後ã?ラベルリソースで
899 * リソース変換を行いますã?(つまりã?記述されたå?そã?もã?では在りません)
900 * PL/SQL ではã€?{#PN}" などとæŒ?®šしてã�?�Ÿåˆ??、同様に "PN" とæŒ?®šしですã?
901 * å†?ƒ¨çš?�«、where 条件にæŒ?®šされたキーと値はã€?#064;KEY と @VAL にã€?
902 * from と where の間ã?æ–?—å?はã€?#064;TBL に対応付けられますã?
903 * {@XXXX} 変数も使用できますã?実データの値を取出したã�??合ã?、[PN]と
904 * すれば、DBTableModel の PN の値を取出しますã?
905 * なにも指定しなã�??合ã?、キー={0} 、å?={1}、from={2} ですã?
906 *
907 * @og.rev 4.2.0.1 (2008/03/27) 新規追åŠ?
908 *
909 * @param keys メãƒ?‚»ージリソースのキー(CSV)
910 * @see #setMsg( String )
911 */
912 public void setLblParamKeys( final String keys ) {
913 msgParamKeys = getCSVParameter( keys );
914 }
915
916 /**
917 * 【TAG】このチェãƒ?‚¯を行う、SQLタイãƒ?を指定しますã?
918 *
919 * @og.tag
920 * SQLタイプã?、INSERT,COPY,UPDATE,MODIFY,DELETE などの記号を指定しますã?
921 * ä¸?ˆ¬には、result 画面から update 画面へ遷移するときã?、command と
922 * 同じにしておけばよいでしょã�??
923 * これは、execType とマッチしたå?合ã?み、このチェãƒ?‚¯がå?ç�?�•れますã?
924 * 簡æ˜?equals タグの代役に使用できますã?
925 * なにも指定しなã�??合ã?、チェãƒ?‚¯は実行されますã?
926 *
927 * @og.rev 4.1.2.0 (2008/03/12) 新規追åŠ?
928 *
929 * @param type こã?チェãƒ?‚¯を行う、SQLタイãƒ?
930 */
931 public void setSqlType( final String type ) {
932 sqlType = nval( getRequestParameter( type ),sqlType );
933 }
934
935 /**
936 * 【TAG】このチェãƒ?‚¯を行う、実行タイãƒ?を指定しますã?
937 *
938 * @og.tag
939 * 実行タイプã?、sqlType とマッチしたå?合ã?み、このチェãƒ?‚¯がå?ç�?�•れますã?
940 * 簡æ˜?equals タグの代役に使用できますã?
941 * execType は、è¤?•°æŒ?®šが可能ですã?単純なæ–?—å?マッチで、sqlType ã‚?
942 * 含めã?、実行されますã?
943 * 例えば、sqlType={@sqlType} execType="INSERT|COPY" とすればã€?
944 * sqlType に、INSERT またã?、COPY が登録されたå?合にチェãƒ?‚¯が掛かりますã?
945 * なにも指定しなã�??合ã?、チェãƒ?‚¯は実行されますã?
946 *
947 * @og.rev 4.1.2.0 (2008/03/12) 新規追åŠ?
948 *
949 * @param type こã?チェãƒ?‚¯を行う、実行タイãƒ?
950 */
951 public void setExecType( final String type ) {
952 execType = nval( getRequestParameter( type ),execType );
953 }
954
955 /**
956 * 【TAG】条件判定するカラãƒ?¼©?¤を指定しますã?
957 *
958 * @og.tag
959 * æŒ?®šã?カラãƒ?¼©?¤の値と、conditionList の値を比è¼?�—てã€?
960 * 存在する場合ã?、check処ç�?‚’実行しますã?
961 * こã?処ç�?�Œ有効なのは、command="ENTRY" の場合ã?みですã?
962 *
963 * @og.rev 4.2.0.1 (2008/03/27) 新規追åŠ?
964 *
965 * @param key カラãƒ?¼©?¤
966 * @see #setConditionList( String )
967 */
968 public void setConditionKey( final String key ) {
969 conditionKey = nval( getRequestParameter( key ),null ) ;
970 }
971
972 /**
973 * 【TAG】条件判定するå?のリストをã€?|"で区åˆ?�£て登録しまã�?初期値:無条件)ã€?
974 *
975 * @og.tag
976 * conditionKey とペアでæŒ?®šしますã?ここには、カラãƒ??設定å?のリストを
977 * æŒ?®šすることで、è¤?•°条件(?¯?²結合)での比è¼?‚’行い、リストにカラãƒ??ã�?
978 * 存在する場合ã?み、check処ç�?‚’実行しますã?
979 * こã?処ç�?�Œ有効なのは、command="ENTRY" の場合ã?みですã?
980 * 設定しなã�??合ã?、無条件に実行しますã?
981 *
982 * @og.rev 4.2.0.1 (2008/03/27) 新規追åŠ?
983 *
984 * @param list 条件判定するå?("|"で区åˆ?
985 * @see #setConditionKey( String )
986 */
987 public void setConditionList( final String list ) {
988 conditionList = nval( getRequestParameter( list ),null ) ;
989 if( conditionList != null ) {
990 conditionList = "|" + conditionList + "|" ;
991 }
992 }
993
994 /**
995 * 【TAG】指定されたキーに従って、メモリ上ã?ãƒ??ブルに対してユニã?クキーチェãƒ?‚¯を行いますã?
996 *
997 * @og.tag
998 * ユニã?クキーチェãƒ?‚¯を行うキーを指定しますã?ここで、指定されたキーに対してã€?
999 * DBTableModelの値をチェãƒ?‚¯しã?全てのキーに同じ値となってã�?‚‹行が存在すればエラーとなりますã?
1000 * こã?チェãƒ?‚¯は、command="ENTRY"の場合ã?み有効ですã?
1001 * またã?こã?チェãƒ?‚¯は他ã?チェãƒ?‚¯(DB存在チェãƒ?‚¯など)と同時に処ç�?�™ることはできませんã€?
1002 * キーが指定され手ã�?‚‹場合ã?、ã?ãƒ?‚£部åˆ?�«記述されてã�?‚‹定義は無視されますã?
1003 * errRemoveの属æ?がtrueにæŒ?®šされてã�?‚‹場合ã?重è¤?¡Œã?、DBTableModelの並びé ?�‹ら見てã€?
1004 * æœ??の行ã?み処ç�?�•れã?2つめ以降ã?重è¤?¡Œã?無視されますã?
1005 * なおã?キーはカンマ区åˆ?‚Š(CSV形å¼?でè¤?•°æŒ?®šが可能ですã?
1006 *
1007 * @og.rev 4.3.4.0 (2008/12/01) 新規追åŠ?
1008 *
1009 * @param clm チェãƒ?‚¯キー(CSV形å¼?
1010 */
1011 public void setUniqCheckClms( final String clm ) {
1012 String tmp = nval( getRequestParameter( clm ),null );
1013 uniqCheckClms = StringUtil.csv2Array( tmp );
1014 }
1015
1016 /**
1017 * 【TAG】エラーが発生した際に、エラーメãƒ?‚»ージの表示前にincludeするJSPを指定しますã?
1018 *
1019 * @og.tag
1020 * エラーが発生した際に、エラーメãƒ?‚»ージの表示前にincludeするJSPを指定しますã?
1021 * エラーが発生してã�?�ªã�??合ã?、ここでæŒ?®šされたJSPがå?ç�?�•れることはありませんã€?
1022 * 通常は、戻るリンクなどを指定しますã?
1023 *
1024 * æŒ?®šã?方法ã?、相対パス、絶対パスの両方でæŒ?®šすることができますã?
1025 * ä½?�—、絶対パスでæŒ?®šしたå?合ã?そã?基点は、コンãƒ?‚ストã?ルートディレクトリになりますã?
1026 * ä¾? beforeErrorJsp = "/jsp/common/history_back.jsp"
1027 *
1028 * @og.rev 5.1.9.0 (2010/08/01) 新規追åŠ?
1029 *
1030 * @param jsp 表示前にincludeするJSPファイルå�?
1031 */
1032 public void setBeforeErrorJsp( final String jsp ) {
1033 beforeErrorJsp = nval( getRequestParameter( jsp ),beforeErrorJsp );
1034 }
1035
1036 /**
1037 * 【TAG】エラーが発生した際に、エラーメãƒ?‚»ージの表示後にincludeするJSPを指定しますã?
1038 *
1039 * @og.tag
1040 * エラーが発生した際に、エラーメãƒ?‚»ージの表示前にincludeするJSPを指定しますã?
1041 * エラーが発生してã�?�ªã�??合ã?、ここでæŒ?®šされたJSPがå?ç�?�•れることはありませんã€?
1042 *
1043 * æŒ?®šã?方法ã?、相対パス、絶対パスの両方でæŒ?®šすることができますã?
1044 * ä½?�—、絶対パスでæŒ?®šしたå?合ã?そã?基点は、コンãƒ?‚ストã?ルートディレクトリになりますã?
1045 * ä¾? afterErrorJsp = "/jsp/common/history_back.jsp"
1046 *
1047 * @og.rev 5.1.9.0 (2010/08/01) 新規追åŠ?
1048 *
1049 * @param jsp 表示後にincludeするJSPファイルå�?
1050 */
1051 public void setAfterErrorJsp( final String jsp ) {
1052 afterErrorJsp = nval( getRequestParameter( jsp ),afterErrorJsp );
1053 }
1054
1055 /**
1056 * 【TAG】データをå?件選択済みとして処ç�?�™るかどã�?�‹[true/false]を指定しまã�?初期値:false)ã€?
1057 *
1058 * @og.tag
1059 * 全てのãƒ??タを選択済みãƒ??タとして扱って処ç�?�—ますã?
1060 * 全件処ç�?�™るå?合にã€?true/false)を指定しますã?
1061 * 初期値は false ですã?
1062 *
1063 * @og.rev 5.1.9.0 (2010/08/01) 新規追åŠ?
1064 *
1065 * @param all 選択済みとして処ç�?�™るかどã�?�‹[true:全件選択済み/false:通常]
1066 */
1067 public void setSelectedAll( final String all ) {
1068 selectedAll = nval( getRequestParameter( all ),selectedAll );
1069 }
1070
1071 /**
1072 * æŒ?®šã?行番号の、カラãƒ?o配å?(int[])に対応したå?の配å?を返しますã?
1073 *
1074 * 表示ãƒ??タの HybsSystem.ROW_SEL_KEY をå?にã€?�¸ばれた 行を
1075 * 処ç�??対象としますã?
1076 *
1077 * @og.rev 4.2.0.1 (2008/03/27) row と clm をå?れ替えますã?(他とあわせまã�?
1078 *
1079 * @param row 行番号
1080 * @param clmNo カラãƒ?o配å?
1081 *
1082 * @return 行番号とカラãƒ?o配å?に対応したã?値の配å?
1083 */
1084 // private String[] getTableModelData( final int[] clmNo, final int row ) {
1085 private String[] getTableModelData( final int row, final int[] clmNo ) {
1086 String[] values = new String[clmNo.length];
1087 for( int i = 0; i < values.length; i++ ) {
1088 values[i] = table.getValue( row, clmNo[i] );
1089 }
1090 return values;
1091 }
1092
1093 /**
1094 * æŒ?®šã?行番号の、カラãƒ?o配å?(int[])に対応したカラãƒ?��の配å?を返しますã?
1095 *
1096 * @og.rev 4.3.1.1 (2008/08/23) å»?¢
1097 *
1098 * @param clmNo カラãƒ?o配å?
1099 *
1100 * @return String[] カラãƒ?o配å?に対応したã?カラãƒ?��の配å?
1101 */
1102 // private String[] getTableModelClm( final int[] clmNo ) {
1103 // String[] clm = new String[clmNo.length];
1104 // for( int i = 0; i < clm.length; i++ ) {
1105 // clm[i] = table.getColumnName( clmNo[i] );
1106 // }
1107 // return clm;
1108 // }
1109
1110 /**
1111 * カラãƒ?o配å?(int[])に対応したカラãƒ?��のメãƒ?‚»ージリソースæ–?—å?を返しますã?
1112 *
1113 * @og.rev 4.3.1.1 (2008/08/23) ErrMessageManager å†?ƒ¨クラスへ移å‹?
1114 *
1115 * @param clmNo カラãƒ?o配å?
1116 *
1117 * @return カラãƒ?o配å?に対応したã?カラãƒ?��のメãƒ?‚»ージリソース
1118 */
1119 // private String getKeysLabel( final int[] clmNo ) {
1120 // ResourceManager resource = getResource();
1121 //
1122 // StringBuilder buf = new StringBuilder();
1123 // if( clmNo.length > 0 ) {
1124 // String key = table.getColumnName( clmNo[0] );
1125 // buf.append( resource.getLabel( key ) );
1126 // for( int i=1; i<clmNo.length; i++ ) {
1127 // key = table.getColumnName( clmNo[i] );
1128 // buf.append( "," ).append( resource.getLabel( key ) );
1129 // }
1130 // }
1131 //
1132 // return buf.toString();
1133 // }
1134
1135 /**
1136 * エラーメãƒ?‚»ージの前後に処ç�?�™るJSPをインクルードしますã?
1137 *
1138 * @og.rev 5.1.9.0 (2010/08/01) 新規作æ?
1139 *
1140 * @param jsp JSP�
1141 */
1142 private void includeJsp( final String jsp ) {
1143 try {
1144 pageContext.include( jsp, false );
1145 } catch ( IOException ex ) {
1146 String errMsg = jsp + " の include に失敗しましたã€?";
1147 throw new HybsSystemException( errMsg,ex );
1148 } catch ( ServletException ex ) {
1149 String errMsg = jsp + " の include に失敗しましたã€?";
1150 throw new HybsSystemException( errMsg,ex );
1151 }
1152 }
1153
1154 /**
1155 * 表示ãƒ??タの HybsSystem.ROW_SEL_KEY をå?にã€?�¸ばれた 行を処ç�??対象としますã?
1156 *
1157 * <del>rowNo[] ã�?null の場合ã?み、取込を行いますã?</del>
1158 *
1159 * @og.rev 5.1.9.0 (2010/08/01) 新規追åŠ?
1160 *
1161 * @return 選択行ã?配å?
1162 */
1163 @Override
1164 protected int[] getParameterRows() {
1165 final int[] rowNo ;
1166 if( selectedAll ) {
1167 int rowCnt = table.getRowCount();
1168 rowNo = new int[ rowCnt ];
1169 for( int i=0; i<rowCnt; i++ ) {
1170 rowNo[i] = i;
1171 }
1172 } else {
1173 rowNo = super.getParameterRows();
1174 }
1175 return rowNo ;
1176 }
1177
1178 /**
1179 * ErrMessage を管ç�?�—てã�?‚‹ メソãƒ?ƒ‰é›?´?ž‹å†?ƒ¨クラス
1180 *
1181 * 繰返し処ç�?ƒ¨と、固定部が混在したエラーメãƒ?‚»ージで、固定部をå?に処ç�?�—ã€?
1182 * 繰返し部は、å¿?¦�時に処ç�?�™るよã�?�«しましたã€?
1183 * またã?実際にエラーが発生してå¿?¦�になるまで、実行遅延させますã?
1184 *
1185 * @og.rev 4.2.1.0 (2008/04/11) 新規追åŠ?
1186 * @og.rev 4.3.0.0 (2008/07/24) クラス宣è¨?‚’staticåŒ?
1187 */
1188 private static final class ErrMessageManager {
1189 // 引数として初期設定される変数
1190 private String title = null;
1191 private String from = null;
1192 private String[] msgKeys = null;
1193 private ResourceManager resource = null;
1194 private DBTableModel table = null;
1195 private int[] clmNo = null;
1196
1197 // å†?ƒ¨引数として処ç�?�•れたキャãƒ?‚·ュ値
1198 private ErrorMessage errMessage = null;
1199 private String names = null;
1200 private String fromLbl = null;
1201 private String[] msgVals = null;
1202
1203 private boolean isFirst = true; // 初期化されてã�?�ªã�?true
1204
1205 /**
1206 * ErrMessage のタイトルを設定しますã?
1207 *
1208 * @param title タイトル
1209 */
1210 public void setTitle( final String title ) { this.title = title; }
1211
1212 /**
1213 * 処ç�?¯¾象のãƒ??ブル名を設定しますã?
1214 *
1215 * @param from ãƒ??ブルå�?
1216 */
1217 public void setFrom( final String from ) { this.from = from; }
1218
1219 /**
1220 * 処ç�?¯¾象のãƒ??ブルオブジェクトを設定しますã?
1221 *
1222 * @param table DBTableModelオブジェクãƒ?
1223 */
1224 public void setDBTableModel( final DBTableModel table ) { this.table = table; }
1225
1226 /**
1227 * ResourceManagerオブジェクトを設定しますã?
1228 *
1229 * @param resource ResourceManagerオブジェクãƒ?
1230 */
1231 public void setResourceManager( final ResourceManager resource ) { this.resource = resource; }
1232
1233 /**
1234 * msgParamKeys 属æ?の配å?を設定しますã?
1235 *
1236 * @param msgKeys 属æ?の配å?
1237 */
1238 public void setParamKeys( final String[] msgKeys ) { this.msgKeys = msgKeys; }
1239
1240 /**
1241 * カラãƒ?��列を設定しますã?
1242 *
1243 * @param clmNo カラãƒ?��
1244 */
1245 public void setClmNos( final int[] clmNo ) { this.clmNo = clmNo ; }
1246
1247 /**
1248 * 初期処ç�?‚’行いますã?
1249 * エラー処ç�??、エラー時ã?み実行する為、å¿?¦�ã?なã�??合ã?、å?ç�?�Œ不要ですã?
1250 * æœ??のエラー出力までは、å?部オブジェクトã?構築å?ç�?‚’行いませんã€?
1251 * ?’回目以降ã?、å?部変数にキャãƒ?‚·ュされた変換値を利用してã€?«˜é?化しますã?
1252 *
1253 * @og.rev 4.2.3.2 (2008/06/20) from がã?null ならã?なにもしなã�??
1254 */
1255 private void firstExecute() {
1256 errMessage = new ErrorMessage( title );
1257
1258 // ãƒ??ブル(from) をキーにラベルリソースから値を取得しますã?
1259 // 4.2.3.2 (2008/06/20) from がã?null ならã?なにもしなã�??
1260 if( from != null ) {
1261 fromLbl = resource.getLabel( from );
1262 }
1263
1264 // カラãƒ?•ª号配å?から、カラãƒ?��のラベルリソースæƒ??のCSVæ–?—å?を作æ?しますã?
1265 names = getKeysLabel( clmNo );
1266
1267 if( msgKeys != null && msgKeys.length > 0 ) {
1268 int size = msgKeys.length;
1269 msgVals = new String[size] ;
1270
1271 for( int i=0; i<size; i++ ) {
1272 String key = msgKeys[i] ;
1273 if( key != null ) {
1274 if( "@KEY".equals( key ) ) { msgVals[i] = names; }
1275 else if( "@TBL".equals( key ) ) { msgVals[i] = fromLbl;}
1276 else if( key.startsWith( "{#" ) && key.endsWith( "}" ) ) {
1277 msgVals[i] = resource.getLabel( key.substring( 2,key.length()-1 ));
1278 }
1279 else {
1280 msgVals[i] = key;
1281 }
1282 }
1283 }
1284 }
1285 }
1286
1287 /**
1288 * カラãƒ?o配å?(int[])に対応したカラãƒ?��のメãƒ?‚»ージリソースæ–?—å?を返しますã?
1289 *
1290 * @param clmNo カラãƒ?o配å?
1291 * @return カラãƒ?o配å?に対応したã?カラãƒ?��のメãƒ?‚»ージリソース
1292 */
1293 private String getKeysLabel( final int[] clmNo ) {
1294 StringBuilder buf = new StringBuilder();
1295 if( table != null && clmNo.length > 0 ) {
1296 String key = table.getColumnName( clmNo[0] );
1297 buf.append( resource.getLabel( key ) );
1298 for( int i=1; i<clmNo.length; i++ ) {
1299 key = table.getColumnName( clmNo[i] );
1300 buf.append( "," ).append( resource.getLabel( key ) );
1301 }
1302 }
1303
1304 return buf.toString();
1305 }
1306
1307 /**
1308 * カラãƒ?��列を設定しますã?
1309 *
1310 * @og.rev 4.3.5.7 (2008/03/22) エラーメãƒ?‚»ージの行番号を実際の行番号とä¸??させるã?
1311 *
1312 * @param row カラãƒ?��
1313 * @param id カラãƒ?��
1314 * @param values æŒ?®šã?行に対する値
1315 */
1316 public void addMessage( final int row, final String id, final String[] values ) {
1317 if( isFirst ) { firstExecute(); isFirst = false; }
1318
1319 String vals = StringUtil.array2csv( values );
1320 if( msgVals == null ) {
1321 // errMessage.addMessage( row, ErrorMessage.NG, id, names, vals, fromLbl );
1322 errMessage.addMessage( row + 1, ErrorMessage.NG, id, names, vals, fromLbl );
1323 }
1324 else {
1325 int size = msgKeys.length;
1326 String[] args = new String[size] ;
1327
1328 for( int i=0; i<size; i++ ) {
1329 String key = msgVals[i] ;
1330 if( key != null ) {
1331 if( "@VAL".equals( key ) ) { args[i] = vals; }
1332 else if( key.startsWith( "[" ) && key.endsWith( "]" ) ) {
1333 if( table != null ) {
1334 args[i] = table.getValue( row,key.substring( 1,key.length()-1 ) );
1335 }
1336 }
1337 else {
1338 args[i] = key;
1339 }
1340 }
1341 }
1342 // errMessage.addMessage( row, ErrorMessage.NG, id, args );
1343 errMessage.addMessage( row + 1, ErrorMessage.NG, id, args );
1344 }
1345 }
1346
1347 /**
1348 * ErrorMessageオブジェクトを返しますã?
1349 *
1350 * @return ErrorMessage オブジェクãƒ?
1351 */
1352 public ErrorMessage getErrMessage() { return errMessage; }
1353 }
1354
1355 /**
1356 * シリアライズ用のカスタãƒ?‚·リアライズ書き込みメソãƒ?ƒ‰
1357 *
1358 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
1359 * @serialData
1360 *
1361 * @param strm ObjectOutputStreamオブジェクãƒ?
1362 */
1363 private void writeObject( final ObjectOutputStream strm ) throws IOException {
1364 strm.defaultWriteObject();
1365 }
1366
1367 /**
1368 * シリアライズ用のカスタãƒ?‚·リアライズ読み込みメソãƒ?ƒ‰
1369 *
1370 * ここでは、transient 宣è¨?�•れたå†?ƒ¨変数のå†??初期化がå¿?¦�なフィールドã?み設定しますã?
1371 *
1372 * @og.rev 4.0.0.0 (2006/09/31) 新規追åŠ?
1373 * @serialData
1374 *
1375 * @param strm ObjectInputStreamオブジェクãƒ?
1376 * @see #release2()
1377 */
1378 private void readObject( final ObjectInputStream strm ) throws IOException, ClassNotFoundException {
1379 strm.defaultReadObject();
1380 }
1381
1382 /**
1383 * こã?オブジェクトã?æ–?—å?表現を返しますã?
1384 * 基本çš?�«ãƒ?ƒ�ãƒ?‚°目çš?�«使用しますã?
1385 *
1386 * @return こã?クラスのæ–?—å?表現
1387 */
1388 @Override
1389 public String toString() {
1390 return org.opengion.fukurou.util.ToString.title(this.getClass().getName() )
1391 .println( "VERSION", VERSION )
1392 .println( "tableId", tableId )
1393 .println( "dbid", dbid )
1394 .println( "command", command )
1395 .println( "exist", exist )
1396 .println( "msg", msg )
1397 .println( "Other...", getAttributes().getAttribute() ).fixForm().toString();
1398 }
1399 }