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 public class Selection_DBRADIO extends Selection_NULL { 049 private final long DB_CACHE_TIME = (long)HybsSystem.sysInt( "DB_CACHE_TIME" ) ; 050 051 private final boolean isClass ; // クエリã§ã‚¯ãƒ©ã‚¹å±žæ?ãŒæŒ‡å®šã•れã¦ã?‚‹ã‹ã©ã?‹ 052 private final boolean isDisable ; // クエリã§é¸æŠžä¸å¯å±žæ?ãŒæŒ‡å®šã•れã¦ã?‚‹ã‹ã©ã?‹ 053 private final long createTime ; // ã‚ャãƒ?‚·ãƒ¥ã®ç ´æ£?‚¿ã‚¤ãƒŸãƒ³ã‚°ã‚’計るãŸã‚ã®ä½œæ?時間 054 055 private final Map<String,Integer> map ; 056 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 label = new String[count]; 106 cls = new String[count]; 107 disabled= new String[count]; 108 map = new LinkedHashMap<String,Integer>(count); 109 110 int len = ( count > 0 ) ? cols[0].length : 0 ; 111 isClass = len > CLS ; // >= 3 ã¨åŒæ„; 112 isDisable = len > DISABLED ; // >= 4 ã¨åŒæ„; 113 114 boolean useLabelData = false ; 115 ResourceManager resource = null; 116 if( len == 1 ) { 117 useLabelData = true; 118 resource = ResourceFactory.newInstance( lang ); 119 } 120 121 for( int i=0; i<count; i++ ) { 122 String value = cols[i][VAL]; 123 if( useLabelData ) { 124 label[i] = resource.getShortLabel( value ); 125 } 126 else { 127 label[i] = cols[i][LBL]; 128 } 129 130 if( isClass ) { 131 cls[i] = cols[i][CLS]; 132 } 133 if( isDisable ) { 134 disabled[i] = cols[i][DISABLED]; 135 } 136 137 map.put( value, Integer.valueOf( i ) ); 138 } 139 140 createTime = System.currentTimeMillis() ; 141 } 142 143 /** 144 * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã? 145 * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã? 146 * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€? 147 * 148 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤ 149 * 150 * @param selectValue é¸æŠžã•れã¦ã?‚‹å€¤ 151 * @param seqFlag シーケンスアクセス機è?ã®æŒ?®? 152 * 153 * @return オプションタグ 154 */ 155 // public String getOption( final String selectValue,final boolean seqFlag ) { 156 // String errMsg = "ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€?; 157 // throw new UnsupportedOperationException( errMsg ); 158 // } 159 160 /** 161 * åˆæœŸå€¤ãŒé¸æŠžæ¸ˆã¿ã® é¸æŠžè‚¢(オプション)ã‚’è¿”ã—ã¾ã™ã? 162 * ã“ã?オプションã¯ã€å¼•æ•°ã®å€¤ã‚’å?期å?ã¨ã™ã‚‹ã‚ªãƒ—ションタグを返ã—ã¾ã™ã? 163 * ※ ã“ã?クラスã§ã¯å®Ÿè£?•れã¦ã?¾ã›ã‚“ã€? 164 * 165 * @og.rev 5.1.3.0 (2010/02/01) 追åŠ? 166 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤ 167 * 168 * @param selectValue é¸æŠžã•れã¦ã?‚‹å€¤ 169 * @param seqFlag シーケンスアクセス機è?ã®æŒ?®? 170 * @param useShortLabel çŸãƒ©ãƒ™ãƒ«ã®æŒ?®? 171 * 172 * @return オプションタグ 173 */ 174 @Override 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 @Override 191 public String getRadio( final String name,final String selectValue,final boolean useLabel ) { 192 String inputTag = "<input type=\"radio\" name=\"" + name + "\" value=\"" ; 193 StringBuilder buf = new StringBuilder( HybsSystem.BUFFER_LARGE ); 194 for( Map.Entry<String, Integer> e : map.entrySet() ) { 195 String val = e.getKey(); // Ver 5.0.0.0 value â‡?val 196 int valIdx = e.getValue().intValue(); 197 if( useLabel ) { 198 buf.append( "<label" ); 199 if( isClass && cls[valIdx] != null && cls[valIdx].length() > 0 ) { 200 buf.append( " class=\"" ).append( cls[valIdx] ).append( "\"" ); 201 } 202 buf.append( ">" ); 203 } 204 buf.append( inputTag ).append( val ).append( "\"" ); 205 if( val.equals( selectValue ) ) { 206 buf.append( " checked=\"checked\"" ); 207 } 208 209 if( isDisable && disabled[valIdx] != null && disabled[valIdx].length() > 0 ) { 210 if( "false".equalsIgnoreCase( disabled[valIdx] ) || "0".equals( disabled[valIdx] ) ) { 211 buf.append( " disabled=\"disabled\"" ); 212 } 213 } 214 215 buf.append( "/>" ); 216 if( useLabel ) { buf.append( label[valIdx] ).append( "</label>" ); } 217 } 218 return buf.toString(); 219 } 220 221 /** 222 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 223 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 224 * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã? 225 * 226 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤ 227 * 228 * @param selectValue é¸æŠžè‚¢ã®å€¤ 229 * 230 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 231 * @see #getValueLabel( String,boolean ) 232 */ 233 // public String getValueLabel( final String selectValue ) { 234 // return getValueLabel( selectValue,false ); 235 // } 236 237 /** 238 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 239 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 240 * ã“ã?メソãƒ?ƒ‰ã§ã¯ã€çŸç¸®ãƒ©ãƒ™ãƒ«ã‚’è¿”ã™ã‹ã©ã?‹ã‚’指定ã™ã‚‹ãƒ•ラグを指定ã—ã¾ã™ã? 241 * getValueLabel( XX,false ) ã¯ã€getValueLabel( XX ) ã¨åŒã˜ã§ã™ã? 242 * 243 * @param selectValue é¸æŠžè‚¢ã®å€¤ 244 * @param flag çŸç¸®ãƒ©ãƒ™ãƒ«ã‚’使用ã™ã‚‹ [true:使用ã™ã‚‹/false:ã—ãªã„] 245 * 246 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 247 * @see #getValueLabel( String ) 248 */ 249 @Override 250 public String getValueLabel( final String selectValue,final boolean flag ) { 251 // マッãƒã™ã‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’探ã™ã? 252 Integer sel = map.get( selectValue ); 253 254 if( sel == null ) { 255 return selectValue; 256 } 257 else { 258 return label[sel.intValue()] ; 259 } 260 } 261 262 /** 263 * é¸æŠžè‚¢(value)ã«å¯¾ã™ã‚‹ãƒ©ãƒ™ãƒ«ã‚’è¿”ã—ã¾ã™ã? 264 * é¸æŠžè‚¢(value)ãŒã?å˜åœ¨ã—ãªã‹ã£ãŸå?åˆã?ã€?¸æŠžè‚¢ãã?ã‚‚ã?ã‚’è¿”ã—ã¾ã™ã? 265 * getValueLabel( XX ) ã¯ã€getValueLabel( XX,false ) ã¨åŒã˜ã§ã™ã? 266 * 267 * @param selectValue é¸æŠžè‚¢ã®å€¤ 268 * 269 * @return é¸æŠžè‚¢ã®ãƒ©ãƒ™ãƒ« 270 * @see #getValueLabel( String,boolean ) 271 */ 272 @Override 273 public String getRadioLabel( final String selectValue ) { 274 275 StringBuilder rtn = new StringBuilder( HybsSystem.BUFFER_MIDDLE ); 276 for( Map.Entry<String, Integer> e : map.entrySet() ) { 277 String val = e.getKey(); // Ver 5.0.0.0 value â‡?val 278 if( val.equals( selectValue ) ) { 279 rtn.append( "â—? ); 280 } 281 else { 282 rtn.append( "ã€? ); 283 } 284 } 285 286 return rtn.toString(); 287 } 288 289 /*** 290 * マルãƒã?ã‚ーセレクトを使用ã™ã‚‹ã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã? 291 * true?šä½¿ç”¨ã™ã‚‹ã€‚false:使用ã—ãªã?ã§ã™ã? 292 * ãŸã ã—ã?実際ã«ä½¿ç”¨ã™ã‚‹ã‹ã©ã?‹ã¯ã€HTMLå‡ºåŠ›æ™‚ã«æ±ºã‚ã‚‹ã“ã¨ãŒå?æ¥ã¾ã™ã? 293 * ã“ã“ã§ã¯ã€USE_MULTI_KEY_SELECT ã?true ã§ã€USE_SIZE(=20)以上ã?å ´åˆã« 294 * true ã‚’è¿”ã—ã¾ã™ã? 295 * 296 * @og.rev 5.7.7.1 (2014/06/13) Selection_NULL ã‚?継承ã™ã‚‹ãŸã‚ã€å‰Šé™¤ 297 * 298 * @return é¸æŠžãƒªã‚¹ãƒˆã§ã€ã?ルãƒã?ã‚ーセレクトを使用ã™ã‚‹ã‹ã©ã?‹(true:使用ã™ã‚‹) 299 */ 300 // public boolean useMultiSelect() { 301 // return false; 302 // } 303 304 /** 305 * オブジェクトã?ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れã‹ã©ã?‹ã‚’è¿”ã—ã¾ã™ã? 306 * ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?ã‚?無効)ã§ã‚れã°ã€true ã‚’ã?有効ã§ã‚れã°ã€? 307 * false ã‚’è¿”ã—ã¾ã™ã? 308 * 309 * @return ã‚ャãƒ?‚·ãƒ¥ãŒæ™‚é–“å?れãªã‚?true 310 */ 311 @Override 312 public boolean isTimeOver() { 313 return ( System.currentTimeMillis() - createTime ) > DB_CACHE_TIME ; 314 } 315 }