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.plugin.column;
017    
018    import org.opengion.fukurou.util.ErrorMessage;
019    import org.opengion.hayabusa.db.AbstractDBType;
020    import org.opengion.hayabusa.db.DBTypeCheckUtil;
021    
022    /**
023     * 半è§?全角混在のä¸?ˆ¬çš?�ª制限ã?なã�?�Š角優先文字å?を扱ã�?‚ºの、カラãƒ?±žæ?を定義しますã?
024     *
025     * DBType_ALL との違いは、valueCheck で、クロスサイトスクリプティングチェãƒ?‚¯ã‚?
026     * 行う為ã€?<', '>'などのãƒ??タは登録できませんã€?
027     * DBType_KX との違いは、デフォルトで IME(仮名漢字変換)は OFF になりますã?
028     *
029     * タイプチェãƒ?‚¯として、以下ã?条件を判定しますã?
030     * ・æ–?­—å?長は、Byte換算でのæ–?­—数との比è¼?
031     * ・æ–?­—パラメータの 正規表現チェãƒ?‚¯
032     * ・クロスサイトスクリプティングチェãƒ?‚¯
033     *
034     * @og.group ãƒ??タ属æ?
035     *
036     * @version  4.0
037     * @author   Kazuhiko Hasegawa
038     * @since    JDK5.0,
039     */
040    public class DBType_XK extends AbstractDBType {
041            //* こã?プログラãƒ??VERSIONæ–?­—å?を設定しますã?       {@value} */
042            private static final String VERSION = "5.2.2.0 (2010/11/01)" ;
043    
044            /**
045             * ãƒ??タが登録可能かどã�?�‹をチェãƒ?‚¯しますã?
046             * ãƒ??タがエラーの場合ã?、そのエラーå†?®¹を返しますã?
047             *
048             * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正
049             * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追åŠ?
050             * @og.rev 5.2.2.0 (2010/11/01) 厳å¯?�«チェãƒ?‚¯(isStrict=true)するフラグを追åŠ?
051             *
052             * @param   key         キー
053             * @param   value       値
054             * @param   sizeX       整数部åˆ??æ–?­—å?の長ã�?
055             * @param   sizeY       少数部åˆ??æ–?­—å?の長ã�?
056             * @param   typeParam   dbType パラメータ
057             * @param   isStrict    厳å¯?�«チェãƒ?‚¯するかどã�?�‹[true:する/false:標準的]
058             *
059             * @return  エラーå†?®¹
060             */
061    //      public ErrorMessage valueCheck( final String key ,final String value ,
062    //                                                                      final int sizeX ,final int sizeY ,final String param ) {
063            @Override
064            public ErrorMessage valueCheck( final String key ,final String value ,
065                                                                            final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) {
066    
067                    ErrorMessage msg = new ErrorMessage();
068                    if( value == null || value.length() == 0 ) { return msg; }
069    
070                    int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1;
071                    String check = DBTypeCheckUtil.byteLengthCheck( value,len );
072                    if( check != null ) {
073                            // æ–?­—å?の長さがæŒ?®šã?長さよりも長ã�?�§すã?
074                            msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) );
075                    }
076    
077                    // 3.6.0.0 (2004/09/22) dbType パラメータを使用したマッチチェãƒ?‚¯
078                    check = DBTypeCheckUtil.matcheCheck( value,typeParam );
079                    if( check != null ) {
080                            // æŒ?®šã?æ–?­—以外ã?æ–?­—が使われてã�?�¾すã?
081                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
082                    }
083    
084                    // クロスサイトスクリプティング対策ï¼?<', '>' は登録させなã�??
085                    msg = xssCheck( key ,value, msg );
086                    return msg;
087            }
088    }