Skip to content

Commit 61d0ad4

Browse files
committed
Fix error code checks for Saxon 12.2 API change
1 parent e4182a0 commit 61d0ad4

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/main/java/com/xmlcalabash/functions/SystemProperty.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public AtomicValue call(XPathContext xPathContext, Sequence[] sequences) throws
9191
staticContext.getNamespaceResolver());
9292
propertyName = new QName(qpropertyName);
9393
} catch (XPathException e) {
94-
if (e.getErrorCodeLocalPart()==null || e.getErrorCodeLocalPart().equals("FOCA0002")
95-
|| e.getErrorCodeLocalPart().equals("FONS0004")) {
94+
String local = e.getErrorCodeQName() == null ? null : e.getErrorCodeQName().getLocalPart();
95+
if (local == null || "FOCA0002".equals(local) || "FONS0004".equals(local)) {
9696
e.setErrorCode("XTDE1390");
9797
}
9898
throw e;

src/main/java/com/xmlcalabash/library/DefaultStep.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.xmlcalabash.io.WritablePipe;
99
import com.xmlcalabash.model.RuntimeValue;
1010
import com.xmlcalabash.runtime.XAtomicStep;
11+
import com.xmlcalabash.util.QNameUtils;
1112
import com.xmlcalabash.util.S9apiUtils;
1213
import net.sf.saxon.Configuration;
1314
import net.sf.saxon.lib.NamespaceConstant;
@@ -356,7 +357,7 @@ public Vector<XdmItem> evaluateXPath(XdmNode doc, HashMap<String,NamespaceUri> n
356357
Throwable sae = saue.getCause();
357358
if (sae instanceof XPathException) {
358359
XPathException xe = (XPathException) sae;
359-
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
360+
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
360361
throw XProcException.dynamicError(26,"Expression refers to context when none is available: " + xpath);
361362
} else {
362363
throw saue;

src/main/java/com/xmlcalabash/library/ValidateWithSCH.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.xmlcalabash.io.WritablePipe;
99
import com.xmlcalabash.model.RuntimeValue;
1010
import com.xmlcalabash.runtime.XAtomicStep;
11+
import com.xmlcalabash.util.QNameUtils;
1112
import com.xmlcalabash.util.S9apiUtils;
1213
import net.sf.saxon.Configuration;
1314
import net.sf.saxon.lib.ResourceRequest;
@@ -224,7 +225,7 @@ private boolean checkFailedAssert(XdmNode doc) {
224225
Throwable sae = saue.getCause();
225226
if (sae instanceof XPathException) {
226227
XPathException xe = (XPathException) sae;
227-
if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
228+
if (QNameUtils.hasForm(xe.getErrorCodeQName(), XProcConstants.NS_XQT_ERRORS, "XPDY0002")) {
228229
throw XProcException.dynamicError(26, step.getNode(), "Expression refers to context when none is available: " + xpath);
229230
} else {
230231
throw saue;

src/main/java/com/xmlcalabash/runtime/XAtomicStep.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@
2424
import com.xmlcalabash.model.PipeNameBinding;
2525
import com.xmlcalabash.model.RuntimeValue;
2626
import com.xmlcalabash.model.Step;
27-
import com.xmlcalabash.util.AxisNodes;
28-
import com.xmlcalabash.util.MessageFormatter;
29-
import com.xmlcalabash.util.S9apiUtils;
30-
import com.xmlcalabash.util.TypeUtils;
27+
import com.xmlcalabash.util.*;
3128
import net.sf.saxon.om.NamespaceMap;
3229
import net.sf.saxon.om.NamespaceUri;
3330
import net.sf.saxon.s9api.Axis;
@@ -706,7 +703,7 @@ protected RuntimeValue computeValue(ComputableValue var) {
706703
Throwable sae = saue.getCause();
707704
if (sae instanceof XPathException) {
708705
XPathException xe = (XPathException) sae;
709-
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
706+
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
710707
throw XProcException.dynamicError(26, step.getNode(), "The expression for $" + var.getName() + " refers to the context item.");
711708
} else {
712709
throw saue;
@@ -828,7 +825,7 @@ protected Vector<XdmItem> evaluateXPath(XdmNode doc, HashMap<String,NamespaceUri
828825
Throwable sae = saue.getCause();
829826
if (sae instanceof XPathException) {
830827
XPathException xe = (XPathException) sae;
831-
if ("http://www.w3.org/2005/xqt-errors".equals(xe.getErrorCodeNamespace()) && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
828+
if (QNameUtils.hasForm(xe.getErrorCodeQName(), "http://www.w3.org/2005/xqt-errors", "XPDY0002")) {
832829
throw XProcException.dynamicError(26, step.getNode(), "Expression refers to context when none is available: " + xpath);
833830
} else {
834831
throw saue;

src/main/java/com/xmlcalabash/util/AxisNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private boolean useWhen(XdmNode element, String xpath) {
222222
Throwable sae = saue.getCause();
223223
if (sae instanceof XPathException) {
224224
XPathException xe = (XPathException) sae;
225-
if (xe.getErrorCodeNamespace() == XProcConstants.NS_XQT_ERRORS && "XPDY0002".equals(xe.getErrorCodeLocalPart())) {
225+
if (QNameUtils.hasForm(xe.getErrorCodeQName(), XProcConstants.NS_XQT_ERRORS, "XPDY0002")) {
226226
throw XProcException.dynamicError(26, element, "Expression refers to context when none is available: " + xpath);
227227
} else {
228228
throw saue;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.xmlcalabash.util;
2+
3+
import net.sf.saxon.om.NamespaceUri;
4+
import net.sf.saxon.om.StructuredQName;
5+
6+
public class QNameUtils {
7+
public static boolean hasForm(StructuredQName qname, String namespace, String localname) {
8+
return qname != null && namespace.equals(qname.getNamespaceUri().toString()) && localname.equals(qname.getLocalPart());
9+
}
10+
11+
public static boolean hasForm(StructuredQName qname, NamespaceUri namespace, String localname) {
12+
return qname != null && namespace == qname.getNamespaceUri() && localname.equals(qname.getLocalPart());
13+
}
14+
}

0 commit comments

Comments
 (0)