【Java开源代码栏目提醒】:网学会员在Java开源代码频道为大家收集整理了WebApplicationContext.java提供大家参考,希望对大家有所帮助!
// ========================================================================
// Copyright (c) 2000 Mort Bay Consulting (Australia) Pty. Ltd.
// $Id: WebApplicationContext.java,v 3.45 2001/02/01 15:03:40 gregwilkins Exp $
// ========================================================================
package com.mortbay.HTTP;
import com.mortbay.HTTP.Handler.ResourceHandler;
import com.mortbay.HTTP.Handler.SecurityHandler;
import com.mortbay.HTTP.Handler.NotFoundHandler;
import com.mortbay.HTTP.Handler.NullHandler;
import com.mortbay.HTTP.Handler.Servlet.Context;
import com.mortbay.HTTP.Handler.Servlet.ServletHandler;
import com.mortbay.HTTP.Handler.Servlet.ServletHolder;
import com.mortbay.Util.Code;
import com.mortbay.Util.Log;
import com.mortbay.Util.Resource;
import com.mortbay.Util.JarResource;
import com.mortbay.Util.XmlParser;
import com.mortbay.Util.StringUtil;
import java.io.IOException;
import java.io.PrintStream;
import java.io.File;
import java.net.URL;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import javax.servlet.UnavailableException;
/* ------------------------------------------------------------ */
/** Standard web.xml configured HandlerContext.
*
* This specialization of HandlerContext uses the standardized web.xml
* to describe a web application and configure the handlers for the
* HandlerContext.
*
* @version $Id: WebApplicationContext.java,v 3.45 2001/02/01 15:03:40 gregwilkins Exp $
* @author Greg Wilkins (gregw)
*/
public class WebApplicationContext extends HandlerContext
{
/* ------------------------------------------------------------ */
private String _name;
private Resource _webApp;
private String _webAppName;
private ServletHandler _servletHandler;
private SecurityHandler _securityHandler;
private Context _context;
private Map _tagLibMap=new HashMap(3);
private NotFoundHandler _notFoundHandler;
/* ------------------------------------------------------------ */
/** Constructor.
* @param httpServer The HttpServer for this context
* @param contextPathSpec The context path spec. Which must be of
* the form / or /path/*
* @param webApp The Web application directory or WAR file.
* @param defaults The defaults xml filename or URL which is
* loaded before any in the web app. Must respect the web.dtd.
* Normally this is passed the file $JETTY_HOME/etc/webdefault.xml
* @exception IOException
*/
WebApplicationContext(HttpServer httpServer,
String contextPathSpec,
String webApp,
String defaults)
throws IOException
{
this(httpServer,contextPathSpec,webApp,defaults,false);
}
/* ------------------------------------------------------------ */
/** Constructor.
* @param httpServer The HttpServer for this context
* @param contextPathSpec The context path spec. Which must be of
* the form / or /path/*
* @param webApp The Web application directory or WAR file.
* @param defaults The defaults xml filename or URL which is
* loaded before any in the web app. Must respect the web.dtd.
* Normally this is passed the file $JETTY_HOME/etc/webdefault.xml
* @param extractWar If true, WAR files are extracted to a
* temporary directory.
* @exception IOException
*/
public WebApplicationContext(HttpServer httpServer,
String contextPathSpec,
String webApp,
String defaults,
boolean extractWar)
throws IOException
{
super(httpServer,contextPathSpec);
// Get parser
XmlParser xmlParser=new XmlParser();
Resource dtd=Resource.newSystemResource("com/mortbay/HTTP/web.dtd");
xmlParser.redirectEntity("web.dtd",dtd);
xmlParser.redirectEntity("web-app_2_2.dtd",dtd);
xmlParser.redirectEntity("-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",dtd);
// Set dir or WAR
Resource _webApp = Resource.newResource(webApp);
if (!_webApp.isDirectory())
{
webApp="jar:"+_webApp+"!/";
_webApp = Resource.newResource(webApp);
}
_webAppName=_
webApp.toString();
if (!_webApp.exists()) {
Code.warning("Web application not found "+_webAppName);
throw new java.io.FileNotFoundException(_webAppName);
}
// Expand
if (extractWar && _webApp instanceof JarResource)
{
File tempDir=File.createTempFile("Jetty-",".war");
if (tempDir.exists())
tempDir.delete();
tempDir.mkdir();
tempDir.deleteOnExit();
Log.e