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 /**
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 */
040 public 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 ?¦?©?¬?¬åŸ‹ã‚ã™ã‚‹æ–?—å?
053 * @param sizeX 整数部åˆ??æ–?—å?ã®é•·ã?
054 * @param sizeY 少数部åˆ??æ–?—å?ã®é•·ã?
055 * @param encode 固定長ã§å¤‰æ›ã™ã‚‹æ–?—エンコーãƒ?
056 *
057 * @return ?¦?©?¬?¬åŸ‹ã‚ã—ãŸæ–°ã—ã„æ–?—å?
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 }