private XdmNode parse(String uri, String base) { XdmNode doc = runtime.parse(uri, base); if (uri.contains("#")) { int pos = uri.indexOf("#"); String ptr = uri.substring(pos+1); if (ptr.matches("^[\\w]+$")) { ptr = "element(" + ptr + ")"; } 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) { doc = nodes.get(0); } else if (nodes.size() != 0) { throw new XProcException(node, "XPointer matches more than one node!?"); } } return doc; } }
public XPointer(XProcRuntime runtime, String xpointer, int readLimit) { this.runtime = runtime; this.readLimit = readLimit; String pointer = xpointer; while (pointer != null) { pointer = parse(pointer); } }
xpointer = new XPointer(runtime, xptr, readLimit); Hashtable<String,String> nsBindings = xpointer.xpathNamespaces(); nodes = xpointer.selectNodes(runtime,subdoc); if (nodes == null) { logger.trace(MessageFormatter.nodeMessage(node, "XInclude parse failed: " + href));
Matcher matcher = scheme.matcher(xpointer); if (matcher.matches()) { // scheme(data) ... QName name = schemeName(matcher.group(1)); String data = matcher.group(2); int dataend = indexOfEnd(data); data = data.substring(1, dataend-1); // 1 because we want to skip the initial "(" data = cleanup(data); matcher = scheme.matcher(xpointer); if (matcher.matches()) { // scheme() ... QName name = schemeName(matcher.group(1)); String data = cleanup(matcher.group(2));
public void testXmlns() { XPointer xp = new XPointer(runtime, "xmlns(a=http://example.com/a) xmlns(b=http://example.com/b)", 1024000); assertNotNull(xp); xp = new XPointer(runtime, "xmlns(a=http://example.com/a)xmlns(b=http://example.com/b)", 1024000); assertNotNull(xp); xp = new XPointer(runtime, "xmlns(a=http://example.com/^(a^))xmlns(b=http://example.com/b)", 1024000); assertNotNull(xp); }
public Vector<XdmNode> selectNodes(XProcRuntime runtime, XdmNode doc) { Vector<XdmNode> result = null; for (XPointerScheme scheme : parts) { String select = scheme.xpathEquivalent(); if (result == null && select != null) { try { result = scheme.selectNodes(runtime, doc, xpathNamespaces()); } catch (XProcException e) { result = null; // try the next one } if (result != null && result.size() == 0) { result = null; } } } return result; }
String readText(final XdmNode node, final XPointer xpointer, String media, InputStream content, long len) throws IOException { String charset = HttpUtils.getCharset(media); if (charset == null && node.getAttributeValue(_encoding) != null) { charset = node.getAttributeValue(_encoding); } if (charset == null) { charset = "utf-8"; } // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(content, charset)); String data = ""; if (xpointer != null) { data = xpointer.selectText(rd, (int) len); } else { String line; while ((line = rd.readLine()) != null) { data += line + "\n"; } } rd.close(); if (trimText) { return data.trim(); } else { return data; } }
xpointer = new XPointer(runtime, xptr, readLimit); matcher.addSubtree(subtree.getResult()); } else { Hashtable<String,String> nsBindings = xpointer.xpathNamespaces(); Vector<XdmNode> nodes = xpointer.selectNodes(runtime,subtree.getResult()); if (nodes == null) { logger.trace(MessageFormatter.nodeMessage(node, "XInclude parse failed: " + href));
Matcher matcher = scheme.matcher(xpointer); if (matcher.matches()) { // scheme(data) ... QName name = schemeName(matcher.group(1)); String data = matcher.group(2); int dataend = indexOfEnd(data); data = data.substring(1, dataend-1); // 1 because we want to skip the initial "(" data = cleanup(data); matcher = scheme.matcher(xpointer); if (matcher.matches()) { // scheme() ... QName name = schemeName(matcher.group(1)); String data = cleanup(matcher.group(2));
public void testSchemes() { XPointer xp = new XPointer(runtime, "xmlns(a=http://example.com/a) a:unk(a=^^b)", 1024000); assertNotNull(xp); xp = new XPointer(runtime, "xmlns(a=http://example.com/a)xmlns(b=http://example.com/b) a:unk(a) b:unk(b)", 1024000); assertNotNull(xp); /* xp = new XPointer("xmlns(a=http://example.com/^(a^))xmlns(b=http://example.com/b) c:unk()", 1024000); assertNotNull(xp); */ } }
public Vector<XdmNode> selectNodes(XProcRuntime runtime, XdmNode doc) { Vector<XdmNode> result = null; for (XPointerScheme scheme : parts) { String select = scheme.xpathEquivalent(); if (result == null && select != null) { try { result = scheme.selectNodes(runtime, doc, xpathNamespaces()); } catch (XProcException e) { result = null; // try the next one } if (result != null && result.size() == 0) { result = null; } } } return result; }
String readText(final XdmNode node, final XPointer xpointer, String media, InputStream content, long len) throws IOException { String charset = HttpUtils.getCharset(media); if (charset == null && node.getAttributeValue(_encoding) != null) { charset = node.getAttributeValue(_encoding); } if (charset == null) { charset = "utf-8"; } // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(content, charset)); String data = ""; if (xpointer != null) { data = xpointer.selectText(rd, (int) len); } else { String line; while ((line = rd.readLine()) != null) { data += line + "\n"; } } rd.close(); if (trimText) { return data.trim(); } else { return data; } }
private XdmNode parse(String uri, String base) { XdmNode doc = runtime.parse(uri, base); if (uri.contains("#")) { int pos = uri.indexOf("#"); String ptr = uri.substring(pos+1); if (ptr.matches("^[\\w]+$")) { ptr = "element(" + ptr + ")"; } 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) { doc = nodes.get(0); } else if (nodes.size() != 0) { throw new XProcException(node, "XPointer matches more than one node!?"); } } return doc; } }
public XPointer(XProcRuntime runtime, String xpointer, int readLimit) { this.runtime = runtime; this.readLimit = readLimit; String pointer = xpointer; while (pointer != null) { pointer = parse(pointer); } }