package mir.config;\r
\r
-import java.io.*;\r
-import java.util.*;\r
-import java.lang.System;\r
-import org.xml.sax.helpers.DefaultHandler;\r
-import org.xml.sax.*;\r
-import javax.xml.parsers.ParserConfigurationException;\r
-import javax.xml.parsers.SAXParser;\r
-import javax.xml.parsers.SAXParserFactory;\r
-\r
-import mir.config.exceptions.*;\r
-import mir.misc.Location;\r
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import mir.config.exceptions.ConfigDefineNotKnownException;
+import mir.config.exceptions.ConfigFailure;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.DefaultHandler;
\r
public class ConfigReader {\r
final static String propertyTagName="property";\r
--- /dev/null
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * 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 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
+ */
+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/")+"/");
+ 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");
+ }
+ try {
+ instance = new MirPropertiesConfiguration(context,contextPath);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ return instance;
+ }
+
+ /**
+ * Sets the context.
+ * @param context The context to set
+ */
+ public static void setContext(ServletContext context) {
+ MirPropertiesConfiguration.context = context;
+ }
+
+ /**
+ * Sets the contextPath.
+ * @param contextPath The contextPath to set
+ */
+ 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));
+ }
+ return returnMap;
+ }
+
+
+ /**
+ * Returns the context.
+ * @return ServletContext
+ */
+ 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();
+ }
+ }
+
+ /**
+ * @see org.apache.commons.configuration.Configuration#getString(java.lang.String)
+ */
+ public String getString(String key) {
+ 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
+ */
+ public PropertiesConfigExc(String msg) {
+ super(msg);
+ }
+ }
+
+ /**
+ * @author idefix
+ */
+ public static class PropertiesConfigFailure extends Failure {
+
+ /**
+ * Constructor for PropertiesConfigExc.
+ * @param arg0
+ */
+ public PropertiesConfigFailure(String msg, Throwable cause) {
+ super(msg,cause);
+ }
+ }
+
+}