📄 cmschacc.java
字号:
* @param editable boolean to determine if the form is editable
* @param extendedView boolean to determine if the view is selectable with DHTML
* @param inheritRes the resource name from which the ace is inherited
* @return StringBuffer with HTML code of the form
*/
private StringBuffer buildPermissionEntryForm(
CmsAccessControlEntry entry,
boolean editable,
boolean extendedView,
String inheritRes) {
StringBuffer result = new StringBuffer(8);
// get name and type of the current entry
I_CmsPrincipal principal = getCms().lookupPrincipal(entry.getPrincipal());
String name = (principal != null) ? principal.getName() : entry.getPrincipal().toString();
String type = getEntryType(entry.getFlags());
if (name == null) {
name = "";
}
// set the parameters for the hidden fields
setParamType(type);
setParamName(name);
// set id value for html attributes
String idValue = type + name + entry.getResource();
// get the localized type label
String typeLocalized = getTypesLocalized()[getEntryTypeInt(entry.getFlags())];
// determine the right image to display
String typeImg = getEntryType(entry.getFlags()).toLowerCase();
// get all permissions of the current entry
CmsPermissionSet permissions = entry.getPermissions();
// build String for disabled check boxes
String disabled = "";
if (!editable) {
disabled = " disabled=\"disabled\"";
}
// build the heading
result.append(dialogRow(HTML_START));
if (extendedView) {
// for extended view, add toggle symbol and link to output
result.append("<a href=\"javascript:toggleDetail('").append(idValue).append("');\">");
result.append("<img src=\"").append(getSkinUri()).append("commons/plus.png\" class=\"noborder\" id=\"ic-").append(
idValue).append("\"></a>");
}
result.append("<img src=\"").append(getSkinUri()).append("commons/");
result.append(typeImg);
result.append(".png\" class=\"noborder\" width=\"16\" height=\"16\" alt=\"");
result.append(typeLocalized);
result.append("\" title=\"");
result.append(typeLocalized);
result.append("\"> <span class=\"textbold\">");
result.append(name);
result.append("</span>");
if (extendedView) {
// for extended view, add short permissions and hidden div
result.append(" (").append(entry.getPermissions().getPermissionString()).append(entry.getResponsibleString()).append(")");
result.append(dialogRow(HTML_END));
// show the resource from which the ace is inherited if present
if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(inheritRes)) {
result.append("<div class=\"dialogpermissioninherit\">");
result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object[] {inheritRes}));
result.append("</div>\n");
}
result.append("<div id =\"").append(idValue).append("\" class=\"hide\">");
} else {
result.append(dialogRow(HTML_END));
}
result.append("<table class=\"dialogpermissiondetails\">\n");
// build the form depending on the editable flag
if (editable) {
result.append("<form action=\"").append(getDialogUri()).append(
"\" method=\"post\" class=\"nomargin\" name=\"set").append(idValue).append("\">\n");
// set parameters to show correct hidden input fields
setParamAction(DIALOG_SET);
result.append(paramsAsHidden());
} else {
result.append("<form class=\"nomargin\">\n");
}
// build headings for permission descriptions
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\"><span class=\"textbold\" unselectable=\"on\">");
result.append(key(Messages.GUI_PERMISSION_0)).append("</span></td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\"><span class=\"textbold\" unselectable=\"on\">");
result.append(key(Messages.GUI_PERMISSION_ALLOWED_0)).append("</span></td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\"><span class=\"textbold\" unselectable=\"on\">");
result.append(key(Messages.GUI_PERMISSION_DENIED_0)).append("</span></td>\n");
result.append("</tr>");
Iterator i = m_permissionKeys.iterator();
// show all possible permissions in the form
while (i.hasNext()) {
String key = (String)i.next();
int value = CmsPermissionSet.getPermissionValue(key);
String keyMessage = key(key);
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\">").append(keyMessage).append("</td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\"><input type=\"checkbox\" name=\"");
result.append(value).append(PERMISSION_ALLOW).append("\" value=\"").append(value).append("\"").append(
disabled);
if (isAllowed(permissions, value)) {
result.append(" checked=\"checked\"");
}
result.append("></td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\"><input type=\"checkbox\" name=\"");
result.append(value).append(PERMISSION_DENY).append("\" value=\"").append(value).append("\"").append(
disabled);
if (isDenied(permissions, value)) {
result.append(" checked=\"checked\"");
}
result.append("></td>\n");
result.append("</tr>\n");
}
// show overwrite checkbox and buttons only for editable entries
if (editable) {
// show owner checkbox
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_LABEL_RESPONSIBLE_0)).append(
"</td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\">");
result.append("<input type=\"checkbox\" name=\"").append(PARAM_RESPONSIBLE).append(
"\" value=\"true\"").append(disabled);
if (isResponsible(entry.getFlags())) {
result.append(" checked=\"checked\"");
}
result.append("></td>\n");
result.append("\t<td class=\"dialogpermissioncell\"> </td>\n");
result.append("</tr>\n");
// show overwrite inherited checkbox
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_OVERWRITE_INHERITED_0)).append(
"</td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\">");
result.append("<input type=\"checkbox\" name=\"").append(PARAM_OVERWRITEINHERITED).append(
"\" value=\"true\"").append(disabled);
if (isOverWritingInherited(entry.getFlags())) {
result.append(" checked=\"checked\"");
}
result.append("></td>\n");
result.append("\t<td class=\"dialogpermissioncell\"> </td>\n");
result.append("</tr>\n");
// show inherit permissions checkbox on folders
if (getInheritOption()) {
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_INHERIT_ON_SUBFOLDERS_0)).append(
"</td>\n");
result.append("\t<td class=\"dialogpermissioncell textcenter\">");
result.append("<input type=\"checkbox\" name=\"").append(PARAM_INHERIT).append("\" value=\"true\"").append(
disabled);
if (isInheriting(entry.getFlags())) {
result.append(" checked=\"checked\"");
}
result.append("></td>\n");
result.append("\t<td class=\"dialogpermissioncell\"> </td>\n");
result.append("</tr>\n");
}
// show "set" and "delete" buttons
result.append("<tr>\n");
result.append("\t<td> </td>\n");
result.append("\t<td class=\"textcenter\"><input class=\"dialogbutton\" type=\"submit\" value=\"").append(
key(Messages.GUI_LABEL_SET_0)).append("\"></form></td>\n");
result.append("\t<td class=\"textcenter\">\n");
// build the form for the "delete" button
result.append("\t\t<form class=\"nomargin\" action=\"").append(getDialogUri()).append(
"\" method=\"post\" name=\"delete").append(idValue).append("\">\n");
// set parameters to show correct hidden input fields
setParamAction(DIALOG_DELETE);
result.append(paramsAsHidden());
result.append("\t\t<input class=\"dialogbutton\" type=\"submit\" value=\"").append(key(Messages.GUI_LABEL_DELETE_0)).append(
"\">\n");
result.append("\t\t</form>\n");
result.append("\t</td>\n");
result.append("</tr>\n");
} else {
// close the form
result.append("</form>\n");
}
result.append("</table>\n");
if (extendedView) {
// close the hidden div for extended view
result.append("</div>");
}
return result;
}
/**
* @see #buildPermissionEntryForm(CmsAccessControlEntry, boolean, boolean, String)
*
* @param id the UUID of the principal of the permission set
* @param curSet the current permission set
* @param editable boolean to determine if the form is editable
* @param extendedView boolean to determine if the view is selectable with DHTML
* @return String with HTML code of the form
*/
private StringBuffer buildPermissionEntryForm(
CmsUUID id,
CmsPermissionSet curSet,
boolean editable,
boolean extendedView) {
String fileName = getParamResource();
int flags = 0;
try {
// TODO: a more elegant way to determine user/group of current id
try {
getCms().readGroup(id);
flags = CmsAccessControlEntry.ACCESS_FLAGS_GROUP;
} catch (CmsException e) {
try {
getCms().readUser(id);
flags = CmsAccessControlEntry.ACCESS_FLAGS_USER;
} catch (CmsException exc) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
}
CmsResource res = getCms().readResource(fileName, CmsResourceFilter.ALL);
CmsAccessControlEntry entry = new CmsAccessControlEntry(res.getResourceId(), id, curSet, flags);
return buildPermissionEntryForm(entry, editable, extendedView, null);
} catch (CmsException e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
return new StringBuffer("");
}
}
/**
* Builds a StringBuffer with HTML code for the access control entries of a resource.<p>
*
* @param entries all access control entries for the resource
* @return StringBuffer with HTML code for all entries
*/
private StringBuffer buildResourceList(ArrayList entries) {
StringBuffer result = new StringBuffer(256);
Iterator i = entries.iterator();
boolean hasEntries = i.hasNext();
if (hasEntries || !getInheritOption()) {
// create headline for resource entries
result.append(dialogSubheadline(key(Messages.GUI_PERMISSION_TITLE_0)));
}
// create the internal form
result.append(buildInternalForm());
if (hasEntries) {
// only create output if entries are present
result.append(dialogSpacer());
// open white box
result.append(dialogWhiteBox(HTML_START));
// list all entries
while (i.hasNext()) {
CmsAccessControlEntry curEntry = (CmsAccessControlEntry)i.next();
result.append(buildPermissionEntryForm(curEntry, this.getEditable(), false, null));
if (i.hasNext()) {
result.append(dialogSeparator());
}
}
// close white box
result.append(dialogWhiteBox(HTML_END));
}
return result;
}
/**
* Builds a String with HTML code to display the responsibles of a resource.<p>
*
* @param show true the responsible list is open
* @return HTML code for the responsibles of the current resource
*/
public String buildResponsibleList(boolean show) {
List parentResources = new ArrayList();
Map responsibles = new HashMap();
CmsObject cms = getCms();
String resourceSitePath = cms.getRequestContext().removeSiteRoot(getParamResource());
try {
// get all parent folders of the current file
parentResources = cms.readPath(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION);
} catch (CmsException e) {
// can usually be ignored
if (CmsChacc.LOG.isInfoEnabled()) {
CmsChacc.LOG.info(e.getLocalizedMessage());
}
}
Iterator i = parentResources.iterator();
while (i.hasNext()) {
CmsResource resource = (CmsResource)i.next();
try {
String sitePath = resource.getRootPath();
Iterator entries = cms.getAccessControlEntries(cms.getRequestContext().removeSiteRoot(sitePath), false).iterator();
while (entries.hasNext()) {
CmsAccessControlEntry ace = (CmsAccessControlEntry)entries.next();
if (ace.isResponsible()) {
I_CmsPrincipal principal = cms.lookupPrincipal(ace.getPrincipal());
responsibles.put(principal, sitePath);
}
}
} catch (CmsException e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
}
if (responsibles.size() == 0) {
return key(Messages.GUI_AVAILABILITY_NO_RESPONSIBLES_0);
}
StringBuffer result = new StringBuffer(512);
result.append(dialogToggleStart(key(Messages.GUI_AVAILABILITY_RESPONSIBLES_0), "responsibles", show));
result.append(dialogWhiteBoxStart());
i = responsibles.keySet().iterator();
while (i.hasNext()) {
I_CmsPrincipal principal = (I_CmsPrincipal)i.next();
String image = "user.png";
if (principal instanceof CmsGroup) {
image = "group.png";
}
result.append("<div class=\"dialogrow\"><img src=\"");
result.append(getSkinUri());
result.append("commons/");
result.append(image);
result.append("\" class=\"noborder\" width=\"16\" height=\"16\" alt=\"Group\" title=\"Group\"> <span class=\"textbold\">");
result.append(principal.getName());
result.append("</span>");
if ("long".equals(getSettings().getPermissionDetailView())) {
result.append("<div class=\"dialogpermissioninherit\">");
String resourceName = ((String)responsibles.get(principal));
if (!resourceSitePath.equals(resourceName)) {
result.append(key(Messages.GUI_PERMISSION_INHERITED_FROM_1, new Object[] {resourceName}));
}
result.append("</div>");
}
result.append("</div>\n");
}
result.append(dialogWhiteBoxEnd());
result.append("</div>\n");
return result.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -