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 * 全角+改行C(CR,LF)のみで構成される文字列を扱う為の、カラム属性を定義します。 025 * 026 * 全角文字とは、「c < 0x7f || ( 0xff65 <= c && c < 0xffa0 ) 以外」 027 * の文字で構成される文字列のことです。 028 * 029 * タイプチェックとして、以下の条件を判定します。 030 * ・全角文字チェック「c < 0x7f || ( 0xff65 <= c && c < 0xffa0 ) 以外」 031 * かつ改行C以外「c != 0x0a && c != 0x0d以外」エラー 032 * ・文字列長は、Byte換算での文字数との比較 033 * ・文字パラメータの 正規表現チェック 034 * 035 * @og.group データ属性 036 * 037 * @version 4.0 038 * @author Hiroki Nakamura 039 * @since JDK5.0, 040 */ 041public class DBType_KCL 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_KCL() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。 051 052 /** 053 * 半角スペースで固定長(半角換算の数)に変換した文字列を返します。 054 * 半角スペース埋めは、文字が半角、全角混在でもかまいません。 055 * なお、エラーチェックは行われません。 056 * 実行前に、必ず valueCheck( String value ,int len ) が行われる必要があります。 057 * 058 * @param value FILL埋めする文字列 059 * @param sizeX 整数部分の文字列の長さ 060 * @param sizeY 小数部分の文字列の長さ 061 * @param encode 固定長で変換する文字エンコード 062 * 063 * @return FILL埋めした新しい文字列 064 */ 065 @Override 066 public String valueFill( final String value ,final int sizeX ,final int sizeY,final String encode ) { 067 final int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 068 069 return StringUtil.stringKFill( value,len,encode ); 070 } 071 072 /** 073 * データが登録可能かどうかをチェックします。 074 * データがエラーの場合は、そのエラー内容を返します。 075 * 076 * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加 077 * 078 * @param key キー 079 * @param value 値 080 * @param sizeX 整数部分の文字列の長さ 081 * @param sizeY 小数部分の文字列の長さ 082 * @param typeParam dbType パラメータ(文字パラメータ) 083 * @param isStrict 厳密にチェックするかどうか[true:する/false:標準的] 084 * 085 * @return エラー内容 086 * @og.rtnNotNull 087 */ 088 @Override 089 public ErrorMessage valueCheck( final String key ,final String value , 090 final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) { 091 092 final ErrorMessage msg = new ErrorMessage(); 093 if( value == null || value.isEmpty() ) { return msg; } 094 095 final int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1; 096 String check = DBTypeCheckUtil.byteLengthCheck( value,len ); 097 if( check != null ) { 098 // 文字列の長さが指定の長さよりも長いです。 099 msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) ); 100 } 101 102 final char[] chs = value.toCharArray() ; 103 for( int i=0; i<chs.length; i++ ) { 104 if( chs[i] < 0x7f || 0xff65 <= chs[i] && chs[i] < 0xffa0 ) { // 6.9.7.0 (2018/05/14) PMD Useless parentheses. 105 if( chs[i] != 0x0a && chs[i] != 0x0d ) { 106 // 全てが全角文字ではありません。 107 msg.addMessage( 0,ErrorMessage.NG,"ERR0007",key,value ); 108 break; 109 } 110 } 111 } 112 113 // 3.6.0.0 (2004/09/22) dbType パラメータ(文字パラメータ)を使用したマッチチェック 114 check = DBTypeCheckUtil.matcheCheck( value,typeParam ); 115 if( check != null ) { 116 // 指定の文字以外の文字が使われています。 117 msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check ); 118 } 119 120 return msg; 121 } 122}