Search in sources :

Example 26 with XMLDBException

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

the class ChmodTask method execute.

/* (non-Javadoc)
     * @see org.apache.tools.ant.Task#execute()
     */
public void execute() throws BuildException {
    Resource res = null;
    super.execute();
    if (permissions == null) {
        if (mode == null) {
            throw (new BuildException("you have to specify permissions"));
        } else {
            permissions = mode;
        }
    }
    try {
        if (resource != null) {
            res = base.getResource(resource);
        }
        setPermissions(res, service);
    } 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 : Resource(org.xmldb.api.base.Resource) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 27 with XMLDBException

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

the class AbstractXMLDBTask method setPermissions.

protected final void setPermissions(final Resource res) throws BuildException {
    Collection base = null;
    UserManagementService service = null;
    if (uri == null) {
        throw (new BuildException("you have to specify an XMLDB collection URI"));
    }
    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");
            setPermissions(res, service);
        }
    } 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 : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService) BuildException(org.apache.tools.ant.BuildException)

Example 28 with XMLDBException

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

the class ServerShutdown method process.

private static void process(final ParsedArguments arguments) {
    final Properties properties = loadProperties();
    final String user = arguments.get(userArg);
    final String passwd = arguments.get(passwordArg);
    String uri = getOpt(arguments, uriArg).orElseGet(() -> properties.getProperty("uri", "xmldb:exist://localhost:8080/exist/xmlrpc"));
    try {
        // initialize database drivers
        final Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
        // create the default database
        final Database database = (Database) cl.newInstance();
        DatabaseManager.registerDatabase(database);
        if (!uri.endsWith(XmldbURI.ROOT_COLLECTION)) {
            uri = uri + XmldbURI.ROOT_COLLECTION;
        }
        final Collection root = DatabaseManager.getCollection(uri, user, passwd);
        final DatabaseInstanceManager manager = (DatabaseInstanceManager) root.getService("DatabaseInstanceManager", "1.0");
        System.out.println("Shutting down database instance at ");
        System.out.println('\t' + uri);
        manager.shutdown();
    } catch (final XMLDBException e) {
        System.err.println("ERROR: " + e.getMessage());
        final Throwable t = e.getCause();
        if (t != null && t instanceof XmlRpcException) {
            System.err.println("CAUSE: " + t.getMessage());
        } else {
            e.printStackTrace();
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Database(org.xmldb.api.base.Database) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) Properties(java.util.Properties) DatabaseInstanceManager(org.exist.xmldb.DatabaseInstanceManager) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XMLDBException(org.xmldb.api.base.XMLDBException) ArgumentException(se.softhouse.jargo.ArgumentException) IOException(java.io.IOException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) StartException(org.exist.start.StartException)

Example 29 with XMLDBException

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

the class AbstractExistHttpServlet method doDatabaseStartup.

private void doDatabaseStartup(Configuration configuration) throws ServletException {
    if (configuration == null) {
        throw new ServletException("Database has not been " + "configured");
    }
    getLog().info("Configuring eXist instance");
    try {
        if (!BrokerPool.isConfigured()) {
            BrokerPool.configure(1, 5, configuration);
        }
    } catch (final EXistException | DatabaseConfigurationException e) {
        throw new ServletException(e.getMessage(), e);
    }
    try {
        getLog().info("Registering XMLDB driver");
        final Class<?> clazz = Class.forName("org.exist.xmldb.DatabaseImpl");
        final Database database = (Database) clazz.newInstance();
        DatabaseManager.registerDatabase(database);
    } catch (final ClassNotFoundException | XMLDBException | IllegalAccessException | InstantiationException e) {
        getLog().info("ERROR", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) Database(org.xmldb.api.base.Database) XMLDBException(org.xmldb.api.base.XMLDBException) EXistException(org.exist.EXistException)

Example 30 with XMLDBException

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

the class XMLDBAbstractCollectionManipulator method eval.

@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
    if (0 == args.length) {
        throw new XPathException(this, "Expected a collection as the argument " + (paramNumber + 1) + ".");
    }
    final boolean collectionNeedsClose = false;
    Collection collection = null;
    final Item item = args[paramNumber].itemAt(0);
    if (Type.subTypeOf(item.getType(), Type.NODE)) {
        final NodeValue node = (NodeValue) item;
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Found node");
        }
        if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
            final org.exist.collections.Collection internalCol = ((NodeProxy) node).getOwnerDocument().getCollection();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Found node");
            }
            try {
                // TODO: use xmldbURI
                collection = getLocalCollection(context, internalCol.getURI().toString());
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Loaded collection {}", collection.getName());
                }
            } catch (final XMLDBException e) {
                throw new XPathException(this, "Failed to access collection: " + internalCol.getURI(), e);
            }
        } else {
            return Sequence.EMPTY_SEQUENCE;
        }
    }
    if (collection == null) {
        // Otherwise, just extract the name as a string:
        final String collectionURI = args[paramNumber].getStringValue();
        if (collectionURI != null) {
            try {
                collection = getCollection(context, collectionURI, Optional.empty(), Optional.empty());
            } catch (final XMLDBException xe) {
                if (errorIfAbsent) {
                    throw new XPathException(this, "Could not locate collection: " + collectionURI, xe);
                }
                collection = null;
            }
        }
        if (collection == null && errorIfAbsent) {
            throw new XPathException(this, "Unable to find collection: " + collectionURI);
        }
    }
    Sequence s = Sequence.EMPTY_SEQUENCE;
    try {
        s = evalWithCollection(collection, args, contextSequence);
    } finally {
        if (collectionNeedsClose && collection != null) {
            try {
                collection.close();
            } catch (final Exception e) {
                throw new XPathException(this, "Unable to close collection", e);
            }
        }
    }
    return s;
}
Also used : Item(org.exist.xquery.value.Item) NodeValue(org.exist.xquery.value.NodeValue) XPathException(org.exist.xquery.XPathException) InTxnLocalCollection(org.exist.xmldb.txn.bridge.InTxnLocalCollection) LocalCollection(org.exist.xmldb.LocalCollection) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) Sequence(org.exist.xquery.value.Sequence) XMLDBException(org.xmldb.api.base.XMLDBException) XPathException(org.exist.xquery.XPathException)

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