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