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() {
    }
}

@@ -396,16 +396,74 @@
 ntext;%0A%0A
+import java.util.Properties;%0Aimport java.io.InputStream;%0A%0A
 import o
@@ -1926,16 +1926,379 @@
 g%22, wc);
+%0A%0A            InputStream externalLinkPropertiesStream =%0A                context.getResourceAsStream(%22/WEB-INF/web.properties%22);%0A            %0A            Properties externalLinkProperties = new Properties();%0A            externalLinkProperties.load(externalLinkPropertiesStream);%0A%0A            context.setAttribute(Constants.WEB_PROPERTIES, externalLinkProperties);
 %0A       

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