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 */
016package org.opengion.hayabusa.taglib;
017
018import java.util.Arrays;
019import java.util.Enumeration;
020import java.util.Locale;
021import java.util.Set;
022import java.util.TreeSet;
023
024import org.opengion.fukurou.util.ErrorMessage;
025import org.opengion.fukurou.util.StringUtil;
026import org.opengion.hayabusa.common.HybsSystem;
027import org.opengion.hayabusa.common.HybsSystemException;
028import org.opengion.hayabusa.db.DBColumn;
029import org.opengion.hayabusa.db.DBTableModel;
030import org.opengion.hayabusa.resource.ResourceManager;                  // 6.4.0.2 (2015/12/11)
031import org.opengion.fukurou.util.ToString;                                              // 6.1.1.0 (2015/01/17)
032import static org.opengion.fukurou.util.StringUtil.nval;
033
034/**
035 * 登録データの物理チェック(整合性チェック、nullチェック)を行うタグです。
036 *
037 * コマンドに対応したチェック方式で、指定のカラムをチェックします。
038 * command="NEW" の場合は、columns 引数にCSV形式で指定したカラム名より
039 * リクエスト情報を取得して、値をチェックします。
040 * 引数チェックでは、"%" や "_" などのあいまい検索時に指定する記号を
041 * 含むとエラーになるカラムはチェック対象からはずす必要がある為、
042 * チェックすべきカラムを指定する必要があります。
043 * command="ENTRY" の場合は、columns 引数に無関係に、全てのリクエストされたカラム
044 * の値をチェックします。これは、先の検索時の場合と異なり、ENTRYでは
045 * データベースに値を設定する為、無条件にチェックする必要があります。
046 * nullCheck は、command に無関係に指定のカラムが null (ゼロ文字列)かどうかを
047 * 判定します。
048 * maxRowCount は、一覧検索時のチェックされた件数が、指定の値を超えた場合に
049 * エラーになります。minRowCount は、同様に、最小選択件数(設定値を含む)の指定です。
050 * このタグは、エラー時には、それ以降のJSP画面を評価しません。BODY 部に記述された
051 * 値は、エラー時のみ表示され、正常時には、なにも表示されません。これは、エラー時の
052 * メッセージや、ユーザーにエラー時のアクションを行ってもらう場合の処理(例えば、
053 * 画面を戻る為のボタンなど)を表示させます。
054 * useColumnLabel を true にセットすると、エラー時のカラム名(ラベル)を、カラムオブジェクトから
055 * 取得するようになります。動的カラム実行時や、DBTableModelに対して、ColumnEditor等で
056 * ラベルを書き換えた場合に、有効です。false の場合は、基本的にはラベルリソースからの
057 * 取得になりますが、ケースによっては、カラムオブジェクトから取得している場合もあります。
058 * この属性は、互換性を重視し、初期値が、false になっています。
059 *
060 * command="MODIFY" , "DELETE" 時には、強制的に、minRowCount="1" で処理します。
061 *
062 * @og.formSample
063 * ●形式:<og:columnCheck command = "…" />
064 * ●形式:<og:columnCheck command = "…" >エラー時のみ処理 </og:columnCheck>
065 * ●body:なし/あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します)
066 *
067 * ●Tag定義:
068 *   <og:columnCheck
069 *       command            【TAG】コマンド[NEW/RENEW/ENTRY]をセットします(初期値:NEW)
070 *       columns            【TAG】チェックすべきカラム列をCSV形式(CSV形式)で指定します
071 *       nullCheck          【TAG】NULL チェックすべきカラム列をカンマ区切(CSV形式)りで指定します
072 *       mustAnyCheck       【TAG】選択必須カラム(指定のカラムの内最低ひとつがNULLでない)を"AA|BB|CC,XX|YY|ZZ" 形式で指定します
073 *       checkType          【TAG】チェック対象のデータ[AUTO/NEW/ENTRY]を指定します(初期値:AUTO)
074 *       maxRowCount        【TAG】ENTRY時にチェックで選択された行数の最大値を設定します
075 *       minRowCount        【TAG】ENTRY時にチェックで選択された行数の最小値を設定します
076 *       tableId            【TAG】(通常は使いません) sessionに登録されている DBTableModel を取り出すキーを指定します
077 *       matchKeys          【TAG】正規表現でのマッチングを行うカラム列をCSV形式(CSV形式)で指定します
078 *       matchVals          【TAG】正規表現でのマッチングを行うカラム列に対する値(正規表現)をCSV形式(CSV形式)で指定します
079 *       realTime           【TAG】(通常は使いません)リアルタイムチェックを行う場合に有効にします(初期値:false)
080 *       useStrict          【TAG】NEWの場合に、厳密にチェックするかどうか[true/false]を指定します(初期値:false)
081 *       useColumnLabel     【TAG】カラムラベルを使用するかどうか[true/false]を指定します(初期値:false)
082 *       checkNames         【TAG】リクエスト変数の正規化を行うカラムをCSV形式で複数指定します
083 *       caseKey            【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null)
084 *       caseVal            【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null)
085 *       caseNN             【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:判定しない)
086 *       caseNull           【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:判定しない)
087 *       caseIf             【TAG】指定の値が、true/TRUE文字列の場合は、このタグは使用されます(初期値:判定しない)
088 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
089 *   >   ... Body ...
090 *   </og:columnCheck>
091 *
092 * ●使用例
093 * <og:columnCheck
094 *     command = "{@command}"
095 *     columns = "AAA,BBB,CCC"  DB定義(DBColumnリソース)で定義した項目(桁数,タイプ等)でチェックします。
096 *     maxRowCount = "1"        チェックで選ばれた 最大選択件数(設定値を含む)を指定。
097 *     minRowCount = "1"        チェックで選ばれた 最小選択件数(設定値を含む)を指定。
098 *     nullCheck = "AAA,CCC"    NULLチェックを実行します。
099 * />
100 *
101 * [エラー時に、BODY部に記述された内容を出力する。正常時には、このBODY部の記述は出力されません。]
102 * <og:columnCheck
103 *     command = "{@command}"
104 *     columns = "AAA,BBB,CCC"      DB定義(DBColumnリソース)で定義した項目(桁数,タイプ等)でチェックします。
105 *     nullCheck = "AAA,CCC"        NULLチェックを実行します。
106 * >
107 *     <form method="POST" action="forward.jsp" target="RESULT">
108 *         <og:input type="button" onClick="history.back()" msg="MSG0049" accesskey="R" td="false" />
109 *     </form>
110 * </og:columnCheck>
111 *
112 * mustAnyCheck 属性に、選択必須カラムを指定します。
113 *      例:mustAnyCheck="AA|BB|CC"
114 *          AA,BB,CC のカラムで選択必須(すべてがnullならエラー)
115 *      例:mustAnyCheck="AA|BB|CC,XX|YY|ZZ"
116 *          AA,BB,CC のセットと、XX,YY,ZZのセットでそれぞれ選択必須。
117 *      例:mustAnyCheck="AA|XX,AA|YY,AA|ZZ"
118 *          AA に値があればすべて成立。そうでない場合は、XX と YY と ZZ がすべて必須。
119 *      例:mustAnyCheck="AA|BB,BB|CC,AA|CC"
120 *          AA,BB,CC の内、どれか2つが必須。AAが成立すればBBかCCが必須。同様に、
121 *          BBが成立すれば、AAかCCが必須。
122 *
123 *  例:query.jsp
124 *        <og:column name="AA" mustAny="true" />
125 *        <og:column name="BB" mustAny="true" />
126 *        <og:column name="XX" mustAny="XYZ"  />
127 *        <og:column name="YY" mustAny="XYZ"  />
128 *      result.jsp
129 *        <og:columnCheck mustAnyCheck="AA|BB,XX|YY" />
130 *      custom/custom.css
131 *          .XYZ { background-color: Green; }
132 *
133 *  例:動的カラムで、entry.jsp でのチェックを行う場合。
134 *     entry.jsp
135 *        <og:columnCheck command="NEW" columns="*" useColumnLabel="true" />
136 *
137 *     useColumnLabel で、動的に作成されたカラム(SAVE=TRUEでキャッシュ済み)を使って
138 *     チェックします。command="NEW" なので、対象カラムを指定するのに、"*" ですべてを選択します。
139 *
140 * @og.group 画面登録
141 *
142 * @version  4.0
143 * @author   Kazuhiko Hasegawa
144 * @since    JDK5.0,
145 */
146public class ColumnCheckTag extends CommonTagSupport {
147        /** このプログラムのVERSION文字列を設定します。   {@value} */
148        private static final String VERSION = "6.9.3.1 (2018/04/02)" ;
149        private static final long serialVersionUID = 693120180402L ;
150
151        /** command 引数に渡す事の出来る コマンド  新規 {@value} */
152        public static final String CMD_NEW      = "NEW" ;
153        /** command 引数に渡す事の出来る コマンド  再検索 {@value}  */
154        public static final String CMD_RENEW = "RENEW" ;
155        /** command 引数に渡す事の出来る コマンド  エントリー {@value} */
156        public static final String CMD_ENTRY   = "ENTRY" ;
157        /** command 引数に渡す事の出来る コマンド リスト  */
158
159        // 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
160        // 4.3.1.1 (2008/08/23) transient 追加
161
162        private String          tableId         = HybsSystem.TBL_MDL_KEY;               // 3.5.4.3 (2004/01/05)
163        private String          command         = CMD_NEW;      // 無指定時は、チェックを行う。
164        private String[]        columns         ;
165        private String[]        nullCheck       ;
166        private String[]        mustAnyCheck;                   // 3.8.0.9 (2005/10/17)
167        private int                     maxRowCount     = -1 ;          // 初期値として,無制限を指定
168        private int                     minRowCount     = -1 ;          // 初期値として,無制限を指定
169        private String          checkType       = "AUTO";
170        private String          bodyString      ;                       // 3.5.4.2 (2003/12/15)
171        private String[]        matchKeys       ;                       // 4.0.0 (2005/11/30)
172        private String[]        matchVals       ;                       // 4.0.0 (2005/11/30)
173        private boolean         isRealTime      ;                       // 4.3.7.0 (2009/06/01)
174        private boolean         isStrict        ;                       // 5.2.2.0 (2010/11/01) NEWの場合に、厳密にチェックするフラグを追加
175
176        private boolean         isColumnLabel;                  // 5.4.3.4 (2012/01/12) true の場合に、カラムラベルを使用します。
177
178        private String          checkNames      ;                       // 5.4.3.8 (2012/01/24)
179
180        /**
181         * デフォルトコンストラクター
182         *
183         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
184         */
185        public ColumnCheckTag() { super(); }            // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
186
187        /**
188         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
189         *
190         * @og.rev 3.5.4.2 (2003/12/15) エラー時に、BODY部に記述された内容を出力する。
191         * @og.rev 5.0.0.2 (2009/09/15) xss対応⇒チェックする
192         * @og.rev 5.7.8.0 (2014/07/04) caseKey,caseVal,caseNN,caseNull 属性を追加
193         *
194         * @return      後続処理の指示( EVAL_BODY_BUFFERED )
195         */
196        @Override
197        public int doStartTag() {
198                // 5.0.0.2 (2009/09/15) XSSチェックしない⇒する
199                // useXssCheck( false );
200
201                // 5.7.8.0 (2014/07/04) 追加
202                return useTag() ? EVAL_BODY_BUFFERED : SKIP_BODY ;
203        }
204
205        /**
206         * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。
207         *
208         * @og.rev 3.5.4.2 (2003/12/15) エラー時に、BODY部に記述された内容を出力する。
209         *
210         * @return      後続処理の指示(SKIP_BODY)
211         */
212        @Override
213        public int doAfterBody() {
214                bodyString = getBodyString();
215
216                return SKIP_BODY ;
217        }
218
219        /**
220         * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。
221         *
222         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
223         * @og.rev 3.4.0.3 (2003/09/10) command="NEW" でエラー発生時には、DBTableModel をクリアする。
224         * @og.rev 3.5.4.2 (2003/12/15) HTMLTableViewForm クラス名変更(⇒ ViewForm_HTMLTable)
225         * @og.rev 3.5.4.2 (2003/12/15) エラー時に、BODY部に記述された内容を出力する。
226         * @og.rev 3.5.4.3 (2004/01/05) tableId 属性を追加。
227         * @og.rev 3.5.4.4 (2004/01/16) エラー結果を表示するテーブル形式のフォーム修正
228         * @og.rev 3.5.5.2 (2004/04/02) TaglibUtil.makeHTMLErrorTable メソッドを利用
229         * @og.rev 4.1.2.1 (2008/03/13) table 属性を追加。
230         * @og.rev 4.3.3.0 (2008/10/01) viewSimple属性追加
231         * @og.rev 4.3.7.0 (2009/06/01) viewSimple属性名称変更 ⇒ isRealTime
232         * @og.rev 5.6.8.3 (2013/09/27) checkTypeがAutoの場合のセットをここで行い、tableModelチェックをcheckTypeで行う。
233         * @og.rev 5.7.8.0 (2014/07/04) caseKey,caseVal,caseNN,caseNull 属性を追加
234         * @og.rev 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
235         *
236         * @return      後続処理の指示
237         */
238        @Override
239        public int doEndTag() {
240                debugPrint();           // 4.0.0 (2005/02/28)
241
242                // 5.7.8.0 (2014/07/04) caseKey,caseVal,caseNN,caseNull 属性を追加
243                if( !useTag() ) { return EVAL_PAGE ; }          // ページの残りを評価する。
244
245                int rtnCode = EVAL_PAGE;
246
247                // 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
248
249                // 5.6.8.3 (2013/09/27) チェックタイプのautoを入れる位置変更
250                if( "AUTO".equals( checkType ) ) { checkType = command; }
251
252                // 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
253                        // 3.5.5.2 (2004/04/02) TaglibUtil.makeHTMLErrorTable メソッドを利用
254                        final ErrorMessage errMsg = makeErrorDBTable();
255                        if( errMsg.getKekka() >= ErrorMessage.NG ) {
256                                if( bodyString != null ) { jspPrint( bodyString ); }    // 3.5.4.2 (2003/12/15)
257
258                                // 4.3.3.0 (2008/10/01)
259                                // 4.3.7.0 (2009/06/01)
260                                if( isRealTime ) { jspPrint( TaglibUtil.makeHTMLSimpleErrorList( errMsg, getResource() ) ); }
261                                else {             jspPrint( TaglibUtil.makeHTMLErrorTable(      errMsg, getResource() ) ); }
262
263                                if( CMD_NEW.equals( command ) ) {
264                                        removeObject( tableId );
265                                }
266                                rtnCode = SKIP_PAGE ;
267                        }
268                        else if( errMsg.getKekka() == ErrorMessage.WARNING ) {
269                                // 4.3.3.0 (2008/10/01)
270                                // 4.3.7.0 (2009/06/01)
271                                if( isRealTime ) { jspPrint( TaglibUtil.makeHTMLSimpleErrorList( errMsg, getResource() ) ); }
272                                else {             jspPrint( TaglibUtil.makeHTMLErrorTable(      errMsg, getResource() ) ); }
273                        }
274
275                return rtnCode ;
276        }
277
278        /**
279         * タグリブオブジェクトをリリースします。
280         *
281         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
282         *
283         * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加
284         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
285         * @og.rev 3.5.4.2 (2003/12/15) エラー時に、BODY部に記述された内容を出力する。
286         * @og.rev 3.5.4.3 (2004/01/05) tableId 属性を追加。
287         * @og.rev 3.8.0.9 (2005/10/17) mustAnyCheck 属性を追加。
288         * @og.rev 4.1.2.1 (2008/03/13) table 属性を追加。
289         * @og.rev 4.3.3.0 (2008/10/01) viewSimple属性追加
290         * @og.rev 4.3.7.0 (2009/06/01) viewSimple属性名称変更 ⇒ isRealTime
291         * @og.rev 5.2.2.0 (2010/11/01) NEWの場合に、厳密にチェックするフラグを追加
292         * @og.rev 5.4.3.4 (2012/01/12) isColumnLabelを追加
293         * @og.rev 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
294         */
295        @Override
296        protected void release2() {
297                super.release2();
298                command         = CMD_NEW;      // 無指定時は、チェックを行う。
299                columns         = null;
300                nullCheck       = null;
301                maxRowCount     = -1 ;          // 初期値として,無制限を指定
302                minRowCount     = -1 ;          // 初期値として,無制限を指定
303                checkType       = "AUTO";
304                bodyString      = null ;        // 3.5.4.2 (2003/12/15)
305                tableId         = HybsSystem.TBL_MDL_KEY;               // 3.5.4.3 (2004/01/05)
306                mustAnyCheck= null;             // 3.8.0.9 (2005/10/17)
307                matchKeys       = null;         // 4.0.0 (2005/11/30)
308                matchVals       = null;         // 4.0.0 (2005/11/30)
309                isRealTime      = false;        // 4.3.7.0 (2009/06/01)
310                isStrict        = false;        // 5.2.2.0 (2010/11/01) NEWの場合に、厳密にチェックするフラグを追加
311                isColumnLabel= false;   // 5.4.3.4 (2012/01/12) true の場合に、カラムラベルを使用します。
312                checkNames      = null;         // 5.4.3.8 (2012/01/24)
313        }
314
315        /**
316         * DBColumn オブジェクトを作成して、DBColumn#valueCheck( String )で
317         * チェックを行う。その結果の、ErrorMessage オブジェクトを DBTableModel に
318         * 取り込んで、エラーの場合は、その表示を行う。
319         * 表示方法は、そのまま ViewForm オブジェクトを作成して、表示を行う。
320         *
321         * @og.rev 3.5.5.2 (2004/04/02) リターン値を、DBTableModel から ErrorMessage に変更
322         * @og.rev 4.0.0.0 (2005/01/31) リターン値の ErrorMessage は、必ず存在する。
323         * @og.rev 4.1.2.1 (2008/03/13) command="MODIFY" , "DELETE" 時には、強制的に、minRowCount="1" で処理します。
324         * @og.rev 5.6.8.3 (2013/09/27) checkTypeのAuto時設定位置をdoEndTagでするように変更
325         *
326         * @return      エラーメッセージのテーブルモデル
327         * @og.rtnNotNull
328         */
329        private ErrorMessage makeErrorDBTable() {
330                ErrorMessage errMsg = new ErrorMessage();
331
332                //if( "AUTO".equals( checkType ) ) { checkType = command; } // 5.6.8.3 (2013/09/27) move
333                if( CMD_ENTRY.equals( checkType ) ) {
334                        errMsg.setTitle( "Request Column Error!" );
335                        errMsg = makeEntryErrorMessage( errMsg );
336                        errMsg = makeMaxRowCountErrorMessage( errMsg );
337                        errMsg = makeMinRowCountErrorMessage( errMsg );
338                }
339                else if( CMD_NEW.equals( checkType ) ) {
340                        errMsg.setTitle( "Entry Column Error!" );
341                        errMsg = makeErrorMessage( errMsg );
342                        errMsg = makeMaxRowCountErrorMessage( errMsg );
343                        errMsg = makeMinRowCountErrorMessage( errMsg );
344                }
345                else if( minRowCount >= 0 || maxRowCount >= 0) {        // -1 は制限無し
346                        errMsg.setTitle( "Row Count Error Limited Error!" );
347                        errMsg = makeMaxRowCountErrorMessage( errMsg );
348                        errMsg = makeMinRowCountErrorMessage( errMsg );
349                }
350                // 4.1.2.1 (2008/03/13) command="MODIFY" , "DELETE" 時には、強制的に、minRowCount="1" で処理します。
351                // 6.3.9.0 (2015/11/06) 条件は効果がない(findbugs)
352                else if( "MODIFY,DELETE".indexOf( checkType ) >= 0 ) {
353                        minRowCount = 1;
354                        errMsg = makeMinRowCountErrorMessage( errMsg );
355                }
356                return errMsg;
357        }
358
359        /**
360         * ErrorMessageをセットします。
361         * 引数のカラム名配列よりリクエスト情報を取得して、値をチェックします。
362         * DBColumn#valueCheck( String ) の結果のErrorMessageをすべて append
363         * していきます。
364         *
365         * @og.rev 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加
366         * @og.rev 3.8.1.0 (2005/10/24) リクエスト情報の正規化変換(DBColumn#valueSet(String))中止
367         * @og.rev 3.8.5.3 (2006/06/30) リクエストに % , _ が含まれたときは、削除します。
368         * @og.rev 4.1.2.1 (2008/03/13) must , mustAny の自動取得追加
369         * @og.rev 5.0.0.2 (2009/09/15) 個別にxssチェックをfalse
370         * @og.rev 5.1.9.0 (2010/08/01) 同じ名前の項目は、1つにまとめる(ラジオボタン等)
371         * @og.rev 5.2.0.0 (2010/09/01) リアルタイムチェックの場合は、must,mustAnyの自動チェックは行わない
372         * @og.rev 5.2.2.0 (2010/11/01) DBColumn#valueCheck で、甘いチェックを行うように、引数に isStrict を追加
373         * @og.rev 5.4.3.4 (2012/01/12) getLabel( String )を、リソースからに統一するとともに、isColumnLabel 対応を行う。
374         * @og.rev 5.4.3.8 (2012/01/28) checkNames対応
375         * @og.rev 6.4.0.2 (2015/12/11) ResourceManagerの取得を、先に行っておく。
376         * @og.rev 6.8.4.2 (2017/12/25) カラムチェックで、#valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
377         *
378         * @param       errMsg  ErrorMessageオブジェクト
379         *
380         * @return      カラムキー + 値 のエラーメッセージオブジェクト
381         */
382        private ErrorMessage makeErrorMessage( final ErrorMessage errMsg ) {
383
384                // 4.1.2.1 (2008/03/13) must , mustAny の自動取得追加
385                // request から取出す 注意:mustAny 以外の自由形式の値は所得していません。
386                // 5.2.0.0 (2010/09/01) リアルタイムチェックの場合は、must,mustAnyの自動チェックは行わない
387                //  (基本的にパラメーターを送らない限り自動チェックは動かないが、RequestCacheにより動くことがある)
388                if( !isRealTime ) {
389                        if( nullCheck == null ) {
390                                nullCheck = getRequestValues( HybsSystem.MUST_KEY + "must" );
391                                // 5.1.9.0 (2010/08/01) 同じ名前の項目は、1つにまとめる(ラジオボタン等)
392                                if( nullCheck != null ) {
393                                        final Set<String> ss = new TreeSet<>();
394                                        ss.addAll( Arrays.asList( nullCheck ) );
395                                        nullCheck = ss.toArray( new String[ss.size()] );                // 5.1.9.0 (2010/08/01) K.H
396                                }
397                        }
398                        if( mustAnyCheck == null ) {
399                                final String[] mustAnyReq = getRequestValues( HybsSystem.MUST_KEY + "mustAny" );
400                                if( mustAnyReq != null && mustAnyReq.length > 0 ) {
401                                        mustAnyCheck = new String[] { StringUtil.array2line( mustAnyReq,"|" ) };
402                                }
403                        }
404                }
405
406                // 6.4.0.2 (2015/12/11) ResourceManagerの取得を、先に行っておく。
407                final ResourceManager resource = getResource();
408
409                if( nullCheck != null && nullCheck.length != 0 ) {
410                        for( int i=0; i<nullCheck.length; i++ ) {
411                                final String clmKey = nullCheck[i];             // 5.4.3.4 (2012/01/12)
412                                // String val  = getRequestValue( nullCheck[i] );
413                                final String val  = getRequestValue( clmKey, false ); // 5.0.0.2 (2009/09/15)
414                                if( val == null || val.isEmpty() ) {
415                                        // 5.4.3.4 (2012/01/12) isColumnLabel 追加
416                                        final String label = isColumnLabel ? getDBColumn( clmKey ).getLabel() : resource.getLabel( clmKey );
417                                        // ERR0012 : 指定のデータがセットされていません。(NULLエラー)。key={0}
418                                        errMsg.addMessage( 0,ErrorMessage.NG,"ERR0012",label );
419                                }
420                        }
421                }
422                // 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加
423                if( mustAnyCheck != null && mustAnyCheck.length != 0 ) {
424                        final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );           // 6.1.0.0 (2014/12/26) refactoring
425                        for( int i=0; i<mustAnyCheck.length; i++ ) {
426                                boolean flag = false;
427                                final String[] mustSub = StringUtil.csv2Array( mustAnyCheck[i],'|' );
428                                for( int j=0; j<mustSub.length; j++ ) {
429                                        // String val  = getRequestValue( mustSub[j] );
430                                        final String val  = getRequestValue( mustSub[j], false ); // 5.0.0.2 (2009/09/15)
431                                        if( val != null && val.length() > 0 ) {
432                                                flag = true; break;             // ひとつでもnullでなければ、OK
433                                        }
434                                }
435                                if( ! flag ) {
436                                        buf.setLength(0);                                                       // 6.1.0.0 (2014/12/26) refactoring
437                                        for( int j=0; j<mustSub.length; j++ ) {
438                                                final String clmKey = mustSub[j];               // 5.4.3.4 (2012/01/12)
439                                                // 5.4.3.4 (2012/01/12) isColumnLabel 追加
440                                                final String label = isColumnLabel ? getDBColumn( clmKey ).getLabel() : resource.getLabel( clmKey );
441                                                buf.append( label ).append( ',' );              // 6.0.2.5 (2014/10/31) char を append する。
442                                        }
443                                        // ERR0036 : 選択必須エラー。以下のデータの内どれかは入力してください。key={0}
444                                        errMsg.addMessage( 0,ErrorMessage.NG,"ERR0036",buf.toString() );
445                                }
446                        }
447                }
448                if( columns != null && columns.length != 0 ) {
449                        for( int i=0; i<columns.length; i++ ) {
450                                // 3.8.1.0 (2005/10/24) リクエスト情報の正規化変換(DBColumn#valueSet(String))中止
451                                // String clmVal = getRequestValue( columns[i] );
452                                String clmVal = getRequestValue( columns[i], false ); // 5.0.0.2 (2009/09/15)
453                                if( clmVal != null && clmVal.length() > 0 ) {
454                                        clmVal = StringUtil.replace( clmVal,"%","" );           // 3.8.5.3 (2006/06/30)
455                                        clmVal = StringUtil.replace( clmVal,"_","" );           // 3.8.5.3 (2006/06/30)
456                                        final DBColumn dbColumn = getDBColumn( columns[i] );
457                                        // 5.4.3.8 (2012/01/24) checkNames対応
458                                        if( ( "," + checkNames + "," ).indexOf( "," + columns[i] + "," ) >= 0 ) {
459                                                // 6.8.4.2 (2017/12/25) カラムチェックで、#valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
460                                                try {
461                                                        final String val = dbColumn.valueSet( clmVal );
462                                                        if( val != null ) { clmVal = val; }
463                                                }
464                                                catch( RuntimeException ex ) {
465                                                        // #valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
466                                                }
467                                        }
468                                        // 5.2.2.0 (2010/11/01) DBColumn#valueCheck で、甘いチェックを行うように、引数に isStrict を追加
469                                        errMsg.append( dbColumn.valueCheck( clmVal,isStrict ) );
470                                }
471                        }
472                }
473                // 4.0.0 (2005/11/30) 正規表現チェックの追加
474                // 6.9.8.0 (2018/05/28) FindBugs:コンストラクタで初期化されていないフィールドを null チェックなしで null 値を利用している
475//              if( matchKeys != null && matchKeys.length != 0 ) {
476                if( matchKeys != null && matchKeys.length > 0 && matchVals != null && matchVals.length > 0 ) {
477                        for( int i=0; i<matchKeys.length; i++ ) {
478                                final String clmKey = matchKeys[i];             // 5.4.3.4 (2012/01/12)
479                                // String val  = getRequestValue( matchKeys[i] );
480                                final String val  = getRequestValue( clmKey, false ); // 5.0.0.2 (2009/09/15)
481                                if( val != null && ! val.matches( matchVals[i] ) ) {
482                                        // 5.4.3.4 (2012/01/12) isColumnLabel 追加
483                                        final String label = isColumnLabel ? getDBColumn( clmKey ).getLabel() : resource.getLabel( clmKey );
484                                        // ERR0037 : データ整合性エラー。指定のキーは整合性チェックの結果マッチしませんでした。key={0} val={1} regex={2}
485                                        errMsg.addMessage( 0,ErrorMessage.NG,"ERR0037",label,val,matchVals[i] );
486                                }
487                        }
488                }
489
490                return errMsg;
491        }
492
493        /**
494         * エントリーデータのErrorMessageをセットします。
495         * 引数のカラム名配列よりエントリーデータ形式のリクエスト情報を取得して、
496         * 値をチェックします。
497         * DBColumn#valueCheck( String ) の結果のErrorMessageをすべて append
498         * していきます。
499         *
500         * @og.rev 3.1.0.0 (2003/03/20) 名前と行番号の区切り記号を "^" から "__" に変更。
501         * @og.rev 3.5.5.0 (2004/03/12) 名前と行番号の区切り記号("__")を、HybsSystem.JOINT_STRING  に変更。
502         * @og.rev 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加
503         * @og.rev 4.1.2.1 (2008/03/13) must , mustAny の自動取得追加
504         * @og.rev 4.3.6.4 (2009/05/01) 削除時に必ずmustAnyチェックエラーになるバグを修正(書込み可能行のみを処理する
505         * @og.rev 4.3.7.0 (2009/06/01) リアルタイムチェックの場合は、must,mustAnyの自動チェックは行わない
506         * @og.rev 5.0.0.2 (2009/09/15) xssチェック
507         * @og.rev 5.4.3.4 (2012/01/12) getLabel( String )を、リソースからに統一するとともに、isColumnLabel 対応を行う。
508         * @og.rev 6.3.9.0 (2015/11/06) コンストラクタで初期化されていないフィールドを null チェックなしで利用している(findbugs)
509         * @og.rev 6.4.0.2 (2015/12/11) ResourceManagerの取得を、先に行っておく。
510         * @og.rev 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
511         * @og.rev 6.8.4.2 (2017/12/25) カラムチェックで、#valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
512         * @og.rev 6.9.3.1 (2018/04/02) カラムチェックで、mustAnyのチェック方法改善
513         *
514         * @param       errMsg  ErrorMessageオブジェクト
515         *
516         * @return      カラムキー + 値 のエラーメッセージオブジェクト
517         */
518        private ErrorMessage makeEntryErrorMessage( final ErrorMessage errMsg ) {
519                final int[] rowNo = getParameterRows();
520                if( rowNo.length == 0 ) { return errMsg; }
521
522                // 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
523                final DBTableModel table = (DBTableModel)getObject( tableId );
524                if( table == null ) {
525                        final String errMsgStr = "検索結果のオブジェクトが存在しません。"
526                                                        + " checkType=[" + checkType + "] , tableId=[" + tableId + "]" ;
527                        throw new HybsSystemException( errMsgStr );
528                }
529
530                // 4.1.2.1 (2008/03/13) must , mustAny の自動取得追加
531                // table から取出す (ソート済み)
532                // 4.3.7.0 (2009/06/01) リアルタイムチェックの場合は、must,mustAnyの自動チェックは行わない
533                if( !isRealTime ) {
534                                if( nullCheck    == null ) { nullCheck    = table.getMustArray();        }
535                                if( mustAnyCheck == null ) { mustAnyCheck = table.getMustAnyArray(); }
536                }
537
538                // 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加
539                boolean[][] rowAnyOne = null;
540                // 4.3.6.4 (2009/05/01)
541                boolean[] rowForCheck = null;
542                if( mustAnyCheck != null && mustAnyCheck.length != 0 ) {
543                        rowAnyOne   = new boolean[rowNo.length][mustAnyCheck.length];
544                        rowForCheck = new boolean[rowNo.length];
545        //              for( int i=0; i<rowNo.length; i++ ) {
546        //                      Arrays.fill( rowAnyOne[i],false );
547        //              }
548                }
549
550                // 6.4.3.2 (2016/02/19) tableId 単位にチェックするが、互換性のため、標準の tableId の処理は、従来どおりとする。
551                final boolean useTid = ! HybsSystem.TBL_MDL_KEY.equals( tableId );              // 反転:tableId を使っている=標準のtableIdではない。
552
553                DBColumn dbColumn = null;       // 5.4.3.4 (2012/01/12) isColumnLabel 対応
554                final Enumeration<?> enume = getParameterNames();               // 4.3.3.6 (2008/11/15) Generics警告対応
555                while( enume.hasMoreElements() ) {
556                        final String key  = (String)(enume.nextElement());
557                        final int    idx  = key.lastIndexOf(HybsSystem.JOINT_STRING);
558
559                        if( idx > 0 ) {
560                                final String column = key.substring(0,idx);
561                                // 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
562                                final int clmNo = table.getColumnNo( column,false );    // エラーを出さない。
563                                if( useTid && clmNo < 0 ) { continue; }                                 // 6.4.3.2 (2016/02/19) tableId指定のテーブルのカラムに存在しない場合は、スルーする。
564
565                                final int    row    = Integer.parseInt( key.substring(idx + 2) );
566                                final String val    = getRequestValue( key, false );    // 5.0.0.2 (2009/09/15)
567
568                                final int i = Arrays.binarySearch( rowNo,row );
569                                if( i >= 0 ) {
570                                        // 5.4.3.4 (2012/01/12) isColumnLabel 対応
571                                        // 6.4.3.2 (2016/02/19) tableはnullチェック済みで、clmNoは先に求めている。
572                                        dbColumn = isColumnLabel && clmNo >= 0 ? table.getDBColumn( clmNo ) : getDBColumn( column );
573
574                                        // 6.8.4.2 (2017/12/25) カラムチェックで、#valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
575                                        String val2 = val;
576                                        try {
577                                                val2 = dbColumn.valueSet( val );
578                                        }
579                                        catch( RuntimeException ex ) {
580                                                // #valueSet(String) で、エラーが発生した場合でも、#valueCheck(String) を行うようにします。
581                                        }
582
583                                        errMsg.append( row+1,dbColumn.valueCheck( val2 ) );
584
585                                        if( nullCheck != null && nullCheck.length != 0 ) {
586                                                final int j = Arrays.binarySearch( nullCheck,column );  // 6.9.3.1 (2018/04/02) リクエストカラムが、nullCheck対象カラムの場合、正のアドレス
587                                                if( j>=0 && ( val2 == null || val2.isEmpty() )) {
588                                                        // ERR0012 : 指定のデータがセットされていません。(NULLエラー)。key={0}
589                                                        errMsg.addMessage( row+1,ErrorMessage.NG,"ERR0012",dbColumn.getLabel() );
590                                                }
591                                        }
592
593                                        // 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加 (mustAnyCheck="AA|BB|CC,XX|YY|ZZ" という形式を、カンマで分解した配列)
594                                        if( rowAnyOne != null ) {
595                                                // 6.9.3.1 (2018/04/02) データが飛んでこないかどうかの判定
596                                                for( int j=0; j<mustAnyCheck.length; j++ ) {
597                                                        if( mustAnyCheck[j].indexOf( column ) >= 0 ) {
598                                                                if( val2 == null || val2.isEmpty() ) {
599                                                                        rowForCheck[i] = true;          // (trueは、処理対象)
600                                                                }
601                                                                else {
602                                                                        rowAnyOne[i][j] = true;         // どれかが存在(trueは、処理対象外)
603                                                                }
604                                                        }
605
606//                                                      if( !rowAnyOne[i][j] &&
607//                                                              mustAnyCheck[j].indexOf( column ) >= 0 &&
608//                                                              val2 != null && val2.length() > 0 ) {
609//                                                                      rowAnyOne[i][j] = true; // どれかが存在(trueは、処理対象外)
610//                                                      }
611                                                }
612//                                              // 4.3.6.4 (2009/05/01)
613//                                              rowForCheck[i] = true;          // (trueは、処理対象)
614                                        }
615
616                                        // 4.0.0 (2005/11/30) 正規表現チェックの追加
617                                        // 6.9.8.0 (2018/05/28) FindBugs:コンストラクタで初期化されていないフィールドを null チェックなしで null 値を利用している
618//                                      if( matchKeys != null && matchKeys.length != 0 ) {
619                                        if( matchKeys != null && matchKeys.length > 0 && matchVals != null && matchVals.length > 0 ) {
620                                                for( int j=0; j<matchKeys.length; j++ ) {
621                                                        if( column.equals( matchKeys[j] ) ) {
622                                                                if( val2 != null && ! val2.matches( matchVals[j] ) ) {
623                                                                        // 互換性はなくなっているが、正規表現チェックは余り使っていないので、統一しておく。
624                                                                        // 5.4.3.4 (2012/01/12) isColumnLabel 対応
625                                                                        // 6.4.3.2 (2016/02/19) dbColumnは、先に、取得済み。
626
627                                                                        // ERR0037 : データ整合性エラー。指定のキーは整合性チェックの結果マッチしませんでした。key={0} val={1} regex={2}
628                                                                        errMsg.addMessage( row+1,ErrorMessage.NG,"ERR0037",dbColumn.getLabel(),val2,matchVals[i] );
629                                                                }
630                                                                break;          // 発見すれば、ループ終了
631                                                        }
632                                                }
633                                        }
634                                }
635                        }
636                }
637
638                // 6.4.0.2 (2015/12/11) ResourceManagerの取得を、先に行っておく。
639                final ResourceManager resource = getResource();
640
641                // 3.8.0.9 (2005/10/17) 選択必須 mustAnyCheck のチェック追加
642                if( rowAnyOne != null ) {
643                        final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE );   // 6.1.0.0 (2014/12/26) refactoring
644                        for( int row=0; row<rowAnyOne.length; row++ ) {
645                                // 4.3.6.4 (2009/05/01) 書込み可能行のみを処理する
646                                if( rowForCheck[row] ) {
647                                        for( int i=0; i<mustAnyCheck.length; i++ ) {
648                                                if( !rowAnyOne[row][i] ) {
649                                                        final String[] mustSub = StringUtil.csv2Array( mustAnyCheck[i], '|' );
650
651                                                        buf.setLength(0);                                                                                       // 6.1.0.0 (2014/12/26) refactoring
652                                                        buf.append( "row=[" ).append( rowNo[row]+1 ).append( "] " );
653                                                        for( int j=0; j<mustSub.length; j++ ) {
654                                                                // ここの処理だけ、他と異なるのは、互換性重視のため。(選択必須は利用頻度が高いので。)
655                                                                // 5.4.3.4 (2012/01/12) isColumnLabel 対応
656                                                                String label = null ;
657                                                                // 6.9.8.0 (2018/05/28) FindBugs:null でないことがわかっている値の冗長な null チェック
658//                                                              if( isColumnLabel && table != null ) {
659                                                                if( isColumnLabel ) {                                                                   // tableは、nullチェック済み
660                                                                        final int clmNo = table.getColumnNo( mustSub[j],false );        // エラーを出さない。
661                                                                        if( clmNo >= 0 ) {
662                                                                                dbColumn = table.getDBColumn( clmNo );
663                                                                        }
664                                                                        if( dbColumn == null ) {
665                                                                                dbColumn = getDBColumn( mustSub[j] );
666                                                                        }
667                                                                        label = dbColumn.getLabel();
668                                                                }
669                                                                else {
670                                                                        label = resource.getLabel( mustSub[j] );                        // 6.4.0.2 (2015/12/11) 互換性のための処置。
671                                                                }
672                                                                buf.append( label ).append( '|' );              // 6.0.2.5 (2014/10/31) char を append する。
673                                                        }
674                                                        // ERR0036 : 選択必須エラー。以下のデータの内どれかは入力してください。key={0}
675                                                        errMsg.addMessage( rowNo[row]+1, ErrorMessage.NG, "ERR0036", buf.toString() );
676                                                }
677                                        }
678                                }
679                        }
680                }
681
682                return errMsg;
683        }
684
685        /**
686         * ErrorMessageをセットします。
687         * リクエストされた件数の最大値に制限を加えます。
688         * 1件だけにしたい場合は,通常はViewでチェックボックスを使用せずに
689         * ラジオボタンを使用してください。
690         *
691         * @param       errMsg  ErrorMessageオブジェクト
692         *
693         * @return      カラムキー + 値 のエラーメッセージオブジェクト
694         */
695        private ErrorMessage makeMaxRowCountErrorMessage( final ErrorMessage errMsg ) {
696                if( maxRowCount < 0 ) { return errMsg; }        // 無制限
697
698                // 件数制限のチェック
699                final int[] rowNo = getParameterRows();
700                final int rowCount = rowNo.length ;
701                if( rowCount > maxRowCount ) {
702                        // ERR0017 : 選択エラー。選択行数({0} 件)が、最大制限値({1} 件)以上選ばれました。
703                        final String arg0 = String.valueOf( rowCount );
704                        final String arg1 = String.valueOf( maxRowCount );
705                        errMsg.addMessage( 0,ErrorMessage.NG,"ERR0017",arg0,arg1 );
706                }
707
708                return errMsg;
709        }
710
711        /**
712         * ErrorMessageをセットします。
713         * リクエストされた件数の最小値に制限を加えます。
714         * 1件だけにしたい場合は,通常はViewでチェックボックスを使用せずに
715         * ラジオボタンを使用してください。
716         *
717         * @param       errMsg  ErrorMessageオブジェクト
718         *
719         * @return      カラムキー + 値 のエラーメッセージオブジェクト
720         */
721        private ErrorMessage makeMinRowCountErrorMessage( final ErrorMessage errMsg ) {
722                if( minRowCount < 0 ) { return errMsg; }        // 無制限
723
724                // 件数制限のチェック
725                final int[] rowNo = getParameterRows();
726                final int rowCount = rowNo.length ;
727                if( rowCount < minRowCount ) {
728                        // ERR0018 : 選択エラー。選択行数({0} 件)が、最小制限値({1} 件)以下選ばれました。
729                        final String arg0 = String.valueOf( rowCount );
730                        final String arg1 = String.valueOf( minRowCount );
731                        errMsg.addMessage( 0,ErrorMessage.NG,"ERR0018",arg0,arg1 );
732                }
733
734                return errMsg;
735        }
736
737        /**
738         * 【TAG】チェックすべきカラム列をCSV形式(CSV形式)で指定します。
739         *
740         * @og.tag columns="AAA,BBB,CCC,DDD"
741         * 分解方法は、通常のパラメータ取得後に、CSV分解します。
742         * "*" を指定すると、command="NEW" のときの判定にすべてのリクエスト文字列を
743         * チェック対象とします。通常は、必要分だけ指定しますが、動的カラムなどの
744         * 場合は、カラム名を予め指定できないため、"*" で指定できるようにします。
745         * その場合、"h_" , "hX_" , maxRowCount , command , pageSize , pagePlus , debug , 
746         * GAMENID , BACK_JSPID , BACK_GAMENID の予約語は、対象から除きます。
747         *
748         * ※ 6.4.0.2 (2015/12/11)
749         *    columns="*" のときのカラムは、リクエスト変数から、上記の予約語も除きますが、
750         *    ResourceManager に存在しない(リソース未登録)カラムも除きます。
751         *
752         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
753         * @og.rev 3.8.8.5 (2007/03/09) 通常のパラメータ取得後に、CSV分解に戻します。
754         * @og.rev 5.4.3.4 (2012/01/12) command="NEW" のときの動的カラム対応( "*" ですべてのリクエスト)
755         * @og.rev 6.4.0.2 (2015/12/11) columns="*" のときのカラムは、リソースに存在する分のみとする。
756         *
757         * @param   clms カラム列(CSV形式)
758         */
759        public void setColumns( final String clms ) {
760                columns = StringUtil.csv2Array( getRequestParameter( clms ) );
761                if( columns.length == 0 ) { columns = null; }
762
763                // 5.4.3.4 (2012/01/12) command="NEW" のときの動的カラム対応( "*" ですべてのリクエスト)
764                if( columns != null && "*".equals( columns[0] ) ) {
765                        final Set<String> clmSet = new TreeSet<>();             // リクエストはバラバラなので、とりあえずソートしておきます。
766
767                        // 6.4.0.2 (2015/12/11) columns="*" のときのカラムは、リソースに存在する分のみとする。
768                        final ResourceManager resource = getResource();
769
770                        final Enumeration<?> enume = getParameterNames();               // Generics警告対応
771                        while( enume.hasMoreElements() ) {
772                                final String clm  = (String)(enume.nextElement());
773                                // 予約語以外を登録します。
774                                // 6.9.7.0 (2018/05/14) PMD These nested if statements could be combined
775//                              if( clm != null && !clm.isEmpty() && !clm.startsWith( "h_" ) && !clm.startsWith( "hX_" ) ) {
776//                                      // 6.4.0.2 (2015/12/11) columns="*" のときのカラムは、リソースに存在する分のみとする。
777//                                      if( resource.getDBColumn( clm ) != null ) {             // 存在チェックのみで使わない。
778                                if( clm != null && !clm.isEmpty() && !clm.startsWith( "h_" ) && !clm.startsWith( "hX_" )
779                                        && resource.getDBColumn( clm ) != null ) {              // 存在チェックのみで使わない。
780                                                clmSet.add( clm );
781//                                      }
782                                }
783                        }
784                        // 予約語を削除します。
785                        clmSet.remove( "maxRowCount" );
786                        clmSet.remove( "command" );
787                        clmSet.remove( "pageSize" );
788                        clmSet.remove( "pagePlus" );
789                        clmSet.remove( "debug" );                                                               // 6.4.0.2 (2015/12/11)
790                        clmSet.remove( "GAMENID" );
791                        clmSet.remove( "BACK_JSPID" );
792                        clmSet.remove( "BACK_GAMENID" );
793
794                        columns = clmSet.toArray( new String[clmSet.size()] );
795                }
796        }
797
798        /**
799         * 【TAG】NULL チェックすべきカラム列をCSV形式(CSV形式)で指定します。
800         *
801         * @og.tag
802         * (must 属性のセットにより、自動処理されます)
803         * nullCheck="AAA,BBB,CCC,DDD"
804         * 分解方法は、通常のパラメータ取得後に、CSV分解します。
805         *
806         * @og.rev 3.5.6.2 (2004/07/05) 先に配列に分解してからリクエスト変数の値を取得
807         * @og.rev 3.8.8.5 (2007/03/09) 通常のパラメータ取得後に、CSV分解に戻します。
808         *
809         * @param   clms カラム列(CSV形式)
810         */
811        public void setNullCheck( final String clms ) {
812                nullCheck = StringUtil.csv2Array( getRequestParameter( clms ) );
813                if( nullCheck.length == 0 ) { nullCheck = null; }
814                else {
815                        Arrays.sort( nullCheck );
816                }
817        }
818
819        /**
820         * 【TAG】選択必須カラム(指定のカラムの内最低ひとつがNULLでない)を"AA|BB|CC,XX|YY|ZZ" 形式で指定します。
821         *
822         * @og.tag
823         * (mustAny 属性のセットにより、自動処理されます)
824         * 複数のカラム属性の値のうち、どれかが null でない場合は正常とし、
825         * すべてが null の場合を警告します。
826         *
827         *  例:mustAnyCheck="AA|BB|CC"
828         *      AA,BB,CC のカラムで選択必須(すべてがnullならエラー)
829         *  例:mustAnyCheck="AA|BB|CC,XX|YY|ZZ"
830         *      AA,BB,CC のセットと、XX,YY,ZZのセットでそれぞれ選択必須。
831         *  例:mustAnyCheck="AA|XX,AA|YY,AA|ZZ"
832         *      AA に値があればすべて成立。そうでない場合は、XX と YY と ZZ がすべて必須。
833         *  例:mustAnyCheck="AA|BB,BB|CC,AA|CC"
834         *      AA,BB,CC の内、どれか2つが必須。AAが成立すればBBかCCが必須。同様に、
835         *      BBが成立すれば、AAかCCが必須。
836         *
837         * 選択必須は、must と同様に、色づけを行う(query.jsp)画面では、mustAny 属性を
838         * セットします。チェックを行う(result.jsp)画面では、columnCheck タグの
839         * mustAnyCheck 属性に、選択必須カラムを指定します。(上記参照)
840         * column タグ等の mustAny 属性に、mustAny="true" とセットすると、生成される
841         * HTMLは、class="mustAny" が出力されます。エンジン標準では、default.css に
842         * .mustAny が定義されています。( background-color: #CCFFFF; )
843         * なお、mustAny 属性に、true 以外の値をセットした場合(mustAny="XYZ")は、
844         * 生成されるHTMLに、class="XYZ" が出力されます。これは、複数のグループ間で
845         * 色を変えて、選択必須を指定する場合に使用します。色は、custom/custom.css
846         * で指定します。
847         * 分解方法は、通常のパラメータ取得後に、CSV分解します。
848         *
849         * @og.rev 3.8.0.9 (2005/10/17) 新規追加
850         * @og.rev 3.8.8.5 (2007/03/09) 通常のパラメータ取得後に、CSV分解に戻します。
851         *
852         * @param   clms 選択必須カラム
853         */
854        public void setMustAnyCheck( final String clms ) {
855                mustAnyCheck = StringUtil.csv2Array( getRequestParameter( clms ) );
856                if( mustAnyCheck.length == 0 ) { mustAnyCheck = null; }
857                else {
858                        Arrays.sort( mustAnyCheck );
859                }
860        }
861
862        /**
863         * 【TAG】コマンド[NEW/RENEW/ENTRY]をセットします(初期値:NEW)。
864         *
865         * @og.tag
866         * コマンドは,HTMLから(get/post)指定されますので,CMD_xxx で設定される
867         * フィールド定数値のいづれかを、指定できます。
868         * 何も設定されない、または、null の場合は、"NEW" が初期値にセットされます。
869         *
870         * @param       cmd コマンド (public static final 宣言されている文字列)
871         * @see         <a href="../../../../constant-values.html#org.opengion.hayabusa.taglib.ColumnCheckTag.CMD_NEW">コマンド定数</a>
872         */
873        public void setCommand( final String cmd ) {
874                final String cmd2 = getRequestParameter( cmd );
875                if( cmd2 != null && cmd2.length() > 0 ) { command = cmd2.toUpperCase(Locale.JAPAN); }
876        }
877
878        /**
879         * 【TAG】 チェック対象のタイプ[AUTO/NEW/ENTRY]を指定します(初期値:AUTO)。
880         *
881         * @og.tag
882         * 通常のリクエストデータタイプは、キーそのものですが,エントリデータは表形式の
883         * データを一括で登録する為、(キー+"__" + 行番号)形式を、バラす必要があります。
884         *
885         * ENTRY は、DBTableModelのリクエスト情報をチェックします。
886         * これは、全データが対象になります。(columns/nullCheck 属性は無効)
887         * AUTO は、command が、上記 NEW か ENTRY かを判断して処理を振り分けます。
888         * 初期値は、AUTO です。
889         *
890         * @param   flag チェックタイプ [AUTO/NEW/ENTRY]
891         */
892        public void setCheckType( final String flag ) {
893                final String ct = getRequestParameter( flag );
894                if( ct != null && ct.length() > 0 ) { checkType = ct ; }
895        }
896
897        /**
898         * 【TAG】チェックで選択された行数の最大値を設定します(初期値:-1 無制限)。
899         *
900         * @og.tag
901         * 制限をかけたい行数(この件数と同じ場合は正常)を指定します。
902         * 最大選択件数を超えた場合は,エラーメッセージを返します。
903         * 例えば、1件のみを正常とする場合は、maxRowCount="1" とします。
904         *
905         * @param   count 最大件数
906         */
907        public void setMaxRowCount( final String count ) {
908                maxRowCount = nval( getRequestParameter( count ),maxRowCount );
909        }
910
911        /**
912         * 【TAG】チェックで選択された行数の最小値を設定します(初期値:-1 無制限)。
913         *
914         * @og.tag
915         * 最小選択件数を超えない場合は、エラーメッセージを返します。
916         * 例えば、1件のみを正常とする場合は、minRowCount="1" とします。
917         *
918         * @param   count 制限をかけたい行数 (この件数と同じ場合は正常)
919         */
920         public void setMinRowCount( final String count ) {
921                minRowCount = nval( getRequestParameter( count ), minRowCount );
922         }
923
924        /**
925         * 【TAG】(通常は使いません)結果のDBTableModelを、sessionに登録するときのキーを指定します
926         *              (初期値:HybsSystem#TBL_MDL_KEY[={@og.value HybsSystem#TBL_MDL_KEY}])。
927         *
928         * @og.tag
929         * 検索結果より、DBTableModelオブジェクトを作成します。これを、下流のviewタグ等に
930         * 渡す場合に、通常は、session を利用します。その場合の登録キーです。
931         * query タグを同時に実行して、結果を求める場合、同一メモリに配置される為、
932         * この tableId 属性を利用して、メモリ空間を分けます。
933         *              (初期値:HybsSystem#TBL_MDL_KEY[={@og.value HybsSystem#TBL_MDL_KEY}])。
934         *
935         * @og.rev 6.4.3.2 (2016/02/19) ENTRY時にチェックする対象を、tableId指定のテーブルのカラムに限定します。
936         *
937         * @param       id テーブルID (sessionに登録する時のID)
938         */
939        public void setTableId( final String id ) {
940                tableId = nval( getRequestParameter( id ),tableId );
941        }
942
943        /**
944         * 【TAG】正規表現でのマッチングを行うカラム列をCSV形式(CSV形式)で指定します。
945         *
946         * @og.tag matchKeys="AAA,BBB,CCC,DDD"
947         * matchKeys属性とmatchVals属性の個数は、同じでなければなりません。
948         * 先に配列に分解してからリクエスト変数の値を取得するようにします。
949         * こうする事で、リクエストにCSV形式の値を設定できるようになります。
950         *
951         * @og.rev 4.0.0.0 (2005/11/30) 新規作成
952         *
953         * @param   keys カラム列(CSV形式)
954         * @see     #setMatchVals( String )
955         */
956        public void setMatchKeys( final String keys ) {
957                matchKeys = getCSVParameter( keys );
958
959                if( matchVals != null && matchKeys.length != matchVals.length ) {
960                        final String errMsg = "matchKeys属性とmatchVals属性の個数が合いません。"
961                                                + CR
962                                                + " matchKeys=[" + matchKeys.length + "]:KEYS="
963                                                + StringUtil.array2csv( matchKeys ) + CR
964                                                + " matchVals=[" + matchVals.length + "]:VLAS="
965                                                + StringUtil.array2csv( matchVals ) + CR ;
966                        throw new HybsSystemException( errMsg );
967                }
968        }
969
970        /**
971         * 【TAG】正規表現でのマッチングを行うカラム列に対する値(正規表現)をCSV形式(CSV形式)で指定します。
972         *
973         * @og.tag matchVals="AAA,BBB,CCC,DDD"
974         * matchKeys属性とmatchVals属性の個数は、同じでなければなりません。
975         * 先に配列に分解してからリクエスト変数の値を取得するようにします。
976         * こうする事で、リクエストにCSV形式の値を設定できるようになります。
977         *
978         * @og.rev 4.0.0.0 (2005/11/30) 新規作成
979         *
980         * @param   vals カラム列に対する値(正規表現)(CSV形式)
981         * @see     #setMatchKeys( String )
982         */
983        public void setMatchVals( final String vals ) {
984                matchVals = getCSVParameter( vals );
985
986                if( matchKeys != null && matchKeys.length != matchVals.length ) {
987                        final String errMsg = "matchKeys属性とmatchVals属性の個数が合いません。"
988                                                + CR
989                                                + " matchKeys=[" + matchKeys.length + "]:KEYS="
990                                                + StringUtil.array2csv( matchKeys ) + CR
991                                                + " matchVals=[" + matchVals.length + "]:VLAS="
992                                                + StringUtil.array2csv( matchVals ) + CR ;
993                        throw new HybsSystemException( errMsg );
994                }
995        }
996
997        /**
998         * 【TAG】(通常は使いません)リアルタイムチェックを行う場合に有効にします(初期値:false)。
999         *
1000         * @og.tag
1001         * リアルタイムチェックを行う場合に有効にする属性です。
1002         * trueが指定された場合、通常のチェックと比較し、以下の差異があります。
1003         * ①エラー結果を簡易フォーマットで出力します。
1004         *   (ViewFormType="HTMLSimpleErrorList"で表示されます。)
1005         *   この簡易フォーマットで出力した場合は、ラベル(短)の定義で出力され、
1006         *   カラム名やデータ等は出力されません。
1007         * ②must,mustAny属性のチェックを行いません。
1008         *   必須及び選択必須は、視覚的に判別できるため、リアルタイムチェックの
1009         *   対象外とします。
1010         *
1011         * @og.rev 4.3.3.0 (2008/10/01) 新規作成
1012         * @og.rev 4.3.7.0 (2009/06/01) viewSimple属性名称変更 ⇒ isRealTime
1013         *
1014         * @param   flag リアルタイムチェック [true:する/false:しない]
1015         */
1016        public void setRealTime( final String flag ) {
1017                isRealTime = nval( getRequestParameter( flag ),isRealTime );
1018        }
1019
1020        /**
1021         * 【TAG】NEWの場合に、厳密にチェックするかどうか[true/false]を指定します(初期値:false)。
1022         *
1023         * @og.tag
1024         * データをチェックするに当たり、あいまい検索などで厳密にチェックすると
1025         * エラーになるケースがあるため、command="NEW" のチェック時には、甘い目の
1026         * チェックを行っています。DBColumn#valueCheck( String , false )
1027         * command="ENTRY" のチェックは、厳密なチェックです。
1028         * このフラグは、検索時でも、厳密なチェックを行いたい場合に、true をセットします。
1029         *
1030         * @og.rev 5.2.2.0 (2010/11/01) 新規作成
1031         *
1032         * @param   flag 厳密チェックか [true:厳密/false:甘い]
1033         */
1034        public void setUseStrict( final String flag ) {
1035                isStrict = nval( getRequestParameter( flag ),isStrict );
1036        }
1037
1038        /**
1039         * 【TAG】カラムラベルを使用するかどうか[true/false]を指定します(初期値:false)。
1040         *
1041         * @og.tag
1042         * カラムラベルはラベルローダーを利用せずにアプリケーション側で
1043         * 追加したラベルをResourceManagerにキャッシュしている所から取り出す
1044         * かどうかを指定します。
1045         * カラムラベルに存在しない場合は、通常のラベルから検索します。
1046         *
1047         * @og.rev 5.4.3.4 (2012/01/12) 新規作成
1048         *
1049         * @param   flag カラムラベル使用 [true:する/false:しない]
1050         */
1051        public void setUseColumnLabel( final String flag ) {
1052                isColumnLabel = nval( getRequestParameter( flag ),isColumnLabel );
1053        }
1054
1055        /**
1056         * 【TAG】リクエスト変数の正規化を行うカラムをCSV形式で複数指定します。
1057         *
1058         * @og.tag
1059         * カラムチェックで正規化が行われていないプラグインに対して強制的に正規化を行います。
1060         * この属性を利用したチェックを行った場合は、queryタグでPL/SQLを動作させる場合にも
1061         * 同名属性でカラムの指定を行う必要があります。
1062         * (queryタグでcheckNamesを利用しない場合はこの属性はnullにしてください)
1063         * この属性はチェックタイプがNEWの場合のみ有効です。
1064         * リアルタイムチェックでこの機能を利用したい場合は、columnTag等のoptionAttributes
1065         * 属性にrtOption='checkNames=VIEW_DATE'のように記述してください。
1066         *
1067         * @og.rev 5.4.3.8 (2012/01/24) 新規追加
1068         * @og.rev 5.4.4.0 (2012/02/01) コメント修正
1069         * @og.rev 5.6.9.4 (2013/10/31) 空白削除を行う
1070         * @og.rev 6.9.2.1 (2018/03/12) 使用箇所が、1箇所だけなので、StringUtilから移動する。
1071         *
1072         * @param       nm 正規化を行うカラム(CSV形式)
1073         */
1074        public void setCheckNames( final String nm ) {
1075//              checkNames = StringUtil.deleteWhitespace( nval( getRequestParameter( nm ),checkNames ) );       // 5.6.9.4 (2013/10/31)
1076                final String tmpNm = nval( getRequestParameter( nm ),checkNames );
1077                checkNames = StringUtil.isNull( tmpNm ) ? checkNames :  tmpNm.replaceAll( "\\s", "" );          // 6.9.2.1 (2018/03/12)
1078        }
1079
1080        /**
1081         * このオブジェクトの文字列表現を返します。
1082         * 基本的にデバッグ目的に使用します。
1083         *
1084         * @return このクラスの文字列表現
1085         * @og.rtnNotNull
1086         */
1087        @Override
1088        public String toString() {
1089                return ToString.title( this.getClass().getName() )
1090                                .println( "VERSION"                     ,VERSION                )
1091                                .println( "tableId"                     ,tableId                )
1092                                .println( "command"                     ,command                )
1093                                .println( "columns"                     ,columns                )
1094                                .println( "nullCheck"           ,nullCheck              )
1095                                .println( "mustAnyCheck"        ,mustAnyCheck   )
1096                                .println( "maxRowCount"         ,maxRowCount    )
1097                                .println( "minRowCount"         ,minRowCount    )
1098                                .println( "checkType"           ,checkType              )
1099                                .println( "matchKeys"           ,matchKeys              )
1100                                .println( "matchVals"           ,matchVals              )
1101                                .println( "realTime"            ,isRealTime             )
1102                                .println( "bodyString"          ,StringUtil.htmlFilter( bodyString ) )
1103                                .println( "Other..."            ,getAttributes().getAttribute() )
1104                                .fixForm().toString() ;
1105        }
1106}