You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by cm...@apache.org on 2003/04/30 11:02:29 UTC
cvs commit: jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant CactifyTask.java WebXmlMergeTask.java
cmlenz 2003/04/30 02:02:29
Modified: integration/ant/src/java/org/apache/cactus/integration/ant
Tag: CACTUS_14_ANT_BRANCH CactifyTask.java
WebXmlMergeTask.java
Log:
Factored out common code into WebXmlIo
Revision Changes Path
No revision
No revision
1.1.2.3 +26 -137 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/Attic/CactifyTask.java
Index: CactifyTask.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/Attic/CactifyTask.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- CactifyTask.java 29 Apr 2003 14:37:23 -0000 1.1.2.2
+++ CactifyTask.java 30 Apr 2003 09:02:28 -0000 1.1.2.3
@@ -57,21 +57,15 @@
package org.apache.cactus.integration.ant;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.cactus.integration.ant.util.AntLog;
import org.apache.cactus.integration.ant.util.ResourceUtils;
import org.apache.cactus.integration.ant.webxml.WebXml;
+import org.apache.cactus.integration.ant.webxml.WebXmlIo;
import org.apache.cactus.integration.ant.webxml.WebXmlMerger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
@@ -79,11 +73,6 @@
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.ZipFileSet;
import org.apache.tools.ant.util.FileUtils;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
-import org.w3c.dom.Document;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
@@ -210,15 +199,25 @@
// Open the archive as JAR file and extract the deployment descriptor
JarFile war = null;
+ WebXml webXml = null;
try
{
war = new JarFile(this.srcFile);
+ webXml = WebXmlIo.parseWebXml(war);
+ }
+ catch (SAXException e)
+ {
+ throw new BuildException(
+ "Parsing of deployment descriptor failed", e);
}
catch (IOException e)
{
throw new BuildException("Failed to open WAR", e);
}
- WebXml webXml = parseWebXml(war);
+ catch (ParserConfigurationException e)
+ {
+ throw new BuildException("XML parser configuration error", e);
+ }
// Add the redirectors the the web application
WebXml redirectorsWebXml = getRedirectorsWebXml();
@@ -234,16 +233,24 @@
try
{
WebXml parsedMergeWebXml =
- parseWebXml(new FileInputStream(this.mergeWebXml));
+ WebXmlIo.parseWebXml(this.mergeWebXml);
checkServletVersions(webXml, parsedMergeWebXml);
merger = new WebXmlMerger(webXml);
merger.setLog(new AntLog(this));
merger.merge(parsedMergeWebXml);
}
- catch (FileNotFoundException fnfe)
+ catch (IOException e)
{
throw new BuildException(
- "Could not merge deployment descriptors", fnfe);
+ "Could not merge deployment descriptors", e);
+ }
+ catch (SAXException e)
+ {
+ throw new BuildException("Parsing of merge file failed", e);
+ }
+ catch (ParserConfigurationException e)
+ {
+ throw new BuildException("XML parser configuration error", e);
}
}
@@ -255,7 +262,7 @@
tmpWebXml.deleteOnExit();
try
{
- writeWebXml(webXml, tmpWebXml);
+ WebXmlIo.writeWebXml(webXml, tmpWebXml);
}
catch (IOException ioe)
{
@@ -424,14 +431,7 @@
{
try
{
- DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(false);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.newDocument();
- doc.appendChild(doc.createElement("web-app"));
- WebXml webXml = new WebXml(doc);
+ WebXml webXml = WebXmlIo.newWebXml();
// Add the filter redirector
webXml.addFilter("FilterRedirector", FILTER_REDIRECTOR_CLASS);
@@ -478,117 +478,6 @@
{
throw new BuildException(
"Could not parse deployment descriptor", e);
- }
- }
-
- /**
- * Parses the web deployment descriptor in the web-application archive.
- *
- * @param theInputStream The input stream containing the descriptor
- * @return The parsed descriptor
- * @throws BuildException If an error occurs locating or parsing the
- * descriptor
- */
- private WebXml parseWebXml(InputStream theInputStream)
- throws BuildException
- {
- try
- {
- DocumentBuilderFactory factory =
- DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- factory.setNamespaceAware(false);
- DocumentBuilder builder = factory.newDocumentBuilder();
-
- // No need to resolve entities here
- builder.setEntityResolver(new EntityResolver()
- {
- public InputSource resolveEntity(String thePublicId,
- String theSystemId)
- throws SAXException, IOException
- {
- return null;
- }
- });
-
- return new WebXml(builder.parse(theInputStream));
- }
- catch (IOException e)
- {
- throw new BuildException(
- "Could not extract information from WAR", e);
- }
- catch (SAXException e)
- {
- throw new BuildException(
- "Could not parse deployment descriptor", e);
- }
- catch (ParserConfigurationException e)
- {
- throw new BuildException(
- "Could not parse deployment descriptor", e);
- }
- }
-
- /**
- * Parses the web deployment descriptor in the web-application archive.
- *
- * @param theWar The WAR file containing the descriptor to parse
- * @return The parsed descriptor
- * @throws BuildException If an error occurs locating or parsing the
- * descriptor
- */
- private WebXml parseWebXml(JarFile theWar)
- throws BuildException
- {
- try
- {
- ZipEntry webXmlEntry = theWar.getEntry("WEB-INF/web.xml");
- InputStream in = theWar.getInputStream(webXmlEntry);
- return parseWebXml(in);
- }
- catch (IOException e)
- {
- throw new BuildException(
- "Could not extract information from WAR", e);
- }
- }
-
- /**
- * Writes the specified document to an output stream.
- *
- * @param theWebXml The descriptor to serialize
- * @param theFile The file to write to
- * @throws IOException If an I/O error occurs
- */
- private void writeWebXml(WebXml theWebXml, File theFile)
- throws IOException
- {
- FileOutputStream out = null;
- try
- {
- log("Writing to file [" + theFile + "]", Project.MSG_VERBOSE);
- out = new FileOutputStream(theFile);
- OutputFormat outputFormat =
- new OutputFormat(theWebXml.getDocument());
- outputFormat.setPreserveSpace(false);
- outputFormat.setIndenting(true);
- XMLSerializer serializer = new XMLSerializer(out, outputFormat);
- serializer.serialize(theWebXml.getDocument());
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException ioe)
- {
- // we'll pass on the original IO error, so ignore this one
- }
- }
}
}
1.11.2.2 +10 -94 jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java
Index: WebXmlMergeTask.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/integration/ant/src/java/org/apache/cactus/integration/ant/WebXmlMergeTask.java,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -u -r1.11.2.1 -r1.11.2.2
--- WebXmlMergeTask.java 27 Apr 2003 10:00:49 -0000 1.11.2.1
+++ WebXmlMergeTask.java 30 Apr 2003 09:02:28 -0000 1.11.2.2
@@ -57,23 +57,19 @@
package org.apache.cactus.integration.ant;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.cactus.integration.ant.util.AntLog;
import org.apache.cactus.integration.ant.webxml.WebXml;
+import org.apache.cactus.integration.ant.webxml.WebXmlIo;
import org.apache.cactus.integration.ant.webxml.WebXmlMerger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.XMLCatalog;
-import org.apache.xml.serialize.OutputFormat;
-import org.apache.xml.serialize.XMLSerializer;
import org.xml.sax.SAXException;
/**
@@ -171,11 +167,11 @@
|| (srcFile.lastModified() > destFile.lastModified())
|| (mergeFile.lastModified() > destFile.lastModified()))
{
- WebXml srcWebXml = parseWebXml(this.srcFile);
- WebXml mergeWebXml = parseWebXml(this.mergeFile);
+ WebXml srcWebXml = WebXmlIo.parseWebXml(this.srcFile);
+ WebXml mergeWebXml = WebXmlIo.parseWebXml(this.mergeFile);
checkServletVersions(srcWebXml, mergeWebXml);
merge(srcWebXml, mergeWebXml);
- writeWebXml(srcWebXml, this.destFile);
+ WebXmlIo.writeWebXml(srcWebXml, this.destFile);
}
else
{
@@ -194,6 +190,11 @@
throw new BuildException("XML parser configuration problem: "
+ pce.getMessage(), pce);
}
+ catch (SAXException saxe)
+ {
+ throw new BuildException("Failed to parse descriptor: "
+ + saxe.getMessage(), saxe);
+ }
catch (IOException ioe)
{
throw new BuildException("An I/O error occurred: "
@@ -315,89 +316,4 @@
merger.merge(theMergeWebXml);
}
- /**
- * Parses a deployment descriptor.
- *
- * @param theFile The file to parse
- * @return The parsed document
- * @throws BuildException If the file could not be parsed
- * @throws ParserConfigurationException If the XML parser was not correctly
- * configured
- * @throws IOException If an I/O error occurs
- */
- private WebXml parseWebXml(File theFile)
- throws BuildException, ParserConfigurationException, IOException
- {
- FileInputStream in = null;
- try
- {
- log("Parsing file [" + theFile + "]", Project.MSG_VERBOSE);
- DocumentBuilder builder = factory.newDocumentBuilder();
- builder.setEntityResolver(this.xmlCatalog);
- in = new FileInputStream(theFile);
- return new WebXml(builder.parse(in));
- }
- catch (SAXException saxe)
- {
- throw new BuildException("Error parsing file ["
- + theFile + "]: " + saxe.getMessage(), saxe);
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException ioe)
- {
- // we'll pass on the original IO error, so ignore this one
- }
- }
- }
- }
-
- /**
- * Writes the specified document to an output stream.
- *
- * @param theWebXml The descriptor to serialize
- * @param theFile The file to write to
- * @throws IOException If an I/O error occurs
- */
- private void writeWebXml(WebXml theWebXml, File theFile)
- throws IOException
- {
- FileOutputStream out = null;
- try
- {
- log("Writing to file [" + theFile + "]", Project.MSG_VERBOSE);
- out = new FileOutputStream(theFile);
- OutputFormat outputFormat =
- new OutputFormat(theWebXml.getDocument());
- if (this.encoding != null)
- {
- outputFormat.setEncoding(this.encoding);
- }
- outputFormat.setIndenting(this.indent);
- outputFormat.setPreserveSpace(false);
- XMLSerializer serializer = new XMLSerializer(out, outputFormat);
- serializer.serialize(theWebXml.getDocument());
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException ioe)
- {
- // we'll pass on the original IO error, so ignore this one
- }
- }
- }
- }
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org