Search in sources :

Example 16 with XMLDBException

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

the class DocumentView method viewDocument.

public void viewDocument() {
    try {
        if (// $NON-NLS-1$
        "XMLResource".equals(resource.getResourceType())) {
            setText((String) resource.getContent());
        } else {
            setText(new String((byte[]) resource.getContent()));
        }
        // lock the resource for editing
        final UserManagementService service = (UserManagementService) // $NON-NLS-1$ //$NON-NLS-2$
        client.current.getService("UserManagementService", "1.0");
        // $NON-NLS-1$
        final Account user = service.getAccount(properties.getProperty("user"));
        final String lockOwner = service.hasUserLock(resource);
        if (lockOwner != null) {
            if (JOptionPane.showConfirmDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.6") + lockOwner + // $NON-NLS-1$
            Messages.getString("DocumentView.7"), // $NON-NLS-1$
            Messages.getString("DocumentView.8"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
                dispose();
                this.setCursor(Cursor.getDefaultCursor());
                return;
            }
        }
        try {
            service.lockResource(resource, user);
        } catch (final XMLDBException ex) {
            System.out.println(ex.getMessage());
            JOptionPane.showMessageDialog(this, // $NON-NLS-1$
            Messages.getString("DocumentView.9"));
            setReadOnly();
        }
        setVisible(true);
    } catch (final XMLDBException ex) {
        // $NON-NLS-1$
        showErrorMessage(Messages.getString("DocumentView.10") + ex.getMessage(), ex);
    }
}
Also used : Account(org.exist.security.Account) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 17 with XMLDBException

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

the class AddGroupTask 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 a group name"));
    }
    try {
        final GroupAider group = new GroupAider(name);
        log("Adding group " + name, Project.MSG_INFO);
        service.addGroup(group);
    } 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) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 18 with XMLDBException

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

the class ChownTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    if ((name == null) || (group == null)) {
        throw (new BuildException("Must specify user and group"));
    }
    try {
        final Account usr = service.getAccount(name);
        if (resource != null) {
            final Resource res = base.getResource(resource);
            service.chown(res, usr, group);
        } else {
            service.chown(usr, group);
        }
    } 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) Resource(org.xmldb.api.base.Resource) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 19 with XMLDBException

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

the class RemoveGroupTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    super.execute();
    if (name == null) {
        throw (new BuildException("You have to specify a name"));
    }
    log("Removing group " + name, Project.MSG_INFO);
    try {
        final Group group = service.getGroup(name);
        if (group != null) {
            service.removeGroup(group);
        } else {
            log("Group " + name + " does not exist.", 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);
        }
    }
}
Also used : Group(org.exist.security.Group) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 20 with XMLDBException

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

the class UserPasswordTask method execute.

@Override
public void execute() throws BuildException {
    super.execute();
    if (name == null) {
        throw (new BuildException("Must specify at least a user name"));
    }
    try {
        log("Looking up user " + name, Project.MSG_INFO);
        final Account usr = service.getAccount(name);
        if (usr != null) {
            log("Setting password for user " + name, Project.MSG_INFO);
            if (secret != null) {
                usr.setCredential(new Password(usr, secret));
                this.service.updateAccount(usr);
            }
        } else {
            final String msg = "user " + name + " not found";
            if (failonerror) {
                throw (new BuildException(msg));
            } else {
                log(msg, Project.MSG_ERR);
            }
        }
    } 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) Password(org.exist.security.internal.Password)

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