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 org.opengion.hayabusa.common.HybsSystem;
019import org.opengion.hayabusa.common.HybsSystemException;
020import org.opengion.hayabusa.db.DBTableModel;
021import org.opengion.hayabusa.db.DBColumn;
022import org.opengion.hayabusa.db.Query;
023import org.opengion.hayabusa.db.QueryFactory;
024import org.opengion.fukurou.util.XHTMLTag;
025import org.opengion.fukurou.util.Attributes;
026import org.opengion.fukurou.db.Transaction;
027import org.opengion.fukurou.db.TransactionReal;
028
029import static org.opengion.fukurou.util.StringUtil.nval ;
030
031import java.io.ObjectOutputStream;
032import java.io.ObjectInputStream;
033import java.io.IOException;
034
035/**
036 * プルダウンメニューの選択項目をSELECT文の結果から作成するタグです。
037 *
038 * 基本的には、queryタグと同じ使い方をします。
039 * このオブジェクトに、 queryId を与えることにより、queryId に対応した Queryオブジェクト
040 * (のサブクラスのオブジェクト)が作成されます。
041 * ここで指定するSELECT文は、『SELECT KEY、LABEL1、LABEL2、・・・ FROM TABLE ・・・』形式 を
042 * している必要があります。特別なケースとして、『SELECT KEY FROM TABLE ・・・』形式の場合は、
043 * LABEL に KEY が 使用されます。
044 * SystemData の USE_SQL_INJECTION_CHECK が true か、quotCheck 属性が true の場合は、
045 * SQLインジェクション対策用のクォーティションチェックを行います。リクエスト引数に
046 * クォーティション(')が含まれると、エラーになります。
047 * 同様にUSE_XSS_CHECKがtrueか、xssCheck属性がtrueの場合は、
048 * クロスサイトススクリプティング(XSS)対策のためless/greater than signのチェックを行います。
049 *
050 * ※ このタグは、Transaction タグの対象です。
051 *
052 * @og.formSample
053 * ●形式:
054 *     <og:queryOption >
055 *          SELECT文 
056 *     </og:queryOption >
057 * ●body:あり(EVAL_BODY_BUFFERED:BODYを評価し、{@XXXX} を解析します)
058 *
059 * ●Tag定義:
060 *   <og:queryOption
061 *       value              【TAG】Optionの初期値で選ばれる値を指定します
062 *       separator          【TAG】複数のラベルを合成するときに使用する項目区切り文字をセットします(初期値:スペース)
063 *       defaultVal         【TAG】value値がNULLの場合に使用される初期値を設定します
064 *       language           【TAG】タグ内部で使用する言語コード[ja/en/zh/…]を指定します
065 *       quotCheck          【TAG】リクエスト情報の クォーティション(') 存在チェックを実施するかどうか[true/false]を設定します (初期値:USE_SQL_INJECTION_CHECK[=true])
066 *       dbid               【TAG】(通常は使いません)Queryオブジェクトを作成する時のDB接続IDを指定します
067 *       addKey             【TAG】項目が一つだけの場合のラベルリソースに、キー情報を追加するかどうかを指定します(初期値:false)
068 *       classUseNo         【TAG】オプションに追加する class 属性の カラム番号を指定します
069 *       groupUseNo         【TAG】オプションのグループ化を行うカラム番号を指定します
070 *       titleUseNo         【TAG】オプションに追加する title 属性の カラム番号を指定します
071 *       xssCheck           【TAG】リクエスト情報の HTMLTag開始/終了文字(><) 存在チェックを実施するかどうか[true/false]を設定します (初期値:USE_XSS_CHECK[=true])
072 *       caseKey            【TAG】このタグ自体を利用するかどうかの条件キーを指定します(初期値:null)
073 *       caseVal            【TAG】このタグ自体を利用するかどうかの条件値を指定します(初期値:null)
074 *       caseNN             【TAG】指定の値が、null/ゼロ文字列 でない場合(Not Null=NN)は、このタグは使用されます(初期値:true)
075 *       caseNull           【TAG】指定の値が、null/ゼロ文字列 の場合は、このタグは使用されます(初期値:true)
076 *       debug              【TAG】デバッグ情報を出力するかどうか[true/false]を指定します(初期値:false)
077 *   >   ... Body ...
078 *   </og:queryOption>
079 *
080 * ●使用例
081 *     <og:select name="CDC" >
082 *         <og:queryOption>
083 *                 select NOSYN,NOSYN,NMSYN from DB01 ORDER BY 1
084 *         </og:queryOption>
085 *     </og:select>
086 *
087 *     <og:select name="CDC" >                選択項目の一番上に空白をセットしたいときoptionタグを組合せることも可能です。
088 *         <og:option lbl="" />               初期値を設定したいときはvalue属性を使います。
089 *         <og:queryOption value="61200" separator=":" >
090 *                 select CDBK,CDBK,NMBK from DB02 ORDER BY 1
091 *         </og:queryOption>
092 *     </og:select>
093 *
094 * @og.group 選択データ制御
095 *
096 * @version  4.0
097 * @author   Kazuhiko Hasegawa
098 * @since    JDK5.0,
099 */
100public class QueryOptionTag extends CommonTagSupport {
101        //* このプログラムのVERSION文字列を設定します。   {@value} */
102        private static final String VERSION = "5.7.1.0 (2013/12/06)" ;
103
104        private static final long serialVersionUID = 571020131206L ;
105
106        private transient DBTableModel  table           = null;
107        private String  selValue        = null;
108        private String  defaultVal      = null;
109        // 4.0.0.0 (2007/10/10) dbid の初期値を、"DEFAULT" から null に変更
110        private String  dbid            = null;
111        private String  sql                     = null;
112        private String  separator       = " ";          // 項目区切り文字
113        private boolean quotCheck       = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" );      // 4.0.0 (2005/08/31)
114        private int             classUseNo      = -1;           // 3.8.5.2 (2006/06/09) オプションに追加するクラス属性
115        private int             groupUseNo      = -1;           // 3.8.5.2 (2006/06/09) キーブレイク時に追加するグループ文字
116        private boolean addKey          = false;        // 4.0.0 (2006/11/15) 項目一つのときにラベルリソース表示時にキーも付加する。
117        private int             titleUseNo      = -1;           // 4.3.8.0 (2009/08/01) オプションのtitle属性
118        private boolean xssCheck        = HybsSystem.sysBool( "USE_XSS_CHECK" );        // 5.0.0.2 (2009/09/15)
119        private String  rawSql          = null;         // 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
120
121        /**
122         * Taglibの開始タグが見つかったときに処理する doStartTag() を オーバーライドします。
123         *
124         * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
125         *
126         * @return      後続処理の指示( EVAL_BODY_BUFFERED )
127         */
128        @Override
129        public int doStartTag() {
130                // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
131                if( useTag() ) {
132                        return EVAL_BODY_BUFFERED ;     // Body を評価する。( extends BodyTagSupport 時)
133                }
134                return SKIP_BODY ;                              // Body を評価しない
135        }
136
137        /**
138         * Taglibのタグ本体を処理する doAfterBody() を オーバーライドします。
139         *
140         * @og.rev 3.1.1.0 (2003/03/28) ボディの内容を取得する処理を、CommonTagSupport で行う。
141         * @og.rev 3.6.0.8 (2004/11/19) エラー発生時に確実にリリースされるように try finally 追加
142         * @og.rev 3.7.1.0 (2005/04/26) DBTableModel がすでにセットされている場合は、SQL処理不要。
143         * @og.rev 4.0.0.0 (2005/01/31) lang ⇒ ResourceManager へ変更
144         * @og.rev 4.0.0.0 (2005/08/31) useQuotCheck() によるSQLインジェクション対策
145         * @og.rev 3.8.6.3 (2006/11/30) SQL 文の前後のスペースを取り除きます。
146         * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得の為,ApplicationInfoオブジェクトを設定
147         * @og.rev 4.3.6.0 (2009/04/01) EventColumn対応
148         * @og.rev 5.0.0.5 (2009/08/28) XSS対策
149         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
150         * @og.rev 5.1.9.0 (2010/08/01) TransactionTag 対応。上位に TransactionTag があれば、そこからConnection をもらう。
151         * @og.rev 5.3.7.0 (2011/07/01) TransactionReal の引数変更
152         * @og.rev 5.3.8.0 (2011/08/01) Transaction発生箇所でclose()
153         *
154         * @return      後続処理の指示(SKIP_BODY)
155         */
156        @Override
157        public int doAfterBody() {
158                // 3.7.1.0 (2005/04/26) DBTableModel がすでにセットされている場合は、SQL処理不要。
159                if( table != null ) { return SKIP_BODY ; }
160
161                // 4.0.0 (2005/08/31) useQuotCheck() によるSQLインジェクション対策
162                useQuotCheck( quotCheck );
163                // 5.0.0.2 (2009/09/15) XSS対策
164                useXssCheck( xssCheck );
165
166                sql = getBodyString().trim();
167                rawSql = getBodyRawString().trim();
168
169                // 4.3.6.0 (2009/04/01) セッションへのSQL文登録
170                // 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
171                Query query = QueryFactory.newInstance();               // 4.0.0 (2005/01/31)
172                Transaction tran = null;
173                try {
174                        // 5.1.9.0 (2010/08/01) TransactionTag 対応
175                        TransactionTag tranTag = (TransactionTag)findAncestorWithClass( this,TransactionTag.class );
176                        if( tranTag == null ) {
177                                tran = new TransactionReal( getApplicationInfo() );             // 5.3.7.0 (2011/07/01) 引数変更
178                        }
179                        else {
180                                tran = tranTag.getTransaction();
181                        }
182                        query.setTransaction( dbid,tran );      // 5.1.9.0 (2010/08/01) TransactionTag 対応
183
184                        query.setResourceManager( getResource() );      // 4.0.0 (2005/01/31)
185
186                        query.setStatement( sql );
187                        query.execute();
188
189                        table = query.getDBTableModel();
190
191                        // 4.0.0 (2005/11/30) 検索結果の件数を、"DB.COUNT" キーでリクエストにセットする。
192                }
193                finally {
194                        QueryFactory.close( query );
195                        if( tran != null ) { tran.close(); }            // 5.3.8.0 (2011/08/01) Transaction発生箇所でclose()
196                }
197                return SKIP_BODY ;
198        }
199
200        /**
201         * Taglibの終了タグが見つかったときに処理する doEndTag() を オーバーライドします。
202         *
203         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
204         * @og.rev 3.3.2.0 (2003/07/07) defaultVal 属性の追加。
205         * @og.rev 3.5.4.0 (2003/11/25) selVal 属性を追加。
206         * @og.rev 5.0.2.0 (2009/11/01) 複数パラメーターの選択に対応
207         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
208         * @og.rev 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
209         * @og.rev 5.7.1.0 (2013/12/06) SelectTag ⇒ OptionAncestorIF に変更して、DatalistTag にも対応。
210         *
211         * @return      後続処理の指示
212         */
213        @Override
214        public int doEndTag() {
215                debugPrint();           // 4.0.0 (2005/02/28)
216                // 5.2.2.0 (2010/11/01) caseKey 、caseVal 属性対応
217                if( useTag() ) {
218                        OptionAncestorIF select = (OptionAncestorIF)findAncestorWithClass( this,OptionAncestorIF.class );
219                        if( select == null ) {
220                                String errMsg = "<b>" + getTagName() + "タグは、SelectTag または、DatalistTag のBODY に記述する必要があります。</b>";
221                                throw new HybsSystemException( errMsg );
222                        }
223                        String selVal = nval( select.getValue(),defaultVal );   // 3.5.4.0 (2003/11/25)
224        //              selValue = nval( selValue,selVal );                                             // 3.5.4.0 (2003/11/25)
225                        selValue = "|" + nval( selValue,selVal ) + "|";                 // 5.0.2.0 (2009/11/01)
226                        makeLabel( select );
227
228                        // 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
229                        select.setRawParam( rawSql );
230                }
231                return EVAL_PAGE ;
232        }
233
234        /**
235         * タグリブオブジェクトをリリースします。
236         * キャッシュされて再利用されるので、フィールドの初期設定を行います。
237         *
238         * @og.rev 2.0.0.4 (2002/09/27) カスタムタグの release() メソッドを、追加
239         * @og.rev 3.0.1.0 (2003/03/03) セパレーターを指定できる様に変更。
240         * @og.rev 3.1.1.2 (2003/04/04) Tomcat4.1 対応。release2() を doEndTag()で呼ぶ。
241         * @og.rev 3.3.2.0 (2003/07/07) defaultVal 属性の追加。
242         * @og.rev 3.8.5.2 (2006/06/09) classUseNo , groupUseNo 属性の追加。
243         * @og.rev 4.0.0.0 (2005/08/31) quotCheck , addKey 属性の追加
244         * @og.rev 4.0.0.0 (2007/10/10) dbid の初期値を、"DEFAULT" から null に変更
245         * @og.rev 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
246         *
247         */
248        @Override
249        protected void release2() {
250                super.release2();
251                table           = null;
252                selValue        = null;
253                defaultVal      = null;
254                dbid            = null;
255                sql                     = null;
256                separator       = " ";
257                classUseNo      = -1;   // 3.8.5.2 (2006/06/09) オプションに追加するクラス属性
258                groupUseNo      = -1;   // 3.8.5.2 (2006/06/09) キーブレイク時に追加するグループ文字
259                quotCheck       = HybsSystem.sysBool( "USE_SQL_INJECTION_CHECK" );      // 4.0.0 (2005/08/31)
260                addKey          = false;                // 4.0.0 (2006/11/15) 項目一つのときにラベルリソース表示時にキーも付加する。
261                titleUseNo              = -1;
262                xssCheck        = HybsSystem.sysBool( "USE_XSS_CHECK" );        // 5.0.0.2 (2009/09/15)
263                rawSql          = null; // 5.1.7.0 (2010/06/01) 動的プルダウン実装見直し
264        }
265
266        /**
267         * DBTableModelをセットします。
268         *
269         * サブクラスより、DBTableModelをセットするのに使います。
270         *
271         * @og.rev 3.7.1.0 (2005/04/26) 新規追加
272         *
273         * @param       table   DBTableModelオブジェクト
274         */
275        protected void setTableModel( final DBTableModel table ) {
276                this.table = table ;
277        }
278
279        /**
280         * オプションを作成します。
281         *
282         * DBTableModel の1番目の値を "value" に、それ以降を文字列を連結させて
283         * BODY属性 に登録するOptionを作成します。
284         *
285         * @og.rev 3.0.1.0 (2003/03/03) 『SELECT KEY FROM TABLE ・・・』形式の場合は、LABEL に KEY を使用。
286         * @og.rev 3.8.0.9 (2005/10/17) 複数選択可能時に全選択を設定する。
287         * @og.rev 3.8.5.2 (2006/06/09) classUseNo 属性と groupUseNo 属性を追加
288         * @og.rev 3.8.9.2 (2007/07/28) グループと、クラスの設定方法のバグ修正
289         * @og.rev 4.3.8.0 (2009/08/01) titleUseNo属性追加
290         * @og.rev 5.0.2.0 (2009/11/01) 複数パラメーターの選択に対応
291         * @og.rev 5.7.1.0 (2013/12/06) SelectTag ⇒ OptionAncestorIF に変更して、DatalistTag にも対応。
292         *
293         * @param   select SelectTagオブジェクト
294         */
295        private void makeLabel( final OptionAncestorIF select ) {
296                boolean multipleAll = select.isMultipleAll();   // 3.8.0.9 (2005/10/17)
297                int rowCnt = table.getRowCount();               // 3.5.5.7 (2004/05/10)
298
299                String bkGroupKey = "";
300                String grpLabel ;
301                for( int row=0; row<rowCnt; row++ ) {
302                        // 3.8.5.2 (2006/06/09) groupUseNo 属性
303                        if( groupUseNo >= 0 ) {
304                                String groupKey = table.getValue( row,groupUseNo );
305                                grpLabel = getRendererValue( row,groupUseNo );
306                                if( !bkGroupKey.equals( groupKey ) ) {          // キーブレイク
307                                        // 3.8.9.2 (2007/07/28) グループと、クラスの設定方法のバグ修正
308                                        if( ! "".equals( bkGroupKey ) ) {
309                                                select.addOption( "</optgroup>" );
310                                        }
311                                        if( ! "".equals( groupKey ) ) {
312                                                select.addOption( "<optgroup label=\"" + grpLabel + "\">" );
313                                        }
314                                        bkGroupKey = groupKey;
315                                }
316                        }
317
318                        Attributes attri = new Attributes();
319                        String value = table.getValue( row,0 );
320                        attri.set( "value", value );
321
322                        // 5.0.2.0 (2009/11/01)
323                        // selValue は、makeLabel( OptionAncestorIF ) が呼ばれる前に、必ずセットされている。
324                        if( multipleAll || selValue.indexOf( "|" + value + "|" ) >= 0 ) {
325                                attri.set( "selected", "selected" );
326                        }
327
328                        // 3.8.5.2 (2006/06/09) classUseNo 属性
329                        if( classUseNo >= 0 ) {
330                                attri.add( "class", table.getValue( row,classUseNo ) );
331                        }
332
333                        StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
334                        boolean titleFlg = false; // 4.3.8.0 (2009/08/01) title属性を付けるかどうか
335                        if( table.getColumnCount() == 1 ) {
336                                // 項目が一つの queryOption では、ラベルリソースが使用されます。
337                                if( addKey ) { buf.append( value ).append( ":" ); }
338                                buf.append( getResource().getLabel( value ) );
339
340                                // 4.3.8.0 (2009/08/01) titleUseNo 属性 セットされている場合かつラベルと異なる場合はtitle属性に追加
341                                if( titleUseNo >= 0 && !getResource().getLabel( value ).equals( table.getValue( row,titleUseNo ) )) {
342                                        titleFlg = true;
343                                }
344                        }
345                        else {
346        //                      if( groupUseNo >= 0 ) {
347        //                              buf.append( grpLabel );
348        //                              buf.append( separator );
349        //                      }
350                                String label = getRendererValue( row,1 );
351                                buf.append( label );
352        //                      attri.set( "label", label );
353                                for( int clm=2; clm<table.getColumnCount(); clm++ ) {
354                                        // 4.3.8.0 (2009/08/01) titleUseNo追加
355                                        // if( clm == groupUseNo || clm == classUseNo ) { continue; }
356                                        if( clm == groupUseNo || clm == classUseNo || clm==titleUseNo) { continue; }
357                                        buf.append( separator );
358                                        buf.append( getRendererValue( row,clm ) );
359                                }
360
361                                // 4.3.8.0 (2009/08/01) titleUseNo 属性 セットされている場合かつラベルと異なる場合はtitle属性に追加
362                                if( titleUseNo >= 0 && !label.equals( table.getValue( row,titleUseNo ) )) {
363                                        titleFlg = true;
364                                }
365                        }
366
367                        // 4.3.7.2 (2009/06/22) タイトル属性セット
368                        if( titleFlg ){
369                                attri.add( "title", table.getValue( row,titleUseNo ) );
370                        }
371
372                        attri.set( "body", buf.toString() );
373                        select.addOption( XHTMLTag.option( attri ) );
374                }
375                if( groupUseNo >= 0 && ! "".equals( bkGroupKey ) ) {    // 3.8.9.2 (2007/07/28)
376                        select.addOption( "</optgroup>" );
377                }
378        }
379
380        /**
381         * 【TAG】Optionの初期値で選ばれる値を指定します。
382         *
383         * @og.tag Optionの初期値で選ばれる値を指定します。
384         *
385         * @param   val Optionの初期値で選ばれる値
386         */
387        public void setValue( final String val ) {
388                selValue = getRequestParameter( val );
389        }
390
391        /**
392         * 【TAG】value値がNULLの場合に使用される初期値を設定します。
393         *
394         * @og.tag
395         * value値がNULLの場合に、この初期値をセットします。
396         *
397         * @og.rev 3.3.2.0 (2003/07/07) defaultVal 属性の追加。(新規作成)
398         *
399         * @param       val 初期値
400         */
401        public void setDefaultVal( final String val ) {
402                defaultVal = getRequestParameter( val );
403        }
404
405        /**
406         * 【TAG】複数のラベルを合成するときに使用する項目区切り文字をセットします(初期値:スペース)。
407         *
408         * @og.tag
409         * 初期値は、スペースです。
410         *
411         * @og.rev 3.0.1.0 (2003/03/03) セパレーターを指定できる様に変更。
412         *
413         * @param   sep 項目区切り文字
414         */
415        public void setSeparator( final String sep ) {
416                separator = nval( getRequestParameter( sep ),separator );
417        }
418
419        /**
420         * 【TAG】オプションに追加する class 属性の カラム番号を指定します。
421         *
422         * @og.tag
423         * オプションは、データベースを検索して作成されますが、そのSQL文のカラム情報を
424         * 使用して オプションに class 属性を追加します。
425         * 各オプションに色をつける場合は、この class 属性に対応する CSS ファイルを用意します。
426         * ここでは、class 属性に使用する SQL文の カラム番号( 先頭が 0 ) を指定します。
427         * 通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定します。
428         * 初期値は、使用しない(-1)です。
429         *
430         * @og.rev 3.8.5.2 (2006/06/09) 新規追加
431         *
432         * @param   no オプションに追加するクラス属性
433         */
434        public void setClassUseNo( final String no ) {
435                classUseNo = nval( getRequestParameter( no ),classUseNo );
436                if( classUseNo == 0 || classUseNo == 1 ) {
437                        String errMsg = "通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定して下さい。";
438                        throw new HybsSystemException( errMsg );
439                }
440        }
441
442        /**
443         * 【TAG】オプションのグループ化を行うカラム番号を指定します。
444         *
445         * @og.tag
446         * オプションは、データベースを検索して作成されますが、そのSQL文のカラム情報を
447         * 使用して オプションをグループ化します。グループ化は optgroup要素をブレイク時に
448         * 出力する事で対応します。
449         * ここでは、グループ化に使用する SQL文の カラム番号( 先頭が 0 ) を指定します。
450         * 通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定します。
451         * 初期値は、使用しない(-1)です。
452         *
453         * @og.rev 3.8.5.2 (2006/06/09) 新規追加
454         *
455         * @param   no キーブレイク時に追加するグループ文字
456         */
457        public void setGroupUseNo( final String no ) {
458                groupUseNo = nval( getRequestParameter( no ),groupUseNo );
459                if( groupUseNo == 0 || groupUseNo == 1 ) {
460                        String errMsg = "通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定して下さい。";
461                        throw new HybsSystemException( errMsg );
462                }
463        }
464
465        /**
466         * 【TAG】リクエスト情報の クォーティション(') 存在チェックを実施するかどうか[true/false]を設定します
467         *              (初期値:USE_SQL_INJECTION_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK}])。
468         *
469         * @og.tag
470         * SQLインジェクション対策の一つとして、暫定的ではありますが、SQLのパラメータに
471         * 渡す文字列にクォーティション(') を許さない設定にすれば、ある程度は防止できます。
472         * 数字タイプの引数には、 or 5=5 などのクォーティションを使用しないコードを埋めても、
473         * 数字チェックで検出可能です。文字タイプの場合は、必ず (')をはずして、
474         * ' or 'A' like 'A のような形式になる為、(')チェックだけでも有効です。
475         * (') が含まれていたエラーにする(true)/かノーチェックか(false)を指定します。
476         * (初期値:システム定数のUSE_SQL_INJECTION_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK}])。
477         *
478         * @og.rev 4.0.0.0 (2005/08/31) 新規追加
479         *
480         * @param   flag クォーティションチェック [true:する/それ以外:しない]
481         * @see         org.opengion.hayabusa.common.SystemData#USE_SQL_INJECTION_CHECK
482         */
483        public void setQuotCheck( final String flag ) {
484                quotCheck = nval( getRequestParameter( flag ),quotCheck );
485        }
486
487        /**
488         * 【TAG】(通常は使いません)Queryオブジェクトを作成する時のDB接続IDを指定します。
489         *
490         * @og.tag
491         * Queryオブジェクトを作成する時のDB接続IDを指定します。
492         * これは、システムリソースで、DEFAULT_DB_URL 等で指定している データベース接続先
493         * 情報に、XX_DB_URL を定義することで、 dbid="XX" とすると、この 接続先を使用して
494         * データベースにアクセスできます。
495         *
496         * @param       id データベース接続ID
497         */
498        public void setDbid( final String id ) {
499                dbid = nval( getRequestParameter( id ),dbid );
500        }
501
502        /**
503         * 【TAG】項目が一つだけの場合のラベルリソースに、キー情報を追加するかどうかを指定します(初期値:false)。
504         *
505         * @og.tag
506         * Queryオブジェクトの項目が一つの場合、ラベル部には、ラベルリソースを使用します。
507         * この時、ラベル無しの場合は、キーが表示されますが、ラベルありの場合は、キーは表示されず
508         * ラベルのみ表示されます。
509         * 都合によっては、キーも表示したい場合がありますので、その様なケースでは、
510         * addKey = "true を設定する事で、キー:ラベル のセットをラベルとして扱います。
511         * 初期値はfalse(キーは付加しない)です。
512         *
513         * @param       id データベース接続ID
514         */
515        public void setAddKey( final String id ) {
516                addKey = nval( getRequestParameter( id ),addKey );
517        }
518
519        /**
520         * 【TAG】リクエスト情報の HTMLTag開始/終了文字(&gt;&lt;) 存在チェックを実施するかどうか[true/false]を設定します
521         *              (初期値:USE_XSS_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK}])。
522         *
523         * @og.tag
524         * クロスサイトスクリプティング(XSS)対策の一環としてless/greater than signについてのチェックを行います。
525         * (&gt;&lt;) が含まれていたエラーにする(true)/かノーチェックか(false)を指定します。
526         * (初期値:システム定数のUSE_XSS_CHECK[={@og.value org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK}])。
527         *
528         * @og.rev 5.0.0.2 (2009/09/15) 新規追加
529         *
530         * @param       flag    XSSチェック [true:する/false:しない]
531         * @see         org.opengion.hayabusa.common.SystemData#USE_XSS_CHECK
532         */
533        public void setXssCheck( final String flag ) {
534                xssCheck = nval( getRequestParameter( flag ),xssCheck );
535        }
536
537        /**
538         * row行,colum列 のデータの値を返します。
539         *
540         * これは、データの値そのものではなく、その値のラベル文字を返します。
541         *
542         * @param   row         行番号
543         * @param   column      カラム番号
544         *
545         * @return  row行,colum列 のデータの値
546         */
547        private String getRendererValue( final int row,final int column ) {
548                String val = table.getValue( row,column );
549                DBColumn clm = table.getDBColumn( column );
550                return clm.getRendererValue( val );
551        }
552
553        /**
554         * 【TAG】オプションに追加する title 属性の カラム番号を指定します。
555         *
556         * @og.tag
557         * オプションは、データベースを検索して作成されますが、そのSQL文のカラム情報を
558         * 使用して オプションに title 属性を追加します。
559         * title属性はマウスオーバー時にツールチップとして表示されるため、
560         * プルダウンの横幅を短くしたい場合に有効です。
561         * 通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定します。
562         * 初期値は、使用しない(-1)です。
563         *
564         * @og.rev 4.3.8.0 (2009/08/01) 新規追加
565         *
566         * @param   no オプションに追加するtitle属性
567         */
568        public void setTitleUseNo( final String no ) {
569                titleUseNo = nval( getRequestParameter( no ),titleUseNo );
570                if( titleUseNo == 0 || titleUseNo == 1 ) {
571                        String errMsg = "通常、カラム番号=0 は キー情報、=1 はラベル情報 です。2 か 3 を指定して下さい。";
572                        throw new HybsSystemException( errMsg );
573                }
574        }
575
576        /**
577         * シリアライズ用のカスタムシリアライズ書き込みメソッド
578         *
579         * @og.rev 4.0.0.0 (2006/09/31) 新規追加
580         * @serialData 一部のオブジェクトは、シリアライズされません。
581         *
582         * @param       strm    ObjectOutputStreamオブジェクト
583         * @throws IOException  入出力エラーが発生した場合
584         */
585        private void writeObject( final ObjectOutputStream strm ) throws IOException {
586                strm.defaultWriteObject();
587        }
588
589        /**
590         * シリアライズ用のカスタムシリアライズ読み込みメソッド
591         *
592         * ここでは、transient 宣言された内部変数の内、初期化が必要なフィールドのみ設定します。
593         *
594         * @og.rev 4.0.0.0 (2006/09/31) 新規追加
595         * @serialData 一部のオブジェクトは、シリアライズされません。
596         *
597         * @param       strm    ObjectInputStreamオブジェクト
598         * @see #release2()
599         * @throws IOException  シリアライズに関する入出力エラーが発生した場合
600         * @throws ClassNotFoundException       クラスを見つけることができなかった場合
601         */
602        private void readObject( final ObjectInputStream strm ) throws IOException , ClassNotFoundException {
603                strm.defaultReadObject();
604        }
605
606        /**
607         * このオブジェクトの文字列表現を返します。
608         * 基本的にデバッグ目的に使用します。
609         *
610         * @return このクラスの文字列表現
611         */
612        @Override
613        public String toString() {
614                return org.opengion.fukurou.util.ToString.title( this.getClass().getName() )
615                                .println( "VERSION"             ,VERSION        )
616                                .println( "selValue"    ,selValue       )
617                                .println( "defaultVal"  ,defaultVal     )
618                                .println( "dbid"                ,dbid           )
619                                .println( "sql"                 ,sql            )
620                                .println( "separator"   ,separator      )
621                                .println( "quotCheck"   ,quotCheck      )
622                                .println( "Other..."    ,getAttributes().getAttribute() )
623                                .fixForm().toString() ;
624        }
625}