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