From f3f43417b5fa3f3310cd7f0ce14cd607735cb00f Mon Sep 17 00:00:00 2001 From: idfx Date: Sun, 2 Feb 2003 17:26:29 +0000 Subject: [PATCH] a small bugfix --- source/mir/config/MirPropertiesConfiguration.java | 32 ++++++++++++++++++++--- source/mir/generator/FreemarkerGenerator.java | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/source/mir/config/MirPropertiesConfiguration.java b/source/mir/config/MirPropertiesConfiguration.java index 2804e748..ecebd1c7 100755 --- a/source/mir/config/MirPropertiesConfiguration.java +++ b/source/mir/config/MirPropertiesConfiguration.java @@ -53,6 +53,10 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { private static MirPropertiesConfiguration instance; private static ServletContext context; private static String contextPath; + + //if one of these properties is not present a new + //emtpy property is added + private String[] needed = {"Producer.DocRoot"}; /** * Constructor for MirPropertiesConfiguration. @@ -61,7 +65,8 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { throws IOException { super(ctx.getRealPath("/WEB-INF/etc/") + "/config.properties", ctx.getRealPath("/WEB-INF/etc/") + "/default.properties"); - this.addProperty("Home", ctx.getRealPath("/WEB-INF/") + "/"); + addProperty("Home", ctx.getRealPath("/WEB-INF/") + "/"); + checkMissing(); } public static synchronized MirPropertiesConfiguration instance() @@ -96,7 +101,11 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { while (iterator.hasNext()) { String key = (String) iterator.next(); - returnMap.put(key, this.getProperty(key)); + Object o = this.getString(key); + if(o == null){ + o = new Object(); + } + returnMap.put(key, o); } return returnMap; @@ -120,6 +129,14 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { return getString("Home") + returnString; } + private void checkMissing(){ + for(int i = 0; i < needed.length; i++){ + if(super.getProperty(needed[i]) == null){ + addProperty(needed[i],""); + } + } + } + public File getFile(String key) throws FileNotFoundException { String path = getStringWithHome(key); File returnFile = new File(path); @@ -138,9 +155,18 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { if (super.getString(key) == null) { return new String(); } - return super.getString(key); } + + /** + * @see org.apache.commons.configuration.Configuration#getString(java.lang.String) + */ + public Object getProperty(String key) { + if (super.getProperty(key) == null) { + return new String(); + } + return super.getProperty(key); + } /** * @author idefix diff --git a/source/mir/generator/FreemarkerGenerator.java b/source/mir/generator/FreemarkerGenerator.java index 72810e78..640550d2 100755 --- a/source/mir/generator/FreemarkerGenerator.java +++ b/source/mir/generator/FreemarkerGenerator.java @@ -69,6 +69,7 @@ public class FreemarkerGenerator implements Generator { template.process((TemplateModelRoot) makeMapAdapter(aValues), (PrintWriter) anOutputWriter); } catch (Throwable t) { + t.printStackTrace(); aLogger.println("Exception occurred: "+t.getMessage()); t.printStackTrace(aLogger); throw new GeneratorFailure( t ); -- 2.11.0