view flys-client/src/main/java/de/intevation/flys/client/server/BaseServletContextListener.java @ 4241:49cb65d5932d

Improved the historical discharge calculation. The calculation now creates new HistoricalWQKms (new subclass of WQKms). Those WQKms are used to create new facets from (new) type 'HistoricalDischargeCurveFacet'. The chart generator is improved to support those facets.
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 24 Oct 2012 14:34:35 +0200
parents 763789a9acca
children
line wrap: on
line source
package de.intevation.flys.client.server;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import de.intevation.flys.client.server.LoggingConfigurator;
import de.intevation.flys.client.server.features.Features;
import de.intevation.flys.client.server.features.XMLFileFeatures;

/**
 * ServletContextListenter to initalize the Features globally for
 * all Servlets
 */
public class BaseServletContextListener implements ServletContextListener {

    public static final String LOG4J_PROPERTIES = "FLYS_CLIENT_LOG4J_PROPERIES";

    public static final Logger logger = Logger.getLogger(BaseServletContextListener.class);

    @Override
    public void  contextInitialized(ServletContextEvent sce) {
        ServletContext sc = sce.getServletContext();

        this.initLogging(sc);

        String filename = sc.getInitParameter("features-file");

        logger.debug("Initializing ServletContext");
        try {
            XMLFileFeatures features = new XMLFileFeatures(sc.getRealPath(filename));
            sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features);
        } catch(IOException e) {
            logger.error(e);
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        //DO NOTHING
    }


    private void initLogging(ServletContext sc) {
        String log4jProperties = System.getenv(LOG4J_PROPERTIES);

        if (log4jProperties == null || log4jProperties.length() == 0) {
            String file = sc.getInitParameter("log4j-properties");

            if (file != null && file.length() > 0) {
                log4jProperties = sc.getRealPath(file);
            }
        }
        System.out.println(log4jProperties);

        LoggingConfigurator.init(log4jProperties);
    }
}

http://dive4elements.wald.intevation.org