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.StringUtil;
019import org.opengion.hayabusa.db.AbstractDBType;
020
021/**
022 * 情報機器事業部向け、品番情報の文字列を扱う為の、カラム属性を定義します。
023 *
024 * 品番情報は、3-5-3品番情報として扱われます。また、それぞれのフィールドにおいて、
025 * 使用可能文字(例えば、Rev文字列の制限)などを考慮しています。
026 *
027 *   電気品番(1桁目が'D' 5桁目が'8'OR'9')は、一番最後の桁をリビジョンUP
028 *   (ABCEFGHJKLMNPRSTUVWY)
029 *       □□□-□□□□□-□□■
030 *   機械品番(上記以外の品番)は、10桁目をリビジョンUPする。
031 *       □□□-□□□□□-□■
032 *   (0123456789ABCEFGHJKLMNPRSTUVWY)
033 *
034 * タイプチェックとして、以下の条件を判定します。
035 * ・文字列長は、Byte換算での文字数との比較
036 * ・半角文字列チェック「 c < 0x20 || c > 0x7e 以外」エラー
037 * ・文字パラメータの 正規表現チェック
038 * ・クロスサイトスクリプティングチェック
039 *
040 * @og.group データ属性
041 *
042 * @version  4.0
043 * @author   Kazuhiko Hasegawa
044 * @since    JDK5.0,
045 */
046public class DBType_PN extends AbstractDBType {
047        /** このプログラムのVERSION文字列を設定します。   {@value} */
048        private static final String VERSION = "6.4.2.0 (2016/01/29)" ;
049
050        private static final String DENKI_REV = "ABCEFGHJKLMNPRSTUVWY";
051        private static final String KIKAI_REV = "0123456789ABCEFGHJKLMNPRSTUVWY";
052
053        /**
054         * デフォルトコンストラクター
055         *
056         * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
057         */
058        public DBType_PN() { super(); }         // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
059
060        /**
061         * 製造品番のRev を UPした文字列を返します。
062         * 引数が null 、ゼロ文字列("")、の場合は,物理的初期設定値
063         * (String getDefault())の値を返します。
064         * 10桁未満、購入品(Z品番)、RevUPできない場合は,そのままの品番を返します。
065         *
066         * 但し、電気品番(1桁目が'D' 5桁目が'8'OR'9')は、一番最後の桁をリビジョンUP
067         *       □□□-□□□□□-□□■
068         *       機械品番(上記以外の品番)は、10桁目をリビジョンUPする。
069         *       □□□-□□□□□-□■
070         *
071         * @og.rev 2.1.3.0 (2002/12/12) RevUP 対象でないコードをRevUPする場合の不具合対応
072         *
073         * @param       value   String引数の文字列
074         *
075         * @return  String引数の文字列を+1した文字列
076         */
077        @Override
078        public String valueAdd( final String value ) {
079                if( value == null || value.isEmpty() ) { return getDefault(); }
080                if( StringUtil.startsChar( value , 'Z' ) ) { return value; }    // 6.2.0.0 (2015/02/27) 1文字 String.startsWith
081
082                char[] ch = value.toCharArray();
083
084                // 電気品番の場合
085                if( ch[0] == 'D' && ( ch[4] == '8' || ch[4] == '9' ) ) {
086                        if( value.length() < 11 ) { return value; }                             // 2002.07.12
087                        final int pos = DENKI_REV.indexOf( (int)ch[10] );
088                        if( pos >= 0 ) { ch[10] = DENKI_REV.charAt( pos+1 ); }
089                        else {           ch[10] ++ ;                         }  // 2.1.3.0 追加
090                }
091                else {
092                        final int pos = KIKAI_REV.indexOf( (int)ch[9] );
093                        if( pos >= 0 ) { ch[9] = KIKAI_REV.charAt( pos+1 ); }
094                        else {           ch[9] ++ ;                         }   // 2.1.3.0 追加
095                }
096
097                return new String( ch );
098        }
099
100        /**
101         * エディターで編集されたデータを登録する場合に、データそのものを
102         * 変換して、実登録データを作成します。
103         * データの表示用文字列を返します。
104         * XXX-XXXXX-XXX 形式で入力された情報を、XXXXXXXXXXX 形式で表示します。
105         * カット&ペースト対策です。
106         *
107         * @og.rev 3.8.6.1 (2006/10/24) 新規追加
108         *
109         * @param       value   (一般に編集データとして登録されたデータ)
110         *
111         * @return  修正後の文字列(一般にデータベースに登録するデータ)
112         */
113        @Override
114        public String valueSet( final String value ) {
115                String newVal = StringUtil.rTrim( value );
116
117                if( newVal != null && newVal.indexOf( '-' ) >= 0 ) {
118                        newVal = StringUtil.replace( newVal,"-","" );
119                }
120
121                return newVal;
122        }
123}