} catch (PermissionDeniedException e) { LOG.warn("xpointer error", e); throw new SAXException(e);
	protected void processXInclude(String href) throws SAXException {		if(href == null)			throw new SAXException("No href attribute found in XInclude include element");		// save some settings		DocumentImpl prevDoc = document;		boolean createContainerElements = serializer.createContainerElements;		serializer.createContainerElements = false;		// parse the href attribute		if (href != null) {			LOG.debug("found href=\"" + href + "\"");			String xpointer = null;			String docName = href;			// try to find xpointer part			int p = href.indexOf('#');			if (-1 < p) {				docName = href.substring(0, p);				xpointer = XMLUtil.decodeAttrMarkup(href.substring(p + 1));				LOG.debug("found xpointer: " + xpointer);			}			// if docName has no collection specified, assume			// current collection 			p = docName.lastIndexOf('/');			if (p < 0 && document != null)				docName = document.getCollection().getName() + '/' + docName;			// retrieve the document			LOG.debug("loading " + docName);			DocumentImpl doc = null;			try {				doc = (DocumentImpl) serializer.broker.getDocument(docName);				if(doc != null && !doc.getPermissions().validate(serializer.broker.getUser(), Permission.READ))					throw new PermissionDeniedException("Permission denied to read xincluded resource");			} catch (PermissionDeniedException e) {				LOG.warn("permission denied", e);				throw new SAXException(e);			}			/* if document has not been found and xpointer is			 * null, throw an exception. If xpointer != null			 * we retry below and interpret docName as			 * a collection.			 */			if (doc == null && xpointer == null)				throw new SAXException("document " + docName + " not found");			if (xpointer == null)				// no xpointer found - just serialize the doc				serializer.serializeToReceiver(doc, false);			else {				// process the xpointer				try {					// build input document set					DocumentSet docs = new DocumentSet();					if (doc == null) {						// try to read documents from the collection						// specified by docName						docs = serializer.broker.getDocumentsByCollection(docName, docs);						// give up						if (docs == null)							throw new SAXException(								"no document or collection " + "called " + docName);					} else {						docs.add(doc);					}					XQueryContext context = new XQueryContext(serializer.broker);					context.setStaticallyKnownDocuments(docs);					xpointer = checkNamespaces(context, xpointer);					context.declareNamespaces(namespaces);										XQueryLexer lexer = new XQueryLexer(context, new StringReader(xpointer));					XQueryParser parser = new XQueryParser(lexer);					XQueryTreeParser treeParser = new XQueryTreeParser(context);					parser.xpointer();					if (parser.foundErrors()) {						throw new SAXException(parser.getErrorMessage());					}					AST ast = parser.getAST();					PathExpr expr = new PathExpr(context);					treeParser.xpointer(ast, expr);					if (treeParser.foundErrors()) {						throw new SAXException(treeParser.getErrorMessage());					}					LOG.info("xpointer query: " + expr.pprint());					long start = System.currentTimeMillis();					Sequence seq = expr.eval(null, null);					switch (seq.getItemType()) {						case Type.NODE :							NodeSet set = (NodeSet) seq;							LOG.info("xpointer found: " + set.getLength());							NodeProxy proxy;							for (Iterator i = set.iterator(); i.hasNext();) {								proxy = (NodeProxy) i.next();								serializer.serializeToReceiver(proxy, false);							}							break;						default :							String val;							for (int i = 0; i < seq.getLength(); i++) {								val = seq.itemAt(i).getStringValue();								characters(val);							}							break;					}				} catch (RecognitionException e) {					LOG.warn("xpointer error", e);					throw new SAXException(e);				} catch (TokenStreamException e) {					LOG.warn("xpointer error", e);					throw new SAXException(e);				} catch (PermissionDeniedException e) {					LOG.warn("xpointer error", e);					throw new SAXException(e);				} catch (XPathException e) {					throw new SAXException(e);				}			}		}		// restore settings		document = prevDoc;		serializer.createContainerElements = createContainerElements;	}