KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportmanager > TempRepository


1 package com.calipso.reportgenerator.reportmanager;
2
3 import org.apache.commons.configuration.Configuration;
4 import org.apache.commons.configuration.PropertiesConfiguration;
5 import org.apache.commons.configuration.ConfigurationException;
6
7 import java.io.File JavaDoc;
8 import java.io.IOException JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.HashMap JavaDoc;
12
13 import com.calipso.reportgenerator.common.InfoException;
14 import com.calipso.reportgenerator.common.LanguageTraslator;
15
16 /**
17  * Calipso Software
18  * User: Breto
19  * Date: 18/04/2006
20  * Time: 17:38:20
21  */

22 public class TempRepository {
23   private String JavaDoc tempPath;
24   private Map JavaDoc values;
25
26   public TempRepository(String JavaDoc tempPath) throws InfoException {
27     this.tempPath = tempPath;
28     if ((this.tempPath==null)||(this.tempPath.equalsIgnoreCase(""))){
29       throw new InfoException(LanguageTraslator.traslate("586"));
30     }
31   }
32
33   public boolean isAcceptedLicence() throws InfoException {
34     if ( getTempConfigurationMap().containsKey("LICENCEACCEPTED")){
35       return getTempConfigurationMap().get("LICENCEACCEPTED").toString().equalsIgnoreCase("TRUE");
36     } else{
37       return false;
38     }
39   }
40
41   public void acceptedLicence(boolean value) throws InfoException {
42     PropertiesConfiguration configuration = (PropertiesConfiguration)getTempConfiguration();
43     configuration.addProperty("LICENCEACCEPTED","TRUE");
44     try {
45       configuration.save();
46     } catch (ConfigurationException e) {
47       throw new InfoException(LanguageTraslator.traslate("585"), e);
48     }
49     values = null;
50   }
51
52   private Map JavaDoc getTempConfigurationMap() throws InfoException {
53     if ((values==null)){
54       fillValues(getTempConfiguration());
55     }
56     return getValues();
57   }
58
59   private void fillValues(Configuration propertiesConfiguration) {
60     Iterator JavaDoc iter = propertiesConfiguration.getKeys();
61     while (iter.hasNext()) {
62       String JavaDoc key = (String JavaDoc) iter.next();
63       String JavaDoc value = propertiesConfiguration.getString(key);
64       getValues().put(key,value);
65     }
66   }
67
68   public Map JavaDoc getValues() {
69     if (values==null){
70       values = new HashMap JavaDoc();
71     }
72     return values;
73   }
74
75
76   private Configuration getTempConfiguration() throws InfoException {
77     File JavaDoc file = new File JavaDoc(tempPath+"/temp.properties");
78     if (!file.exists()){
79       try {
80         file.createNewFile();
81       } catch (IOException JavaDoc e) {
82         throw new InfoException(LanguageTraslator.traslate("583"), e);
83       }
84     }
85     try {
86       return new PropertiesConfiguration(file);
87     } catch (ConfigurationException e) {
88       throw new InfoException(LanguageTraslator.traslate("584"), e);
89     }
90   }
91 }
92
Popular Tags