some codeformatting, license for the new classes
[mir.git] / source / mir / config / MirPropertiesConfiguration.java
index 5441545..50196e8 100755 (executable)
  * to your version of the file, but you are not obligated to do so.  If you do
  * not wish to do so, delete this exception statement from your version.
  */
 package mir.config;
 
+import multex.Exc;
+import multex.Failure;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
 import javax.servlet.ServletContext;
 
-import multex.Exc;
-import multex.Failure;
-
-import org.apache.commons.configuration.PropertiesConfiguration;
-
 
 /**
  * @author idefix
@@ -53,30 +53,34 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration {
   private static MirPropertiesConfiguration instance;
   private static ServletContext context;
   private static String contextPath;
-  
-       /**
-        * Constructor for MirPropertiesConfiguration.
-        */
-       private MirPropertiesConfiguration(ServletContext ctx, String ctxPath) 
-                                         throws IOException {
-               super(ctx.getRealPath("/WEB-INF/etc/") + "/config.properties", 
-                     ctx.getRealPath("/WEB-INF/etc/") + "/default.properties");
-    this.addProperty("Home", ctx.getRealPath("/WEB-INF/")+"/");
+
+  /**
+   * Constructor for MirPropertiesConfiguration.
+   */
+  private MirPropertiesConfiguration(ServletContext ctx, String ctxPath)
+    throws IOException {
+    super(ctx.getRealPath("/WEB-INF/etc/") + "/config.properties",
+      ctx.getRealPath("/WEB-INF/etc/") + "/default.properties");
+    this.addProperty("Home", ctx.getRealPath("/WEB-INF/") + "/");
     this.addProperty("RootUri", ctxPath);
-       }
+  }
 
   public static synchronized MirPropertiesConfiguration instance()
-       throws PropertiesConfigExc {
-    if(instance == null){
-      if(context == null || contextPath == null || contextPath.length() == 0){
-        throw new MirPropertiesConfiguration.PropertiesConfigExc("Context was not set");
+    throws PropertiesConfigExc {
+    if (instance == null) {
+      if ((context == null) || (contextPath == null) ||
+          (contextPath.length() == 0)) {
+        throw new MirPropertiesConfiguration.PropertiesConfigExc(
+          "Context was not set");
       }
+
       try {
-        instance = new MirPropertiesConfiguration(context,contextPath);
+        instance = new MirPropertiesConfiguration(context, contextPath);
       } catch (IOException e) {
         e.printStackTrace();
-      }                                     
+      }
     }
+
     return instance;
   }
 
@@ -87,7 +91,7 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration {
   public static void setContext(ServletContext context) {
     MirPropertiesConfiguration.context = context;
   }
-  
+
   /**
    * Sets the contextPath.
    * @param contextPath The contextPath to set
@@ -95,18 +99,19 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration {
   public static void setContextPath(String contextPath) {
     MirPropertiesConfiguration.contextPath = contextPath;
   }
-  
-  public Map allSettings(){
-               Iterator iterator = this.getKeys();
-               Map returnMap = new HashMap();
-               while(iterator.hasNext()){
-                 String key = (String)iterator.next();
-                       returnMap.put(key,this.getProperty(key));                       
-               }
+
+  public Map allSettings() {
+    Iterator iterator = this.getKeys();
+    Map returnMap = new HashMap();
+
+    while (iterator.hasNext()) {
+      String key = (String) iterator.next();
+      returnMap.put(key, this.getProperty(key));
+    }
+
     return returnMap;
   }
 
-
   /**
    * Returns the context.
    * @return ServletContext
@@ -114,40 +119,43 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration {
   public static ServletContext getContext() {
     return context;
   }
-       
-       public String getStringWithHome(String key){
-         String returnString = getString(key);
-         if(returnString == null){
-           returnString = new String();
-         }
-         return getString("Home") + returnString;
-       }
-       
-       public File getFile(String key) throws FileNotFoundException{
-         String path = getStringWithHome(key);
-         File returnFile = new File(path);
-         if(returnFile.exists()){
-           return returnFile; 
-         } else {
-           throw new FileNotFoundException();
-         }
-       }
-       
+
+  public String getStringWithHome(String key) {
+    String returnString = getString(key);
+
+    if (returnString == null) {
+      returnString = new String();
+    }
+
+    return getString("Home") + returnString;
+  }
+
+  public File getFile(String key) throws FileNotFoundException {
+    String path = getStringWithHome(key);
+    File returnFile = new File(path);
+
+    if (returnFile.exists()) {
+      return returnFile;
+    } else {
+      throw new FileNotFoundException();
+    }
+  }
+
   /**
    * @see org.apache.commons.configuration.Configuration#getString(java.lang.String)
    */
   public String getString(String key) {
-    if(super.getString(key) == null){
+    if (super.getString(key) == null) {
       return new String();
     }
+
     return super.getString(key);
   }
-  
+
   /**
    * @author idefix
    */
   public static class PropertiesConfigExc extends Exc {
-
     /**
      * Constructor for PropertiesConfigExc.
      * @param arg0
@@ -161,14 +169,12 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration {
    * @author idefix
    */
   public static class PropertiesConfigFailure extends Failure {
-
     /**
      * Constructor for PropertiesConfigExc.
      * @param arg0
      */
     public PropertiesConfigFailure(String msg, Throwable cause) {
-      super(msg,cause);
+      super(msg, cause);
     }
   }
-
 }