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
023 /**
024 * ãƒ??タのコード情報を取り扱ã�?‚¯ラスですã?
025 *
026 * æ–?—å?の 「キー:ラベル キー:ラベル」ã?æƒ??から、HTMLのメニューã‚?ƒªストを作æ?するための
027 * オプションタグを作æ?したりã?与えられたキーをもとに、チェãƒ?‚¯済みのオプションタグã‚?
028 * 作æ?したりしますã?
029 * ラベル にスペã?スを含ませる場合ã?、ダブルクォーãƒ??ションで囲ってくださいã€?
030 *
031 * @og.rev 5.6.6.0 (2013/07/05) 新規追åŠ?
032 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?基本実è£?�¨しますã?
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 public class Selection_KEYVAL extends Selection_NULL {
041 private final String ORG_KEYVAL ;
042
043 private final String CACHE ;
044
045 /**
046 * コンストラクター
047 *
048 * @og.rev 5.6.7.1 (2013/08/09) 「キー:ラベル キー:ラベル」å?解に、クオートå?ç�?‚’åŠ?‘³
049 *
050 * @param strCode コードデータパラメータæ–?—å?
051 */
052 public Selection_KEYVAL( final String strCode ) {
053 ORG_KEYVAL = strCode ;
054
055 if( strCode != null && strCode.indexOf( ':' ) > 0 ) {
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 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
091 *
092 * @param selectValue 選択されてã�?‚‹値
093 * @param seqFlag シーケンスアクセス機è? [true:ON/false:OFF]
094 *
095 * @return オプションタグ
096 * @see #getOption( String, boolean, boolean )
097 */
098 // public String getOption( final String selectValue,final boolean seqFlag ) {
099 // return getOption( selectValue, seqFlag, false );
100 // }
101
102 /**
103 * 初期値が選択済みの 選択肢(オプション)を返しますã?
104 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
105 * こã?クラスでは、useShortLabel は、無視されますã?(常に、false でã�?
106 *
107 * @param selectValue 選択されてã�?‚‹値
108 * @param seqFlag シーケンスアクセス機è? [true:ON/false:OFF]
109 * @param useShortLabel ラベル(短)をã?ースとしたオプション表示を行うかどã�?�‹(常にfalse)ã€?
110 *
111 * @return オプションタグ
112 * @see #getOption( String, boolean )
113 */
114 @Override
115 public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) {
116 // マッチするアドレスを探すã?キーの前後ã?ãƒ?ƒ–ルクオートをåŠ?‘³して検索
117 String selVal = "\"" + selectValue + "\"" ;
118
119 int indx = CACHE.indexOf( selVal );
120
121 if( indx < 0 ) {
122 // 4.0.0 (2005/01/31)
123 if( selectValue != null && selectValue.length() > 0 ) {
124 String errMsg = "コードに存在しなã�??が指定されましたã€?
125 + " value=[" + selectValue + "]"
126 + HybsSystem.CR + ORG_KEYVAL ;
127 LogWriter.log( errMsg );
128 }
129 return CACHE;
130 }
131 else {
132 int addIndx = indx + selVal.length() ; // selected の挿入位置
133
134 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_MIDDLE );
135 // 3.6.0.6 (2004/10/22) シーケンスアクセス機è?を指定すã‚?seqFlag を導å?
136 if( seqFlag ) {
137 buf.append( "<option value=\"" ).append( selectValue ).append( "\"" );
138 }
139 else {
140 buf.append( CACHE.substring( 0,addIndx ) );
141 }
142 buf.append( " selected=\"selected\"" );
143 buf.append( CACHE.substring( addIndx ) );
144 return buf.toString() ;
145 }
146 }
147
148 /**
149 * 初期値が選択済みの 選択肢(オプション)を返しますã?
150 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
151 * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
152 *
153 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
154 *
155 * @param name ラジオの name
156 * @param selectValue 選択されてã�?‚‹値
157 * @param useLabel ラベル表示の有無 [true:æœ?false:無]
158 *
159 * @return オプションタグ
160 */
161 // public String getRadio( final String name,final String selectValue,final boolean useLabel ) {
162 // String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
163 // throw new UnsupportedOperationException( errMsg );
164 // }
165
166 /**
167 * 初期値が選択済みの 選択肢(オプション)を返しますã?
168 * こã?オプションは、引数の値をå?期å?とするオプションタグを返しますã?
169 * ※ こã?クラスでは実è£?�•れてã�?�¾せんã€?
170 *
171 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
172 *
173 * @param selectValue 選択されてã�?‚‹値
174 *
175 * @return オプションタグ
176 */
177 // public String getRadioLabel( final String selectValue ) {
178 // String errMsg = "こã?クラスでは実è£?�•れてã�?�¾せんã€?;
179 // throw new UnsupportedOperationException( errMsg );
180 // }
181
182 /**
183 * 選択肢(value)に対するラベルを返しますã?
184 * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
185 * getValueLabel( XX ) は、getValueLabel( XX,false ) と同じですã?
186 *
187 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
188 *
189 * @param selectValue 選択肢の値
190 *
191 * @return 選択肢のラベル
192 * @see #getValueLabel( String,boolean )
193 */
194 // public String getValueLabel( final String selectValue ) {
195 // return getValueLabel( selectValue,false );
196 // }
197
198 /**
199 * 選択肢(value)に対するラベルを返しますã?
200 * 選択肢(value)がã?存在しなかったå?合ã?ã€?�¸択肢そã?もã?を返しますã?
201 * getValueLabel( XX,false ) は、getValueLabel( XX ) と同じですã?
202 *
203 * ※ こã?クラスでは、短縮ラベルは使用されませんã€?
204 *
205 * @param selectValue 選択肢の値
206 * @param flag 短縮ラベルã‚?[true:使用する/false:しない](常に false)
207 *
208 * @return 選択肢のラベル
209 * @see #getValueLabel( String )
210 */
211 @Override
212 public String getValueLabel( final String selectValue,final boolean flag ) {
213 // マッチするアドレスを探すã?キーの前後ã?ãƒ?ƒ–ルクオートをåŠ?‘³して検索
214 String selVal = "\"" + selectValue + "\"" ;
215
216 int indx = CACHE.indexOf( selVal );
217
218 if( indx < 0 ) {
219 // マッチしなければã€?�¸択肢そã?もã?を返すã€?
220 return selectValue;
221 }
222 else {
223 // マッチすれã?、キー以下ã?BODY部のæ–?—å?をå?りå?して返すã€?
224 int stIdx = indx + selVal.length() + 1 ; // ?‹ï¼?はã€?>" の位置
225 int edIdx = CACHE.indexOf( '<',stIdx ); // 終äº?‚¢ドレス
226
227 return CACHE.substring( stIdx,edIdx );
228 }
229 }
230
231 /**
232 * マルチã?キーセレクトを使用するかどã�?�‹を返しますã?
233 * true?š使用する。false:使用しなã�?ですã?
234 * ただしã?実際に使用するかどã�?�‹は、HTML出力時に決めることがå?来ますã?
235 * ここでは、USE_MULTI_KEY_SELECT ã�?true で、USE_SIZE(=20)以上ã?場合に
236 * true を返しますã?
237 *
238 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
239 *
240 * ※ ここでは、常に false を返しますã?
241 *
242 * @return 選択リストで、ã?ルチã?キーセレクトを使用するかどã�?�‹(true:使用する)
243 */
244 // public boolean useMultiSelect() {
245 // return false;
246 // }
247
248 /**
249 * オブジェクトã?キャãƒ?‚·ュが時間å?れかどã�?�‹を返しますã?
250 * キャãƒ?‚·ュが時間å?ã‚?無効)であれば、true をã?有効であればã€?
251 * false を返しますã?
252 *
253 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承するため、削除
254 *
255 * ※ ここでは、常に false を返しますã?
256 *
257 * @return キャãƒ?‚·ュが時間å?れなã‚?true
258 */
259 // public boolean isTimeOver() {
260 // return false;
261 // }
262 }