diff options
author | Simon Steiner <ssteiner@apache.org> | 2022-07-22 10:07:35 +0000 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2022-07-22 10:07:35 +0000 |
commit | d7b29ae0a5f2b89fdbcf6eac131a94fc10896aea (patch) | |
tree | 18101a41bdecaafd97089c4012f3a06e3c43d487 | |
parent | 92a2c95835e0af0d9e531324a426a5a45073a662 (diff) | |
download | xmlgraphics-fop-d7b29ae0a5f2b89fdbcf6eac131a94fc10896aea.tar.gz xmlgraphics-fop-d7b29ae0a5f2b89fdbcf6eac131a94fc10896aea.zip |
FOP-3085: Remove Xalan for tests
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1902935 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java | 44 | ||||
-rw-r--r-- | fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java | 42 |
2 files changed, 59 insertions, 27 deletions
diff --git a/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java b/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java index 2af8884dd..7090bd532 100644 --- a/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java +++ b/fop-core/src/test/java/org/apache/fop/layoutengine/EvalCheck.java @@ -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 LayoutEngineCheck, IFCheck { 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 LayoutEngineCheck, IFCheck { } 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); diff --git a/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java b/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java index 5509d754d..724a14432 100644 --- a/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java +++ b/fop-core/src/test/java/org/apache/fop/layoutengine/TrueCheck.java @@ -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 LayoutEngineCheck, IFCheck { 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 LayoutEngineCheck, IFCheck { } 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 { |