blob: 71b8479717d0f4b74999b8d1c99e08780365f164 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// ========================================================================
// Copyright (c) 2000-2009 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
package org.eclipse.jetty.webapp;
import java.util.Map;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
/**
*
* JettyWebConfiguration.
*
* Looks for Xmlconfiguration files in WEB-INF. Searches in order for the first of jettyX-web.xml, jetty-web.xml or web-jetty.xml
*
*
*
*/
public class JettyWebXmlConfiguration extends AbstractConfiguration
{
private static final Logger LOG = Log.getLogger(JettyWebXmlConfiguration.class);
/** The value of this property points to the WEB-INF directory of
* the web-app currently installed.
* it is passed as a property to the jetty-web.xml file */
public static final String PROPERTY_THIS_WEB_INF_URL = "this.web-inf.url";
public static final String XML_CONFIGURATION = "org.eclipse.jetty.webapp.JettyWebXmlConfiguration";
public static final String JETTY_WEB_XML = "jetty-web.xml";
/**
* Configure
* Apply web-jetty.xml configuration
* @see Configuration#configure(WebAppContext)
*/
@Override
public void configure (WebAppContext context) throws Exception
{
//cannot configure if the _context is already started
if (context.isStarted())
{
if (LOG.isDebugEnabled()){LOG.debug("Cannot configure webapp after it is started");}
return;
}
if(LOG.isDebugEnabled())
LOG.debug("Configuring web-jetty.xml");
Resource web_inf = context.getWebInf();
// handle any WEB-INF descriptors
if(web_inf!=null&&web_inf.isDirectory())
{
// do jetty.xml file
Resource jetty=web_inf.addPath("jetty7-web.xml");
if(!jetty.exists())
jetty=web_inf.addPath(JETTY_WEB_XML);
if(!jetty.exists())
jetty=web_inf.addPath("web-jetty.xml");
if(jetty.exists())
{
// No server classes while configuring
String[] old_server_classes = context.getServerClasses();
try
{
context.setServerClasses(null);
if(LOG.isDebugEnabled())
LOG.debug("Configure: "+jetty);
XmlConfiguration jetty_config = (XmlConfiguration)context.getAttribute(XML_CONFIGURATION);
if (jetty_config==null)
jetty_config=new XmlConfiguration(jetty.getURL());
else
context.removeAttribute(XML_CONFIGURATION);
setupXmlConfiguration(context,jetty_config, web_inf);
jetty_config.configure(context);
}
finally
{
if (context.getServerClasses()==null)
context.setServerClasses(old_server_classes);
}
}
}
}
/**
* Configures some well-known properties before the XmlConfiguration reads
* the configuration.
* @param jetty_config The configuration object.
*/
private void setupXmlConfiguration(WebAppContext context, XmlConfiguration jetty_config, Resource web_inf)
{
setupXmlConfiguration(jetty_config,web_inf);
}
/**
* Configures some well-known properties before the XmlConfiguration reads
* the configuration.
* @param jetty_config The configuration object.
*/
private void setupXmlConfiguration(XmlConfiguration jetty_config, Resource web_inf)
{
Map<String,String> props = jetty_config.getProperties();
props.put(PROPERTY_THIS_WEB_INF_URL, String.valueOf(web_inf.getURL()));
}
}
|