name = args[1].getStringValue();
source = new BinarySource(data, true);
} else {
String uri = args[0].getStringValue();
if (uri.startsWith(XmldbURI.XMLDB_URI_PREFIX)) {
Collection collection = null;
DocumentImpl doc = null;
try {
XmldbURI resourceURI = XmldbURI.xmldbUriFor(uri);
collection = context.getBroker().openCollection(resourceURI.removeLastSegment(), Lock.READ_LOCK);
if (collection == null) {
LOG.warn("collection not found: " + resourceURI.getCollectionPath());
return Sequence.EMPTY_SEQUENCE;
}
doc = collection.getDocumentWithLock(context.getBroker(), resourceURI.lastSegment(), Lock.READ_LOCK);
if (doc == null)
return Sequence.EMPTY_SEQUENCE;
if (doc.getResourceType() != DocumentImpl.BINARY_FILE ||
!doc.getMetadata().getMimeType().equals("application/xquery")) {
throw new XPathException(this, "XQuery resource: " + uri + " is not an XQuery or " +
"declares a wrong mime-type");
}
source = new DBSource(context.getBroker(), (BinaryDocument) doc, false);
name = doc.getFileURI().toString();
} catch (URISyntaxException e) {
throw new XPathException(this, "invalid module uri: " + uri + ": " + e.getMessage(), e);
} catch (LockException e) {
throw new XPathException(this, "internal lock error: " + e.getMessage());
} catch(PermissionDeniedException pde) {
throw new XPathException(this, pde.getMessage(), pde);
} finally {
if (doc != null)
doc.getUpdateLock().release(Lock.READ_LOCK);
if(collection != null)
collection.release(Lock.READ_LOCK);
}
} else {
// first check if the URI points to a registered module
String location = context.getModuleLocation(uri);
if (location != null)