Skip to content

Commit

Permalink
Fix error code checks for Saxon 12.2 API change
Browse files Browse the repository at this point in the history
  • Loading branch information
ndw committed May 7, 2023
1 parent e4182a0 commit 61d0ad4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/xmlcalabash/functions/SystemProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public AtomicValue call(XPathContext xPathContext, Sequence[] sequences) throws
staticContext.getNamespaceResolver());
propertyName = new QName(qpropertyName);
} catch (XPathException e) {
if (e.getErrorCodeLocalPart()==null || e.getErrorCodeLocalPart().equals("FOCA0002")
|| e.getErrorCodeLocalPart().equals("FONS0004")) {
String local = e.getErrorCodeQName() == null ? null : e.getErrorCodeQName().getLocalPart();
if (local == null || "FOCA0002".equals(local) || "FONS0004".equals(local)) {
e.setErrorCode("XTDE1390");
}
throw e;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/xmlcalabash/library/DefaultStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.QNameUtils;
import com.xmlcalabash.util.S9apiUtils;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.NamespaceConstant;
Expand Down Expand Up @@ -356,7 +357,7 @@ public Vector<XdmItem> evaluateXPath(XdmNode doc, HashMap<String,NamespaceUri> n
Throwable sae = saue.getCause();
if (sae instanceof XPathException) {
XPathException xe = (XPathException) sae;
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
throw XProcException.dynamicError(26,"Expression refers to context when none is available: " + xpath);
} else {
throw saue;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/xmlcalabash/library/ValidateWithSCH.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.runtime.XAtomicStep;
import com.xmlcalabash.util.QNameUtils;
import com.xmlcalabash.util.S9apiUtils;
import net.sf.saxon.Configuration;
import net.sf.saxon.lib.ResourceRequest;
Expand Down Expand Up @@ -224,7 +225,7 @@ private boolean checkFailedAssert(XdmNode doc) {
Throwable sae = saue.getCause();
if (sae instanceof XPathException) {
XPathException xe = (XPathException) sae;
if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
if (QNameUtils.hasForm(xe.getErrorCodeQName(), XProcConstants.NS_XQT_ERRORS, "XPDY0002")) {
throw XProcException.dynamicError(26, step.getNode(), "Expression refers to context when none is available: " + xpath);
} else {
throw saue;
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/xmlcalabash/runtime/XAtomicStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import com.xmlcalabash.model.PipeNameBinding;
import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.model.Step;
import com.xmlcalabash.util.AxisNodes;
import com.xmlcalabash.util.MessageFormatter;
import com.xmlcalabash.util.S9apiUtils;
import com.xmlcalabash.util.TypeUtils;
import com.xmlcalabash.util.*;
import net.sf.saxon.om.NamespaceMap;
import net.sf.saxon.om.NamespaceUri;
import net.sf.saxon.s9api.Axis;
Expand Down Expand Up @@ -706,7 +703,7 @@ protected RuntimeValue computeValue(ComputableValue var) {
Throwable sae = saue.getCause();
if (sae instanceof XPathException) {
XPathException xe = (XPathException) sae;
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
throw XProcException.dynamicError(26, step.getNode(), "The expression for $" + var.getName() + " refers to the context item.");
} else {
throw saue;
Expand Down Expand Up @@ -828,7 +825,7 @@ protected Vector<XdmItem> evaluateXPath(XdmNode doc, HashMap<String,NamespaceUri
Throwable sae = saue.getCause();
if (sae instanceof XPathException) {
XPathException xe = (XPathException) sae;
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
throw XProcException.dynamicError(26, step.getNode(), "Expression refers to context when none is available: " + xpath);
} else {
throw saue;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/xmlcalabash/util/AxisNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private boolean useWhen(XdmNode element, String xpath) {
Throwable sae = saue.getCause();
if (sae instanceof XPathException) {
XPathException xe = (XPathException) sae;
if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
if (QNameUtils.hasForm(xe.getErrorCodeQName(), XProcConstants.NS_XQT_ERRORS, "XPDY0002")) {
throw XProcException.dynamicError(26, element, "Expression refers to context when none is available: " + xpath);
} else {
throw saue;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/xmlcalabash/util/QNameUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.xmlcalabash.util;

import net.sf.saxon.om.NamespaceUri;
import net.sf.saxon.om.StructuredQName;

public class QNameUtils {
public static boolean hasForm(StructuredQName qname, String namespace, String localname) {
return qname != null && namespace.equals(qname.getNamespaceUri().toString()) && localname.equals(qname.getLocalPart());
}

public static boolean hasForm(StructuredQName qname, NamespaceUri namespace, String localname) {
return qname != null && namespace == qname.getNamespaceUri() && localname.equals(qname.getLocalPart());
}
}

0 comments on commit 61d0ad4

Please sign in to comment.