KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > common > ReportGeneratorConfiguration


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 JavaDoc;
8 import java.io.File JavaDoc;
9 import java.io.InputStream JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.awt.*;
14 import java.net.URL JavaDoc;
15
16
17 /**
18  * Configuración del ReportGegnerator.
19  */

20 public class ReportGeneratorConfiguration implements java.io.Serializable JavaDoc {
21
22   private Map JavaDoc values;
23
24   /**
25    * Inicializa la configuración
26    * @param reportGeneratorConfiguration
27    * @throws com.calipso.reportgenerator.common.InfoException
28    */

29   public ReportGeneratorConfiguration(Configuration reportGeneratorConfiguration) throws InfoException {
30     fillValues(reportGeneratorConfiguration);
31     validate();
32   }
33
34   public Map JavaDoc getValues() {
35     if (values==null){
36       values = new HashMap JavaDoc();
37     }
38     return values;
39   }
40
41   private void fillValues(Configuration reportGeneratorConfiguration) {
42     Iterator JavaDoc iter = reportGeneratorConfiguration.getKeys();
43     while (iter.hasNext()) {
44       String JavaDoc key = (String JavaDoc) iter.next();
45       String JavaDoc value = reportGeneratorConfiguration.getString(key);
46       getValues().put(key,value);
47     }
48
49   }
50
51   /**
52    * Inicializa la configuración a partir de un file
53    * @param file
54    * @throws com.calipso.reportgenerator.common.InfoException
55    */

56   public ReportGeneratorConfiguration(String JavaDoc file) throws InfoException {
57     try {
58       fillValues(new PropertiesConfiguration(file));
59       validate();
60     } catch (Exception JavaDoc e) {
61       throw new InfoException(LanguageTraslator.traslate("228"),e);
62     }
63   }
64
65    /**
66     * Valida que la configuración sea la correcta
67    */

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 JavaDoc getDistributedHost(){
80    return (String JavaDoc) values.get("DistributedHost");
81  }
82
83  public String JavaDoc getDistributedPort(){
84    return (String JavaDoc) values.get("DistributedPort");
85  }
86
87  public String JavaDoc getReportDefinitionRepositoryPath() {
88    return (String JavaDoc) values.get("ReportDefinitionRepositoryPath");
89  }
90
91  public String JavaDoc getReportSourceDefinitionRepositoryPath() {
92    return (String JavaDoc) values.get("ReportSourceDefinitionRepositoryPath");
93  }
94
95  public String JavaDoc getReportSourceRepositoryPath() {
96    return (String JavaDoc) values.get("ReportSourceRepositoryPath");
97  }
98
99  public String JavaDoc getReportViewRepositoryPath(){
100    return (String JavaDoc) values.get("ReportViewRepositoryPath");
101  }
102
103  public String JavaDoc getINITIAL_CONTEXT_FACTORY(){
104    return (String JavaDoc) values.get("INITIAL_CONTEXT_FACTORY");
105  }
106
107  public String JavaDoc getJavaNamingFactoryUrlPkgs(){
108    return (String JavaDoc) values.get("java.naming.factory.url.pkgs");
109  }
110
111
112  public String JavaDoc getDatePattern() {
113    return (String JavaDoc) 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 JavaDoc getLocaleLanguage() {
126    if(values.containsKey("Language")){
127     if((values.get("Language")).equals("")){
128       return "ES";
129     }else{
130       return (String JavaDoc) values.get("Language");
131     }
132   }
133   return "ES";
134  }
135
136   public String JavaDoc getCountry() {
137     if(values.containsKey("Country")){
138       return (String JavaDoc) values.get("Country");
139     }
140     return "";
141   }
142
143   public String JavaDoc getSourceReportDefinitionsPath() {
144     return (String JavaDoc) values.get("SourceReportDefinitionsPath");
145   }
146
147   public String JavaDoc getSourceReportSourceDefinitionsPath() {
148     return (String JavaDoc) values.get("SourceReportSourceDefinitionsPath");
149   }
150
151   public String JavaDoc getSourceReportViewsPath() {
152     return (String JavaDoc) values.get("SourceReportViewsPath");
153   }
154
155   public String JavaDoc getSourceReportSchemasPath() {
156     return (String JavaDoc) values.get("SourceReportSchemasPath");
157   }
158
159   public String JavaDoc getFrameworkPlatform() {
160     return (String JavaDoc) values.get("FrameworkPlatform");
161   }
162
163   public String JavaDoc getCachePath() {
164     return (String JavaDoc) values.get("CachePath");
165   }
166
167   public String JavaDoc getCacheSizeLimit() {
168     return (String JavaDoc) values.get("CacheSizeLimit");
169   }
170
171   public String JavaDoc getUsersRepositoryPath() {
172     return (String JavaDoc) values.get("UsersRepositoryPath");
173   }
174
175   public String JavaDoc getBasePath() {
176     if ( values.containsKey("BasePath")){
177       return (String JavaDoc) values.get("BasePath");
178     }else {
179       return ".";
180     }
181   }
182
183   public String JavaDoc getLanguagesPath() {
184     if ( values.containsKey("LanguagesPath")){
185       return (String JavaDoc) values.get("LanguagesPath");
186     }else {
187       return ".";
188     }
189   }
190
191   public String JavaDoc getImagesPath() {
192     if ( values.containsKey("ImagesPath")){
193       return (String JavaDoc) values.get("ImagesPath");
194     }else {
195       return ".";
196     }
197   }
198
199   public String JavaDoc getJasperReportPath() {
200     String JavaDoc returnStr = "";
201     if (values.containsKey("JasperReportPath")){
202       returnStr = (String JavaDoc) values.get("JasperReportPath");
203     }
204     return returnStr;
205   }
206
207   public String JavaDoc getPolloPath() {
208     String JavaDoc returnStr = "";
209     if (values.containsKey("PolloPath")){
210       returnStr = (String JavaDoc) values.get("PolloPath");
211     }
212     return returnStr;
213   }
214
215
216   public String JavaDoc getJasperCompilerClass() {
217     String JavaDoc returnStr = "";
218     if (values.containsKey("JasperCompilerClass")){
219       returnStr = (String JavaDoc) values.get("JasperCompilerClass");
220     }
221     return returnStr;
222   }
223
224   public String JavaDoc getReportManagerEJB_SFName() {
225     String JavaDoc returnStr = "ReportManagerSF";
226     if (values.containsKey("ReportManagerEJB_SFName")){
227       returnStr = (String JavaDoc) values.get("ReportManagerEJB_SFName");
228     }
229     return returnStr;
230   }
231
232   public String JavaDoc getReportManagerEJB_SLName() {
233     String JavaDoc returnStr = "ReportManagerSL";
234     if (values.containsKey("ReportManagerEJB_SLName")){
235       returnStr = (String JavaDoc) values.get("ReportManagerEJB_SLName");
236     }
237     return returnStr;
238   }
239
240   public static PropertiesConfiguration getConfiguration(String JavaDoc propertiesPath) throws InfoException {
241     PropertiesConfiguration config = null;
242     try{
243       config = new PropertiesConfiguration(ReportGeneratorConfiguration.getConfigurationPath(propertiesPath));
244     }catch (Exception JavaDoc e){
245       ClassLoader JavaDoc loader = ReportGeneratorConfiguration.class.getClassLoader();
246       InputStream JavaDoc inputStream = loader.getResourceAsStream("ReportGeneratorConfiguration.properties");
247       config = new PropertiesConfiguration();
248       try {
249         config.load(inputStream);
250       } catch (Exception JavaDoc e1) {
251         throw new InfoException("372", e);
252       }
253     }
254     return config;
255   }
256
257   public static String JavaDoc getConfigurationPath(String JavaDoc propertiesPath) {
258     if (!propertiesPath.equals("")){
259       return propertiesPath + "/ReportGeneratorConfiguration.properties";
260     } else {
261       String JavaDoc property = System.getProperty("CalipsoConfigurationRoot");
262       if(property != null) {
263         return property + "/ReportGeneratorConfiguration.properties";
264       }else{
265         return "./ReportGeneratorConfiguration.properties";
266       }
267     }
268   }
269
270   /**
271    * Retorna el directorio de las imágenes
272    * @return
273    */

274   public File JavaDoc getImageDir() {
275     File JavaDoc file = new File JavaDoc(getImagesPath());
276     String JavaDoc frameWork = getFrameworkPlatform();
277     if(file.listFiles() != null) {
278       File JavaDoc [] 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   /**
289    * Retorna el path de una imagen
290    * @param imageName
291    * @return
292    */

293   public String JavaDoc getImagePath(String JavaDoc imageName) {
294    String JavaDoc imagePath = null;
295    File JavaDoc file = getImageDir();
296    if(file != null) {
297      File JavaDoc [] 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   /**
312    * Retorna una imagen
313    * @param imageName
314    * @return
315    */

316   public Image getImage(String JavaDoc imageName){
317     Image image = null;
318     try{
319      String JavaDoc path = getImagePath(imageName);
320      if (path != null){
321       image = java.awt.Toolkit.getDefaultToolkit().getImage(path);
322      }
323      if(image == null){
324        //Si viene de jar
325
try{
326          //URL url = this.getClass().getResource(path);
327
URL JavaDoc url = getResourceUrl(imageName);
328          if(url!=null){
329            image = Toolkit.getDefaultToolkit().getImage(url);
330          }
331        }catch(Exception JavaDoc e){
332          e.printStackTrace();
333        }
334        /*if(image != null)
335        System.out.println("Levanto la imagen del jar");*/

336      }
337      /*if(image == null){
338        String path1 = path.substring(path.lastIndexOf("\\") + 1);
339        try{
340          URL url = this.getClass().getResource(path1);
341          image = Toolkit.getDefaultToolkit().getImage(url);
342        }catch(Exception e){
343          e.printStackTrace();
344        }
345        if(image != null)
346        System.out.println("funciono solo con el nombre");
347      }
348      if(image == null){
349        String path2 = path.substring(1);
350        try{
351          URL url = this.getClass().getResource(path2);
352          image = Toolkit.getDefaultToolkit().getImage(url);
353        }catch(Exception e){
354          e.printStackTrace();
355        }
356        if(image != null)
357        System.out.println("funciono sacandole el punto");
358      }
359      return image;
360    }else if(image == null){
361      try{
362        URL url = this.getClass().getResource("com/calipso/reportgenerator/userinterface/images/" + imageName + ".jpg");
363        image = Toolkit.getDefaultToolkit().getImage(url);
364      }catch(Exception e){
365        e.printStackTrace();
366      }
367      } */

368    }catch (Exception JavaDoc e){
369      e.printStackTrace();
370    }
371    return image;
372  }
373
374   private URL JavaDoc getResourceUrl(String JavaDoc imageName) {
375     URL JavaDoc url = null;
376     String JavaDoc[] ext = new String JavaDoc[]{"gif", "jpg"};
377     String JavaDoc framework = getFrameworkPlatform();
378     for (int i = 0; i < ext.length; i++) {
379       String JavaDoc 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 JavaDoc getSourceReportLayoutPath() {
389     return (String JavaDoc) values.get("SourceReportLayoutsPath");
390   }
391
392   public String JavaDoc getReportLayoutStyle() {
393     return (String JavaDoc) values.get("ReportLayoutStyle");
394   }
395
396   public String JavaDoc getRolsRepositoryPath() {
397     return (String JavaDoc) values.get("RolsRepositoryPath");
398   }
399
400   public String JavaDoc getUserDataRepositoryPath() {
401     return (String JavaDoc) values.get("UserDataRepositoryPath");
402   }
403
404   public String JavaDoc getTempPath() {
405     return (String JavaDoc) values.get("TempPath");
406   }
407   
408   public String JavaDoc getRolDataRepositoryPath() {
409     return (String JavaDoc) values.get("RolDataRepositoryPath");
410   }
411
412   public String JavaDoc getMicroReportRepositoryPath(){
413     return (String JavaDoc) values.get("MicroReportRepositoryPath");
414   }
415
416   public boolean isCsvSerialized() {
417     if(values.get("CsvSerialized")==null){
418       return true;
419     }
420     return ((String JavaDoc)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 JavaDoc)values.get("BlockSize"));
428   }
429
430   public String JavaDoc getCachedDBlUrl() {
431     return (String JavaDoc)values.get("CachedDBlUrl");
432   }
433
434   public String JavaDoc getCachedDBUserName() {
435     return (String JavaDoc)values.get("CachedDBUserName");
436   }
437
438   public String JavaDoc getCachedDBPassword() {
439     return (String JavaDoc)values.get("CachedDBPassword");
440   }
441
442   public String JavaDoc getCachedDBJDBCClassName() {
443     return (String JavaDoc)values.get("CachedDBJDBCClassName");
444   }
445
446   public String JavaDoc getClientLogFile() {
447     return (String JavaDoc)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 JavaDoc getSQLBuilder() {
465     return (String JavaDoc)values.get("SQLBuilder");
466   }
467 }
468
Popular Tags