view gwt-client/src/main/java/org/dive4elements/river/client/server/BaseServletContextListener.java @ 8870:c26fb37899ca

Introduced groups for modules. Modules marked with the same group-id, will be put together in the ui. Also using now the localization info from the server instead of localizing the modules again on the client side.
author gernotbelger
date Wed, 07 Feb 2018 11:59:13 +0100
parents 5e38e2924c07
children 654aaa0d7576
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.client.server;

import java.io.IOException;

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

import org.apache.log4j.Logger;

import org.dive4elements.river.client.server.features.Features;
import org.dive4elements.river.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 log = Logger.getLogger(
        BaseServletContextListener.class);

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

        this.initLogging(sc);

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

        log.debug("Initializing ServletContext");
        try {
            XMLFileFeatures features = new XMLFileFeatures(
                sc.getRealPath(filename));
            sc.setAttribute(Features.CONTEXT_ATTRIBUTE, features);
        } catch(IOException e) {
            log.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