package com.calipso.reportgenerator.reportmanager;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import com.calipso.reportgenerator.common.InfoException;
import com.calipso.reportgenerator.common.LanguageTraslator;
/**
* Calipso Software
* User: Breto
* Date: 18/04/2006
* Time: 17:38:20
*/
public class TempRepository {
private String tempPath;
private Map values;
public TempRepository(String tempPath) throws InfoException {
this.tempPath = tempPath;
if ((this.tempPath==null)||(this.tempPath.equalsIgnoreCase(""))){
throw new InfoException(LanguageTraslator.traslate("586"));
}
}
public boolean isAcceptedLicence() throws InfoException {
if ( getTempConfigurationMap().containsKey("LICENCEACCEPTED")){
return getTempConfigurationMap().get("LICENCEACCEPTED").toString().equalsIgnoreCase("TRUE");
} else{
return false;
}
}
public void acceptedLicence(boolean value) throws InfoException {
PropertiesConfiguration configuration = (PropertiesConfiguration)getTempConfiguration();
configuration.addProperty("LICENCEACCEPTED","TRUE");
try {
configuration.save();
} catch (ConfigurationException e) {
throw new InfoException(LanguageTraslator.traslate("585"), e);
}
values = null;
}
private Map getTempConfigurationMap() throws InfoException {
if ((values==null)){
fillValues(getTempConfiguration());
}
return getValues();
}
private void fillValues(Configuration propertiesConfiguration) {
Iterator iter = propertiesConfiguration.getKeys();
while (iter.hasNext()) {
String key = (String) iter.next();
String value = propertiesConfiguration.getString(key);
getValues().put(key,value);
}
}
public Map getValues() {
if (values==null){
values = new HashMap();
}
return values;
}
private Configuration getTempConfiguration() throws InfoException {
File file = new File(tempPath+"/temp.properties");
if (!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
throw new InfoException(LanguageTraslator.traslate("583"), e);
}
}
try {
return new PropertiesConfiguration(file);
} catch (ConfigurationException e) {
throw new InfoException(LanguageTraslator.traslate("584"), e);
}
}
}
|