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