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 ; 8 import java.io.IOException ; 9 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 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)||(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 getTempConfigurationMap() throws InfoException { 53 if ((values==null)){ 54 fillValues(getTempConfiguration()); 55 } 56 return getValues(); 57 } 58 59 private void fillValues(Configuration propertiesConfiguration) { 60 Iterator iter = propertiesConfiguration.getKeys(); 61 while (iter.hasNext()) { 62 String key = (String ) iter.next(); 63 String value = propertiesConfiguration.getString(key); 64 getValues().put(key,value); 65 } 66 } 67 68 public Map getValues() { 69 if (values==null){ 70 values = new HashMap (); 71 } 72 return values; 73 } 74 75 76 private Configuration getTempConfiguration() throws InfoException { 77 File file = new File (tempPath+"/temp.properties"); 78 if (!file.exists()){ 79 try { 80 file.createNewFile(); 81 } catch (IOException 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 |