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 = "6.4.2.0 (2016/01/29)" ; 043 044 /** 045 * デフォルトコンストラクター 046 * 047 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor. 048 */ 049 public DBType_K() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 050 051 /** 052 * 半角スペースで固定長(半角換算の数)に変換した文字列を返します。 053 * 半角スペース埋めは、文字が半角、全角混在でもかまいません。 054 * なお、エラーチェックは行われません。 055 * 実行前に、必ず valueCheck( String value ,int len ) が行われる必要があります。 056 * 057 * @og.rev 3.5.4.5 (2004/01/23) エンコード指定に変更します。 058 * 059 * @param value FILL埋めする文字列 060 * @param sizeX 整数部分の文字列の長さ 061 * @param sizeY 小数部分の文字列の長さ 062 * @param encode 固定長で変換する文字エンコード 063 * 064 * @return FILL埋めした新しい文字列 065 */ 066 @Override 067 public String valueFill( final String value ,final int sizeX ,final int sizeY,final String encode ) { 068 final int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 069 070 return StringUtil.stringKFill( value,len,encode ); 071 } 072 073 /** 074 * データが登録可能かどうかをチェックします。 075 * データがエラーの場合は、そのエラー内容を返します。 076 * 077 * @og.rev 3.0.1.3 (2003/03/11) DBTypeCheckUtilクラスを利用するように修正 078 * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータ(文字パラメータ)を引数に追加 079 * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加 080 * 081 * @param key キー 082 * @param value 値 083 * @param sizeX 整数部分の文字列の長さ 084 * @param sizeY 小数部分の文字列の長さ 085 * @param typeParam dbType パラメータ(文字パラメータ) 086 * @param isStrict 厳密にチェックするかどうか[true:する/false:標準的] 087 * 088 * @return エラー内容 089 * @og.rtnNotNull 090 */ 091 @Override 092 public ErrorMessage valueCheck( final String key ,final String value , 093 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) { 094 095 final ErrorMessage msg = new ErrorMessage(); 096 if( value == null || value.isEmpty() ) { return msg; } 097 098 final int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 099 String check = DBTypeCheckUtil.byteLengthCheck( value,len ); 100 if( check != null ) { 101 // 文字列の長さが指定の長さよりも長いです。 102 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) ); 103 } 104 105 final char[] chs = value.toCharArray() ; 106 for( int i=0; i<chs.length; i++ ) { 107 if( chs[i] < 0x7f || 0xff65 <= chs[i] && chs[i] < 0xffa0 ) { // 6.9.7.0 (2018/05/14) PMD Useless parentheses. 108 // 全てが全角文字ではありません。 109 msg.addMessage( 0,ErrorMessage.NG,"ERR0007",key,value ); 110 break; 111 } 112 } 113 114 // 3.6.0.0 (2004/09/22) dbType パラメータ(文字パラメータ)を使用したマッチチェック 115 check = DBTypeCheckUtil.matcheCheck( value,typeParam ); 116 if( check != null ) { 117 // 指定の文字以外の文字が使われています。 118 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check ); 119 } 120 121 return msg; 122 } 123}