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 java.util.Calendar;
019    
020    import org.opengion.fukurou.util.ErrorMessage;
021    import org.opengion.fukurou.util.StringUtil;
022    import org.opengion.hayabusa.db.AbstractDBType;
023    import org.opengion.hayabusa.db.DBTypeCheckUtil;
024    import org.opengion.fukurou.util.HybsDateUtil;
025    
026    /**
027     * æ–?­—å?ã®æ™‚間属æ?(æ™?åˆ?ç§?ã®åŠè§’ã?時間を扱ã?‚ºã®ã€ã‚«ãƒ©ãƒ?±žæ?を定義ã—ã¾ã™ã?
028     *
029     * HHmmss ã«å¯¾å¿œã—ã¦ã?‚‹å¿?¦ãŒã‚りã¾ã™ã?
030     * (HHmmã®ãƒ??ã‚¿ã§ã‚‚利用å¯èƒ½ã§ã?
031     * ãŸã ã—ã?日付ã?æ•´åˆæ?ãƒã‚§ãƒ?‚¯ã¯è¡Œã„ã¾ã›ã‚“ãŒã?valueAdd( String value )ã§ã®
032     * 日付ã?åŠ?®—時ã«ã¯ã€æ­£å¼ãªæ—¥ä»˜ãƒ‡ãƒ¼ã‚¿ã«ã¦åŠ?®—ã—ã¾ã™ã?
033     *
034     * タイプãƒã‚§ãƒ?‚¯ã¨ã—ã¦ã€ä»¥ä¸‹ã?æ¡ä»¶ã‚’判定ã—ã¾ã™ã?
035     * ・æ–?­—å?é•·ã¯ã€ç›´æŽ¥è¨ˆç®—ã§æ–?­—æ•°ã¨ã®æ¯”è¼?
036     * ・日付使用æ–?­—ãƒã‚§ãƒ?‚¯ã€?'0' > c || '9' < c)以外ã?エラー
037     * ・æ–?­—パラメータ㮠正è¦è¡¨ç¾ãƒã‚§ãƒ?‚¯
038     *
039     * @og.group ãƒ??タ属æ?
040     * @og.rev 5.4.3.6 (2012/01/20)  タイプãƒã‚§ãƒ?‚¯ãŒæŠœã‘ã¦ã?‚‹ã®ã§è¿½åŠ?
041     *
042     * @version  4.0
043     * @author   Kazuhiko Hasegawa
044     * @since    JDK5.0,
045     */
046    public class DBType_HMS extends AbstractDBType {
047            //* ã“ã?プログラãƒ??VERSIONæ–?­—å?を設定ã—ã¾ã™ã?       {@value} */
048            private static final String VERSION = "5.6.1.0 (2013/02/01)" ;
049    
050            /**
051             * Stringå¼•æ•°ã®æ–?­—å?を+1ã—ãŸæ–‡å­—å?ã‚’è¿”ã—ã¾ã™ã?
052             * ã“れã¯ã€è‹±å­—ã?å ´å?A,B,C ãªã©)ã¯ã€B,C,D ã®ã‚ˆã†ã«,æœ?µ‚æ¡ã?æ–?­—コードを
053             * ?‹ï¼?ã—ã¾ã™ã?
054             * æ–?­—å?ãŒæ•°å­—タイプã?å ´åˆã?, æ•°å­—ã«å¤‰æ›ã—ã¦ã€?1 ã—ã¾ã™ã?(æ¡ä¸ŠãŒã‚Šã‚‚ã‚り)
055             * 混在タイプã?å ´åˆã?,æœ?¾Œã?æ¡ã ã‘を確èªã—㦠?‹ï¼‘ã—ã¾ã™ã?
056             * 引数ã?null ã®å ´åˆã¨ã€ã‚¼ãƒ­æ–?­—å?("")ã®å ´åˆã?,物ç?š„åˆæœŸè¨­å®šå?(String getDefault())
057             * ã®å€¤ã‚’è¿”ã—ã¾ã™ã?
058             *
059             * @param       value   Stringå¼•æ•°ã®æ–?­—å?
060             *
061             * @return  Stringå¼•æ•°ã®æ–?­—å?を+1ã—ãŸæ–‡å­—å?
062             */
063            @Override
064            public String valueAdd( final String value ) {
065                    if( value == null || value.length() == 0 ) { return getDefault(); }
066    
067                    int hour = Integer.parseInt( value.substring( 0,2 ) );
068    
069                    // å…ˆé?ã« 00 を付加ã™ã‚‹ç‚ºã«ã€æ•°å­—ã? 100 を加算ã—ã¦ã?‚‹ã€?
070                    if( hour < 24 ) { hour = 101 + hour; }
071                    else                    { hour = 100; }
072    
073                    String rtn = hour + value.substring( 2 );
074    
075                    return rtn.substring( 1 );
076            }
077    
078            /**
079             * Stringå¼•æ•°ã®æ–?­—å?ã«ã€ç¬¬?’å¼•æ•°ã«æŒ?®šã?æ–?­—å?(æ•°å­—ã?日付ç­?を加算ã—ã¦è¿”ã—ã¾ã™ã?
080             *
081             * ã“ã“ã§ã¯ã€HHmmss å½¢å¼ã?ãƒ??ã‚¿ã«ã€æ™‚é–“ã‚’åŠ?®—ã—ã¾ã™ã?
082             *
083             * ã“ã? HMS ã¯ã€å¼•æ•°ã«ã€æ—¥ä»˜å˜ä½ã‚’æŒ?®šã§ãã¾ã™ã?å˜ä½ã?ã€HHmmss å½¢å¼ã?
084             * ?‘文字をæŒ?®šã—ã¾ã™ã?大æ–?­—ã?å°æ–‡å­—も識別ã—ã¾ã™ã?value="5H" ã¨ã™ã‚Œã°ã€?¼•時間ã?value="5m"
085             * ã¨ã™ã‚Œã°ã€?¼•å? 追åŠ?—ã¾ã™ã?
086             * æŒ?®šã—ãªã??åˆã?ã€æ™‚を加算ã—ã¾ã™ã?
087             *
088             * ã“ã“ã®ãƒ??ã‚¿ã¯ã€æ™‚é–“ãŒç¹°ã‚Šè¶Šã—ã¦ã‚‚ã?日付ã«å½±éŸ¿ã—ã¾ã›ã‚“ã€?
089             * ã¾ãŸã??’4時間をè¶?ˆãŸå?åˆã?ã€?0 æ™‚ã«æˆ»ã‚Šã¾ã™ã?
090             *
091             * @og.rev 5.6.0.3 (2012/01/24) ADD ã«ã€å¼•æ•°ã®å€¤ã‚’加算ã™ã‚‹æ©Ÿè?を追åŠ?—ã¾ã™ã?
092             * @og.rev 5.6.1.0 (2013/02/01) åŠ?®—ã™ã‚‹å¼•æ•°ã«ã€æ—¥ä»˜å˜ä½?'H','m','s')を指定å¯èƒ½ã«ã—ã¾ã™ã?
093             *
094             * @param   value  String引数
095             * @param   add    åŠ?®—ã™ã‚‹æ™‚間文字å?(å˜ä½ä»˜ã:['H','m','s'])
096             *
097             * @return  å¼•æ•°ã®æ–?­—å?ã«æ™‚間を加算ã—ã¾ã™ã?
098             */
099            @Override
100            public String valueAdd( final String value,final String add ) {
101                    if( value == null || value.length() == 0 ) { return getDefault(); }
102    
103                    // 日付文字å?ã«ãƒ?ƒŸãƒ¼ã®å¹´æœˆæ—¥ã‚’追åŠ?—ã¦ãŠãã€?
104                    return HybsDateUtil.getDatePlus( ("20100101" + value),add,Calendar.HOUR_OF_DAY,"HHmmss" );
105    
106    //              int addSu = 1;
107    //              if( add != null && !add.isEmpty() ) {
108    //                      addSu = Integer.parseInt( add );
109    //              }
110    
111    //              int hour = Integer.parseInt( value.substring( 0,2 ) ) + addSu;
112    
113                    // å…ˆé?ã« 00 を付加ã™ã‚‹ç‚ºã«ã€æ•°å­—ã? 100 を加算ã—ã¦ã?‚‹ã€‚ã¾ãŸã?24時間をè¶?ˆã‚‹å?åˆã?ã€?0 ã«æˆ»ã‚‹ã?
114    //              String rtn = ( 100 + ( hour % 24 ) ) + value.substring( 2 );            // 後ã‚ã¯ã€MMSSã®åˆ?
115                    //           ~~~~~~~~~~~~~~~~~~~~~~~   ~~~~~~~~~~~~~~~~~~~~
116                    //           数字部åˆ?                 MMSSã®æ–?­—å?部åˆ?
117    
118                    // å…ˆé?æ–?­—å?を削除ã™ã‚‹ã€?
119    //              return rtn.substring( 1 );
120            }
121    
122            /**
123             * エãƒ?‚£ã‚¿ãƒ¼ã§ç·¨é›?•れãŸãƒ??タを登録ã™ã‚‹å ´åˆã«ã€ãƒ‡ãƒ¼ã‚¿ãã?ã‚‚ã?ã‚?
124             * 変æ›ã—ã¦ã€å®Ÿç™»éŒ²ãƒ??タを作æ?ã—ã¾ã™ã?
125             * 例ãˆã°,大æ–?­—ã?ã¿ã®ãƒ•ィールドãªã‚‰ã?大æ–?­—化ã—ã¾ã™ã?
126             * 実登録ãƒ??ã‚¿ã®ä½œæ?ã¯ã€DBType オブジェクトを利用ã—ã¾ã™ã?ã§,
127             * ã“れ㨠Editor ã¨ãŒã‚¢ãƒ³ãƒžãƒƒãƒã?å ´åˆã?ã€ã†ã¾ãデータ変æ›
128             * ã•れãªã?¯èƒ½æ€§ãŒã‚りã¾ã™ã?ã§ã€æ³¨æ„願ã„ã¾ã™ã?
129             *
130             * @param       value   (ä¸?ˆ¬ã«ç·¨é›?ƒ‡ãƒ¼ã‚¿ã¨ã—ã¦ç™»éŒ²ã•れãŸãƒ‡ãƒ¼ã‚¿)
131             *
132             * @return  修正後ã?æ–?­—å?(ä¸?ˆ¬ã«ãƒ??タベã?スã«ç™»éŒ²ã™ã‚‹ãƒ??ã‚¿)
133             */
134            @Override
135            public String valueSet( final String value ) {
136                    if( value == null || value.length() == 0 ) { return ""; }
137                    return StringUtil.lTrim0( StringUtil.deleteChar( value,':' ) );
138            }
139    
140            /**
141             * ãƒ??ã‚¿ãŒç™»éŒ²å¯èƒ½ã‹ã©ã?‹ã‚’ãƒã‚§ãƒ?‚¯ã—ã¾ã™ã?
142             * ãƒ??ã‚¿ãŒã‚¨ãƒ©ãƒ¼ã®å ´åˆã?ã€ãã®ã‚¨ãƒ©ãƒ¼å†?®¹ã‚’è¿”ã—ã¾ã™ã?
143             *
144             * @og.rev 5.2.3.6 (2012/01/20) 数値ã®ã¿ã«é™å®šã™ã‚‹ãŸã‚ã«è¿½åŠ?
145             * @og.rev 5.6.0.3 (2012/01/24) ADD ã«ã€å¼•æ•°ã®å€¤ã‚’加算ã™ã‚‹æ©Ÿè?を追åŠ?—ã¾ã™ã?
146             *
147             * @param   key         キー
148             * @param   value       値
149             * @param   sizeX       整数部åˆ??æ–?­—å?ã®é•·ã?
150             * @param   sizeY       少数部åˆ??æ–?­—å?ã®é•·ã?
151             * @param   typeParam   dbType パラメータ
152             * @param   isStrict    厳å¯?«ãƒã‚§ãƒ?‚¯ã™ã‚‹ã‹ã©ã?‹[true:ã™ã‚‹/false:標準的]
153             *
154             * @return  エラーå†?®¹
155             */
156            @Override
157            public ErrorMessage valueCheck( final String key ,final String value ,
158                                                                            final int sizeX ,final int sizeY ,final String typeParam ,final boolean isStrict) {
159                    String checkVal = valueSet(value); // ?šã?念ã®ãŸã‚外ã—ã¦ãŠã
160    
161                    ErrorMessage msg = new ErrorMessage();
162                    if( checkVal == null || checkVal.length() == 0 ) { return msg; }
163    
164                    int len = (sizeY == 0) ? sizeX : sizeX + sizeY + 1;
165                    if( isStrict ) {
166                            if( len != checkVal.length() ) {
167                                    // æ–?­—å?ã®é•·ã•ãŒæŒ?®šã?é•·ã•ã¨ç•°ãªã‚Šã¾ã™ã?
168                                    msg.addMessage( 0,ErrorMessage.NG,"ERR0011", key,value, String.valueOf( value.length() ), String.valueOf( len ) );
169                            }
170                    }
171                    else {
172                            if( len < checkVal.length() ) {
173                                    // æ–?­—å?ã®é•·ã•ãŒæŒ?®šã?é•·ã•よりも長ã?§ã™ã?
174                                    msg.addMessage( 0,ErrorMessage.NG,"ERR0006",key,value,
175                                                                                    String.valueOf( value.length() ),String.valueOf( len ) );
176                            }
177                    }
178    
179    //              StringBuilder val = new StringBuilder();
180    //              boolean isError = false;
181    //              for( int i=0; i<checkVal.length(); i++ ) {
182    //                      char ch = checkVal.charAt( i );
183    //                      if( ('0' > ch || '9' < ch) ) {
184    //                              val.append( "<span class=\"NG\">" ).append( ch ).append( "</span>" );
185    //                              isError = true;
186    //                      }
187    //                      else {
188    //                              val.append( ch );
189    //                      }
190    //              }
191    //              if( isError ) {
192    //                      // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
193    //                      msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,val.toString() );
194    //              }
195    
196                    // 5.6.0.3 (2012/01/24) æ–?­—ã?ç¯?›²ãƒã‚§ãƒ?‚¯
197                    String check = DBTypeCheckUtil.rangeCheck( checkVal, '0', '9' );
198                    if( check != null ) {
199                            // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
200                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
201                    }
202    
203                    // 5.6.0.3 (2012/01/24) 時å?ç§’ã?æ•´åˆæ?ãƒã‚§ãƒ?‚¯
204                    check = DBTypeCheckUtil.hmsFormatCheck( checkVal );
205                    if( check != null ) {
206                            // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
207                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
208                    }
209    
210                    // 3.6.0.0 (2004/09/22) dbType パラメータを使用ã—ãŸãƒžãƒƒãƒãƒã‚§ãƒ?‚¯
211                    check = DBTypeCheckUtil.matcheCheck( checkVal,typeParam );
212                    if( check != null ) {
213                            // æŒ?®šã?æ–?­—以外ã?æ–?­—ãŒä½¿ã‚れã¦ã?¾ã™ã?
214                            msg.addMessage( 0,ErrorMessage.NG,"ERR0009", key,check );
215                    }
216    
217                    return msg;
218            }
219    }