java.lang.Object
org.bzdev.ejws.WebxmlParser
Parser for web.xml files.
This parser handles only a subset of the elements that can appear
in these files. Other elements are ignored.
The web.xml file should start with the following directives (this may be updated as newer versions of the servlet specification are released):
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<version>2.5</version>
While ignored by the parser, it is a good idea to include a display-name
element and a description element, as these are used by various tools used
to configure web servers that support servlets. The display-name element
provides a title for a web application.
<dislay-name>NAME</display-name>
the description element provides a description of a web application - a
short paragraph indicating what the application does.
<description>....</description>
A jsp-config directive should be used if JSP pages are provided for
error messages (support for JSP pages by the FileHandler class is
limited). Multiple property-group elements are allowed, associating a
character encoding with a url pattern. A literal URL pattern must start
with a '/' and match the path for some resource. A wildcard pattern can
start with a '*', followed non-wildcard symbols making up a path. It can
also end with a '*' but then must start with a '/'. The '*' matches any
number of characters in a URL's path.
<jsp-config>
<jsp-property-group>
<url-pattern>/controls/error.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
The mime-mapping element associates MIME types with file extensions.
There should be one element per extension.
<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>
The welcome-file-list element contains a sequence of welcome-file
elements, each providing a path to a file to load when a URI's path
matches the context path. It replaces the convention that some
web servers use of loading an index.html file in this case. The
first matching one is used.
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
Error page elements indicate where to find error pages. The page
lookup can be based on the HTTP response code (given in the exception-code
element) or the class name of a Java exception (given in the exception-type
element). In either case, the path to the resource is given in
a location element, and that path must start with a "/". For example,
<error-page>
<exception-code>100</exception-code>
<location>/.../error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-code>
<location>/.../eerror.jsp</location>
</error-page>
Finally, the web-app element has to be terminated:
</web-app>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
WebxmlParser
Constructor.- Throws:
ParserConfigurationException
- an error occurred configuring the parserSAXException
- an error occurred during parsing
-
-
Method Details
-
parse
Parse the input given a file- Parameters:
file
- the file to parsemap
- a WebMap used to store the configuration specified by the web.xml file being parsed- Throws:
SAXException
- a parser error occurredIOException
- an IO error occurred
-
parse
public void parse(String urlAsString, WebMap map) throws MalformedURLException, SAXException, IOException Parse the input- Parameters:
urlAsString
- the URL for the file to parsemap
- a WebMap used to store the configuration specified by the web.xml file being parsed- Throws:
MalformedURLException
- the URL was malformedSAXException
- a parser error occurredIOException
- an IO error occurred
-
parse
Parse the input- Parameters:
url
- the URL for the file to parsemap
- a WebMap used to store the configuration specified by the web.xml file being parsed- Throws:
SAXException
- a parser error occurredIOException
- an IO error occurred
-
parse
Parse the input given an input stream- Parameters:
is
- the input stream to parseurl
- a string representation of the URL for the input; null if no URL is availablemap
- a WebMap used to store the configuration specified by the web.xml file being parsed- Throws:
SAXException
- a parser error occurredIOException
- an IO error occurred
-