⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmschacc.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            while (i.hasNext()) {
                CmsAccessControlEntry curEntry = (CmsAccessControlEntry)i.next();
                // build the list with enabled extended view and resource name
                result.append(buildPermissionEntryForm(curEntry, false, true, getConnectedResource(curEntry, parents)));
            }
        } else {
            // show the short view, use an ACL to build the list
            try {
                // get the inherited ACL of the parent folder 
                CmsAccessControlList acList = getCms().getAccessControlList(
                    CmsResource.getParentFolder(getParamResource()),
                    false);
                Iterator i = acList.getPrincipals().iterator();
                while (i.hasNext()) {
                    CmsUUID principalId = (CmsUUID)i.next();
                    if (!principalId.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID)) {
                        CmsPermissionSet permissions = acList.getPermissions(principalId);
                        // build the list with enabled extended view only
                        result.append(buildPermissionEntryForm(principalId, permissions, false, true));
                    }
                }
            } catch (CmsException e) {
                // can usually be ignored
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
            }
        }
        return result;
    }

    /**
     * Builds a String with HTML code to display the form to add a new access control entry for the current resource.<p>
     * 
     * @return HTML String with the form
     */
    private String buildInternalForm() {

        StringBuffer result = new StringBuffer(128);

        CmsResource resource = null;
        boolean internal = false;

        // try to read the internal flag from the resource
        try {
            resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
            internal = resource.isInternal();
        } catch (CmsException e) {
            // an error occurred reading the resource 
            LOG.error(e.getLocalizedMessage());
        }

        if ((resource != null) && (resource.isFile())) {
            // only show internal check box on files
            result.append("<form action=\"").append(getDialogUri()).append(
                "\" method=\"post\" name=\"internal\" class=\"nomargin\">\n");
            result.append("<table border=\"0\" width=\"100%\">\n");
            result.append("<tr>\n");
            result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_INTERNAL_0));
            result.append(" <input type=\"checkbox\" name=\"");
            result.append(PARAM_INTERNAL);
            result.append("\" value=\"true\"");
            if (internal) {
                result.append(" checked=\"checked\"");
            }
            if (!getEditable()) {
                result.append(" disabled=\"disabled\"");
            }
            result.append(" ></td>\n");
            if (getEditable()) {
                result.append("<td><input  type=\"submit\" class=\"dialogbutton\" value=\"").append(
                    key(Messages.GUI_LABEL_SET_0)).append("\">");
            }
            result.append("</td>\n");
            result.append("</tr>\n");
            result.append("</table>\n");
            setParamAction(DIALOG_INTERNALUSE);
            setParamType(null);
            setParamName(null);
            result.append(paramsAsHidden());
            result.append("</form>\n");
        }
        return result.toString();

    }

    /**
     * Creates an HTML input form for the current access control entry.<p>
     * 
     * @param entry the current access control entry
     * @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 id = (principal != null) ? principal.getName() : entry.getPrincipal().toString();
        String name;
        String ou = null;
        int flags = 0;
        if (principal instanceof CmsGroup) {
            name = key(org.opencms.security.Messages.GUI_ORGUNIT_DISPLAY_NAME_2, new Object[] {
                ((CmsGroup)principal).getDescription(getLocale()),
                principal.getSimpleName()});
            ou = CmsOrganizationalUnit.getParentFqn(id);
            flags = CmsAccessControlEntry.ACCESS_FLAGS_GROUP;
        } else if (principal instanceof CmsUser) {
            name = ((CmsUser)principal).getFullName();
            ou = CmsOrganizationalUnit.getParentFqn(id);
            flags = CmsAccessControlEntry.ACCESS_FLAGS_USER;
        } else if ((id != null) && id.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString())) {
            name = key(Messages.GUI_LABEL_ALLOTHERS_0);
            flags = CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS;
        } else if ((id != null) && id.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID.toString())) {
            name = key(Messages.GUI_LABEL_OVERWRITEALL_0);
            flags = CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL;
        } else {
            // check if it is the case of a role
            CmsRole role = CmsRole.valueOfId(entry.getPrincipal());
            if (role != null) {
                name = role.getName(getLocale());
                id = role.getRoleName();
                flags = CmsAccessControlEntry.ACCESS_FLAGS_ROLE;
            } else {
                name = entry.getPrincipal().toString();
            }
        }

        if ((flags > 0) && ((entry.getFlags() & flags) == 0)) {
            // the flag is set to the wrong principal type
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle(getLocale()).key(Messages.ERR_INVALID_ACE_1, entry.toString()));
            }
            entry = new CmsAccessControlEntry(
                entry.getResource(),
                entry.getPrincipal(),
                entry.getAllowedPermissions(),
                entry.getDeniedPermissions(),
                (entry.getFlags() | flags));
        } else if (entry.getFlags() < CmsAccessControlEntry.ACCESS_FLAGS_USER) {
            // the flag is set to NO principal type
            if (LOG.isErrorEnabled()) {
                LOG.error(Messages.get().getBundle(getLocale()).key(Messages.ERR_INVALID_ACE_1, entry.toString()));
            }
            entry = new CmsAccessControlEntry(
                entry.getResource(),
                entry.getPrincipal(),
                entry.getAllowedPermissions(),
                entry.getDeniedPermissions(),
                (entry.getFlags() | CmsAccessControlEntry.ACCESS_FLAGS_GROUP));
        }

        String type = getEntryType(entry.getFlags(), false);

        if (id == null) {
            id = "";
        }

        // set the parameters for the hidden fields
        setParamType(type);
        setParamName(id);

        // set id value for html attributes
        String idValue = type + id + entry.getResource();

        // get the localized type label
        int typeInt = getEntryTypeInt(entry.getFlags());
        String typeLocalized = UNKNOWN_TYPE;
        if (typeInt >= 0) {
            typeLocalized = getTypesLocalized()[typeInt];
        }

        // determine the right image to display
        String typeImg = getTypes(true)[0];
        if (typeInt >= 0) {
            typeImg = getEntryType(entry.getFlags(), true).toLowerCase();
        }

        // get all permissions of the current entry
        CmsPermissionSet permissions = entry.getPermissions();

        // build String for disabled check boxes
        String disabled = "";
        if (!editable || (typeInt < 0)) {
            disabled = " disabled=\"disabled\"";
        }

        // build the heading
        if (!id.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID.toString())) {
            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>");
            } else {
                result.append("<img src='").append(getSkinUri()).append(
                    "explorer/project_none.gif' class='noborder' width='16' height='16' >");
            }
            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("\">&nbsp;<span class=\"textbold\">");
            result.append(name);
            result.append("</span>");
            if (!id.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString())) {
                if (extendedView) {
                    // for extended view, add short permissions
                    result.append("&nbsp;(").append(entry.getPermissions().getPermissionString()).append(")");
                }
                try {
                    if ((ou != null)
                        && (OpenCms.getOrgUnitManager().getOrganizationalUnits(getCms(), "", true).size() > 1)) {
                        result.append("<br>");
                        result.append("<img src='").append(getSkinUri()).append(
                            "explorer/project_none.gif' class='noborder' width='16' height='16' >");
                        result.append("<img src='").append(getSkinUri()).append(
                            "explorer/project_none.gif' class='noborder' width='16' height='16' >");
                        result.append("&nbsp;");
                        try {
                            result.append(OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), ou).getDisplayName(
                                getLocale()));
                        } catch (CmsException e) {
                            result.append(ou);
                        }
                    }
                } catch (CmsException e) {
                    // should never happen
                    if (LOG.isInfoEnabled()) {
                        LOG.info(e.getLocalizedMessage());
                    }
                }
            }
            result.append(dialogRow(HTML_END));
            if (extendedView) {
                // show the resource from which the ace is inherited if present
                if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(inheritRes)) {
                    result.append("<div class=\"dialogpermissioninherit\">");
                    result.append("<img src='").append(getSkinUri()).append(
                        "explorer/project_none.gif' class='noborder' width='16' height='16' >");
                    result.append("&nbsp;");
                    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\">");
            }
            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 check box and buttons only for editable entries
            if (editable) {
                // do not show the responsible option for the 'all others' ace
                if (!id.equals(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID.toString())) {
                    // show owner check box
                    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())) {
      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -