Skip to content

Commit

Permalink
BATIK-1329: Remove xalan
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/batik/trunk@1903209 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
simonsteiner1984 committed Aug 3, 2022
1 parent f6ae43c commit 490aed3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*/
package org.apache.batik.bridge.svg12;

import java.util.ArrayList;

import org.apache.xml.utils.PrefixResolver;
import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;

import org.apache.batik.anim.dom.XBLOMContentElement;
import org.apache.batik.dom.AbstractDocument;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.xpath.XPathException;

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 java.util.ArrayList;
import java.util.Iterator;

/**
* A class to handle the XPath Pattern syntax for XBL content elements.
*
Expand All @@ -48,12 +50,7 @@ public class XPathPatternContentSelector extends AbstractContentSelector {
/**
* The XPath expression.
*/
protected XPath xpath;

/**
* The XPath context.
*/
protected XPathContext context;
protected XPathExpression xpath;

/**
* The selected nodes.
Expand Down Expand Up @@ -81,10 +78,11 @@ public XPathPatternContentSelector(ContentManager cm,
* Parses the XPath selector.
*/
protected void parse() {
context = new XPathContext();
try {
xpath = new XPath(expression, null, prefixResolver, XPath.MATCH);
} catch (javax.xml.transform.TransformerException te) {
XPath xPathAPI = XPathFactory.newInstance().newXPath();
xPathAPI.setNamespaceContext(prefixResolver);
xpath = xPathAPI.compile(expression);
} catch (XPathExpressionException te) {
AbstractDocument doc
= (AbstractDocument) contentElement.getOwnerDocument();
throw doc.createXPathException
Expand Down Expand Up @@ -173,9 +171,8 @@ protected boolean descendantSelected(Node n) {
protected void update(Node n) {
if (!isSelected(n)) {
try {
double matchScore
= xpath.execute(context, n, prefixResolver).num();
if (matchScore != XPath.MATCH_SCORE_NONE) {
Double matchScore = (Double) xpath.evaluate(n, XPathConstants.NUMBER);
if (matchScore != null) {
if (!descendantSelected(n)) {
nodes.add(n);
}
Expand All @@ -186,7 +183,7 @@ protected void update(Node n) {
n = n.getNextSibling();
}
}
} catch (javax.xml.transform.TransformerException te) {
} catch (XPathExpressionException te) {
AbstractDocument doc
= (AbstractDocument) contentElement.getOwnerDocument();
throw doc.createXPathException
Expand Down Expand Up @@ -217,36 +214,20 @@ public int getLength() {
/**
* Xalan prefix resolver.
*/
protected class NSPrefixResolver implements PrefixResolver {

/**
* Get the base URI for this resolver. Since this resolver isn't
* associated with a particular node, returns null.
*/
public String getBaseIdentifier() {
return null;
}

protected class NSPrefixResolver implements NamespaceContext {
/**
* Resolves the given namespace prefix.
*/
public String getNamespaceForPrefix(String prefix) {
public String getNamespaceURI(String prefix) {
return contentElement.lookupNamespaceURI(prefix);
}

/**
* Resolves the given namespace prefix.
*/
public String getNamespaceForPrefix(String prefix, Node context) {
// ignore the context node
return contentElement.lookupNamespaceURI(prefix);
public String getPrefix(String namespaceURI) {
return null;
}

/**
* Returns whether this PrefixResolver handles a null prefix.
*/
public boolean handlesNullPrefixes() {
return false;
public Iterator getPrefixes(String namespaceURI) {
return null;
}
}
}
5 changes: 0 additions & 5 deletions batik-dom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@
<artifactId>batik-xml</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>${xalan.version}</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
Expand Down
134 changes: 25 additions & 109 deletions batik-dom/src/main/java/org/apache/batik/dom/AbstractDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.apache.batik.util.SoftDoublyIndexedTable;
import org.apache.batik.constants.XMLConstants;

import org.apache.xml.utils.PrefixResolver;

import org.apache.xpath.XPath;
import org.apache.xpath.XPathContext;
import org.apache.xpath.objects.XObject;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
Expand Down Expand Up @@ -79,6 +73,13 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.w3c.dom.xpath.XPathNSResolver;
import org.w3c.dom.xpath.XPathResult;

import javax.xml.namespace.NamespaceContext;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

/**
* This class implements the {@link org.w3c.dom.Document} interface.
*
Expand Down Expand Up @@ -2177,7 +2178,7 @@ protected class XPathExpr implements XPathExpression {
/**
* The compiled XPath expression.
*/
protected XPath xpath;
protected javax.xml.xpath.XPathExpression xpath;

/**
* The namespace resolver.
Expand All @@ -2189,11 +2190,6 @@ protected class XPathExpr implements XPathExpression {
*/
protected NSPrefixResolver prefixResolver;

/**
* The XPathContext object.
*/
protected XPathContext context;

/**
* Creates a new XPathExpr object.
*/
Expand All @@ -2202,9 +2198,10 @@ public XPathExpr(String expr, XPathNSResolver res)
resolver = res;
prefixResolver = new NSPrefixResolver();
try {
xpath = new XPath(expr, null, prefixResolver, XPath.SELECT);
context = new XPathContext();
} catch (javax.xml.transform.TransformerException te) {
XPath xPathAPI = XPathFactory.newInstance().newXPath();
xPathAPI.setNamespaceContext(prefixResolver);
xpath = xPathAPI.compile(expr);
} catch (XPathExpressionException te) {
throw createXPathException
(XPathException.INVALID_EXPRESSION_ERR,
"xpath.invalid.expression",
Expand Down Expand Up @@ -2245,48 +2242,25 @@ public Object evaluate(Node contextNode, short type, Object res)
new Object[] {(int) contextNode.getNodeType(),
contextNode.getNodeName() });
}
context.reset();
XObject result = null;
try {
result = xpath.execute(context, contextNode, prefixResolver);
} catch (javax.xml.transform.TransformerException te) {
throw createXPathException
(XPathException.INVALID_EXPRESSION_ERR,
"xpath.error",
new Object[] { xpath.getPatternString(),
te.getMessage() });
}

try {
switch (type) {
case XPathResult.ANY_UNORDERED_NODE_TYPE:
case XPathResult.FIRST_ORDERED_NODE_TYPE:
return convertSingleNode(result, type);
return new Result((Node) xpath.evaluate(contextNode, XPathConstants.NODE), type);
case XPathResult.BOOLEAN_TYPE:
return convertBoolean(result);
return new Result((Boolean) xpath.evaluate(contextNode, XPathConstants.BOOLEAN));
case XPathResult.NUMBER_TYPE:
return convertNumber(result);
return new Result((Double) xpath.evaluate(contextNode, XPathConstants.NUMBER));
case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
return convertNodeIterator(result, type);
return new Result((Node) xpath.evaluate(contextNode, XPathConstants.NODE), type);
case XPathResult.STRING_TYPE:
return convertString(result);
case XPathResult.ANY_TYPE:
switch (result.getType()) {
case XObject.CLASS_BOOLEAN:
return convertBoolean(result);
case XObject.CLASS_NUMBER:
return convertNumber(result);
case XObject.CLASS_STRING:
return convertString(result);
case XObject.CLASS_NODESET:
return convertNodeIterator
(result,
XPathResult.UNORDERED_NODE_ITERATOR_TYPE);
}
return new Result((String) xpath.evaluate(contextNode, XPathConstants.STRING));
}
} catch (javax.xml.transform.TransformerException te) {
} catch (XPathExpressionException | TransformerException te) {
throw createXPathException
(XPathException.TYPE_ERR,
"xpath.cannot.convert.result",
Expand All @@ -2296,45 +2270,6 @@ public Object evaluate(Node contextNode, short type, Object res)
return null;
}

/**
* Converts an XObject to a single node XPathResult.
*/
protected Result convertSingleNode(XObject xo, short type)
throws javax.xml.transform.TransformerException {
return new Result(xo.nodelist().item(0), type);
}

/**
* Converts an XObject to a boolean XPathResult.
*/
protected Result convertBoolean(XObject xo)
throws javax.xml.transform.TransformerException {
return new Result(xo.bool());
}

/**
* Converts an XObject to a number XPathResult.
*/
protected Result convertNumber(XObject xo)
throws javax.xml.transform.TransformerException {
return new Result(xo.num());
}

/**
* Converts an XObject to a string XPathResult.
*/
protected Result convertString(XObject xo) {
return new Result(xo.str());
}

/**
* Converts an XObject to a node iterator XPathResult.
*/
protected Result convertNodeIterator(XObject xo, short type)
throws javax.xml.transform.TransformerException {
return new Result(xo.nodelist(), type);
}

/**
* XPathResult implementation.
* XXX Namespace nodes are not handled correctly, since Xalan returns
Expand Down Expand Up @@ -2537,42 +2472,23 @@ public Node snapshotItem(int i) {
/**
* Xalan prefix resolver.
*/
protected class NSPrefixResolver implements PrefixResolver {

/**
* Get the base URI for this resolver. Since this resolver isn't
* associated with a particular node, returns null.
*/
public String getBaseIdentifier() {
return null;
}

protected class NSPrefixResolver implements NamespaceContext {
/**
* Resolves the given namespace prefix.
*/
public String getNamespaceForPrefix(String prefix) {
public String getNamespaceURI(String prefix) {
if (resolver == null) {
return null;
}
return resolver.lookupNamespaceURI(prefix);
}

/**
* Resolves the given namespace prefix.
*/
public String getNamespaceForPrefix(String prefix, Node context) {
// ignore the context node
if (resolver == null) {
return null;
}
return resolver.lookupNamespaceURI(prefix);
public String getPrefix(String namespaceURI) {
return null;
}

/**
* Returns whether this PrefixResolver handles a null prefix.
*/
public boolean handlesNullPrefixes() {
return false;
public Iterator getPrefixes(String namespaceURI) {
return null;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions lib/LICENSE.xalan-2.7.2.txt

This file was deleted.

4 changes: 0 additions & 4 deletions lib/README.xalan-2.7.2.txt

This file was deleted.

Binary file removed lib/xalan-2.7.2.jar
Binary file not shown.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<release.version>2.5.2</release.version>
<rhino.version>1.7.7</rhino.version>
<surefire.version>2.18.1</surefire.version>
<xalan.version>2.7.2</xalan.version>
<xmlapis.version>1.4.01</xmlapis.version>
<xmlapisext.version>1.3.04</xmlapisext.version>
<xmlgraphics.commons.version>2.4.0-SNAPSHOT</xmlgraphics.commons.version>
Expand Down

0 comments on commit 490aed3

Please sign in to comment.