use of org.exist.client.security.ModeDisplay 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