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