DocumentSet docs = new DocumentSet(); Collection collection = broker.getCollection(path); if (collection != null) { collection.allDocs(broker, docs, true, true); } else { DocumentImpl doc = (DocumentImpl) broker.getDocument(path); if (doc != null) { if(!doc.getPermissions().validate(broker.getUser(), Permission.READ)) throw new PermissionDeniedException("Not allowed to read collection"); docs.add(doc); } else broker.getAllDocuments(docs); }
	protected String search(DBBroker broker, String query, String path,			int howmany, int start, Properties outputProperties, int enclose)	throws BadRequestException, PermissionDeniedException {		String result = null;		try {			DocumentSet docs = new DocumentSet();			Collection collection = broker.getCollection(path);			if (collection != null) {				collection.allDocs(broker, docs, true, true);			} else {				DocumentImpl doc = (DocumentImpl) broker.getDocument(path);				if (doc != null) {				    if(!doc.getPermissions().validate(broker.getUser(), Permission.READ))						throw new PermissionDeniedException("Not allowed to read collection");					docs.add(doc);				} else					broker.getAllDocuments(docs);			}			Source source = new StringSource(query);			XQuery xquery = broker.getXQueryService();			XQueryPool pool = xquery.getXQueryPool();			CompiledXQuery compiled = pool.borrowCompiledXQuery(source);			XQueryContext context;			if(compiled == null)			    context = xquery.newContext();			else			    context = compiled.getContext();			context.setStaticallyKnownDocuments(docs);						if(compiled == null)			    compiled = xquery.compile(context, source);			checkPragmas(context, outputProperties);			try {			    long startTime = System.currentTimeMillis();			    Sequence resultSequence = xquery.execute(compiled, null);			    long queryTime = System.currentTimeMillis() - startTime;				LOG.debug("Found " + resultSequence.getLength() + " in " + queryTime + "ms.");				return printResults(broker, resultSequence, howmany, start,						queryTime, outputProperties, enclose);			} finally {			    pool.returnCompiledXQuery(source, compiled);			}		} catch (XPathException e) {			throw new BadRequestException(e.getMessage(), e);		} catch (IOException e) {		    throw new BadRequestException(e.getMessage(), e);        }	}