Search in sources :

Example 56 with XMLDBException

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

the class RemoteUserManagementService method getGroup.

@Override
public Group getGroup(final String name) throws XMLDBException {
    try {
        final List<Object> params = new ArrayList<>();
        params.add(name);
        final Map<String, Object> tab = (Map<String, Object>) collection.execute("getGroup", params);
        if (tab != null && !tab.isEmpty()) {
            final Group group = new GroupAider((Integer) tab.get("id"), (String) tab.get("realmId"), (String) tab.get("name"));
            final Object[] managers = (Object[]) tab.get("managers");
            for (final Object manager : managers) {
                group.addManager(getAccount((String) manager));
            }
            final Map<String, String> metadata = (Map<String, String>) tab.get("metadata");
            for (final Map.Entry<String, String> m : metadata.entrySet()) {
                if (AXSchemaType.valueOfNamespace(m.getKey()) != null) {
                    group.setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
                } else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
                    group.setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
                }
            }
            return group;
        }
        return null;
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde);
    }
}
Also used : Group(org.exist.security.Group) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 57 with XMLDBException

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

the class RemoteUserManagementService method getPermissions.

@Override
public Permission getPermissions(final Resource res) throws XMLDBException {
    if (res == null) {
        throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, "resource is null");
    }
    // TODO : use dedicated function in XmldbURI
    final String path = ((RemoteCollection) res.getParentCollection()).getPath() + "/" + res.getId();
    try {
        final List<Object> params = new ArrayList<>();
        params.add(path);
        final Map result = (Map) collection.execute("getPermissions", params);
        final String owner = (String) result.get("owner");
        final String group = (String) result.get("group");
        final int mode = (Integer) result.get("permissions");
        final Stream<ACEAider> aces = extractAces(result.get("acl"));
        return getPermission(owner, group, mode, aces);
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
    }
}
Also used : ACEAider(org.exist.security.internal.aider.ACEAider) XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 58 with XMLDBException

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

the class LocalIndexQueryService method reindexCollection.

@Override
public void reindexCollection(final XmldbURI col) throws XMLDBException {
    final XmldbURI collectionPath = resolve(col);
    read(collectionPath).apply((collection, broker, transaction) -> {
        try {
            broker.reindexCollection(transaction, collectionPath);
            broker.sync(Sync.MAJOR);
            return null;
        } catch (final LockException e) {
            throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e);
        }
    });
}
Also used : LockException(org.exist.util.LockException) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 59 with XMLDBException

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

the class LocalXMLResource method getContentAsSAX.

@Override
public void getContentAsSAX(final ContentHandler handler) throws XMLDBException {
    // case 1: content is an external DOM node
    if (root != null && !(root instanceof NodeValue)) {
        try {
            final String option = collection.getProperty(Serializer.GENERATE_DOC_EVENTS, "false");
            final DOMStreamer streamer = (DOMStreamer) SerializerPool.getInstance().borrowObject(DOMStreamer.class);
            try {
                streamer.setContentHandler(handler);
                streamer.setLexicalHandler(lexicalHandler);
                streamer.serialize(root, option.equalsIgnoreCase("true"));
            } finally {
                SerializerPool.getInstance().returnObject(streamer);
            }
        } catch (final Exception e) {
            throw new XMLDBException(ErrorCodes.INVALID_RESOURCE, e.getMessage(), e);
        }
    } else {
        withDb((broker, transaction) -> {
            try {
                // case 2: content is an atomic value
                if (value != null) {
                    value.toSAX(broker, handler, getProperties());
                // case 3: content is an internal node or a document
                } else {
                    final Serializer serializer = broker.borrowSerializer();
                    try {
                        serializer.setUser(user);
                        serializer.setProperties(getProperties());
                        serializer.setSAXHandlers(handler, lexicalHandler);
                        if (root != null) {
                            serializer.toSAX((NodeValue) root);
                        } else if (proxy != null) {
                            serializer.toSAX(proxy);
                        } else {
                            read(broker, transaction).apply((document, broker1, transaction1) -> {
                                try {
                                    serializer.toSAX(document);
                                    return null;
                                } catch (final SAXException e) {
                                    throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
                                }
                            });
                        }
                    } finally {
                        broker.returnSerializer(serializer);
                    }
                }
                return null;
            } catch (final SAXException e) {
                throw new XMLDBException(ErrorCodes.VENDOR_ERROR, e.getMessage(), e);
            }
        });
    }
}
Also used : Tuple3(com.evolvedbinary.j8fu.tuple.Tuple3) StoredNode(org.exist.dom.persistent.StoredNode) Txn(org.exist.storage.txn.Txn) SAXSerializer(org.exist.util.serializer.SAXSerializer) net.sf.cglib.proxy(net.sf.cglib.proxy) BrokerPool(org.exist.storage.BrokerPool) TransformerException(javax.xml.transform.TransformerException) NodeProxy(org.exist.dom.persistent.NodeProxy) AtomicValue(org.exist.xquery.value.AtomicValue) MimeType(org.exist.util.MimeType) Tuple(com.evolvedbinary.j8fu.tuple.Tuple.Tuple) StringValue(org.exist.xquery.value.StringValue) LexicalHandler(org.xml.sax.ext.LexicalHandler) SerializerPool(org.exist.util.serializer.SerializerPool) AttrImpl(org.exist.dom.memtree.AttrImpl) Subject(org.exist.security.Subject) Node(org.w3c.dom.Node) NodeValue(org.exist.xquery.value.NodeValue) org.xml.sax(org.xml.sax) DocumentImpl(org.exist.dom.memtree.DocumentImpl) NodeImpl(org.exist.dom.memtree.NodeImpl) DOMSerializer(org.exist.util.serializer.DOMSerializer) XMLResource(org.xmldb.api.modules.XMLResource) Method(java.lang.reflect.Method) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) XMLDBException(org.xmldb.api.base.XMLDBException) NodeList(org.w3c.dom.NodeList) Properties(java.util.Properties) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DOMStreamer(org.exist.util.serializer.DOMStreamer) StringWriter(java.io.StringWriter) Type(org.exist.xquery.value.Type) IOException(java.io.IOException) DocumentType(org.w3c.dom.DocumentType) Stream(java.util.stream.Stream) XMLUtil(org.exist.dom.persistent.XMLUtil) NodeId(org.exist.numbering.NodeId) DBBroker(org.exist.storage.DBBroker) Serializer(org.exist.storage.serializers.Serializer) Optional(java.util.Optional) ErrorCodes(org.xmldb.api.base.ErrorCodes) ConsumerE(com.evolvedbinary.j8fu.function.ConsumerE) XPathException(org.exist.xquery.XPathException) NodeValue(org.exist.xquery.value.NodeValue) DOMStreamer(org.exist.util.serializer.DOMStreamer) XMLDBException(org.xmldb.api.base.XMLDBException) TransformerException(javax.xml.transform.TransformerException) XMLDBException(org.xmldb.api.base.XMLDBException) IOException(java.io.IOException) XPathException(org.exist.xquery.XPathException) SAXSerializer(org.exist.util.serializer.SAXSerializer) DOMSerializer(org.exist.util.serializer.DOMSerializer) Serializer(org.exist.storage.serializers.Serializer)

Example 60 with XMLDBException

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

the class RemoteXMLResource method getContentAsSAX.

@Override
public void getContentAsSAX(final ContentHandler handler) 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);
        }
        XMLReader reader = xmlReader;
        if (reader == null) {
            final SAXParserFactory saxFactory = ExistSAXParserFactory.getSAXParserFactory();
            saxFactory.setNamespaceAware(true);
            saxFactory.setValidating(false);
            final SAXParser sax = saxFactory.newSAXParser();
            reader = sax.getXMLReader();
            reader.setFeature(FEATURE_SECURE_PROCESSING, true);
        }
        reader.setContentHandler(handler);
        if (lexicalHandler != null) {
            reader.setProperty(Namespaces.SAX_LEXICAL_HANDLER, lexicalHandler);
        }
        reader.parse(is);
    } catch (final ParserConfigurationException | SAXException | IOException 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 : InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) StringReader(java.io.StringReader) SAXParser(javax.xml.parsers.SAXParser) XMLDBException(org.xmldb.api.base.XMLDBException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) ExistSAXParserFactory(org.exist.util.ExistSAXParserFactory) SAXException(org.xml.sax.SAXException)

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