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.fukurou.util.StringUtil; 020import org.opengion.hayabusa.db.AbstractDBType; 021import org.opengion.hayabusa.db.DBTypeCheckUtil; 022 023/** 024 * 全角のみで構成される文字列を扱う為の、カラム属性を定義します。 025 * 026 * 全角文字とは、「c < 0x7f || ( 0xff65 <= c && c < 0xffa0 ) 以外」 027 * の文字で構成される文字列のことです。 028 * 029 * タイプチェックとして、以下の条件を判定します。 030 * ・全角文字チェック「c < 0x7f || ( 0xff65 <= c && c < 0xffa0 ) 以外」エラー 031 * ・文字列長は、Byte換算での文字数との比較 032 * ・文字パラメータの 正規表現チェック 033 * 034 * @og.group データ属性 035 * 036 * @version 4.0 037 * @author Kazuhiko Hasegawa 038 * @since JDK5.0, 039 */ 040public class DBType_K extends AbstractDBType { 041 //* このプログラムのVERSION文字列を設定します。 {@value} */ 042 private static final String VERSION = "5.2.2.0 (2010/11/01)" ; 043 044 /** 045 * 半角スペースで固定長(半角換算の数)に変換した文字列を返します。 046 * 半角スペース埋めは、文字が半角、全角混在でもかまいません。 047 * なお、エラーチェックは行われません。 048 * 実行前に、必ず valueCheck( String value ,int len ) が行われる必要があります。 049 * 050 * @og.rev 3.5.4.5 (2004/01/23) エンコード指定に変更します。 051 * 052 * @param value FILL埋めする文字列 053 * @param sizeX 整数部分の文字列の長さ 054 * @param sizeY 少数部分の文字列の長さ 055 * @param encode 固定長で変換する文字エンコード 056 * 057 * @return FILL埋めした新しい文字列 058 */ 059 @Override 060 public String valueFill( final String value ,final int sizeX ,final int sizeY,final String encode ) { 061 int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 062 063 return StringUtil.stringKFill( value,len,encode ); 064 } 065 066 /** 067 * データが登録可能かどうかをチェックします。 068 * データがエラーの場合は、そのエラー内容を返します。 069 * 070 * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正 071 * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追加 072 * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加 073 * 074 * @param key キー 075 * @param value 値 076 * @param sizeX 整数部分の文字列の長さ 077 * @param sizeY 少数部分の文字列の長さ 078 * @param typeParam dbType パラメータ 079 * @param isStrict 厳密にチェックするかどうか[true:する/false:標準的] 080 * 081 * @return エラー内容 082 */ 083// public ErrorMessage valueCheck( final String key ,final String value , 084// final int sizeX ,final int sizeY ,final String param ) { 085 @Override 086 public ErrorMessage valueCheck( final String key ,final String value , 087 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) { 088 089 ErrorMessage msg = new ErrorMessage(); 090 if( value == null || value.length() == 0 ) { return msg; } 091 092 int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 093 String check = DBTypeCheckUtil.byteLengthCheck( value,len ); 094 if( check != null ) { 095 // 文字列の長さが指定の長さよりも長いです。 096 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) ); 097 } 098 099 char[] chs = value.toCharArray() ; 100 for( int i=0; i<chs.length; i++ ) { 101 if( chs[i] < 0x7f || ( 0xff65 <= chs[i] && chs[i] < 0xffa0 ) ) { 102 // 全てが全角文字ではありません。 103 msg.addMessage( 0,ErrorMessage.NG,"ERR0007",key,value ); 104 break; 105 } 106 } 107 108 // 3.6.0.0 (2004/09/22) dbType パラメータを使用したマッチチェック 109 check = DBTypeCheckUtil.matcheCheck( value,typeParam ); 110 if( check != null ) { 111 // 指定の文字以外の文字が使われています。 112 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check ); 113 } 114 115 return msg; 116 } 117}