Search in sources :

Example 81 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class AddUserTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    if (name == null) {
        throw (new BuildException("Must specify at leat a user name"));
    }
    try {
        final UserAider usr = new UserAider(name);
        if (secret != null) {
            usr.setPassword(secret);
        }
        if (primaryGroup != null) {
            usr.addGroup(primaryGroup);
        }
        log("Adding user " + name, Project.MSG_INFO);
        service.addAccount(usr);
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) UserAider(org.exist.security.internal.aider.UserAider)

Example 82 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class ListUsersTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    try {
        log("Listing all users", Project.MSG_DEBUG);
        final Account[] users = service.getAccounts();
        if (users != null) {
            boolean isFirst = true;
            final StringBuilder buffer = new StringBuilder();
            for (final Account user : users) {
                // only insert separator for 2nd or later item
                if (isFirst) {
                    isFirst = false;
                } else {
                    buffer.append(separator);
                }
                buffer.append(user.getName());
            }
            if (buffer.length() > 0) {
                log("Setting output property " + outputproperty + " to " + buffer.toString(), Project.MSG_DEBUG);
                getProject().setNewProperty(outputproperty, buffer.toString());
            }
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 83 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class UserTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    if (uri == null) {
        throw (new BuildException("you have to specify an XMLDB collection URI"));
    }
    registerDatabase();
    try {
        log("Get base collection: " + uri, Project.MSG_DEBUG);
        base = DatabaseManager.getCollection(uri, user, password);
        if (base == null) {
            final String msg = "Collection " + uri + " could not be found.";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        } else {
            service = (UserManagementService) base.getService("UserManagementService", "1.0");
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 84 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class XMLDBCreateTask method execute.

@Override
public void execute() throws BuildException {
    if (uri == null) {
        throw (new BuildException("you have to specify an XMLDB collection URI"));
    }
    registerDatabase();
    try {
        log("Get base collection: " + uri, Project.MSG_DEBUG);
        final Collection base = DatabaseManager.getCollection(uri, user, password);
        if (base == null) {
            final String msg = "Collection " + uri + " could not be found.";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        } else {
            Collection root = null;
            if (collection != null) {
                log("Creating collection " + collection + " in base collection " + uri, Project.MSG_DEBUG);
                root = mkcol(base, uri, collection);
            } else {
                root = base;
            }
            if (permissions != null) {
                setPermissions(root);
            }
            log("Created collection " + root.getName(), Project.MSG_INFO);
        }
    } catch (final XMLDBException e) {
        final String msg = "XMLDB exception caught: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    } catch (final URISyntaxException e) {
        final String msg = "URISyntaxException: " + e.getMessage();
        if (failonerror) {
            throw (new BuildException(msg, e));
        } else {
            log(msg, e, Project.MSG_ERR);
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) URISyntaxException(java.net.URISyntaxException)

Example 85 with XMLDBException

use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.

the class EvalTest method evalWithMissingVariableReferenceShouldReportTheSameErrorEachTime.

/**
 * The original issue was caused by VariableReference inside util:eval
 * not calling XQueryContext#popNamespaceContext when a variable
 * reference could not be resolved, which led to the wrong
 * namespaces being present in the XQueryContext the next time
 * the same query was executed
 */
@Test
public void evalWithMissingVariableReferenceShouldReportTheSameErrorEachTime() throws XMLDBException {
    final String testHomeName = "testEvalWithMissingVariableReferenceShouldReportTheSameErrorEachTime";
    final Collection testHome = createCollection(testHomeName);
    final String configModuleName = "config-test.xqm";
    final String configModule = "xquery version \"1.0\";\r\n" + "module namespace ct = \"http://config/test\";\r\n" + "declare variable $ct:var1 { request:get-parameter(\"var1\", ()) };";
    writeModule(testHome, configModuleName, configModule);
    final String testModuleName = "test.xqy";
    final String testModule = "import module namespace ct = \"http://config/test\" at \"xmldb:exist:///db/" + testHomeName + "/" + configModuleName + "\";\r\n" + "declare namespace x = \"http://x\";\r\n" + "declare function local:hello() {\r\n" + " (\r\n" + "<x:hello>hello</x:hello>,\r\n" + "util:eval(\"$ct:var1\")\r\n" + ")\r\n" + "};\r\n" + "local:hello()";
    writeModule(testHome, testModuleName, testModule);
    // run the 1st time
    try {
        executeModule(testHome, testModuleName);
    } catch (final XMLDBException e) {
        final Throwable cause = e.getCause();
        assertTrue(cause instanceof XPathException);
        assertEquals(ErrorCodes.XPDY0002, ((XPathException) cause).getErrorCode());
    }
    // run a 2nd time, error code should be the same!
    try {
        executeModule(testHome, testModuleName);
    } catch (final XMLDBException e) {
        final Throwable cause = e.getCause();
        assertTrue(cause instanceof XPathException);
        assertEquals(ErrorCodes.XPDY0002, ((XPathException) cause).getErrorCode());
    }
}
Also used : XPathException(org.exist.xquery.XPathException) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

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