Search in sources :

Example 51 with XMLDBException

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());
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Example 52 with XMLDBException

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());
    }
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) XMLDBException(org.xmldb.api.base.XMLDBException) StringSource(org.exist.source.StringSource) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) Test(org.junit.Test)

Example 53 with XMLDBException

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);
    }
}
Also used : Path(java.nio.file.Path) FileSet(org.apache.tools.ant.types.FileSet) XMLDBException(org.xmldb.api.base.XMLDBException) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) EXistXQueryService(org.exist.xmldb.EXistXQueryService) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) Collection(org.xmldb.api.base.Collection) BuildException(org.apache.tools.ant.BuildException) StringSource(org.exist.source.StringSource)

Example 54 with XMLDBException

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;
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) URISyntaxException(java.net.URISyntaxException)

Example 55 with XMLDBException

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);
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) ACEAider(org.exist.security.internal.aider.ACEAider) ACLPermission(org.exist.security.ACLPermission) Permission(org.exist.security.Permission) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Aggregations

XMLDBException (org.xmldb.api.base.XMLDBException)174 Collection (org.xmldb.api.base.Collection)66 Resource (org.xmldb.api.base.Resource)34 URISyntaxException (java.net.URISyntaxException)30 XMLResource (org.xmldb.api.modules.XMLResource)30 ResourceSet (org.xmldb.api.base.ResourceSet)23 BuildException (org.apache.tools.ant.BuildException)21 IOException (java.io.IOException)19 XPathException (org.exist.xquery.XPathException)18 PermissionDeniedException (org.exist.security.PermissionDeniedException)16 SAXException (org.xml.sax.SAXException)16 EXistException (org.exist.EXistException)15 UserManagementService (org.exist.xmldb.UserManagementService)15 XPathQueryService (org.xmldb.api.modules.XPathQueryService)13 BinaryResource (org.xmldb.api.modules.BinaryResource)12 ArrayList (java.util.ArrayList)11 Account (org.exist.security.Account)11 EXistResource (org.exist.xmldb.EXistResource)10 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)10 Properties (java.util.Properties)9