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.fukurou.util.KanaFilter;
021    import org.opengion.hayabusa.db.AbstractDBType;
022    import org.opengion.hayabusa.db.DBTypeCheckUtil;
023    
024    /**
025     * åŠè§?全角混在ã®ã‚¯ãƒ©ã‚¹ã§ã™ãŒã€åŠè§’カタカナã?ã¿ã‚’é?ã•ãªã?–‡å­—å?を扱ã?‚ºã®ã€ã‚«ãƒ©ãƒ?±žæ?を定義ã—ã¾ã™ã?
026     *
027     * åŠè§’カタカナã?定義ã¯ã€\uFF61 ã‹ã‚‰ \uFF9F ã¾ã§ã§ã™ã?
028     * åŠè§’カタカナを入力ã™ã‚‹ã¨ã€å?角カタカナã«å¤‰æ›ã—ã¦ã€ç™»éŒ²ã—ã¦ã?¾ã™ã?
029     * ã“ã?変æ›å‡¦ç?«ã€KanaFilter#han2zen を使用ã—ã¦ã?¾ã™ã?ã“れã¯ã€?
030     * 『CJKV日中韓越情報処ç??ã®ãƒ•ィルターアルゴリズãƒ?§æ¿ç‚¹ã‚?Šæ¿ç‚¹ã®æ­£ã—ã„処ç?‚‚å«ã¾ã‚Œã¦ã?¾ã™ã?
031     *
032     * タイプãƒã‚§ãƒ?‚¯ã¨ã—ã¦ã€ä»¥ä¸‹ã?æ¡ä»¶ã‚’判定ã—ã¾ã™ã?
033     * ・æ–?­—å?é•·ã¯ã€Byteæ›ç®—ã§ã®æ–?­—æ•°ã¨ã®æ¯”è¼?
034     * ・åŠè§’文字+å?角カタカナãƒã‚§ãƒ?‚¯ã€Œc < 0x20 || ( c >= 0xff61 && c <= 0xff9f )以外ã?エラー
035     * ・æ–?­—パラメータ㮠正è¦è¡¨ç¾ãƒã‚§ãƒ?‚¯
036     * ・クロスサイトスクリプティングãƒã‚§ãƒ?‚¯
037     *
038     * @og.rev 3.4.0.0 (2003/09/01) æ–°è¦ä½œæ?
039     * @og.group ãƒ??タ属æ?
040     *
041     * @version  4.0
042     * @author   Kazuhiko Hasegawa
043     * @since    JDK5.0,
044     */
045    public class DBType_XKZ extends AbstractDBType {
046            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
047            private static final String VERSION = "5.2.2.0 (2010/11/01)" ;
048    
049            /**
050             * エãƒ?‚£ã‚¿ãƒ¼ã§ç·¨é›?•れãŸãƒ??タを登録ã™ã‚‹å ´åˆã«ã€ãƒ‡ãƒ¼ã‚¿ãã?ã‚‚ã?ã‚?
051             * 変æ›ã—ã¦ã€å®Ÿç™»éŒ²ãƒ??タを作æ?ã—ã¾ã™ã?
052             * 例ãˆã°,大æ–?­—ã?ã¿ã®ãƒ•ィールドãªã‚‰ã?大æ–?­—化ã—ã¾ã™ã?
053             * 実登録ãƒ??ã‚¿ã®ä½œæ?ã¯ã€DBType オブジェクトを利用ã—ã¾ã™ã?ã§,
054             * ã“れ㨠Editor ã¨ãŒã‚¢ãƒ³ãƒžãƒƒãƒã?å ´åˆã?ã€ã†ã¾ãデータ変æ›
055             * ã•れãªã?¯èƒ½æ€§ãŒã‚りã¾ã™ã?ã§ã€æ³¨æ„願ã„ã¾ã™ã?
056             *
057             * @param       value   (ä¸?ˆ¬ã«ç·¨é›?ƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ç™»éŒ²ã•れãŸãƒ‡ãƒ¼ã‚¿)
058             *
059             * @return  修正後ã?æ–?­—å?(ä¸?ˆ¬ã«ãƒ??タベã?スã«ç™»éŒ²ã™ã‚‹ãƒ??ã‚¿)
060             */
061            @Override
062            public String valueSet( final String value ) {
063                    if( value == null ) { return null; }
064                    return KanaFilter.han2zen( StringUtil.rTrim( value ) );
065            }
066    
067            /**
068             * ãƒ??ã‚¿ãŒç™»éŒ²å¯èƒ½ã‹ã©ã?‹ã‚’ãƒã‚§ãƒ?‚¯ã—ã¾ã™ã?
069             * ãƒ??ã‚¿ãŒã‚¨ãƒ©ãƒ¼ã®å ´åˆã?ã€ãã®ã‚¨ãƒ©ãƒ¼å†?®¹ã‚’è¿”ã—ã¾ã™ã?
070             *
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                    StringBuilder val = new StringBuilder();
100                    boolean isError = false;
101                    for( int i=0; i<value.length(); i++ ) {
102                            char ch = value.charAt( i );
103                            if( ch < 0x20 || ( ch >= 0xff61 && ch <= 0xff9f ) ) {
104                                    val.append( "<span class=\"NG\">" ).append( ch ).append( "</span>" );
105                                    isError = true;
106                            }
107                            else {
108                                    val.append( ch );
109                            }
110                    }
111                    if( isError ) {
112                            // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
113                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,val.toString() );
114                    }
115    
116                    // 3.6.0.0 (2004/09/22) dbType パラメータを使用ã—ãŸãƒžãƒƒãƒãƒã‚§ãƒ?‚¯
117                    check = DBTypeCheckUtil.matcheCheck( value,typeParam );
118                    if( check != null ) {
119                            // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
120                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
121                    }
122    
123                    // クロスサイトスクリプティング対策ï¼?<', '>' ã¯ç™»éŒ²ã•ã›ãªã??
124                    msg = xssCheck( key ,value, msg );
125    
126                    return msg;
127            }
128    }