001: //========================================================================
002: //$Id: JettyWebXmlConfiguration.java,v 1.5 2005/11/19 00:32:42 gregwilkins Exp $
003: //Copyright 2000-2005 Mort Bay Consulting Pty. Ltd.
004: //------------------------------------------------------------------------
005: //Licensed under the Apache License, Version 2.0 (the "License");
006: //you may not use this file except in compliance with the License.
007: //You may obtain a copy of the License at
008: //http://www.apache.org/licenses/LICENSE-2.0
009: //Unless required by applicable law or agreed to in writing, software
010: //distributed under the License is distributed on an "AS IS" BASIS,
011: //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: //See the License for the specific language governing permissions and
013: //limitations under the License.
014: //========================================================================
015:
016: package org.mortbay.jetty.webapp;
017:
018: import org.mortbay.log.Log;
019: import org.mortbay.resource.Resource;
020: import org.mortbay.xml.XmlConfiguration;
021:
022: /**
023: *
024: * JettyWebConfiguration.
025: *
026: * Looks for Xmlconfiguration files in WEB-INF. Searches in order for the first of jetty6-web.xml, jetty-web.xml or web-jetty.xml
027: *
028: * @author janb
029: *
030: */
031: public class JettyWebXmlConfiguration implements Configuration {
032: private WebAppContext _context;
033:
034: /**
035: * @see Configuration#setWebAppContext
036: */
037: public void setWebAppContext(WebAppContext context) {
038: _context = context;
039: }
040:
041: public WebAppContext getWebAppContext() {
042: return _context;
043: }
044:
045: /** configureClassPath
046: * Not used.
047: * @see Configuration#configureClassLoader
048: */
049: public void configureClassLoader() throws Exception {
050: }
051:
052: /** configureDefaults
053: * Not used.
054: * @see Configuration#configureDefaults
055: */
056: public void configureDefaults() throws Exception {
057: }
058:
059: /** configureWebApp
060: * Apply web-jetty.xml configuration
061: * @see Configuration#configureWebApp()
062: */
063: public void configureWebApp() throws Exception {
064: //cannot configure if the _context is already started
065: if (_context.isStarted()) {
066: if (Log.isDebugEnabled()) {
067: Log
068: .debug("Cannot configure webapp after it is started");
069: }
070: return;
071: }
072:
073: if (Log.isDebugEnabled())
074: Log.debug("Configuring web-jetty.xml");
075:
076: Resource web_inf = getWebAppContext().getWebInf();
077: // handle any WEB-INF descriptors
078: if (web_inf != null && web_inf.isDirectory()) {
079: // do jetty.xml file
080: Resource jetty = web_inf.addPath("jetty6-web.xml");
081: if (!jetty.exists())
082: jetty = web_inf.addPath("jetty-web.xml");
083: if (!jetty.exists())
084: jetty = web_inf.addPath("web-jetty.xml");
085:
086: if (jetty.exists()) {
087: // Give permission to see Jetty classes for the duration
088: String[] old_server_classes = _context
089: .getServerClasses();
090: try {
091: String[] server_classes = new String[2 + (old_server_classes == null ? 0
092: : old_server_classes.length)];
093: server_classes[0] = "-org.mortbay.jetty.";
094: server_classes[1] = "-org.mortbay.util.";
095: if (server_classes != null)
096: System.arraycopy(old_server_classes, 0,
097: server_classes, 2,
098: old_server_classes.length);
099:
100: _context.setServerClasses(server_classes);
101: if (Log.isDebugEnabled())
102: Log.debug("Configure: " + jetty);
103: XmlConfiguration jetty_config = new XmlConfiguration(
104: jetty.getURL());
105: jetty_config.configure(getWebAppContext());
106: } finally {
107: _context.setServerClasses(old_server_classes);
108: }
109: }
110: }
111: }
112:
113: /** deconfigureWebApp
114: * @see Configuration#deconfigureWebApp()
115: */
116: public void deconfigureWebApp() throws Exception {
117:
118: }
119:
120: }
|