package org.intermine.web;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

import org.intermine.metadata.Model;
import org.intermine.web.config.WebConfig;
import org.intermine.objectstore.ObjectStore;
import org.intermine.objectstore.ObjectStoreFactory;

/**
 * Initialiser for the InterMine web application
 * Anything that needs global initialisation goes here.
 *
 * @author Andrew Varley
 */

public class InitialiserPlugin implements PlugIn
{
    /**
     * Init method called at Servlet initialisation
     *
     * @param servlet ActionServlet that is managing all the modules
     * in this web application
     * @param config ModuleConfig for the module with which this
     * plug-in is associated
     *
     * @throws ServletException if this <code>PlugIn</code> cannot
     * be successfully initialized
     */
    public void init(ActionServlet servlet, ModuleConfig config)
        throws ServletException {

        ServletContext context = servlet.getServletContext();

        try {
            WebConfig wc =
                WebConfig.parse(context.getResourceAsStream("/WEB-INF/webconfig-model.xml"));
            ObjectStore os = ObjectStoreFactory.getObjectStore();
            Model model = os.getModel();
            
            context.setAttribute(Constants.OBJECTSTORE, os);
            context.setAttribute(Constants.MODEL, model);
            context.setAttribute("webconfig", wc);
        } catch (Exception e) {
            throw new ServletException("there was a problem while initialising", e);
        }
    }

    /**
     * Destroy method called at Servlet destroy
     */
    public void destroy() {
    }
}

package org.intermine.web;

/*
 * Copyright (C) 2002-2004 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import java.util.Properties;
import java.io.InputStream;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;

import org.intermine.metadata.Model;
import org.intermine.web.config.WebConfig;
import org.intermine.objectstore.ObjectStore;
import org.intermine.objectstore.ObjectStoreFactory;

/**
 * Initialiser for the InterMine web application
 * Anything that needs global initialisation goes here.
 *
 * @author Andrew Varley
 */

public class InitialiserPlugin implements PlugIn
{
    /**
     * Init method called at Servlet initialisation
     *
     * @param servlet ActionServlet that is managing all the modules
     * in this web application
     * @param config ModuleConfig for the module with which this
     * plug-in is associated
     *
     * @throws ServletException if this <code>PlugIn</code> cannot
     * be successfully initialized
     */
    public void init(ActionServlet servlet, ModuleConfig config)
        throws ServletException {

        ServletContext context = servlet.getServletContext();

        try {
            WebConfig wc =
                WebConfig.parse(context.getResourceAsStream("/WEB-INF/webconfig-model.xml"));
            ObjectStore os = ObjectStoreFactory.getObjectStore();
            Model model = os.getModel();
            
            context.setAttribute(Constants.OBJECTSTORE, os);
            context.setAttribute(Constants.MODEL, model);
            context.setAttribute("webconfig", wc);

            InputStream externalLinkPropertiesStream =
                context.getResourceAsStream("/WEB-INF/web.properties");
            
            Properties externalLinkProperties = new Properties();
            externalLinkProperties.load(externalLinkPropertiesStream);

            context.setAttribute(Constants.WEB_PROPERTIES, externalLinkProperties);
        } catch (Exception e) {
            throw new ServletException("there was a problem while initialising", e);
        }
    }

    /**
     * Destroy method called at Servlet destroy
     */
    public void destroy() {
    }
}

Read /WEB-INF/web.properties and set WEB_PROPERTIES on the Context.