d7e208a9a56355fb482fa7e8a875c075d8a48ce8
[mir.git] / source / mir / misc / Configuration.java
1 package  mir.misc;
2
3 import  java.net.*;
4 import  java.io.*;
5 import  java.util.*;
6 import  java.lang.*;
7
8
9 /**
10  * Diese Klasse realisert den Zugriff auf die Konfiguration.
11  *
12  */
13 public class Configuration {
14   
15   private static HashMap  confs = new HashMap(); // key: conffilename, confHash
16   private String          confFilename;
17   
18   private static String   defaultconfFilename;
19   static ResourceBundle conf;
20
21   protected static void initConfResource(String confName) {
22     conf = ResourceBundle.getBundle(confName);
23     confs.put("confname",confName);
24   }
25
26   protected static Enumeration getResourceKeys() {
27     return conf.getKeys();
28   }
29
30
31   /**
32    * Fragt ab, ob das Betriebssystem Windows ist.
33    * @return true wenn ja, sonst false.
34    */
35   protected static boolean isWindows() {
36     return System.getProperty("os.name").toLowerCase().indexOf("win") >= 0;
37   }
38
39    /**
40    * Liefert Wert einer Property zurueck
41    * @param propName
42    * @return Wert der Property
43    */
44   protected static String getProperty(String propName) {  // default
45     return conf.getString(propName);
46   }
47   
48    /**
49    * Checks if open posting should be direct or indirect
50    * @return true if open posting should be direct
51    */
52   protected static boolean directOp() {
53     String op = conf.getString("DirectOpenposting");
54     if(op.equals("yes") || op.equals("Yes") || op.equals("y") || op.equals("Y")){
55       return true;
56     }
57     return false;
58   }
59
60   /**
61    * Liest eine Property eines Modules aus der Konfiguration
62    * @param filename
63    * @param theModule
64    * @param propName
65    * @return Wert der Property
66    */
67   protected String getProperty(String filename ,String theModule, String propName) {
68     return getProperty(filename, theModule + "." + propName);
69   }
70
71     /**
72    * Liest eine Property aus der Konfiguration
73    * @param filename
74    * @param propName
75    * @return Wert der Property
76    */
77   protected static String getProperty(String filename, String propName) {
78     if (filename != null) {
79       String prop = null;
80       HashMap conf = ((HashMap)confs.get("confname"));
81
82       if (conf == null) {
83         System.err.println("Keine Konfiguration fuer " + filename);
84       } else {
85         prop = (String)conf.get(propName);
86       }
87
88       if (prop == null) {
89         System.err.println("Keine Konfiguration fuer " + filename + " " + propName);
90       }
91
92       return prop;
93
94     } else {
95         System.err.println("--- filename null!");
96     }
97
98     return null;
99   }
100
101   /**
102    * Liefert Hashtable mit den Konfigurationen
103    * @return
104    */
105   public static HashMap getConfs(){
106     return confs;
107   }
108
109 } //end of class