[Bug 355854] provide simple mechanism to convert jetty6 jetty-web.xml files to jetty7 on the fly

This commit is contained in:
Jesse McConnell 2011-08-25 11:27:59 -05:00
parent 103d7a87c2
commit 06881d2717
1 changed files with 36 additions and 1 deletions

View File

@ -13,8 +13,10 @@
package org.eclipse.jetty.webapp;
import java.io.InputStream;
import java.util.Map;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.xml.XmlConfiguration;
@ -77,12 +79,28 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
{
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());
{
String jettyXml = IO.toString(jetty.getURL().openStream());
if ( jettyXml.contains("org.mortbay.") )
{
Log.warn("Detected jetty 6 configuration, attempting to automatically convert");
jettyXml = convertFromJetty6(jettyXml);
}
jetty_config=new XmlConfiguration(jettyXml);
}
else
{
context.removeAttribute(XML_CONFIGURATION);
}
setupXmlConfiguration(context,jetty_config, web_inf);
jetty_config.configure(context);
}
@ -116,4 +134,21 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
props.put(PROPERTY_THIS_WEB_INF_URL, String.valueOf(web_inf.getURL()));
}
/*
* convert specific o.m.jetty paths to o.e.jetty paths
*/
private String convertFromJetty6(String jettyXml)
{
// XMLConfiguration(String) will tack on <?xml directives, so make sure we pare this down to just
// the Configure
if ( !jettyXml.startsWith("<Configure"))
{
jettyXml = jettyXml.substring(jettyXml.indexOf("<Configure"));
}
jettyXml = jettyXml.replace("org.mortbay.jetty.webapp.WebAppContext","org.eclipse.jetty.webapp.WebAppContext");
return jettyXml;
}
}