use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class MapTest method effectiveBooleanValue.
@Test
public void effectiveBooleanValue() {
try {
final XQueryService queryService = (XQueryService) server.getRoot().getService("XQueryService", "1.0");
queryService.query("fn:boolean(map{})");
} catch (final XMLDBException e) {
final Throwable cause = e.getCause();
if (cause instanceof XPathException) {
final XPathException xpe = (XPathException) cause;
assertEquals(ErrorCodes.FORG0006, xpe.getErrorCode());
return;
}
}
fail("effectiveBooleanValue of a map should cause the error FORG0006");
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class NewResourceDialog method createResource.
private void createResource(final ResourceType resourceType, final String filename, final String moduleNamespace, final String moduleNamespacePrefix) {
final StringBuilder resourceContentBuilder = new StringBuilder();
try (final InputStream is = getClass().getResourceAsStream(resourceType.getTemplatePath());
final Reader reader = new InputStreamReader(is)) {
final char[] buf = new char[1024];
int read = -1;
while ((read = reader.read(buf)) > -1) {
resourceContentBuilder.append(buf, 0, read);
}
} catch (final IOException ioe) {
ClientFrame.showErrorMessage(ioe.getMessage(), ioe);
}
final String resourceContent;
if (resourceType == ResourceType.XQUERY_LIBRARY) {
resourceContent = resourceContentBuilder.toString().replaceAll("\\$NS", moduleNamespace).replaceAll("\\$PREFIX", moduleNamespacePrefix);
} else {
resourceContent = resourceContentBuilder.toString();
}
try {
final String resName = URIUtils.urlEncodeUtf8((isNullOrEmpty(filename) ? DEFAULT_FILENAME : filename) + "." + resourceType.getFileExtension());
final String resType = resourceType == ResourceType.XML_DOCUMENT ? XMLResource.RESOURCE_TYPE : BinaryResource.RESOURCE_TYPE;
final Collection collection = client.current;
final Resource resource = collection.createResource(resName, resType);
resource.setContent(resourceContent);
((EXistResource) resource).setMimeType(resourceType.getMimeType());
collection.storeResource(resource);
collection.close();
client.reloadCollection();
} catch (final XMLDBException xmldbe) {
ClientFrame.showErrorMessage(xmldbe.getMessage(), xmldbe);
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class ClientFrame method removeAction.
private void removeAction(final ActionEvent ev) {
final ResourceDescriptor[] res = getSelectedResources();
final Collection removeRootCollection = client.current;
// String cmd;
if (JOptionPane.showConfirmDialog(this, // $NON-NLS-1$ //$NON-NLS-2$
Messages.getString("ClientFrame.104") + Messages.getString("ClientFrame.105"), Messages.getString("ClientFrame.106"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// $NON-NLS-1$
final Runnable removeTask = () -> {
// $NON-NLS-1$ //$NON-NLS-2$
final ProgressMonitor monitor = new ProgressMonitor(ClientFrame.this, Messages.getString("ClientFrame.107"), Messages.getString("ClientFrame.108"), 1, res.length);
monitor.setMillisToDecideToPopup(500);
monitor.setMillisToPopup(500);
for (int i = 0; i < res.length; i++) {
final ResourceDescriptor resource = res[i];
if (resource.isCollection()) {
try {
final EXistCollectionManagementService mgtService = (EXistCollectionManagementService) removeRootCollection.getService(// $NON-NLS-1$
"CollectionManagementService", // $NON-NLS-1$
"1.0");
mgtService.removeCollection(resource.getName());
} catch (final XMLDBException e) {
showErrorMessage(e.getMessage(), e);
}
} else {
try {
final Resource res1 = removeRootCollection.getResource(resource.getName().toString());
removeRootCollection.removeResource(res1);
} catch (final XMLDBException e) {
showErrorMessage(e.getMessage(), e);
}
}
monitor.setProgress(i + 1);
if (monitor.isCanceled()) {
return;
}
}
try {
removeRootCollection.close();
} catch (final XMLDBException e) {
showErrorMessage(e.getMessage(), e);
}
try {
client.getResources();
} catch (final XMLDBException e) {
showErrorMessage(e.getMessage(), e);
}
};
client.newClientThread("remove", removeTask).start();
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class ClientFrame method editUsersAction.
private void editUsersAction(final ActionEvent ev) {
try {
final UserManagementService userManagementService = getUserManagementService();
final UserManagerDialog userManager = new UserManagerDialog(userManagementService, client.getProperties().getProperty(InteractiveClient.USER), this);
userManager.setVisible(true);
} catch (final XMLDBException e) {
// $NON-NLS-1$
showErrorMessage(Messages.getString("ClientFrame.185"), e);
e.printStackTrace();
}
}
use of org.xmldb.api.base.XMLDBException in project exist by eXist-db.
the class ClientFrame method setPermAction.
private void setPermAction(final ActionEvent ev) throws PermissionDeniedException {
if (fileman.getSelectedRowCount() == 0) {
return;
}
try {
final Collection collection = client.getCollection();
final UserManagementService service = getUserManagementService();
String name = null;
String created = null;
String modified = null;
String size = null;
String messageDigestType = null;
String messageDigestValue = null;
String mimeType = null;
String owner = null;
String group = null;
ModeDisplay mode = null;
SimpleACLPermissionAider acl = null;
final DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
final List<ResourceDescriptor> selected = new ArrayList<>();
boolean firstPerm = true;
for (final int row : fileman.getSelectedRows()) {
final ResourceDescriptor selectedRow = resources.getRow(row);
selected.add(selectedRow);
final XmldbURI thisName = selectedRow.getName();
final String thisCreated;
final String thisModified;
final String thisMessageDigestType;
final String thisMessageDigestValue;
final String thisSize;
final String thisMimeType;
final Permission thisPerm;
if (selectedRow.isCollection()) {
final Collection coll = collection.getChildCollection(thisName.toString());
thisCreated = dateTimeFormat.format(((EXistCollection) coll).getCreationTime());
thisModified = NON_APPLICABLE;
thisMimeType = COLLECTION_MIME_TYPE;
thisMessageDigestType = NON_APPLICABLE;
thisMessageDigestValue = NON_APPLICABLE;
thisSize = NON_APPLICABLE;
thisPerm = service.getPermissions(coll);
} else {
final Resource res = collection.getResource(thisName.toString());
thisCreated = dateTimeFormat.format(((EXistResource) res).getCreationTime());
thisModified = dateTimeFormat.format(((EXistResource) res).getLastModificationTime());
thisMimeType = ((EXistResource) res).getMimeType();
if (res instanceof EXistBinaryResource) {
final MessageDigest messageDigest = ((EXistBinaryResource) res).getContentDigest(DigestType.BLAKE_256);
thisMessageDigestType = messageDigest.getDigestType().getCommonNames()[0];
thisMessageDigestValue = messageDigest.toHexString();
thisSize = humanSize(((EXistBinaryResource) res).getContentLength());
} else {
thisMessageDigestType = NON_APPLICABLE;
thisMessageDigestValue = NON_APPLICABLE;
thisSize = NON_APPLICABLE;
}
thisPerm = service.getPermissions(res);
}
name = getUpdated(name, () -> URIUtils.urlDecodeUtf8(thisName));
created = getUpdated(created, thisCreated);
modified = getUpdated(modified, thisModified);
mimeType = getUpdated(mimeType, thisMimeType);
messageDigestType = getUpdated(messageDigestType, thisMessageDigestType);
messageDigestValue = getUpdated(messageDigestValue, thisMessageDigestValue);
size = getUpdated(size, thisSize);
owner = getUpdated(owner, () -> thisPerm.getOwner().getName());
group = getUpdated(group, () -> thisPerm.getGroup().getName());
mode = getUpdatedMode(mode, thisPerm);
if (firstPerm) {
if (thisPerm instanceof ACLPermission) {
final ACLPermission thisAcl = (ACLPermission) thisPerm;
acl = new SimpleACLPermissionAider();
for (int i = 0; i < thisAcl.getACECount(); i++) {
acl.addACE(thisAcl.getACEAccessType(i), thisAcl.getACETarget(i), thisAcl.getACEWho(i), thisAcl.getACEMode(i));
}
} else {
acl = null;
}
firstPerm = false;
} else {
if (acl != null && thisPerm instanceof ACLPermission) {
final ACLPermission thisAcl = (ACLPermission) thisPerm;
if (!acl.aclEquals(thisAcl)) {
acl = null;
}
}
}
}
final EditPropertiesDialog editPropertiesDialog = new EditPropertiesDialog(service, client.getProperties().getProperty(InteractiveClient.USER), collection, name, mimeType, created, modified, size, messageDigestType, messageDigestValue, owner, group, mode, acl, selected);
editPropertiesDialog.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(final WindowEvent e) {
try {
client.reloadCollection();
} catch (final XMLDBException xmldbe) {
// $NON-NLS-1$
showErrorMessage(Messages.getString("ClientFrame.197") + xmldbe.getMessage(), xmldbe);
xmldbe.printStackTrace();
}
}
});
editPropertiesDialog.setVisible(true);
} catch (final XMLDBException e) {
// $NON-NLS-1$
showErrorMessage(Messages.getString("ClientFrame.197") + e.getMessage(), e);
e.printStackTrace();
}
}
Aggregations