Skip to content

XPathExpressionFactory should fallback to Jaxen if no JAXP 1.3 XPath implementation is available [SWS-264] #420

Closed
@gregturn

Description

@gregturn

Laurent Bihanic opened SWS-264 and commented

When running with Java 5 without any JAXP 1.3 XPath implementation available but Jaxen present, XPathExpressionFactory fails to fallback to Jaxen.

The following patch fixes the problem :

--- ../spring-ws-1.0.3/modules/xml/src/main/java/org/springframework/xml/xpath/XPathExpressionFactory.java 2007-12-21 16:26:18.000000000 +0100
+++ XPathExpressionFactory.java 2008-01-08 18:12:38.000000000 +0100
@@ -42,10 +42,14 @@

private static final String JAXEN_CLASS_NAME = "org.jaxen.XPath";
  • private static boolean jaxpAvailable;
    private static boolean jaxenAvailable;

    static {
    // Check whether Jaxen is available

  jaxpAvailable = (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13);
  // Check whether Jaxen is available
  try {
      ClassUtils.forName(JAXEN_CLASS_NAME);
      jaxenAvailable = true;

@@ -81,11 +85,27 @@
public static XPathExpression createXPathExpression(String expression, Map namespaces)
throws IllegalStateException, XPathParseException {
Assert.hasLength(expression, "expression is empty");


if (JaxpVersion.getJaxpVersion() >= JaxpVersion.JAXP_13) {
  logger.trace("Creating [javax.xml.xpath.XPathExpression]");
  return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
  if (jaxpAvailable) {
  try {
  logger.trace("Creating [javax.xml.xpath.XPathExpression]");
  return Jaxp13XPathExpressionFactory.createXPathExpression(expression, namespaces);
  }
  catch (XPathException e) {
  throw e;
  }
  catch (Throwable e) {
  // 'Cause we may get an ExceptionInInitializerError from JAXP
  // XPathFactory
  jaxpAvailable = false;
  if (!jaxenAvailable) {
  throw new XPathParseException(
  "Could not compile [" + expression + "] to a XPathExpression: " + e.getMessage(), e);
  }
  // Else: try with Jaxen...
      }
  }
  else if (jaxenAvailable) {
  if (jaxenAvailable) {
      logger.trace("Creating [org.jaxen.XPath]");
      return JaxenXPathExpressionFactory.createXPathExpression(expression, namespaces);
  }

Affects: 1.0.3

Attachments:

Referenced from: commits dd4309d, a1d72b6

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions