use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class JavaFunctionsTest method lists.
/**
* Tests simple list functions to make sure java functions are being
* called properly
*/
@Test
public void lists() throws XPathException {
try {
String query = "declare namespace list='java:java.util.ArrayList'; " + "let $list := list:new() " + "let $actions := (list:add($list,'a'),list:add($list,'b'),list:add($list,'c')) " + "return list:get($list,1)";
ResourceSet result = existEmbeddedServer.executeQuery(query);
String r = (String) result.getResource(0).getContent();
assertEquals("b", r);
} catch (XMLDBException e) {
// if exception is a java binding exception and java binding is disabled then this is a success
if (e.getMessage().indexOf("Java binding is disabled in the current configuration") > -1 && !javabindingenabled) {
return;
}
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class InternalModuleTest method requestResponseSessionVariables_4_x_x_Api.
/**
* The $request:request, $session:session, and
* $response:response variables were removed in eXist-db 5.0.0.
*/
@Test
public void requestResponseSessionVariables_4_x_x_Api() throws XMLDBException {
final Source querySource = new StringSource("document{" + EOL + " <vars>" + EOL + " <request>{empty($request:request)}</request>" + EOL + " <session>{empty($session:session)}</session>" + EOL + " <response>{empty($response:response)}</response>" + EOL + " </vars>" + EOL + "}");
final EXistXQueryService queryService = (EXistXQueryService) existServer.getRoot().getService("XQueryService", "1.0");
try {
requestResponseSessionVariablesQuery_4_x_X_Api(queryService, querySource);
fail("Expected XQuery error XPST0008");
} catch (final XMLDBException e) {
assertTrue(e.getCause() instanceof XPathException);
final XPathException xpe = (XPathException) e.getCause();
// TODO(AR) should be XPST0008, eXist-db has a bug with the error code, see: https://github.com/eXist-db/exist/issues/2060
assertEquals(ErrorCodes.XPDY0002, xpe.getErrorCode());
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class XQDocTask method execute.
@Override
public void execute() throws BuildException {
registerDatabase();
try {
int p = uri.indexOf(XmldbURI.ROOT_COLLECTION);
if (p == Constants.STRING_NOT_FOUND)
throw new BuildException("invalid uri: '" + uri + "'");
String baseURI = uri.substring(0, p);
String path;
if (p == uri.length() - 3)
path = "";
else
path = uri.substring(p + 3);
Collection root = null;
if (createCollection) {
root = DatabaseManager.getCollection(baseURI + XmldbURI.ROOT_COLLECTION, user, password);
root = mkcol(root, baseURI, XmldbURI.ROOT_COLLECTION, path);
} else
root = DatabaseManager.getCollection(uri, user, password);
EXistXQueryService service = (EXistXQueryService) root.getService("XQueryService", "1.0");
Source source = new StringSource(XQUERY);
service.declareVariable("collection", root.getName());
service.declareVariable("uri", "");
if (moduleURI != null) {
service.declareVariable("uri", moduleURI);
service.declareVariable("data", "");
service.execute(source);
} else {
for (FileSet fileSet : fileSets) {
DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject());
scanner.scan();
String[] files = scanner.getIncludedFiles();
log("Found " + files.length + " files to upload.\n");
Path baseDir = scanner.getBasedir().toPath();
for (String s : files) {
Path file = baseDir.resolve(s);
log("Storing " + s + " ...\n");
byte[] data = read(file);
try {
service.declareVariable("name", FileUtils.fileName(file));
service.declareVariable("data", data);
service.execute(source);
} catch (XMLDBException e) {
String msg = "XMLDB exception caught: " + e.getMessage();
if (failonerror)
throw new BuildException(msg, e);
else
log(msg, e, Project.MSG_ERR);
}
}
}
}
} catch (XMLDBException e) {
String msg = "XMLDB exception caught: " + e.getMessage();
if (failonerror)
throw new BuildException(msg, e);
else
log(msg, e, Project.MSG_ERR);
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class RemoteResourceSet method getResourceNode.
private RemoteXMLResource getResourceNode(final int pos, final Map<String, String> nodeDetail) throws XMLDBException {
final String doc = nodeDetail.get("docUri");
final Optional<String> s_id = Optional.ofNullable(nodeDetail.get("nodeId"));
final Optional<String> s_type = Optional.ofNullable(nodeDetail.get("type"));
final XmldbURI docUri;
try {
docUri = XmldbURI.xmldbUriFor(doc);
} catch (final URISyntaxException e) {
throw new XMLDBException(ErrorCodes.INVALID_URI, e.getMessage(), e);
}
final RemoteCollection parent;
if (docUri.startsWith(XmldbURI.DB)) {
parent = RemoteCollection.instance(leasableXmlRpcClient, docUri.removeLastSegment());
} else {
// fake to provide a RemoteCollection for local files that have been transferred by xml-rpc
parent = collection;
}
parent.setProperties(outputProperties);
final RemoteXMLResource res = new RemoteXMLResource(parent, handle, pos, docUri, s_id, s_type);
res.setProperties(outputProperties);
return res;
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class RemoteUserManagementService method listResourcePermissions.
@Override
public Permission[] listResourcePermissions() throws XMLDBException {
try {
final List<Object> params = new ArrayList<>();
params.add(collection.getPath());
final Map result = (Map) collection.execute("listDocumentPermissions", params);
final Permission[] perm = new Permission[result.size()];
final String[] resources = collection.listResources();
Object[] t;
for (int i = 0; i < resources.length; i++) {
t = (Object[]) result.get(resources[i]);
final String owner = (String) t[0];
final String group = (String) t[1];
final int mode = (Integer) t[2];
final Stream<ACEAider> aces = extractAces(t[3]);
perm[i] = getPermission(owner, group, mode, aces);
}
return perm;
} catch (final PermissionDeniedException pde) {
throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
}
}
Aggregations