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.fukurou.util.StringUtil; 020 import org.opengion.hayabusa.db.AbstractDBType; 021 import org.opengion.hayabusa.db.DBTypeCheckUtil; 022 023 import java.util.Locale ; 024 025 /** 026 * 半角文字+半角カタカナ?大??みに制限された??を扱?の、カラ??を定義します? 027 * 028 * ホスト?信用なので、半角カタカナ小文字を半角カタカナ大?に変換します? 029 * 通常の半角文字や半角カタカナを入力すると、大?に変換後に、チェ?を行います? 030 * 半角カタカナ?小文字とは、??,?,?,?,?,?,?,?,?」?ことで、これらの??を? 031 * 「ア,?,?,?,?,???????」に置き換えます? 032 * 033 * タイプチェ?として、以下?条件を判定します? 034 * ・??長は、Byte換算での?数との比? 035 * ・半角文字+半角カタカナチェ? 036 * ・?パラメータの 正規表現チェ? 037 * ・クロスサイトスクリプティングチェ? 038 * 039 * @og.group ??タ属? 040 * 041 * @version 4.0 042 * @author Kazuhiko Hasegawa 043 * @since JDK5.0, 044 */ 045 public class DBType_XHU extends AbstractDBType { 046 //* こ?プログラ??VERSION??を設定します? {@value} */ 047 private static final String VERSION = "5.2.2.0 (2010/11/01)" ; 048 049 /** 050 * エ?ターで編?れた??タを登録する場合に、データそ?も?? 051 * 変換して、実登録??タを作?します? 052 * 例えば,大??みのフィールドなら?大?化します? 053 * 実登録??タの作?は、DBType オブジェクトを利用します?で, 054 * これと Editor とがアンマッチ?場合?、うまくデータ変換 055 * されな?能性があります?で、注意願います? 056 * 057 * @og.rev 3.3.3.0 (2003/07/09) 前後?スペ?スを取り除?おく? 058 * @og.rev 3.3.3.1 (2003/07/18) 後ろスペ?スを取り除く?(StringUtil#rTrim) 059 * @og.rev 3.4.0.0 (2003/09/01) 半角カナ文字化け対??,?,?,?,??の変換処??? 060 * 061 * @param value (?に編?ータとして登録されたデータ) 062 * 063 * @return 修正後???(?に??タベ?スに登録する??タ) 064 */ 065 @Override 066 public String valueSet( final String value ) { 067 if( value == null ) { return null; } 068 String rtnVal = StringUtil.rTrim( value ); 069 char[] ch = (rtnVal).toCharArray(); // 3.3.3.1 (2003/07/18) 070 071 boolean flag = false; 072 for( int i=0; i<ch.length; i++ ) { 073 switch( ch[i] ) { 074 // 3.4.0.0 (2003/09/01) 半角カナ文字化け対??,?,?,?,??の変換処??? 075 // case '±' : ch[i] = '?'; flag = true; break; 076 // case '´' : ch[i] = '?'; flag = true; break; 077 // case '¶' : ch[i] = '?'; flag = true; break; 078 // case '°' : ch[i] = '?'; flag = true; break; 079 // case '? : ch[i] = '??; flag = true; break; 080 case '?' : ch[i] = '?'; flag = true; break; 081 case '?' : ch[i] = '?'; flag = true; break; 082 case '?' : ch[i] = '?'; flag = true; break; 083 case '?' : ch[i] = '?'; flag = true; break; 084 case '?' : ch[i] = '?'; flag = true; break; 085 case '?' : ch[i] = '??; flag = true; break; 086 case '?' : ch[i] = '??; flag = true; break; 087 case '?' : ch[i] = '??; flag = true; break; 088 case '?' : ch[i] = '?'; flag = true; break; 089 default : break; 090 } 091 } 092 if( flag ) { 093 rtnVal = new String( ch ); 094 } 095 return rtnVal.toUpperCase(Locale.JAPAN); 096 } 097 098 /** 099 * ??タが登録可能かど?をチェ?します? 100 * ??タがエラーの場合?、そのエラー?を返します? 101 * 102 * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正 103 * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追? 104 * @og.rev 3.6.1.0 (2005/01/05) 半角カタカナに、??』を含めます?(0xff65 以??0xff64以? 105 * @og.rev 5.2.2.0 (2010/11/01) 厳?チェ?(isStrict=true)するフラグを追? 106 * 107 * @param key キー 108 * @param value 値 109 * @param sizeX 整数部????の長? 110 * @param sizeY 少数部????の長? 111 * @param typeParam dbType パラメータ 112 * @param isStrict 厳?チェ?するかど?[true:する/false:標準的] 113 * 114 * @return エラー? 115 */ 116 // public ErrorMessage valueCheck( final String key ,final String value , 117 // final int sizeX ,final int sizeY ,final String param ) { 118 @Override 119 public ErrorMessage valueCheck( final String key ,final String value , 120 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) { 121 122 ErrorMessage msg = new ErrorMessage(); 123 if( value == null || value.length() == 0 ) { return msg; } 124 125 int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 126 String check = DBTypeCheckUtil.byteLengthCheck( value,len ); 127 if( check != null ) { 128 // ??の長さが??長さよりも長?す? 129 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) ); 130 } 131 132 StringBuilder val = new StringBuilder(); 133 boolean isError = false; 134 for( int i=0; i<value.length(); i++ ) { 135 char ch = value.charAt( i ); 136 // 半角カタカナ?小文?? ? ? ? ? ? ? ? ?)も?NG 137 if( ch < 0x20 || ( ch > 0x7e && ch < 0xff64 ) || 138 ( ch > 0xff66 && ch < 0xff70 ) || ( ch >= 0xffa0 ) ) { 139 val.append( "<span class=\"NG\">" ).append( ch ).append( "</span>" ); 140 isError = true; 141 } 142 else { 143 val.append( ch ); 144 } 145 } 146 if( isError ) { 147 // ???以外??が使われて?す? 148 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,val.toString() ); 149 } 150 151 // 3.6.0.0 (2004/09/22) dbType パラメータを使用したマッチチェ? 152 check = DBTypeCheckUtil.matcheCheck( value,typeParam ); 153 if( check != null ) { 154 // ???以外??が使われて?す? 155 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check ); 156 } 157 158 // クロスサイトスクリプティング対策?<', '>' は登録させな?? 159 msg = xssCheck( key ,value, msg ); 160 161 return msg; 162 } 163 }