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