org.apache.maven.j2ee
Class WarFile

java.lang.Object
  extended byjava.util.zip.ZipFile
      extended byjava.util.jar.JarFile
          extended byorg.apache.maven.j2ee.WarFile
All Implemented Interfaces:
ZipConstants

public class WarFile
extends JarFile

Represents a J2EE War File

Version:
$Id: WarFile.java 170200 2005-05-15 06:24:19Z brett $
Author:
dIon Gillard

Field Summary
static String LIB
          lib entry in the war for jar files
static String WEB_XML
          web.xml entry in the war
 
Fields inherited from class java.util.jar.JarFile
MANIFEST_NAME
 
Fields inherited from class java.util.zip.ZipFile
CENATT, CENATX, CENCOM, CENCRC, CENDSK, CENEXT, CENFLG, CENHDR, CENHOW, CENLEN, CENNAM, CENOFF, CENSIG, CENSIZ, CENTIM, CENVEM, CENVER, ENDCOM, ENDHDR, ENDOFF, ENDSIG, ENDSIZ, ENDSUB, ENDTOT, EXTCRC, EXTHDR, EXTLEN, EXTSIG, EXTSIZ, LOCCRC, LOCEXT, LOCFLG, LOCHDR, LOCHOW, LOCLEN, LOCNAM, LOCSIG, LOCSIZ, LOCTIM, LOCVER, OPEN_DELETE, OPEN_READ
 
Constructor Summary
WarFile(File warFile)
          Creates a new instance of WarFile
WarFile(File warFile, boolean verify)
          Creates a new instance of WarFile
WarFile(File warFile, boolean verify, int mode)
          Creates a new instance of WarFile
WarFile(String name)
          Creates a new instance of WarFile
WarFile(String name, boolean verify)
          Creates a new instance of WarFile
 
Method Summary
 File extract(JarEntry entry)
          Extract the given entry to a temporary file
 Map getErrorPages()
          Get a map of error pages to error locations.
 FormLoginConfig getFormLoginConfig()
          Get the <form-login-config> details specified in the war file, or null if the element is not present
 Map getJSPs()
          Get a map of servlet name -> jsp file.
 Set getLibEntries()
          Provide a set of jar files as found in WEB-INF/lib
 Map getServletMappings()
          Get a map of servlet name -> url pattern for all defined servlets
 Map getServlets()
          Get a map of servlet name -> servlet class.
 Map getTaglibs()
          Get a map of taglib-uri -> taglib-location.
protected  org.dom4j.Document getWebXml()
          Get the web.xml back as a dom4j Document, for easier processing
 JarEntry getWebXmlEntry()
          Retrieves the WEB-INF/web.xml entry if it exists.
 boolean hasFile(String fileName)
          Tests whether a 'file' exists in the war.
 
Methods inherited from class java.util.jar.JarFile
entries, getEntry, getInputStream, getJarEntry, getManifest
 
Methods inherited from class java.util.zip.ZipFile
close, finalize, getName, size
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WEB_XML

public static final String WEB_XML
web.xml entry in the war

See Also:
Constant Field Values

LIB

public static final String LIB
lib entry in the war for jar files

See Also:
Constant Field Values
Constructor Detail

WarFile

public WarFile(String name)
        throws IOException
Creates a new instance of WarFile

Parameters:
name - the file name of a war file
Throws:
IOException - when an I/O error occurs

WarFile

public WarFile(String name,
               boolean verify)
        throws IOException
Creates a new instance of WarFile

Parameters:
name - the file name of a war file
verify - whether or not to verify the war file if it is signed
Throws:
IOException - when an I/O error occurs

WarFile

public WarFile(File warFile)
        throws IOException
Creates a new instance of WarFile

Parameters:
warFile - a J2EE .war file
Throws:
IOException - when an I/O error occurs

WarFile

public WarFile(File warFile,
               boolean verify)
        throws IOException
Creates a new instance of WarFile

Parameters:
warFile - a J2EE .war file
verify - whether or not to verify the war file if it is signed
Throws:
IOException - when an I/O error occurs

WarFile

public WarFile(File warFile,
               boolean verify,
               int mode)
        throws IOException
Creates a new instance of WarFile

Parameters:
warFile - a J2EE .war file
verify - whether or not to verify the war file if it is signed
mode - the mode in which the file is to be opened
Throws:
IOException - when an I/O error occurs
Method Detail

getWebXmlEntry

public JarEntry getWebXmlEntry()
Retrieves the WEB-INF/web.xml entry if it exists.

Returns:
a JarEntry for web.xml

getServlets

public Map getServlets()
                throws IOException
Get a map of servlet name -> servlet class. The map has a size of zero if there are no servlets or no web.xml in the war.

Returns:
a map of servlets held in the war.
Throws:
IOException - if there are problems reading from the war

getJSPs

public Map getJSPs()
            throws IOException
Get a map of servlet name -> jsp file. The map has a size of zero if there are no jsp files defined or no web.xml in the war.

Returns:
a map of jsps defined using the <servlet> tag held in the war.
Throws:
IOException - if there are problems reading from the war

getTaglibs

public Map getTaglibs()
               throws IOException
Get a map of taglib-uri -> taglib-location. The map has zero size if there are no taglibs defined or no web.xml in the war

Returns:
a map of uri to location
Throws:
IOException - when an I/O error occurs reading the war

getWebXml

protected org.dom4j.Document getWebXml()
                                throws IOException
Get the web.xml back as a dom4j Document, for easier processing

Returns:
a Document representing the web.xml
Throws:
IOException - if there are any issues reading the web.xml or producing the xml document

getLibEntries

public Set getLibEntries()
Provide a set of jar files as found in WEB-INF/lib

Returns:
a set of jar files as entries from WEB-INF/lib

extract

public File extract(JarEntry entry)
             throws IOException
Extract the given entry to a temporary file

Parameters:
entry - a previously retrieved entry from the jar file
Returns:
the File created
Throws:
IOException - when an I/O error occurs reading the war

hasFile

public boolean hasFile(String fileName)
Tests whether a 'file' exists in the war. A file in this case is a jar entry prefixed with a '/'. e.g. the file /WEB-INF/web.xml is the same as the jar entry WEB-INF/web.xml

Parameters:
fileName - an entry in the war to be searched for
Returns:
whether the entry exists

getErrorPages

public Map getErrorPages()
                  throws IOException
Get a map of error pages to error locations. The key of the map is either the <error-code> or < exception-type>, the value is <location>.

Returns:
a map of error page to error location
Throws:
IOException - if there are problems reading from the war

getFormLoginConfig

public FormLoginConfig getFormLoginConfig()
                                   throws IOException
Get the <form-login-config> details specified in the war file, or null if the element is not present

Returns:
a FormLoginConfig with the login and error pages
Throws:
IOException - if there are problems reading from the war

getServletMappings

public Map getServletMappings()
                       throws IOException
Get a map of servlet name -> url pattern for all defined servlets

Returns:
a map as specified
Throws:
IOException - if there are problems reading from the war


Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.