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 }