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 * Char または Varchar2 属性に対応する文字型クラスで、DBType_XK との違いは、
026 * valueCheck で、クロスサイトスクリプティングチェックを行わない為、
027 * '<', '>'などのデータを、直接データベースに登録することが可能です。
028 * よって、このDBTypeを使用する場合は、必ず、Editor_HTML 、Renderer_HTML
029 * を使用して、'<', '>'などのデータをエスケープ表示させてください。
030 *
031 * タイプチェックとして、以下の条件を判定します。
032 * ・文字列長は、Byte換算での文字数との比較
033 * ・文字パラメータの 正規表現チェック
034 *
035 * @og.rev 3.3.3.2 (2003/07/24) 新規作成
036 * @og.group データ属性
037 *
038 * @version  4.0
039 * @author   Kazuhiko Hasegawa
040 * @since    JDK5.0,
041 */
042public class DBType_ALL extends AbstractDBType {
043        //* このプログラムのVERSION文字列を設定します。   {@value} */
044        private static final String VERSION = "5.2.2.0 (2010/11/01)" ;
045
046        /**
047         * データが登録可能かどうかをチェックします。
048         * データがエラーの場合は、そのエラー内容を返します。
049         *
050         * @og.rev 3.6.0.0 (2004/09/22) dbType パラメータを引数に追加
051         * @og.rev 5.2.2.0 (2010/11/01) 厳密にチェック(isStrict=true)するフラグを追加
052         *
053         * @param   key         キー
054         * @param   value       値
055         * @param   sizeX       整数部分の文字列の長さ
056         * @param   sizeY       少数部分の文字列の長さ
057         * @param   typeParam   dbType パラメータ
058         * @param   isStrict    厳密にチェックするかどうか[true:する/false:標準的]
059         *
060         * @return  エラー内容
061         */
062//      public ErrorMessage valueCheck( final String key ,final String value ,
063//                                                                      final int sizeX ,final int sizeY ,final String param ) {
064        @Override
065        public ErrorMessage valueCheck( final String key ,final String value ,
066                                                                        final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) {
067
068                ErrorMessage msg = new ErrorMessage();
069                if( value == null || value.length() == 0 ) { return msg; }
070
071                int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1;
072                String check = DBTypeCheckUtil.byteLengthCheck( value,len );
073                if( check != null ) {
074                        // 文字列の長さが指定の長さよりも長いです。
075                        msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,check,String.valueOf( len ) );
076                }
077
078                // 3.6.0.0 (2004/09/22) dbType パラメータを使用したマッチチェック
079                check = DBTypeCheckUtil.matcheCheck( value,typeParam );
080                if( check != null ) {
081                        // 指定の文字以外の文字が使われています。
082                        msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
083                }
084
085                return msg;
086        }
087}