Parse an WAR descriptor to extract meaninful information for Cactus,
the results being stored in a
object.
| Method from org.apache.cactus.integration.ant.deployment.WarParser Detail: |
public static final WarDeployableFile parse(File theDeployableFile) {
WarDeployableFile deployable = new WarDeployableFile();
try
{
deployable.setFile(theDeployableFile);
deployable.setWarArchive(new DefaultWarArchive(
new FileInputStream(theDeployableFile)));
deployable.setTestContext(parseWebContext(theDeployableFile));
deployable.setServletRedirectorMapping(
parseServletRedirectorMapping(deployable.getWarArchive()));
deployable.setFilterRedirectorMapping(
parseFilterRedirectorMapping(deployable.getWarArchive()));
deployable.setJspRedirectorMapping(
parseJspRedirectorMapping(deployable.getWarArchive()));
}
catch (IOException e)
{
throw new BuildException("Failed to parse deployment descriptor "
+ "for WAR file [" + theDeployableFile + "].", e);
}
catch (ParserConfigurationException e)
{
throw new BuildException("Failed to parse deployment descriptor "
+ "for WAR file [" + theDeployableFile + "].", e);
}
catch (SAXException e)
{
throw new BuildException("Failed to parse deployment descriptor "
+ "for WAR file [" + theDeployableFile + "].", e);
}
return deployable;
}
Parse an WAR descriptor to extract meaninful information for Cactus. |
static String parseFilterRedirectorMapping(WarArchive theWar) throws IOException, SAXException, ParserConfigurationException {
Iterator filterNames = theWar.getWebXml().getFilterNamesForClass(
"org.apache.cactus.server.FilterTestRedirector");
if (filterNames.hasNext())
{
// we only care about the first definition and the first mapping
String name = (String) filterNames.next();
Iterator mappings = theWar.getWebXml().getFilterMappings(name);
if (mappings.hasNext())
{
return (String) mappings.next();
}
}
return null;
}
Find the first URL-pattern to which the Cactus filter redirector is
mapped in the deployment descriptor. |
static String parseJspRedirectorMapping(WarArchive theWar) throws IOException, SAXException, ParserConfigurationException {
// To get the JSP redirector mapping, we must first get the full path to
// the corresponding JSP file in the WAR
String jspRedirectorPath = theWar.findResource("jspRedirector.jsp");
if (jspRedirectorPath != null)
{
jspRedirectorPath = "/" + jspRedirectorPath;
Iterator jspNames = theWar.getWebXml().getServletNamesForJspFile(
jspRedirectorPath);
if (jspNames.hasNext())
{
// we only care about the first definition and the first
// mapping
String name = (String) jspNames.next();
Iterator mappings =
theWar.getWebXml().getServletMappings(name);
if (mappings.hasNext())
{
return (String) mappings.next();
}
}
}
return null;
}
Find the first URL-pattern to which the Cactus JSP redirector is
mapped in the deployment descriptor. |
static String parseServletRedirectorMapping(WarArchive theWar) throws IOException, SAXException, ParserConfigurationException {
Iterator servletNames = theWar.getWebXml().getServletNamesForClass(
"org.apache.cactus.server.ServletTestRedirector");
if (servletNames.hasNext())
{
// we iterate over all of the servlet names but return the first met only --//TODO to be fixed
while(servletNames.hasNext()) {
String name = (String) servletNames.next();
Iterator mappings = theWar.getWebXml().getServletMappings(name);
if (mappings.hasNext())
{
return (String) mappings.next();
}
}
}
return null;
}
Find the first URL-pattern to which the Cactus servlet redirector is
mapped in the deployment descriptor. |
protected static String parseWebContext(File theDeployableFile) {
String context = theDeployableFile.getName();
int warIndex = context.toLowerCase().lastIndexOf(".war");
if (warIndex >= 0)
{
context = context.substring(0, warIndex);
}
return context;
}
|