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 * 半角文字+半角カタカナとは、X 属æ?に半角カタカナをåŠ?�ˆたã?
026 * 「c < 0x20 || ( c > 0x7e && c < 0xff64 ) || ( c >= 0xffa0 ) 以外ã?
027 * でのみ構æ?された文字å?のことですã?
028 *
029 * タイプチェãƒ?‚¯として、以下ã?条件を判定しますã?
030 * ・æ–?—å?長は、Byte換算でのæ–?—数との比è¼?
031 * ・半角文字+半角カタカナチェãƒ?‚¯
032 * ・æ–?—パラメータの 正規表現チェãƒ?‚¯
033 * ・クロスサイトスクリプティングチェãƒ?‚¯
034 *
035 * @og.group ãƒ??タ属æ?
036 *
037 * @version 4.0
038 * @author Kazuhiko Hasegawa
039 * @since JDK5.0,
040 */
041 public class DBType_XH extends AbstractDBType {
042 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
043 private static final String VERSION = "5.2.2.0 (2010/11/01)" ;
044
045 /**
046 * ãƒ??タが登録可能かどã�?�‹をチェãƒ?‚¯しますã?
047 * ãƒ??タがエラーの場合ã?、そのエラーå†?®¹を返しますã?
048 *
049 * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正
050 * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追åŠ?
051 * @og.rev 3.6.1.0 (2005/01/05) 半角カタカナに、ã??¤』を含めますã?(0xff65 以ä¸?â†?0xff64以ä¸?
052 * @og.rev 5.2.2.0 (2010/11/01) 厳å¯?�«チェãƒ?‚¯(isStrict=true)するフラグを追åŠ?
053 *
054 * @param key キー
055 * @param value 値
056 * @param sizeX 整数部åˆ??æ–?—å?の長ã�?
057 * @param sizeY 少数部åˆ??æ–?—å?の長ã�?
058 * @param typeParam dbType パラメータ
059 * @param isStrict 厳å¯?�«チェãƒ?‚¯するかどã�?�‹[true:する/false:標準的]
060 *
061 * @return エラーå†?®¹
062 */
063 // public ErrorMessage valueCheck( final String key ,final String value ,
064 // final int sizeX ,final int sizeY ,final String param ) {
065 @Override
066 public ErrorMessage valueCheck( final String key ,final String value ,
067 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) {
068
069 ErrorMessage msg = new ErrorMessage();
070 if( value == null || value.length() == 0 ) { return msg; }
071
072 int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1;
073 String check = DBTypeCheckUtil.byteLengthCheck( value,len );
074 if( check != null ) {
075 // æ–?—å?の長さがæŒ?®šã?長さよりも長ã�?�§すã?
076 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) );
077 }
078
079 StringBuilder val = new StringBuilder();
080 boolean isError = false;
081 for( int i=0; i<value.length(); i++ ) {
082 char ch = value.charAt( i );
083 if( ch < 0x20 || ( ch > 0x7e && ch < 0xff64 ) || ( ch >= 0xffa0 ) ) {
084 val.append( "<span class=\"NG\">" ).append( ch ).append( "</span>" );
085 isError = true;
086 }
087 else {
088 val.append( ch );
089 }
090 }
091 if( isError ) {
092 // æŒ?®šã?æ–?—以外ã?æ–?—が使われてã�?�¾すã?
093 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,val.toString() );
094 }
095
096 // 3.6.0.0 (2004/09/22) dbType パラメータを使用したマッチチェãƒ?‚¯
097 check = DBTypeCheckUtil.matcheCheck( value,typeParam );
098 if( check != null ) {
099 // æŒ?®šã?æ–?—以外ã?æ–?—が使われてã�?�¾すã?
100 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
101 }
102
103 // クロスサイトスクリプティング対策ï¼?<', '>' は登録させなã�??
104 msg = xssCheck( key ,value, msg );
105
106 return msg;
107 }
108 }