while ((read = reader.read(ary)) != -1) {
super.characters(ary,0,read);
}
} catch (SourceNotFoundException e) {
useFallbackLevel++;
fallBackException = new CascadingException("Resource not found: " + url.getURI());
getLogger().error("xIncluded resource not found: " + url.getURI(), e);
} finally {
if (reader != null) reader.close();
if (isr != null) isr.close();
if (is != null) is.close();
}
} else if (parse.equals("xml")) {
getLogger().debug("Parse type is XML");
// Check loop inclusion
if (isLoopInclusion(url.getURI(), xpointer)) {
throw new ProcessingException("Detected loop inclusion of href=" + url.getURI() + ", xpointer=" + xpointer);
}
XIncludePipe subPipe = new XIncludePipe();
subPipe.init(url.getURI(), xpointer);
subPipe.setConsumer(xmlConsumer);
subPipe.setParent(this);
try {
if (xpointer != null && xpointer.length() > 0) {
XPointer xptr;
xptr = XPointerFrameworkParser.parse(NetUtils.decodePath(xpointer));
XPointerContext context = new XPointerContext(xpointer, url, subPipe, manager);
for (Iterator iter = namespaces.keySet().iterator(); iter.hasNext();) {
String prefix = (String) iter.next();
context.addPrefix(prefix, (String) namespaces.get(prefix));
}
xptr.process(context);
} else {
SourceUtil.toSAX(manager, url, new IncludeXMLConsumer(subPipe));
}
// restore locator on the consumer
if (locator != null)
xmlConsumer.setDocumentLocator(locator);
} catch (ResourceNotFoundException e) {
useFallbackLevel++;
fallBackException = new CascadingException("Resource not found: " + url.getURI());
getLogger().error("xIncluded resource not found: " + url.getURI(), e);
} catch (ParseException e) {
// this exception is thrown in case of an invalid xpointer expression
useFallbackLevel++;
fallBackException = new CascadingException("Error parsing xPointer expression", e);
fallBackException.fillInStackTrace();
getLogger().error("Error parsing XPointer expression, will try to use fallback.", e);
} catch(SAXException e) {
getLogger().error("Error in processXIncludeElement", e);
throw e;