svn commit: r1902935 - in /xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine: EvalCheck.java TrueCheck.java
[email protected] Fri, 22 Jul 2022 10:07:36 -0000
| Newsgroups | gmane.text.xml.fop.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: ssteiner
Date: Fri Jul 22 10:07:35 2022
New Revision: 1902935
URL: http://svn.apache.org/viewvc?rev=1902935&view=rev
Log:
FOP-3085: Remove Xalan for tests
Modified:
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java
xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java
Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java?rev=1902935&r1=1902934&r2=1902935&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java Fri Jul 22 10:07:35 2022
@@ -19,17 +19,20 @@
package org.apache.fop.layoutengine;
-import javax.xml.transform.TransformerException;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import org.apache.xml.utils.PrefixResolver;
-import org.apache.xml.utils.PrefixResolverDefault;
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
-
import org.apache.fop.intermediate.IFCheck;
+import org.apache.fop.util.XMLConstants;
/**
* Simple check that requires an XPath expression to evaluate to true.
@@ -39,20 +42,33 @@ public class EvalCheck implements Layout
private String expected;
private String xpath;
private double tolerance;
- private PrefixResolver prefixResolver;
+ private NamespaceContext ctx;
/**
* Creates a new instance from a DOM node.
* @param node DOM node that defines this check
*/
- public EvalCheck(Node node) {
+ public EvalCheck(final Node node) {
this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
Node nd = node.getAttributes().getNamedItem("tolerance");
if (nd != null) {
this.tolerance = Double.parseDouble(nd.getNodeValue());
}
- this.prefixResolver = new PrefixResolverDefault(node);
+ ctx = new NamespaceContext() {
+ public String getNamespaceURI(String prefix) {
+ if ("xml".equals(prefix)) {
+ return XMLConstants.XML_NAMESPACE;
+ }
+ return node.lookupNamespaceURI(prefix);
+ }
+ public Iterator getPrefixes(String val) {
+ return null;
+ }
+ public String getPrefix(String uri) {
+ return null;
+ }
+ };
}
/** {@inheritDoc} */
@@ -66,13 +82,15 @@ public class EvalCheck implements Layout
}
private void doCheck(Document doc) {
- XObject res;
+ String actual;
try {
- res = XPathAPI.eval(doc, xpath, prefixResolver);
- } catch (TransformerException e) {
+ XPath xPathAPI = XPathFactory.newInstance().newXPath();
+ xPathAPI.setNamespaceContext(ctx);
+ XPathExpression expr = xPathAPI.compile(xpath);
+ actual = (String) expr.evaluate(doc, XPathConstants.STRING);
+ } catch (XPathExpressionException e) {
throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
}
- String actual = res.str(); //Second str() seems to fail. D'oh!
if (tolerance != 0) {
double v1 = Double.parseDouble(expected);
double v2 = Double.parseDouble(actual);
Modified: xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java?rev=1902935&r1=1902934&r2=1902935&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java (original)
+++ xmlgraphics/fop/trunk/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java Fri Jul 22 10:07:35 2022
@@ -19,17 +19,18 @@
package org.apache.fop.layoutengine;
-import javax.xml.transform.TransformerException;
+import java.util.Iterator;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import org.apache.xml.utils.PrefixResolver;
-import org.apache.xml.utils.PrefixResolverDefault;
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XBoolean;
-import org.apache.xpath.objects.XObject;
-
import org.apache.fop.intermediate.IFCheck;
/**
@@ -39,19 +40,29 @@ public class TrueCheck implements Layout
private String xpath;
private String failureMessage;
- private PrefixResolver prefixResolver;
+ private NamespaceContext ctx;
/**
* Creates a new instance from a DOM node.
* @param node DOM node that defines this check
*/
- public TrueCheck(Node node) {
+ public TrueCheck(final Node node) {
this.xpath = node.getAttributes().getNamedItem("xpath").getNodeValue();
Node nd = node.getAttributes().getNamedItem("fail-msg");
if (nd != null) {
this.failureMessage = nd.getNodeValue();
}
- this.prefixResolver = new PrefixResolverDefault(node);
+ ctx = new NamespaceContext() {
+ public String getNamespaceURI(String prefix) {
+ return node.lookupNamespaceURI(prefix);
+ }
+ public Iterator getPrefixes(String val) {
+ return null;
+ }
+ public String getPrefix(String uri) {
+ return null;
+ }
+ };
}
/** {@inheritDoc} */
@@ -65,13 +76,16 @@ public class TrueCheck implements Layout
}
private void doCheck(Document doc) {
- XObject res;
+ boolean res;
try {
- res = XPathAPI.eval(doc, xpath, prefixResolver);
- } catch (TransformerException e) {
+ XPath xPathAPI = XPathFactory.newInstance().newXPath();
+ xPathAPI.setNamespaceContext(ctx);
+ XPathExpression expr = xPathAPI.compile(xpath);
+ res = (boolean) expr.evaluate(doc, XPathConstants.BOOLEAN);
+ } catch (XPathExpressionException e) {
throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
}
- if (!XBoolean.S_TRUE.equals(res)) {
+ if (!res) {
if (failureMessage != null) {
throw new AssertionError(failureMessage);
} else {