1 package com.calipso.reportgenerator.common; 2 3 4 import org.apache.commons.configuration.Configuration; 5 import org.apache.commons.configuration.PropertiesConfiguration; 6 7 import java.io.IOException ; 8 import java.io.File ; 9 import java.io.InputStream ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import java.util.HashMap ; 13 import java.awt.*; 14 import java.net.URL ; 15 16 17 20 public class ReportGeneratorConfiguration implements java.io.Serializable { 21 22 private Map values; 23 24 29 public ReportGeneratorConfiguration(Configuration reportGeneratorConfiguration) throws InfoException { 30 fillValues(reportGeneratorConfiguration); 31 validate(); 32 } 33 34 public Map getValues() { 35 if (values==null){ 36 values = new HashMap (); 37 } 38 return values; 39 } 40 41 private void fillValues(Configuration reportGeneratorConfiguration) { 42 Iterator iter = reportGeneratorConfiguration.getKeys(); 43 while (iter.hasNext()) { 44 String key = (String ) iter.next(); 45 String value = reportGeneratorConfiguration.getString(key); 46 getValues().put(key,value); 47 } 48 49 } 50 51 56 public ReportGeneratorConfiguration(String file) throws InfoException { 57 try { 58 fillValues(new PropertiesConfiguration(file)); 59 validate(); 60 } catch (Exception e) { 61 throw new InfoException(LanguageTraslator.traslate("228"),e); 62 } 63 } 64 65 68 public void validate() throws InfoException { 69 if (getValues().isEmpty()){ 70 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("81")); 71 } 72 } 73 74 75 public boolean getIsDistributed(){ 76 return (values.get("IsDistributed").equals("true")); 77 } 78 79 public String getDistributedHost(){ 80 return (String ) values.get("DistributedHost"); 81 } 82 83 public String getDistributedPort(){ 84 return (String ) values.get("DistributedPort"); 85 } 86 87 public String getReportDefinitionRepositoryPath() { 88 return (String ) values.get("ReportDefinitionRepositoryPath"); 89 } 90 91 public String getReportSourceDefinitionRepositoryPath() { 92 return (String ) values.get("ReportSourceDefinitionRepositoryPath"); 93 } 94 95 public String getReportSourceRepositoryPath() { 96 return (String ) values.get("ReportSourceRepositoryPath"); 97 } 98 99 public String getReportViewRepositoryPath(){ 100 return (String ) values.get("ReportViewRepositoryPath"); 101 } 102 103 public String getINITIAL_CONTEXT_FACTORY(){ 104 return (String ) values.get("INITIAL_CONTEXT_FACTORY"); 105 } 106 107 public String getJavaNamingFactoryUrlPkgs(){ 108 return (String ) values.get("java.naming.factory.url.pkgs"); 109 } 110 111 112 public String getDatePattern() { 113 return (String ) values.get("DatePattern"); 114 } 115 116 public boolean queryCacheEnabled() { 117 if(values.containsKey("queryCacheEnabled")){ 118 return (values.get("queryCacheEnabled").equals("true")); 119 } else { 120 return true; 121 } 122 123 } 124 125 public String getLocaleLanguage() { 126 if(values.containsKey("Language")){ 127 if((values.get("Language")).equals("")){ 128 return "ES"; 129 }else{ 130 return (String ) values.get("Language"); 131 } 132 } 133 return "ES"; 134 } 135 136 public String getCountry() { 137 if(values.containsKey("Country")){ 138 return (String ) values.get("Country"); 139 } 140 return ""; 141 } 142 143 public String getSourceReportDefinitionsPath() { 144 return (String ) values.get("SourceReportDefinitionsPath"); 145 } 146 147 public String getSourceReportSourceDefinitionsPath() { 148 return (String ) values.get("SourceReportSourceDefinitionsPath"); 149 } 150 151 public String getSourceReportViewsPath() { 152 return (String ) values.get("SourceReportViewsPath"); 153 } 154 155 public String getSourceReportSchemasPath() { 156 return (String ) values.get("SourceReportSchemasPath"); 157 } 158 159 public String getFrameworkPlatform() { 160 return (String ) values.get("FrameworkPlatform"); 161 } 162 163 public String getCachePath() { 164 return (String ) values.get("CachePath"); 165 } 166 167 public String getCacheSizeLimit() { 168 return (String ) values.get("CacheSizeLimit"); 169 } 170 171 public String getUsersRepositoryPath() { 172 return (String ) values.get("UsersRepositoryPath"); 173 } 174 175 public String getBasePath() { 176 if ( values.containsKey("BasePath")){ 177 return (String ) values.get("BasePath"); 178 }else { 179 return "."; 180 } 181 } 182 183 public String getLanguagesPath() { 184 if ( values.containsKey("LanguagesPath")){ 185 return (String ) values.get("LanguagesPath"); 186 }else { 187 return "."; 188 } 189 } 190 191 public String getImagesPath() { 192 if ( values.containsKey("ImagesPath")){ 193 return (String ) values.get("ImagesPath"); 194 }else { 195 return "."; 196 } 197 } 198 199 public String getJasperReportPath() { 200 String returnStr = ""; 201 if (values.containsKey("JasperReportPath")){ 202 returnStr = (String ) values.get("JasperReportPath"); 203 } 204 return returnStr; 205 } 206 207 public String getPolloPath() { 208 String returnStr = ""; 209 if (values.containsKey("PolloPath")){ 210 returnStr = (String ) values.get("PolloPath"); 211 } 212 return returnStr; 213 } 214 215 216 public String getJasperCompilerClass() { 217 String returnStr = ""; 218 if (values.containsKey("JasperCompilerClass")){ 219 returnStr = (String ) values.get("JasperCompilerClass"); 220 } 221 return returnStr; 222 } 223 224 public String getReportManagerEJB_SFName() { 225 String returnStr = "ReportManagerSF"; 226 if (values.containsKey("ReportManagerEJB_SFName")){ 227 returnStr = (String ) values.get("ReportManagerEJB_SFName"); 228 } 229 return returnStr; 230 } 231 232 public String getReportManagerEJB_SLName() { 233 String returnStr = "ReportManagerSL"; 234 if (values.containsKey("ReportManagerEJB_SLName")){ 235 returnStr = (String ) values.get("ReportManagerEJB_SLName"); 236 } 237 return returnStr; 238 } 239 240 public static PropertiesConfiguration getConfiguration(String propertiesPath) throws InfoException { 241 PropertiesConfiguration config = null; 242 try{ 243 config = new PropertiesConfiguration(ReportGeneratorConfiguration.getConfigurationPath(propertiesPath)); 244 }catch (Exception e){ 245 ClassLoader loader = ReportGeneratorConfiguration.class.getClassLoader(); 246 InputStream inputStream = loader.getResourceAsStream("ReportGeneratorConfiguration.properties"); 247 config = new PropertiesConfiguration(); 248 try { 249 config.load(inputStream); 250 } catch (Exception e1) { 251 throw new InfoException("372", e); 252 } 253 } 254 return config; 255 } 256 257 public static String getConfigurationPath(String propertiesPath) { 258 if (!propertiesPath.equals("")){ 259 return propertiesPath + "/ReportGeneratorConfiguration.properties"; 260 } else { 261 String property = System.getProperty("CalipsoConfigurationRoot"); 262 if(property != null) { 263 return property + "/ReportGeneratorConfiguration.properties"; 264 }else{ 265 return "./ReportGeneratorConfiguration.properties"; 266 } 267 } 268 } 269 270 274 public File getImageDir() { 275 File file = new File (getImagesPath()); 276 String frameWork = getFrameworkPlatform(); 277 if(file.listFiles() != null) { 278 File [] files = file.listFiles(); 279 for(int i = 0 ; i < files.length ; i++) { 280 if(files [i].getName().toUpperCase().trim().equals(frameWork)) { 281 return files [i]; 282 } 283 } 284 } 285 return null; 286 } 287 288 293 public String getImagePath(String imageName) { 294 String imagePath = null; 295 File file = getImageDir(); 296 if(file != null) { 297 File [] files = file.listFiles(); 298 for(int i = 0 ; i < files.length ; i++) { 299 if(files [i].getName().trim().equalsIgnoreCase(imageName+".jpg") || 300 files [i].getName().trim().equalsIgnoreCase(imageName+".png") || 301 files [i].getName().trim().equalsIgnoreCase(imageName+".bmp") || 302 files [i].getName().trim().equalsIgnoreCase(imageName+".gif")) { 303 imagePath = files [i].toString(); 304 break; 305 } 306 } 307 } 308 return imagePath; 309 } 310 311 316 public Image getImage(String imageName){ 317 Image image = null; 318 try{ 319 String path = getImagePath(imageName); 320 if (path != null){ 321 image = java.awt.Toolkit.getDefaultToolkit().getImage(path); 322 } 323 if(image == null){ 324 try{ 326 URL url = getResourceUrl(imageName); 328 if(url!=null){ 329 image = Toolkit.getDefaultToolkit().getImage(url); 330 } 331 }catch(Exception e){ 332 e.printStackTrace(); 333 } 334 336 } 337 368 }catch (Exception e){ 369 e.printStackTrace(); 370 } 371 return image; 372 } 373 374 private URL getResourceUrl(String imageName) { 375 URL url = null; 376 String [] ext = new String []{"gif", "jpg"}; 377 String framework = getFrameworkPlatform(); 378 for (int i = 0; i < ext.length; i++) { 379 String s = ext[i]; 380 url = this.getClass().getClassLoader().getResource("com/calipso/reportgenerator/userinterface/images/" + framework + "/" + imageName.toLowerCase() + "." + s); 381 if(url!=null){ 382 return url; 383 } 384 } 385 return url; 386 } 387 388 public String getSourceReportLayoutPath() { 389 return (String ) values.get("SourceReportLayoutsPath"); 390 } 391 392 public String getReportLayoutStyle() { 393 return (String ) values.get("ReportLayoutStyle"); 394 } 395 396 public String getRolsRepositoryPath() { 397 return (String ) values.get("RolsRepositoryPath"); 398 } 399 400 public String getUserDataRepositoryPath() { 401 return (String ) values.get("UserDataRepositoryPath"); 402 } 403 404 public String getTempPath() { 405 return (String ) values.get("TempPath"); 406 } 407 408 public String getRolDataRepositoryPath() { 409 return (String ) values.get("RolDataRepositoryPath"); 410 } 411 412 public String getMicroReportRepositoryPath(){ 413 return (String ) values.get("MicroReportRepositoryPath"); 414 } 415 416 public boolean isCsvSerialized() { 417 if(values.get("CsvSerialized")==null){ 418 return true; 419 } 420 return ((String )values.get("CsvSerialized")).equalsIgnoreCase("true"); 421 } 422 423 public int getBlockSize() { 424 if(values.get("BlockSize") == null){ 425 return 0; 426 } 427 return Integer.parseInt((String )values.get("BlockSize")); 428 } 429 430 public String getCachedDBlUrl() { 431 return (String )values.get("CachedDBlUrl"); 432 } 433 434 public String getCachedDBUserName() { 435 return (String )values.get("CachedDBUserName"); 436 } 437 438 public String getCachedDBPassword() { 439 return (String )values.get("CachedDBPassword"); 440 } 441 442 public String getCachedDBJDBCClassName() { 443 return (String )values.get("CachedDBJDBCClassName"); 444 } 445 446 public String getClientLogFile() { 447 return (String )values.get("ClientLogFile"); 448 } 449 450 public boolean isDatawareHouseEnabled(){ 451 if(values.containsKey("DatawareHouseEnabled")){ 452 return (values.get("DatawareHouseEnabled").toString()).equalsIgnoreCase("true"); 453 } 454 return false; 455 } 456 457 public int getFetchSize() { 458 if(values.containsKey("FetchSize")){ 459 return Integer.parseInt(values.get("FetchSize").toString()); 460 } 461 return 1000; 462 } 463 464 public String getSQLBuilder() { 465 return (String )values.get("SQLBuilder"); 466 } 467 } 468 | Popular Tags |