]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3053: Reduce use of xalan
authorSimon Steiner <ssteiner@apache.org>
Mon, 14 Feb 2022 09:07:28 +0000 (09:07 +0000)
committerSimon Steiner <ssteiner@apache.org>
Mon, 14 Feb 2022 09:07:28 +0000 (09:07 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1898051 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/test/java/org/apache/fop/URIResolutionTestCase.java
fop-core/src/test/java/org/apache/fop/intermediate/TestAssistant.java

index e01271f2b620fe279de061b0c7ab6d476eeb9da4..40eb722123aef409726a060d14d6675965ea5ad1 100644 (file)
@@ -36,6 +36,10 @@ import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.sax.TransformerHandler;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -46,8 +50,6 @@ import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
 
 import org.apache.xmlgraphics.io.Resource;
 import org.apache.xmlgraphics.io.ResourceResolver;
@@ -155,14 +157,9 @@ public class URIResolutionTestCase {
         return doc;
     }
 
-    private String evalXPath(Document doc, String xpath) {
-        XObject res;
-        try {
-            res = XPathAPI.eval(doc, xpath);
-        } catch (TransformerException e) {
-            throw new RuntimeException("XPath evaluation failed: " + e.getMessage());
-        }
-        return res.str();
+    private String evalXPath(Document doc, String xpath) throws XPathExpressionException {
+        XPath xPath = XPathFactory.newInstance().newXPath();
+        return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING);
     }
 
     /**
index 4f56f9c7df473d0635702793b89d83da524b72b9..901bef2e6377077e60d7d8911ddb289a3e5535a5 100644 (file)
@@ -35,13 +35,14 @@ import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.sax.SAXTransformerFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
-import org.apache.xpath.XPathAPI;
-import org.apache.xpath.objects.XObject;
-
 import org.apache.fop.apps.EnvironmentProfile;
 import org.apache.fop.apps.EnvironmentalProfileFactory;
 import org.apache.fop.apps.FopFactory;
@@ -128,33 +129,36 @@ public class TestAssistant {
 
     private boolean isBase14KerningEnabled(Document testDoc) {
         try {
-            XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/base14kerning");
-            String s = xo.str();
+            String s = eval(testDoc, "/testcase/cfg/base14kerning");
             return ("true".equalsIgnoreCase(s));
-        } catch (TransformerException e) {
+        } catch (XPathExpressionException e) {
             throw new RuntimeException("Error while evaluating XPath expression", e);
         }
     }
 
     private boolean isStrictValidation(Document testDoc) {
         try {
-            XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/strict-validation");
-            return !("false".equalsIgnoreCase(xo.str()));
-        } catch (TransformerException e) {
+            String s = eval(testDoc, "/testcase/cfg/strict-validation");
+            return !("false".equalsIgnoreCase(s));
+        } catch (XPathExpressionException e) {
             throw new RuntimeException("Error while evaluating XPath expression", e);
         }
     }
 
     private boolean isTableBorderOverpaint(Document testDoc) {
         try {
-            XObject xo = XPathAPI.eval(testDoc, "/testcase/cfg/table-border-overpaint");
-            String s = xo.str();
+            String s = eval(testDoc, "/testcase/cfg/table-border-overpaint");
             return "true".equalsIgnoreCase(s);
-        } catch (TransformerException e) {
+        } catch (XPathExpressionException e) {
             throw new RuntimeException("Error while evaluating XPath expression", e);
         }
     }
 
+    private String eval(Document doc, String xpath) throws XPathExpressionException {
+        XPath xPath = XPathFactory.newInstance().newXPath();
+        return (String) xPath.compile(xpath).evaluate(doc, XPathConstants.STRING);
+    }
+
     /**
      * Loads a test case into a DOM document.
      * @param testFile the test file