/*
 * Copyright 2006 Wyona
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.wyona.org/licenses/APACHE-LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.wyona.yanel.core.map;

import java.io.File;
import java.lang.ClassNotFoundException;
import java.lang.IllegalAccessException;
import java.lang.InstantiationException;
import java.net.URL;
import java.util.Properties;

import org.apache.log4j.Category;

import org.wyona.commons.io.FileUtil;

/**
 *
 */
public class RealmConfiguration {

    private static Category log = Category.getInstance(RealmConfiguration.class);

    public static final String DEFAULT_CONFIGURATION_FILE = "yanel.properties";
    public static String CONFIGURATION_FILE = DEFAULT_CONFIGURATION_FILE;

    private URL propertiesURL;

    public String proxyHostName;
    public String proxyPort;
    public String proxyPrefix;

    java.util.HashMap hm = new java.util.HashMap();

    /**
     *
     */
    public RealmConfiguration() {
        this(DEFAULT_CONFIGURATION_FILE);
    }

    /**
     *
     */
    public RealmConfiguration(String configurationFile) {
        CONFIGURATION_FILE = configurationFile;

        propertiesURL = RealmConfiguration.class.getClassLoader().getResource(CONFIGURATION_FILE);
        if (propertiesURL == null) {
            log.error("No such resource: " + CONFIGURATION_FILE);
            return;
        }

        Properties props = new Properties();
        try {
            props.load(propertiesURL.openStream());
            File propsFile = new File(propertiesURL.getFile());

            File realmsConfigFile = new File(props.getProperty("realms-config"));
            if (!realmsConfigFile.isAbsolute()) {
                realmsConfigFile = FileUtil.file(propsFile.getParentFile().getAbsolutePath(), realmsConfigFile.toString());
            }
            log.error("DEBUG: Realms Configuration: " + realmsConfigFile);

            // TODO: This is actually a servlet thing and should be moved there ...
            proxyHostName = props.getProperty("proxy-host-name");
            proxyPort = props.getProperty("proxy-port");
            proxyPrefix = props.getProperty("proxy-prefix");
            log.debug("Proxy Settings: " + proxyHostName + ", " + proxyPort + ", " + proxyPrefix);
        } catch (Exception e) {
            log.error(e);
        }
    }

    /**
     *
     */
    public String getConfigurationFile() {
        return CONFIGURATION_FILE;
    }
}

@@ -863,16 +863,159 @@
 egory;%0A%0A
+import org.apache.avalon.framework.configuration.Configuration;%0Aimport org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;%0A%0A
 import o
@@ -1044,16 +1044,16 @@
 leUtil;%0A
-
 %0A/**%0A *%0A
@@ -1361,16 +1361,53 @@
 esURL;%0A%0A
+    private File realmsConfigFile; %0A%0A
     publ
@@ -2202,21 +2202,16 @@
         
-File 
 realmsCo
@@ -2529,16 +2529,42 @@
 igFile);
+%0A            readRealms();
 %0A%0A      
@@ -3061,24 +3061,24 @@
 ionFile() %7B%0A
-
         retu
@@ -3105,11 +3105,567 @@
 E;%0A    %7D
+%0A%0A    /**%0A     *%0A     */%0A    public void readRealms() %7B%0A        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();%0A        Configuration config;%0A%0A        try %7B%0A            config = builder.buildFromFile(realmsConfigFile);%0A%0A            Configuration%5B%5D realmElements = config.getChildren(%22realm%22);%0A            for (int i = 0;i %3C realmElements.length; i++) %7B%0A                log.error(%22DEBUG: %22 + realmElements%5Bi%5D.getAttribute(%22mount-point%22, null));%0A            %7D%0A        %7D catch (Exception e) %7B%0A            log.error(e);%0A        %7D%0A    %7D
 %0A%7D%0A

read realms config started