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.hayabusa.db;
017    
018    import org.opengion.hayabusa.common.HybsSystem;
019    import org.opengion.fukurou.util.LogWriter;
020    import org.opengion.hayabusa.resource.CodeData;
021    
022    /**
023     * ãƒ??ã‚¿ã®ã‚³ãƒ¼ãƒ‰æƒ…報をå–り扱ã?‚¯ãƒ©ã‚¹ã§ã™ã?
024     *
025     * æ–?­—å?㮠「キー:ラベル キー:ラベルã€ã?æƒ??ã‹ã‚‰ã€HTMLã®ãƒ¡ãƒ‹ãƒ¥ãƒ¼ã‚?ƒªã‚¹ãƒˆã‚’作æ?ã™ã‚‹ãŸã‚ã® 
026     * オプションタグを作æ?ã—ãŸã‚Šã?与ãˆã‚‰ã‚ŒãŸã‚­ãƒ¼ã‚’ã‚‚ã¨ã«ã€ãƒã‚§ãƒ?‚¯æ¸ˆã¿ã®ã‚ªãƒ—ションタグã‚?
027     * 作æ?ã—ãŸã‚Šã—ã¾ã™ã?
028     *
029     * @og.rev 5.6.6.0 (2013/07/05) æ–°è¦è¿½åŠ?
030     * @og.group é¸æŠžãƒ‡ãƒ¼ã‚¿åˆ¶å¾¡
031     *
032     * @version  4.0
033     * @author   Kazuhiko Hasegawa
034     * @since    JDK5.0,
035     */
036    public class Selection_KEYVAL implements Selection {
037            private final String    ORG_KEYVAL ;
038    
039            private final String    CACHE ;
040    
041            /**
042             * コンストラクター
043             *
044             * @param       strCode コードデータパラメータæ–?­—å?
045             */
046            public Selection_KEYVAL( final String strCode ) {
047                    ORG_KEYVAL = strCode ;
048    
049                    if( strCode != null && strCode.indexOf( ':' ) > 0 ) {
050                            String[] keyvals = strCode.split( " " );                        // 「キー:ラベル キー:ラベルã€?ã‚’ã?キー:ラベル ã®é…å?ã«åˆ?§£ã™ã‚‹ã€?
051                            int size = keyvals.length;
052    
053                            StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
054                            for( int i=0; i<size; i++ ) {
055                                    String keyval = keyvals[i] ;
056                                    int idx ;
057                                    if( keyval == null || keyval.length() <= 0 || (idx = keyval.indexOf( ':' )) < 0 ) { continue; }           // スペã?スã§åˆ?§£ã—ãŸçµæžœ
058    
059                                    String key = keyval.substring( 0,idx ).trim();
060                                    String val = keyval.substring( idx+1 ).trim();
061    
062                                    buf.append( "<option value=\"" ).append( key ).append( "\"" );
063                                    buf.append( ">" ).append( val ).append( "</option>" );
064                            }
065    
066                            CACHE = buf.toString();
067                    }
068                    else {
069                            CACHE = "";
070                    }
071            }
072    
073            /**
074             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
075             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
076             * ã“ã?メソãƒ?ƒ‰ã§ã¯ã€ãƒ©ãƒ™ãƒ«(短)ãŒè¨­å®šã•れã¦ã?‚‹å ´åˆã§ã‚‚ã?ã“れを使用ã›ãšã«å¿?šãƒ©ãƒ™ãƒ«(é•·)を使用ã—ã¾ã™ã?
077             *
078             * @param   selectValue  é¸æŠžã•れã¦ã?‚‹å€¤
079             * @param   seqFlag  シーケンスアクセス機è? [true:ON/false:OFF]
080             *
081             * @return  オプションタグ
082             * @see     #getOption( String, boolean, boolean )
083             */
084            public String getOption( final String selectValue,final boolean seqFlag ) {
085                    return getOption( selectValue, seqFlag, false );
086            }
087    
088            /**
089             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
090             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
091             * <del>ã“ã?メソãƒ?ƒ‰ã§ã¯ã€å¼•æ•°ã®useShortLabelãŒtrueã«æŒ?®šã•れãŸå ´åˆã«ã€ãƒ©ãƒ™ãƒ«(短)ã‚’ã?ースã¨ã—ãŸ
092             * ãƒ??ルãƒãƒƒãƒ—表示を行ã„ã¾ã™ã?</del>
093             * ã“ã?クラスã§ã¯ã€useShortLabel ã¯ã€ç„¡è¦–ã•れã¾ã™ã?(常ã«ã€false ã§ã?
094             *
095             * @param   selectValue  é¸æŠžã•れã¦ã?‚‹å€¤
096             * @param   seqFlag  シーケンスアクセス機è? [true:ON/false:OFF]
097             * @param   useShortLabel ラベル(短)ã‚’ã?ースã¨ã—ãŸã‚ªãƒ—ション表示を行ã†ã‹ã©ã?‹(常ã«false)ã€?
098             *
099             * @return  オプションタグ
100             * @see     #getOption( String, boolean )
101             */
102            public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
103                    // マッãƒã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’探ã™ã?キーã®å‰å¾Œã?ãƒ?ƒ–ルクオートをåŠ?‘³ã—ã¦æ¤œç´¢
104                    String selVal = "\"" + selectValue + "\"" ;
105    
106                    int indx = CACHE.indexOf( selVal );
107    
108                    if( indx < 0 ) {
109                            // 4.0.0 (2005/01/31)
110                            if( selectValue != null && selectValue.length() > 0 ) {
111                                    String errMsg = "コードã«å­˜åœ¨ã—ãªã??ãŒæŒ‡å®šã•れã¾ã—ãŸã€?
112                                                            + " value=[" + selectValue + "]"
113                                                            + HybsSystem.CR + ORG_KEYVAL ;
114                                    LogWriter.log( errMsg );
115                            }
116                            return CACHE;
117                    }
118                    else {
119                            int addIndx = indx + (selVal.length()) ;        // selected ã®æŒ¿å…¥ä½ç½®
120    
121                            StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
122                            // 3.6.0.6 (2004/10/22) シーケンスアクセス機è?を指定ã™ã‚?seqFlag ã‚’å°Žå?
123                            if( seqFlag ) {
124                                    buf.append( "<option value=\"" ).append( selectValue ).append( "\"" );
125                            }
126                            else {
127                                    buf.append( CACHE.substring( 0,addIndx ) );
128                            }
129                            buf.append( " selected=\"selected\"" );
130                            buf.append( CACHE.substring( addIndx ) );
131                            return buf.toString() ;
132                    }
133            }
134    
135            /**
136             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
137             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
138             * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?
139             *
140             * @param   name         ラジオ㮠name
141             * @param   selectValue  é¸æŠžã•れã¦ã?‚‹å€¤
142             * @param   useLabel     ãƒ©ãƒ™ãƒ«è¡¨ç¤ºã®æœ‰ç„¡ [true:æœ?false:ç„¡]
143             *
144             * @return  オプションタグ
145             */
146            public String getRadio( final String name,final String selectValue,final boolean useLabel ) {
147                    String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?;
148                    throw new UnsupportedOperationException( errMsg );
149            }
150    
151            /**
152             * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã?
153             * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã?
154             * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?
155             *
156             * @param   selectValue  é¸æŠžã•れã¦ã?‚‹å€¤
157             *
158             * @return  オプションタグ
159             */
160            public String getRadioLabel( final String selectValue ) {
161                    String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?;
162                    throw new UnsupportedOperationException( errMsg );
163            }
164    
165            /**
166             * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã?
167             * é¸æŠžè‚¢(value)ãŒã?存在ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã?
168             * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã?
169             *
170             * @param   selectValue é¸æŠžè‚¢ã®å€¤
171             *
172             * @return  é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«
173             * @see     #getValueLabel( String,boolean )
174             */
175            public String getValueLabel( final String selectValue ) {
176                    return getValueLabel( selectValue,false );
177            }
178    
179            /**
180             * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã?
181             * é¸æŠžè‚¢(value)ãŒã?存在ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã?
182             * <del>ã“ã?メソãƒ?ƒ‰ã§ã¯ã€çŸ­ç¸®ãƒ©ãƒ™ãƒ«ã‚’è¿”ã™ã‹ã©ã?‹ã‚’指定ã™ã‚‹ãƒ•ラグを指定ã—ã¾ã™ã?</del>
183             * getValueLabel( XX,false ) ã¯ã€getValueLabel( XX ) ã¨åŒã˜ã§ã™ã?
184             *
185             * ※ ã“ã?クラスã§ã¯ã€çŸ­ç¸®ãƒ©ãƒ™ãƒ«ã¯ä½¿ç”¨ã•れã¾ã›ã‚“ã€?
186             *
187             * @param       selectValue     é¸æŠžè‚¢ã®å€¤
188             * @param       flag    短縮ラベルã‚?[true:使用ã™ã‚‹/false:ã—ãªã„](常㫠false)
189             *
190             * @return  é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ«
191             * @see     #getValueLabel( String )
192             */
193            public String getValueLabel( final String selectValue,final boolean flag ) {
194                    // マッãƒã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’探ã™ã?キーã®å‰å¾Œã?ãƒ?ƒ–ルクオートをåŠ?‘³ã—ã¦æ¤œç´¢
195                    String selVal = "\"" + selectValue + "\"" ;
196    
197                    int indx = CACHE.indexOf( selVal );
198    
199                    if( indx < 0 ) {
200                            // マッãƒã—ãªã‘れã°ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã™ã€?
201                            return selectValue;
202                    }
203                    else {
204                            // マッãƒã™ã‚Œã?ã€ã‚­ãƒ¼ä»¥ä¸‹ã?BODYéƒ¨ã®æ–?­—å?ã‚’å?りå?ã—ã¦è¿”ã™ã€?
205                            int stIdx = indx + (selVal.length()) + 1 ;                      // ?‹ï¼?ã¯ã€?>" ã®ä½ç½®
206                            int edIdx = CACHE.indexOf( '<',stIdx );                              // 終äº?‚¢ãƒ‰ãƒ¬ã‚¹
207    
208                            return CACHE.substring( stIdx,edIdx );
209                    }
210            }
211    
212            /**
213             * マルãƒã?キーセレクトを使用ã™ã‚‹ã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã?
214             * true?šä½¿ç”¨ã™ã‚‹ã€‚false:使用ã—ãªã?ã§ã™ã?
215             * ãŸã ã—ã?実際ã«ä½¿ç”¨ã™ã‚‹ã‹ã©ã?‹ã¯ã€HTMLå‡ºåŠ›æ™‚ã«æ±ºã‚ã‚‹ã“ã¨ãŒå?æ¥ã¾ã™ã?
216             * ã“ã“ã§ã¯ã€USE_MULTI_KEY_SELECT ã?true ã§ã€USE_SIZE(=20)以上ã?å ´åˆã«
217             * true ã‚’è¿”ã—ã¾ã™ã?
218             *
219             * ※ ã“ã“ã§ã¯ã€å¸¸ã« false ã‚’è¿”ã—ã¾ã™ã?
220             *
221             * @return  é¸æŠžãƒªã‚¹ãƒˆã§ã€ã?ルãƒã?キーセレクトを使用ã™ã‚‹ã‹ã©ã?‹(true:使用ã™ã‚‹)
222             */
223            public boolean useMultiSelect() {
224                    return false;
225            }
226    
227            /**
228             * オブジェクトã?キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã?
229             * キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?ã‚?無効)ã§ã‚れã°ã€true ã‚’ã?有効ã§ã‚れã°ã€?
230             * false ã‚’è¿”ã—ã¾ã™ã?
231             *
232             * ※ ã“ã“ã§ã¯ã€å¸¸ã« false ã‚’è¿”ã—ã¾ã™ã?
233             *
234             * @return  キャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れãªã‚?true
235             */
236            public boolean isTimeOver() {
237                    return false;
238            }
239    }