Permalink
Browse files

Support barename xpointers in XInclude

  • Loading branch information...
ndw committed Apr 15, 2016
1 parent b0ebaf0 commit 7e5e8eeeaa81c5be15fdfac859023607959e00bb
@@ -226,7 +226,7 @@ private XdmNode parse(String uri, String base) {
ptr = "element(" + ptr + ")";
}
- XPointer xptr = new XPointer(ptr, 1024 * 1000); // does this need to be configurable? No, because there can be only one fragid, right?
+ XPointer xptr = new XPointer(runtime, ptr, 1024 * 1000); // does this need to be configurable? No, because there can be only one fragid, right?
Vector<XdmNode> nodes = xptr.selectNodes(runtime, doc);
if (nodes.size() == 1) {
@@ -245,7 +245,7 @@ public boolean processStartElement(XdmNode node) throws SaxonApiException {
if ("text".equals(parse) && !xptr.trim().startsWith("text(")) {
xptr = "text(" + xptr + ")";
}
- xpointer = new XPointer(xptr, readLimit);
+ xpointer = new XPointer(runtime, xptr, readLimit);
}
if ("text".equals(parse)) {
@@ -1,5 +1,6 @@
package com.xmlcalabash.util;
+import com.xmlcalabash.core.XProcConstants;
import net.sf.saxon.s9api.*;
import java.io.BufferedReader;
@@ -29,8 +30,10 @@
private Vector<XPointerScheme> parts = new Vector<XPointerScheme> ();
private int readLimit = 0;
+ private XProcRuntime runtime = null;
- public XPointer(String xpointer, int readLimit) {
+ public XPointer(XProcRuntime runtime, String xpointer, int readLimit) {
+ this.runtime = runtime;
this.readLimit = readLimit;
String pointer = xpointer;
while (pointer != null) {
@@ -103,6 +106,13 @@ private String parse(String xpointer) {
// FIXME: Hack! Is this acceptable?
if (xpointer.startsWith("/") && !xpointer.contains("(")) {
xpointer = "element(" + xpointer + ")";
+ } else {
+ try {
+ TypeUtils.checkType(runtime, xpointer, XProcConstants.xs_NCName, null);
+ xpointer = "element(" + xpointer + ")";
+ } catch (XProcException xe) {
+ // nop
+ }
}
xpointer = xpointer.trim();
@@ -48,21 +48,21 @@ public void testElement() {
*/
public void testXmlns() {
- XPointer xp = new XPointer("xmlns(a=http://example.com/a) xmlns(b=http://example.com/b)", 1024000);
+ XPointer xp = new XPointer(null, "xmlns(a=http://example.com/a) xmlns(b=http://example.com/b)", 1024000);
assertNotNull(xp);
- xp = new XPointer("xmlns(a=http://example.com/a)xmlns(b=http://example.com/b)", 1024000);
+ xp = new XPointer(null, "xmlns(a=http://example.com/a)xmlns(b=http://example.com/b)", 1024000);
assertNotNull(xp);
- xp = new XPointer("xmlns(a=http://example.com/^(a^))xmlns(b=http://example.com/b)", 1024000);
+ xp = new XPointer(null, "xmlns(a=http://example.com/^(a^))xmlns(b=http://example.com/b)", 1024000);
assertNotNull(xp);
}
public void testSchemes() {
- XPointer xp = new XPointer("xmlns(a=http://example.com/a) a:unk(a=^^b)", 1024000);
+ XPointer xp = new XPointer(null, "xmlns(a=http://example.com/a) a:unk(a=^^b)", 1024000);
assertNotNull(xp);
- xp = new XPointer("xmlns(a=http://example.com/a)xmlns(b=http://example.com/b) a:unk(a) b:unk(b)", 1024000);
+ xp = new XPointer(null, "xmlns(a=http://example.com/a)xmlns(b=http://example.com/b) a:unk(a) b:unk(b)", 1024000);
assertNotNull(xp);
/*

0 comments on commit 7e5e8ee

Please sign in to comment.