001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.global;
006:
007: import org.apache.struts.action.ActionServlet;
008: import org.apache.struts.action.PlugIn;
009: import org.apache.struts.config.ModuleConfig;
010: import java.io.File;
011: import javax.servlet.ServletException;
012:
013: /**
014: * GeoServerPlugIn purpose.
015: *
016: * <p>
017: * Used to load the config into GeoServer. Is a pre-Condition for ConfigPlugIn.
018: * This is started by struts.
019: * </p>
020: *
021: * <p></p>
022: *
023: * @author dzwiers, Refractions Research, Inc.
024: * @version $Id: GeoServerPlugIn.java 6326 2007-03-15 18:36:40Z jdeolive $
025: *
026: * @see org.vfny.geoserver.config.ConfigPlugIn
027: * @REVISIT: There seems to be quite a bit of code duplication in this class
028: * with LoadXMLAction, loading things, especially with the
029: * validation stuff. Anyway we could cut that down? Have one call
030: * the other? Too close to release to do sucha refactoring but
031: * in 1.4 we should. -CH
032: */
033: public class GeoServerPlugIn implements PlugIn {
034: /**
035: * To allow for this class to be used as a precondition, and be pre-inited.
036: *
037: * @see org.vfny.geoserver.config.ConfigPlugIn
038: */
039: private boolean started = false;
040:
041: /**
042: * Implement destroy.
043: *
044: * <p>
045: * Does Nothing
046: * </p>
047: *
048: * @see org.apache.struts.action.PlugIn#destroy()
049: */
050: public void destroy() {
051: }
052:
053: /**
054: * Implement init.
055: *
056: * <p>
057: * This does the load of the config files for GeoServer. Check the struts
058: * configuration if this is not laoding correctly.
059: * </p>
060: *
061: * @param as Used to get ServletContext
062: * @param mc Not used
063: *
064: * @throws javax.servlet.ServletException
065: * @throws ServletException when a load error occurs
066: *
067: * @see org.apache.struts.action.PlugIn#init(org.apache.struts.action.ActionServlet,
068: * org.apache.struts.config.ModuleConfig)
069: */
070: public void init(ActionServlet as, ModuleConfig mc)
071: throws javax.servlet.ServletException {
072: if (started) {
073: return;
074: }
075:
076: //JD: kill this
077: // ServletContext sc = as.getServletContext()eos;
078: // File geoserverDataDir = GeoserverDataDirectory.getGeoserverDataDirectory(sc); //geoserver_home fix
079: //
080: // try {
081: // File f = geoserverDataDir; //geoserver_home fix
082: // XMLConfigReader cr = new XMLConfigReader(f,sc);
083: //
084: // GeoServer gs = new GeoServer();
085: // sc.setAttribute(GeoServer.WEB_CONTAINER_KEY, gs);
086: //
087: // Data dt = new Data(f,gs);
088: // sc.setAttribute(Data.WEB_CONTAINER_KEY, dt);
089: //
090: // WFS wfs = new WFS();
091: // sc.setAttribute(WFS.WEB_CONTAINER_KEY, wfs);
092: //
093: // WMS wms = new WMS();
094: // sc.setAttribute(WMS.WEB_CONTAINER_KEY, wms);
095: //
096: // GeoValidator gv = new GeoValidator();
097: // sc.setAttribute(GeoValidator.WEB_CONTAINER_KEY, gv);
098: //
099: // if (cr.isInitialized()) {
100: // gs.load(cr.getGeoServer(),sc);
101: // wfs.load(cr.getWfs());
102: // wms.load(cr.getWms());
103: // dt.load(cr.getData());
104: //
105: // wfs.setGeoServer(gs);
106: // wms.setGeoServer(gs);
107: // wfs.setData(dt);
108: // wms.setData(dt);
109: // } else {
110: // throw new ConfigurationException(
111: // "An error occured loading the initial configuration.");
112: // }
113: //
114: //
115: // try {
116: // File plugInDir = findConfigDir(geoserverDataDir, "plugIns");
117: // File validationDir = findConfigDir(geoserverDataDir, "validation");
118: // Map plugIns = null;
119: // Map testSuites = null;
120: // if(plugInDir.exists()){
121: // plugIns = XMLReader.loadPlugIns(plugInDir);
122: // if(validationDir.exists()){
123: // testSuites = XMLReader.loadValidations(validationDir, plugIns);
124: // gv.load(testSuites,plugIns);
125: // }
126: // testSuites = new HashMap();
127: // }else{
128: // plugIns = new HashMap();
129: // }
130: // wfs.setValidation(gv);
131: // } catch (Exception e) {
132: // // LOG error
133: // e.printStackTrace();
134: // }
135: // } catch (ConfigurationException e) {
136: // sc.setAttribute(GeoServer.WEB_CONTAINER_KEY, null);
137: // sc.setAttribute(Data.WEB_CONTAINER_KEY, null);
138: // sc.setAttribute(WFS.WEB_CONTAINER_KEY, null);
139: // sc.setAttribute(WMS.WEB_CONTAINER_KEY, null);
140: // sc.setAttribute(GeoValidator.WEB_CONTAINER_KEY, null);
141: // throw new ServletException(e);
142: // }
143: started = true;
144: }
145:
146: private File findConfigDir(File rootDir, String name)
147: throws Exception {
148: return GeoserverDataDirectory.findConfigDir(rootDir, name);
149: }
150: }
|