Search in sources :

Example 61 with XMLDBException

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

the class RemoteXMLResource method getContentAsDOM.

@Override
public Node getContentAsDOM() throws XMLDBException {
    final InputSource is;
    InputStream cis = null;
    try {
        if (content != null) {
            is = new InputSource(new StringReader(content));
        } else {
            cis = getStreamContent();
            is = new InputSource(cis);
        }
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);
        final DocumentBuilder builder = factory.newDocumentBuilder();
        final Document doc = builder.parse(is);
        final boolean isDocumentNode = type.map(t -> t.equals("document-node()")).orElse(true);
        if (isDocumentNode) {
            return doc;
        } else {
            return doc.getFirstChild();
        }
    } catch (final SAXException | IOException | ParserConfigurationException e) {
        throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
    } finally {
        if (cis != null) {
            try {
                cis.close();
            } catch (final IOException ioe) {
                LOG.warn(ioe.getMessage(), ioe);
            }
        }
    }
}
Also used : SAXSerializer(org.exist.util.serializer.SAXSerializer) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) TransformerException(javax.xml.transform.TransformerException) TemporaryFileManager(org.exist.util.io.TemporaryFileManager) SAXParserFactory(javax.xml.parsers.SAXParserFactory) MimeType(org.exist.util.MimeType) ArrayList(java.util.ArrayList) XmlRpcException(org.apache.xmlrpc.XmlRpcException) StringValue(org.exist.xquery.value.StringValue) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) LexicalHandler(org.xml.sax.ext.LexicalHandler) XMLReader(org.xml.sax.XMLReader) Namespaces(org.exist.Namespaces) Document(org.w3c.dom.Document) Node(org.w3c.dom.Node) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) SAXParser(javax.xml.parsers.SAXParser) VirtualTempPath(org.exist.util.io.VirtualTempPath) OutputStreamWriter(java.io.OutputStreamWriter) FEATURE_SECURE_PROCESSING(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING) ContentHandler(org.xml.sax.ContentHandler) DOMSerializer(org.exist.util.serializer.DOMSerializer) XMLResource(org.xmldb.api.modules.XMLResource) XMLDBException(org.xmldb.api.base.XMLDBException) OutputStream(java.io.OutputStream) InputSource(org.xml.sax.InputSource) Properties(java.util.Properties) UTF_8(java.nio.charset.StandardCharsets.UTF_8) IOException(java.io.IOException) ExistSAXParserFactory(org.exist.util.ExistSAXParserFactory) DocumentType(org.w3c.dom.DocumentType) List(java.util.List) Logger(org.apache.logging.log4j.Logger) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DocumentTypeImpl(org.exist.dom.persistent.DocumentTypeImpl) Optional(java.util.Optional) ErrorCodes(org.xmldb.api.base.ErrorCodes) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) LogManager(org.apache.logging.log4j.LogManager) Leasable(org.exist.util.Leasable) InputStream(java.io.InputStream) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) InputStream(java.io.InputStream) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 62 with XMLDBException

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

the class InTxnLocalCollection method getChildCollection.

@Override
public org.xmldb.api.base.Collection getChildCollection(final String name) throws XMLDBException {
    final XmldbURI childURI;
    try {
        childURI = XmldbURI.xmldbUriFor(name);
    } catch (final URISyntaxException e) {
        throw new XMLDBException(ErrorCodes.INVALID_URI, e);
    }
    final XmldbURI nameUri = this.<XmldbURI>read().apply((collection, broker, transaction) -> {
        XmldbURI childName = null;
        if (collection.hasChildCollection(broker, childURI)) {
            childName = getPathURI().append(childURI);
        }
        return childName;
    });
    if (nameUri != null) {
        return new InTxnLocalCollection(user, brokerPool, this, nameUri);
    } else {
        return null;
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) URISyntaxException(java.net.URISyntaxException)

Example 63 with XMLDBException

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

the class XmldbApiSecurityTest method addCollectionUserAce.

@Override
protected void addCollectionUserAce(final String collectionUri, final String user_uid, final String mode, final boolean allow, final String uid, final String pwd) throws ApiException {
    Collection parentCol = null;
    Collection subCol = null;
    try {
        final String parentColUri = collectionUri.substring(0, collectionUri.lastIndexOf('/'));
        final String subColName = collectionUri.substring(collectionUri.lastIndexOf('/') + 1);
        parentCol = DatabaseManager.getCollection(getBaseUri() + parentColUri, uid, pwd);
        final UserManagementService ums = (UserManagementService) parentCol.getService("UserManagementService", "1.0");
        final Permission subColPermissions = ums.getSubCollectionPermissions(parentCol, subColName);
        subCol = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
        final List<ACEAider> aces = new ArrayList<>();
        final ACEAider ace = new ACEAider(allow ? ACLPermission.ACE_ACCESS_TYPE.ALLOWED : ACLPermission.ACE_ACCESS_TYPE.DENIED, ACLPermission.ACE_TARGET.USER, user_uid, SimpleACLPermission.aceSimpleSymbolicModeToInt(mode));
        aces.add(ace);
        ums.setPermissions(subCol, subColPermissions.getOwner().getName(), subColPermissions.getGroup().getName(), subColPermissions.getMode(), aces);
    } catch (final XMLDBException | PermissionDeniedException e) {
        throw new ApiException(e);
    } finally {
        if (subCol != null) {
            try {
                subCol.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
        if (parentCol != null) {
            try {
                parentCol.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : ACEAider(org.exist.security.internal.aider.ACEAider) ArrayList(java.util.ArrayList) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 64 with XMLDBException

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

the class XmldbApiSecurityTest method createCol.

@Override
protected void createCol(final String collectionName, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + "/db", uid, pwd);
        CollectionManagementService cms = (CollectionManagementService) col.getService("CollectionManagementService", "1.0");
        cms.createCollection(collectionName);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 65 with XMLDBException

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

the class XmldbApiSecurityTest method chownRes.

@Override
protected void chownRes(final String resourceUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
        final Resource resource = col.getResource(getResourceName(resourceUri));
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chown(resource, ums.getAccount(owner_uid), group_gid);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

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