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 java.util.LinkedHashMap; 019 import java.util.Map; 020 021 import org.opengion.fukurou.db.DBUtil; 022 import org.opengion.fukurou.util.ApplicationInfo; 023 import org.opengion.hayabusa.common.HybsSystem; 024 import org.opengion.hayabusa.resource.ResourceFactory; 025 import org.opengion.hayabusa.resource.ResourceManager; 026 027 /** 028 * ãƒ??ã‚¿ã®ã‚³ãƒ¼ãƒ‰æƒ…å ±ã‚’å–り扱ã?‚¯ãƒ©ã‚¹ã§ã™ã? 029 * 030 * コードã?ã‚ーã¨ãƒ©ãƒ™ãƒ«ã®æƒ??ã‹ã‚‰ã€HTMLã®ãƒ¡ãƒ‹ãƒ¥ãƒ¼ã‚?ƒªã‚¹ãƒˆã‚’作æ?ã™ã‚‹ãŸã‚㮠オプション 031 * タグを作æ?ã—ãŸã‚Šã?与ãˆã‚‰ã‚ŒãŸã‚ーをもã¨ã«ã€ãƒã‚§ãƒ?‚¯æ¸ˆã¿ã®ã‚ªãƒ—ションタグを作æ?ã—ãŸã‚? 032 * ã—ã¾ã™ã? 033 * QUERYã®ãれãžã‚Œã®ã‚«ãƒ©ãƒ??ã€ä»¥ä¸‹ã?æ„味をæŒã¡ã¾ã™ã? 034 * 第?‘カラãƒ?å¿??) : ラジオボタンã®ã‚ー(値) 035 * 第?’カラãƒ? : ラベル(æŒ?®šã•れãªã??åˆã?ã€ãƒ©ãƒ™ãƒ«ãƒªã‚½ãƒ¼ã‚¹ã®çŸç¸®ãƒ©ãƒ™ãƒ«ã‚’使用ã—ã¾ã? 036 * 第?“カラãƒ? : クラス ãã?オプションã«è‰²ã¥ã‘ãªã©ã‚’行ã†ç‚ºã®æŒ?®šã—ã¾ã™ã? 037 * NULL(ã¾ãŸã?ã€ã‚¼ãƒæ–?—å?)ã®å ´åˆã?ã€?©ç”¨ã•れã¾ã›ã‚“ã€? 038 * 第?”カラãƒ? : ã“ã?値ã¯'false'åˆã?'0'ã§ã‚ã‚‹å ´åˆã«ãã?ãƒ©ã‚¸ã‚ªãƒœã‚¿ãƒ³ã‚’é¸æŠžä¸å¯ã«ã—ã¾ã™ã? 039 * NULL(ã¾ãŸã?ã€ã‚¼ãƒæ–?—å?)ã®å ´åˆã?ã€?¸æŠžå¯èƒ½ã«ãªã‚Šã¾ã™ã? 040 * 041 * @og.group é¸æŠžãƒ‡ãƒ¼ã‚¿åˆ¶å¾¡ 042 * 043 * @version 4.0 044 * @author Hiroki Nakamura 045 * @since JDK5.0, 046 */ 047 public class Selection_DBRADIO implements Selection { 048 private final long DB_CACHE_TIME = (long)HybsSystem.sysInt( "DB_CACHE_TIME" ) ; 049 050 private final boolean isClass ; // クエリã§ã‚¯ãƒ©ã‚¹å±žæ?ãŒæŒ‡å®šã•れã¦ã?‚‹ã‹ã©ã?‹ 051 private final boolean isDisable ; // クエリã§é¸æŠžä¸å¯å±žæ?ãŒæŒ‡å®šã•れã¦ã?‚‹ã‹ã©ã?‹ 052 private final long createTime ; // ã‚ャãƒ?‚·ãƒ¥ã®ç ´æ£?‚¿ã‚¤ãƒŸãƒ³ã‚°ã‚’計るãŸã‚ã®ä½œæ?時間 053 054 private final Map<String,Integer> map ; 055 056 // private final String[] value ; // 値 // 5.1.9.0 (2010/08/01) å»?¢ 057 private final String[] label ; // ラベル 058 private final String[] cls ; // クラス 059 private final String[] disabled ; // ラジオå˜ä½ã?disable 060 061 private static final int VAL = 0; 062 private static final int LBL = 1; 063 private static final int CLS = 2; 064 private static final int DISABLED = 3; 065 066 private static final ApplicationInfo appInfo; 067 static { 068 /** コãƒã‚¯ã‚·ãƒ§ãƒ³ã«ã‚¢ãƒ—リケーションæƒ??を追記ã™ã‚‹ã‹ã©ã?‹æŒ?®?*/ 069 boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ; 070 071 // 3.8.7.0 (2006/12/15) アクセスãƒã‚°å–å¾—ã?為,ApplicationInfoオブジェクトをè¨å®? 072 if( USE_DB_APPLICATION_INFO ) { 073 String SYSTEM_ID = HybsSystem.sys( "SYSTEM_ID" ); 074 appInfo = new ApplicationInfo(); 075 // ユーザーID,IPアドレス,ホストå 076 appInfo.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME ); 077 // ç”»é¢ID,æ“ä½?プãƒã‚°ãƒ©ãƒ?D 078 appInfo.setModuleInfo( "Selection_DBRADIO",null,null ); 079 } 080 else { 081 appInfo = null; 082 } 083 } 084 085 /** 086 * コンストラクター 087 * 088 * ?¤?¢æ¤œç´¢ç”¨ã®?³?±?¬æ–?‚’与ãˆã¦ã€å?期化ã—ã¾ã™ã? 089 * SQLæ–??ã€KEY,SNAMEã§ã€SNAMEãŒè¨å®šã•れã¦ãªã??åˆã?ã€LNAMEを使用ã—ã¾ã™ã? 090 * LNAME ã¯ã€??常ã®å€¤ã‚’è¿”ã™å ´åˆã«ã€SNAME ã¯ã€ä¸?¦§è¡¨ç¤ºã®å€¤ã‚’è¿”ã™å ´åˆã«ä½¿ç”¨ã—ã¾ã™ã? 091 * 特別ã«ã€KEY ã®ã¿ã®å ´åˆã?ã€lang ã«åŸºã¥ã?ResourceManager ã‹ã‚‰?—ï¾ï¾žï¾™ã‚’å–å¾—ã—ã¾ã™ã? 092 * ãŸã ã—ã?ãã?å ´åˆã?ã€ã‚ªãƒ¼ãƒŠã?(SYSTEM_ID)ã¯é¸ã¹ã¾ã›ã‚“ã€? 093 * 094 * @og.rev 5.1.9.0 (2010/08/01) String[] value å»?¢ 095 * 096 * @param newQuery DB検索(SQL)æ–?—å? 097 * @param dbid ãƒ??タベã?ス接続å?ID 098 * @param lang リソースを使用ã™ã‚‹å ´åˆã?è¨?ª? 099 */ 100 public Selection_DBRADIO( final String newQuery,final String dbid,final String lang ) { 101 102 String[][] cols = DBUtil.dbExecute( newQuery,null,appInfo,dbid ); 103 int count = cols.length; 104 105 // value = new String[count]; // 5.1.9.0 (2010/08/01) K.H 106 label = new String[count]; 107 cls = new String[count]; 108 disabled= new String[count]; 109 map = new LinkedHashMap<String,Integer>(count); 110 111 int len = ( count > 0 ) ? cols[0].length : 0 ; 112 isClass = ( len > CLS ); // >= 3 ã¨åŒæ„; 113 isDisable = ( len > DISABLED ); // >= 4 ã¨åŒæ„; 114 115 boolean useLabelData = false ; 116 ResourceManager resource = null; 117 if( len == 1 ) { 118 useLabelData = true; 119 resource = ResourceFactory.newInstance( lang ); 120 } 121 122 for( int i=0; i<count; i++ ) { 123 // value[i] = cols[i][VAL]; 124 String value = cols[i][VAL]; 125 if( useLabelData ) { 126 // label[i] = resource.getShortLabel( value[i] ); 127 label[i] = resource.getShortLabel( value ); 128 } 129 else { 130 label[i] = cols[i][LBL]; 131 } 132 133 if( isClass ) { 134 cls[i] = cols[i][CLS]; 135 } 136 if( isDisable ) { 137 disabled[i] = cols[i][DISABLED]; 138 } 139 140 // map.put( value[i], Integer.valueOf( i ) ); 141 map.put( value, Integer.valueOf( i ) ); 142 } 143 144 createTime = System.currentTimeMillis() ; 145 } 146 147 /** 148 * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã? 149 * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã? 150 * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€? 151 * 152 * @param selectValue é¸æŠžã•れã¦ã?‚‹å€¤ 153 * @param seqFlag シーケンスアクセス機è?ã®æŒ?®? 154 * 155 * @return オプションタグ 156 */ 157 public String getOption( final String selectValue,final boolean seqFlag ) { 158 String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?; 159 throw new UnsupportedOperationException( errMsg ); 160 } 161 162 /** 163 * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã? 164 * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã? 165 * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€? 166 * 167 * @og.rev 5.1.3.0 (2010/02/01) 追åŠ? 168 * 169 * @param selectValue é¸æŠžã•れã¦ã?‚‹å€¤ 170 * @param seqFlag シーケンスアクセス機è?ã®æŒ?®? 171 * @param useShortLabel çŸãƒ©ãƒ™ãƒ«ã®æŒ?®? 172 * 173 * @return オプションタグ 174 */ 175 public String getOption( final String selectValue,final boolean seqFlag, final boolean useShortLabel ) { 176 String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?; 177 throw new UnsupportedOperationException( errMsg ); 178 } 179 180 /** 181 * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã? 182 * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã? 183 * 184 * @param name ラジオ㮠name 185 * @param selectValue é¸æŠžã•れã¦ã?‚‹å€¤ 186 * @param useLabel ãƒ©ãƒ™ãƒ«è¡¨ç¤ºã®æœ‰ç„¡ [true:æœ?false:ç„¡] 187 * 188 * @return オプションタグ 189 */ 190 public String getRadio( final String name,final String selectValue,final boolean useLabel ) { 191 String inputTag = "<input type=\"radio\" name=\"" + name + "\" value=\"" ; 192 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE ); 193 for( Map.Entry<String, Integer> e : map.entrySet() ) { 194 String val = e.getKey(); // Ver 5.0.0.0 value â‡?val 195 int valIdx = e.getValue().intValue(); 196 if( useLabel ) { 197 buf.append( "<label" ); 198 if( isClass && cls[valIdx] != null && cls[valIdx].length() > 0 ) { 199 buf.append( " class=\"" ).append( cls[valIdx] ).append( "\"" ); 200 } 201 buf.append( ">" ); 202 } 203 buf.append( inputTag ).append( val ).append( "\"" ); 204 if( val.equals( selectValue ) ) { 205 buf.append( " checked=\"checked\"" ); 206 } 207 208 if( isDisable && disabled[valIdx] != null && disabled[valIdx].length() > 0 ) { 209 if( "false".equalsIgnoreCase( disabled[valIdx] ) || "0".equals( disabled[valIdx] ) ) { 210 buf.append( " disabled=\"disabled\"" ); 211 } 212 } 213 214 buf.append( "/>" ); 215 if( useLabel ) { buf.append( label[valIdx] ).append( "</label>" ); } 216 } 217 return buf.toString(); 218 } 219 220 /** 221 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 222 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 223 * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã? 224 * 225 * @param selectValue é¸æŠžè‚¢ã®å€¤ 226 * 227 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 228 * @see #getValueLabel( String,boolean ) 229 */ 230 public String getValueLabel( final String selectValue ) { 231 return getValueLabel( selectValue,false ); 232 } 233 234 /** 235 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 236 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 237 * ã“ã?メソãƒ?ƒ‰ã§ã¯ã€çŸç¸®ãƒ©ãƒ™ãƒ«ã‚’è¿”ã™ã‹ã©ã?‹ã‚’指定ã™ã‚‹ãƒ•ラグを指定ã—ã¾ã™ã? 238 * getValueLabel( XX,false ) ã¯ã€getValueLabel( XX ) ã¨åŒã˜ã§ã™ã? 239 * 240 * @param selectValue é¸æŠžè‚¢ã®å€¤ 241 * @param flag çŸç¸®ãƒ©ãƒ™ãƒ«ã‚’使用ã™ã‚‹ [true:使用ã™ã‚‹/false:ã—ãªã„] 242 * 243 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 244 * @see #getValueLabel( String ) 245 */ 246 public String getValueLabel( final String selectValue,final boolean flag ) { 247 // マッãƒã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’探ã™ã? 248 Integer sel = map.get( selectValue ); 249 250 if( sel == null ) { 251 return selectValue; 252 } 253 else { 254 return label[sel.intValue()] ; 255 } 256 } 257 258 /** 259 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 260 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 261 * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã? 262 * 263 * @param selectValue é¸æŠžè‚¢ã®å€¤ 264 * 265 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 266 * @see #getValueLabel( String,boolean ) 267 */ 268 public String getRadioLabel( final String selectValue ) { 269 270 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 271 for( Map.Entry<String, Integer> e : map.entrySet() ) { 272 String val = e.getKey(); // Ver 5.0.0.0 value â‡?val 273 if( val.equals( selectValue ) ) { 274 rtn.append( "â—? ); 275 } 276 else { 277 rtn.append( "ã€? ); 278 } 279 } 280 281 return rtn.toString(); 282 } 283 284 /*** 285 * マルãƒã?ã‚ーセレクトを使用ã™ã‚‹ã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã? 286 * true?šä½¿ç”¨ã™ã‚‹ã€‚false:使用ã—ãªã?ã§ã™ã? 287 * ãŸã ã—ã?実際ã«ä½¿ç”¨ã™ã‚‹ã‹ã©ã?‹ã¯ã€HTMLå‡ºåŠ›æ™‚ã«æ±ºã‚ã‚‹ã“ã¨ãŒå?æ¥ã¾ã™ã? 288 * ã“ã“ã§ã¯ã€USE_MULTI_KEY_SELECT ã?true ã§ã€USE_SIZE(=20)以上ã?å ´åˆã« 289 * true ã‚’è¿”ã—ã¾ã™ã? 290 * 291 * @return é¸æŠžãƒªã‚¹ãƒˆã§ã€ã?ルãƒã?ã‚ーセレクトを使用ã™ã‚‹ã‹ã©ã?‹(true:使用ã™ã‚‹) 292 */ 293 public boolean useMultiSelect() { 294 return false; 295 } 296 297 /** 298 * オブジェクトã?ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã? 299 * ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?ã‚?無効)ã§ã‚れã°ã€true ã‚’ã?有効ã§ã‚れã°ã€? 300 * false ã‚’è¿”ã—ã¾ã™ã? 301 * 302 * @return ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れãªã‚?true 303 */ 304 public boolean isTimeOver() { 305 return ( System.currentTimeMillis() - createTime > DB_CACHE_TIME ) ; 306 } 307 }