this.expression = expression;
}
public boolean process(XPointerContext xpointerContext) throws SAXException, ResourceNotFoundException {
Document document = xpointerContext.getDocument();
ServiceManager manager = xpointerContext.getServiceManager();
XPathProcessor xpathProcessor = null;
try {
try {
xpathProcessor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
} catch (Exception e) {
throw new SAXException("XPointerPart: error looking up XPathProcessor.", e);
}
NodeList nodeList = xpathProcessor.selectNodeList(document, expression, xpointerContext);
if (nodeList.getLength() > 0) {
XMLConsumer consumer = xpointerContext.getXmlConsumer();
LocatorImpl locator = new LocatorImpl();
locator.setSystemId(xpointerContext.getSource().getURI());
consumer.setDocumentLocator(locator);
for (int i = 0; i < nodeList.getLength(); i++) {
DOMStreamer streamer = new DOMStreamer();
streamer.setConsumer(consumer);
streamer.stream(nodeList.item(i));
}
return true;
} else {
if (xpointerContext.getLogger().isDebugEnabled())
xpointerContext.getLogger().debug("XPointer: expression \"" + expression + "\" gave no results.");
return false;
}
} finally {
if (xpathProcessor != null)
manager.release(xpathProcessor);
}
}