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 = "4.0.0.0 (2005/08/31)" ; 049 050 private static final String DENKI_REV = "ABCEFGHJKLMNPRSTUVWY"; 051 private static final String KIKAI_REV = "0123456789ABCEFGHJKLMNPRSTUVWY"; 052 053 /** 054 * 製造品番のRev を UPした文字列を返します。 055 * 引数が null 、ゼロ文字列("")、の場合は,物理的初期設定値 056 * (String getDefault())の値を返します。 057 * 10桁未満、購入品(Z品番)、RevUPできない場合は,そのままの品番を返します。 058 * 059 * 但し、電気品番(1桁目が'D' 5桁目が'8'OR'9')は、一番最後の桁をリビジョンUP 060 * □□□-□□□□□-□□■ 061 * 機械品番(上記以外の品番)は、10桁目をリビジョンUPする。 062 * □□□-□□□□□-□■ 063 * 064 * @og.rev 2.1.3.0 (2002/12/12) RevUP 対象でないコードをRevUPする場合の不具合対応 065 * 066 * @param value String引数の文字列 067 * 068 * @return String引数の文字列を+1した文字列 069 */ 070 @Override 071 public String valueAdd( final String value ) { 072 if( value == null || value.length() == 0 ) { return getDefault(); } 073 if( value.length() < 10 || value.charAt(0) == 'Z' ) { return value; } 074 075 char[] ch = value.toCharArray(); 076 077 // 電気品番の場合 078 if( ch[0] == 'D' && ( ch[4] == '8' || ch[4] == '9' ) ) { 079 if( value.length() < 11 ) { return value; } // 2002.07.12 080 int pos = DENKI_REV.indexOf( (int)ch[10] ); 081 if( pos >= 0 ) { ch[10] = DENKI_REV.charAt( pos+1 ); } 082 else { ch[10] ++ ; } // 2.1.3.0 追加 083 } 084 else { 085 int pos = KIKAI_REV.indexOf( (int)ch[9] ); 086 if( pos >= 0 ) { ch[9] = KIKAI_REV.charAt( pos+1 ); } 087 else { ch[9] ++ ; } // 2.1.3.0 追加 088 } 089 090 return new String( ch ); 091 } 092 093 /** 094 * エディターで編集されたデータを登録する場合に、データそのものを 095 * 変換して、実登録データを作成します。 096 * データの表示用文字列を返します。 097 * XXX-XXXXX-XXX 形式で入力された情報を、XXXXXXXXXXX 形式で表示します。 098 * カット&ペースト対策です。 099 * 100 * @og.rev 3.8.6.1 (2006/10/24) 新規追加 101 * 102 * @param value (一般に編集データとして登録されたデータ) 103 * 104 * @return 修正後の文字列(一般にデータベースに登録するデータ) 105 */ 106 @Override 107 public String valueSet( final String value ) { 108 String newVal = StringUtil.rTrim( value ); 109 110 if( newVal != null && newVal.indexOf( '-' ) >= 0 ) { 111 newVal = StringUtil.replace( newVal,"-","" ); 112 } 113 114 return newVal; 115 } 116}