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;
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;
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);
}
/**
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;
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