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);
}
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
}
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());
}
}
Aggregations