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