xqueryDoc = "application/xquery".equals(doc.getMimeType());
xqueryDoc = "application/xquery".equals(doc.getMetadata().getMimeType());
	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 (p != Constants.STRING_NOT_FOUND) {				docName = href.substring(0, p);				xpointer = XMLUtil.decodeAttrMarkup(href.substring(p + 1));				LOG.debug("found xpointer: " + xpointer);			}                        // extract possible parameters in the URI            Map params = null;            int paramsStart = docName.indexOf('?');            if (paramsStart != Constants.STRING_NOT_FOUND) {                if (paramsStart < docName.length() - 1) {                    String paramStr = docName.substring(paramsStart + 1);                    params = processParameters(paramStr);                }                docName = docName.substring(0, paramsStart);            }            			// if docName has no collection specified, assume			// current collection             ///TODO : use dedicated function in XmldbURI			p = docName.lastIndexOf("/");			if (p == Constants.STRING_NOT_FOUND && document != null)				docName = document.getCollection().getName() + "/" + docName;			// retrieve the document			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");                        /* Check if the document is a stored XQuery */            boolean xqueryDoc = false;            if (doc != null && doc.getResourceType() == DocumentImpl.BINARY_FILE) {                xqueryDoc = "application/xquery".equals(doc.getMimeType());            }            			if (xpointer == null && !xqueryDoc)				// no xpointer found - just serialize the doc				serializer.serializeToReceiver(doc, false);			else {				// process the xpointer or the stored XQuery				try {                     Source source;                    if (xpointer == null)                        source = new DBSource(serializer.broker, (BinaryDocument) doc, true);                    else {                        xpointer = checkNamespaces(xpointer);                        source = new StringSource(xpointer);                    }                    XQuery xquery = serializer.broker.getXQueryService();                    XQueryPool pool = xquery.getXQueryPool();                    XQueryContext context;                    CompiledXQuery compiled = pool.borrowCompiledXQuery(serializer.broker, source);                    if (compiled != null)                        context = compiled.getContext();                    else                        context = xquery.newContext();                    context.declareNamespaces(namespaces);                    context.declareNamespace("xinclude", XINCLUDE_NS);                    context.declareVariable("xinclude:current-doc", document.getFileName());                    context.declareVariable("xinclude:current-collection", document.getCollection().getName());                    if (xpointer != null) {    					if(doc != null)    						context.setStaticallyKnownDocuments(new String[] { doc.getName() } );    					else    						context.setStaticallyKnownDocuments(new String[] { docName });                    }                                        // pass parameters as variables					if (params != null) {                        for (Iterator i = params.entrySet().iterator(); i.hasNext(); ) {                            Map.Entry entry = (Map.Entry) i.next();                            context.declareVariable(entry.getKey().toString(), entry.getValue());                        }                    }                                        if(compiled == null) {                        try {                            compiled = xquery.compile(context, source, xpointer != null);                        } catch (IOException e) {                            throw new SAXException("I/O error while reading query for xinclude: " + e.getMessage(), e);                        }                    }                    LOG.info("xpointer query: " + ExpressionDumper.dump((Expression) compiled));                    Sequence seq = xquery.execute(compiled, null);                    					if(Type.subTypeOf(seq.getItemType(), Type.NODE)) {						LOG.info("xpointer found: " + seq.getLength());												NodeValue node;						for (SequenceIterator i = seq.iterate(); i.hasNext();) {							node = (NodeValue) i.nextItem();							serializer.serializeToReceiver(node, false);						}					} else {						String val;						for (int i = 0; i < seq.getLength(); i++) {							val = seq.itemAt(i).getStringValue();							characters(val);						}					}				} catch (XPathException e) {					LOG.warn("xpointer error", e);					throw new SAXException("Error while processing XInclude expression: " + e.getMessage(), e);				}			}		}		// restore settings		document = prevDoc;		serializer.createContainerElements = createContainerElements;	}