Author: jeremias
Date: Fri Jan 30 11:27:56 2009
New Revision: 739244
URL: http://svn.apache.org/viewvc?rev=739244&view=rev
Log:
Added validation against XML Schema of the intermediate format so we notice
when either changes incompatibly.
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java?rev=739244&r1=739243&r2=739244&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/AbstractIntermediateTestCase.java
Fri Jan 30 11:27:56 2009
@@ -22,6 +22,7 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
@@ -41,6 +42,8 @@
import org.custommonkey.xmlunit.XMLTestCase;
import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
@@ -94,6 +97,7 @@
saveDOM(intermediate, new File(outputDir,
getName() + ".1" + getIntermediateFileExtension()));
}
+ validate(intermediate);
}
/** {...@inheritdoc} */
@@ -117,6 +121,16 @@
}
/**
+ * Validates the intermediate format file.
+ * @param doc the intermediate file
+ * @throws IOException if an IO error occurs while loading the schema
+ * @throws SAXException if a SAX-related exception (including a validation
error) occurs
+ */
+ protected void validate(Document doc) throws SAXException, IOException {
+ //nop by default
+ }
+
+ /**
* Builds an intermediate format document from a source file.
* @param source the source file
* @param templates the (optional) stylesheet
Modified:
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
URL:
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java?rev=739244&r1=739243&r2=739244&view=diff
==============================================================================
---
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
(original)
+++
xmlgraphics/fop/branches/Temp_AreaTreeNewDesign/test/java/org/apache/fop/intermediate/IFParserTestCase.java
Fri Jan 30 11:27:56 2009
@@ -20,18 +20,28 @@
package org.apache.fop.intermediate;
import java.io.File;
+import java.io.IOException;
import java.io.OutputStream;
+import javax.xml.XMLConstants;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamResult;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
@@ -47,6 +57,24 @@
*/
public class IFParserTestCase extends AbstractIntermediateTestCase {
+ private static Schema ifSchema;
+
+ private static Schema getIFSchema() throws SAXException {
+ if (ifSchema == null) {
+ SchemaFactory sFactory;
+ try {
+ sFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ } catch (IllegalArgumentException iae) {
+ System.out.println("No suitable SchemaFactory for XML Schema
validation found!");
+ return null;
+ }
+ File ifSchemaFile = new File(
+
"src/documentation/intermediate-format-ng/fop-intermediate-format-ng.xsd");
+ ifSchema = sFactory.newSchema(ifSchemaFile);
+ }
+ return ifSchema;
+ }
+
/**
* Constructor for the test suite that is used for each test file.
* @param testFile the test file to run
@@ -107,6 +135,31 @@
}
/** {...@inheritdoc} */
+ protected void validate(Document doc) throws SAXException, IOException {
+ Schema schema = getIFSchema();
+ if (schema == null) {
+ return; //skip validation;
+ }
+ Validator validator = schema.newValidator();
+ validator.setErrorHandler(new ErrorHandler() {
+
+ public void error(SAXParseException exception) throws SAXException
{
+ throw exception;
+ }
+
+ public void fatalError(SAXParseException exception) throws
SAXException {
+ throw exception;
+ }
+
+ public void warning(SAXParseException exception) throws
SAXException {
+ //ignore
+ }
+
+ });
+ validator.validate(new DOMSource(doc));
+ }
+
+ /** {...@inheritdoc} */
protected void parseAndRender(Source src, OutputStream out) throws
Exception {
IFParser parser = new IFParser();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]