a small bugfix
authoridfx <idfx>
Sun, 2 Feb 2003 17:26:29 +0000 (17:26 +0000)
committeridfx <idfx>
Sun, 2 Feb 2003 17:26:29 +0000 (17:26 +0000)
source/mir/config/MirPropertiesConfiguration.java
source/mir/generator/FreemarkerGenerator.java

index 2804e74..ecebd1c 100755 (executable)
@@ -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
index 72810e7..640550d 100755 (executable)
@@ -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 );