01: package com.calipso.reportgenerator.reportmanager;
02:
03: import org.apache.commons.configuration.Configuration;
04: import org.apache.commons.configuration.PropertiesConfiguration;
05: import org.apache.commons.configuration.ConfigurationException;
06:
07: import java.io.File;
08: import java.io.IOException;
09: import java.util.Iterator;
10: import java.util.Map;
11: import java.util.HashMap;
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 tempPath;
24: private Map values;
25:
26: public TempRepository(String tempPath) throws InfoException {
27: this .tempPath = tempPath;
28: if ((this .tempPath == null)
29: || (this .tempPath.equalsIgnoreCase(""))) {
30: throw new InfoException(LanguageTraslator.traslate("586"));
31: }
32: }
33:
34: public boolean isAcceptedLicence() throws InfoException {
35: if (getTempConfigurationMap().containsKey("LICENCEACCEPTED")) {
36: return getTempConfigurationMap().get("LICENCEACCEPTED")
37: .toString().equalsIgnoreCase("TRUE");
38: } else {
39: return false;
40: }
41: }
42:
43: public void acceptedLicence(boolean value) throws InfoException {
44: PropertiesConfiguration configuration = (PropertiesConfiguration) getTempConfiguration();
45: configuration.addProperty("LICENCEACCEPTED", "TRUE");
46: try {
47: configuration.save();
48: } catch (ConfigurationException e) {
49: throw new InfoException(LanguageTraslator.traslate("585"),
50: e);
51: }
52: values = null;
53: }
54:
55: private Map getTempConfigurationMap() throws InfoException {
56: if ((values == null)) {
57: fillValues(getTempConfiguration());
58: }
59: return getValues();
60: }
61:
62: private void fillValues(Configuration propertiesConfiguration) {
63: Iterator iter = propertiesConfiguration.getKeys();
64: while (iter.hasNext()) {
65: String key = (String) iter.next();
66: String value = propertiesConfiguration.getString(key);
67: getValues().put(key, value);
68: }
69: }
70:
71: public Map getValues() {
72: if (values == null) {
73: values = new HashMap();
74: }
75: return values;
76: }
77:
78: private Configuration getTempConfiguration() throws InfoException {
79: File file = new File(tempPath + "/temp.properties");
80: if (!file.exists()) {
81: try {
82: file.createNewFile();
83: } catch (IOException e) {
84: throw new InfoException(LanguageTraslator
85: .traslate("583"), e);
86: }
87: }
88: try {
89: return new PropertiesConfiguration(file);
90: } catch (ConfigurationException e) {
91: throw new InfoException(LanguageTraslator.traslate("584"),
92: e);
93: }
94: }
95: }
|