View Javadoc

1   //========================================================================
2   //$Id: JettyWebXmlConfiguration.java,v 1.5 2005/11/19 00:32:42 gregwilkins Exp $
3   //Copyright 2000-2005 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //Licensed under the Apache License, Version 2.0 (the "License");
6   //you may not use this file except in compliance with the License.
7   //You may obtain a copy of the License at 
8   //http://www.apache.org/licenses/LICENSE-2.0
9   //Unless required by applicable law or agreed to in writing, software
10  //distributed under the License is distributed on an "AS IS" BASIS,
11  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  //See the License for the specific language governing permissions and
13  //limitations under the License.
14  //========================================================================
15  
16  package org.mortbay.jetty.webapp;
17  
18  import org.mortbay.log.Log;
19  import org.mortbay.resource.Resource;
20  import org.mortbay.xml.XmlConfiguration;
21  
22  
23  /**
24   * 
25   * JettyWebConfiguration.
26   * 
27   * Looks for Xmlconfiguration files in WEB-INF.  Searches in order for the first of jetty6-web.xml, jetty-web.xml or web-jetty.xml
28   *
29   * @author janb
30   *
31   */
32  public class JettyWebXmlConfiguration implements Configuration
33  {
34      private WebAppContext _context;
35  
36      
37      /**
38       * @see Configuration#setWebAppContext
39       */
40      public void setWebAppContext (WebAppContext context)
41      {
42         _context = context;
43      }
44  
45      public WebAppContext getWebAppContext ()
46      {
47          return _context;
48      }
49      
50      /** configureClassPath
51       * Not used.
52       * @see Configuration#configureClassLoader
53       */
54      public void configureClassLoader () throws Exception
55      {
56      }
57  
58      /** configureDefaults
59       * Not used.
60       * @see Configuration#configureDefaults
61       */
62      public void configureDefaults () throws Exception
63      {
64      }
65  
66      /** configureWebApp
67       * Apply web-jetty.xml configuration
68       * @see Configuration#configureWebApp()
69       */
70      public void configureWebApp () throws Exception
71      {
72          //cannot configure if the _context is already started
73          if (_context.isStarted())
74          {
75              if (Log.isDebugEnabled()){Log.debug("Cannot configure webapp after it is started");}
76              return;
77          }
78          
79          if(Log.isDebugEnabled())
80              Log.debug("Configuring web-jetty.xml");
81          
82          Resource web_inf=getWebAppContext().getWebInf();
83          // handle any WEB-INF descriptors
84          if(web_inf!=null&&web_inf.isDirectory())
85          {
86              // do jetty.xml file
87              Resource jetty=web_inf.addPath("jetty6-web.xml");
88              if(!jetty.exists())
89                  jetty=web_inf.addPath("jetty-web.xml");
90              if(!jetty.exists())
91                  jetty=web_inf.addPath("web-jetty.xml");
92  
93              if(jetty.exists())
94              {
95                  // No server classes while configuring 
96                  String[] old_server_classes = _context.getServerClasses();
97                  try
98                  {
99                      _context.setServerClasses(null);
100                     if(Log.isDebugEnabled())
101                         Log.debug("Configure: "+jetty);
102                     XmlConfiguration jetty_config=new XmlConfiguration(jetty.getURL());
103                     jetty_config.configure(getWebAppContext());
104                 }
105                 finally
106                 {
107                     if (_context.getServerClasses()==null)
108                         _context.setServerClasses(old_server_classes);
109                 }
110             }
111         }
112     }
113     
114     
115     /** deconfigureWebApp
116      * @see Configuration#deconfigureWebApp()
117      */
118     public void deconfigureWebApp () throws Exception
119     {
120     
121     }
122     
123 }