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 */ 016package org.opengion.plugin.column; 017 018import org.opengion.fukurou.util.ErrorMessage; 019import org.opengion.hayabusa.db.AbstractDBType; 020import 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 */ 041public class DBType_XH extends AbstractDBType { 042 /** このプログラムのVERSION文字列を設定します。 {@value} */ 043 private static final String VERSION = "6.4.2.0 (2016/01/29)" ; 044 045 /** 046 * デフォルトコンストラクター 047 * 048 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 049 */ 050 public DBType_XH() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 051 052 /** 053 * データが登録可能かどうかをチェックします。 054 * データがエラーの場合は、そのエラー内容を返します。 055 * 056 * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正 057 * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータ(文字パラメータ)を引数に追加 058 * @og.rev 3.6.1.0 (2005/01/05) 半角カタカナに、『、』を含めます。(0xff65 以上 → 0xff64以上) 059 * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加 060 * 061 * @param key キー 062 * @param value 値 063 * @param sizeX 整数部分の文字列の長さ 064 * @param sizeY 小数部分の文字列の長さ 065 * @param typeParam dbType パラメータ(文字パラメータ) 066 * @param isStrict 厳密にチェックするかどうか[true:する/false:標準的] 067 * 068 * @return エラー内容 069 * @og.rtnNotNull 070 */ 071 @Override 072 public ErrorMessage valueCheck( final String key ,final String value , 073 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) { 074 075 // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD) 076 final ErrorMessage msg = new ErrorMessage(); 077 if( value == null || value.isEmpty() ) { return msg; } 078 079 final int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 080 String check = DBTypeCheckUtil.byteLengthCheck( value,len ); 081 if( check != null ) { 082 // 文字列の長さが指定の長さよりも長いです。 083 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) ); 084 } 085 086 final StringBuilder buf = new StringBuilder( BUFFER_MIDDLE ); 087 boolean isError = false; 088 for( int i=0; i<value.length(); i++ ) { 089 final char ch = value.charAt( i ); 090 if( ch < 0x20 || ch > 0x7e && ch < 0xff64 || ch >= 0xffa0 ) { // 6.9.7.0 (2018/05/14) PMD Useless parentheses. 091 buf.append( "<span class=\"NG\">" ).append( ch ).append( "</span>" ); 092 isError = true; 093 } 094 else { 095 buf.append( ch ); 096 } 097 } 098 if( isError ) { 099 // 指定の文字以外の文字が使われています。 100 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,buf.toString() ); 101 } 102 103 // 3.6.0.0 (2004/09/22) dbType パラメータ(文字パラメータ)を使用したマッチチェック 104 check = DBTypeCheckUtil.matcheCheck( value,typeParam ); 105 if( check != null ) { 106 // 指定の文字以外の文字が使われています。 107 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check ); 108 } 109 110 // クロスサイトスクリプティング対策:'<', '>' は登録させない。 111 // 6.3.9.1 (2015/11/27) Found 'DD'-anomaly for variable(PMD) 112 return xssCheck( key ,value, msg ); 113 } 114}