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

📄 cmspropertyadvanced.java

📁 找了很久才找到到源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            if (resource.isFolder()) {
                m_isFolder = true;
                if (!getParamResource().endsWith("/")) {
                    // append folder separator to resource name
                    setParamResource(getParamResource() + "/");
                }
            }
        } catch (CmsException e) {
            // error reading resource, log the error
            LOG.error(e.getLocalizedMessage());
        }

        // set the dialog type
        setParamDialogtype(DIALOG_TYPE);
        boolean isPopup = Boolean.valueOf(getParamIsPopup()).booleanValue();
        // set the action for the JSP switch 
        if (DIALOG_SHOW_DEFINE.equals(getParamAction())) {
            setAction(ACTION_SHOW_DEFINE);
            setParamTitle(key(Messages.GUI_PROPERTY_NEW_DEF_1, new Object[] {CmsResource.getName(getParamResource())}));
        } else if (DIALOG_SAVE_EDIT.equals(getParamAction())) {
            if (isPopup) {
                setAction(ACTION_CLOSEPOPUP_SAVE);
            } else {
                setAction(ACTION_SAVE_EDIT);
            }
        } else if (DIALOG_SAVE_DEFINE.equals(getParamAction())) {
            setAction(ACTION_SAVE_DEFINE);
        } else if (DIALOG_CANCEL.equals(getParamAction())) {
            if (isPopup) {
                setAction(ACTION_CLOSEPOPUP);
            } else {
                setAction(ACTION_CANCEL);
            }
        } else {
            // set the default action: show edit form  
            setAction(ACTION_DEFAULT);
            if (!isEditable()) {
                setParamTitle(key(Messages.GUI_PROPERTIES_OF_1, new Object[] {CmsResource.getName(getParamResource())}));
            } else {
                setParamTitle(key(
                    Messages.GUI_PROPERTIES_EDIT_1,
                    new Object[] {CmsResource.getName(getParamResource())}));
            }
            // check if the user switched a tab
            m_tabSwitched = false;
            if (DIALOG_SWITCHTAB.equals(getParamAction())) {
                m_tabSwitched = true;
            }
        }
    }

    /**
     * Returns whether the properties are editable or not depending on the lock state of the resource and the current project.<p>
     * 
     * @return true if properties are editable, otherwise false
     */
    protected boolean isEditable() {

        if (m_isEditable == null) {

            if (getCms().getRequestContext().currentProject().isOnlineProject()
                || !getCms().isInsideCurrentProject(getParamResource())) {
                // we are in the online project or resource does not belong to project, no editing allowed
                m_isEditable = Boolean.FALSE;

            } else {
                // we are in an offline project

                // check permissions
                if (!checkResourcePermissions(CmsPermissionSet.ACCESS_WRITE, false)) {
                    getSettings().setErrorMessage(null);
                    m_isEditable = Boolean.FALSE;
                    return m_isEditable.booleanValue();
                }

                // check lock state
                String resourceName = getParamResource();
                CmsResource file = null;
                CmsLock lock = null;
                try {
                    file = getCms().readResource(resourceName, CmsResourceFilter.ALL);
                    // check if resource is a folder
                    if (file.isFolder() && !resourceName.endsWith("/")) {
                        resourceName += "/";
                    }
                } catch (CmsException e) {
                    // should usually never happen
                    if (LOG.isInfoEnabled()) {
                        LOG.info(e.getLocalizedMessage());
                    }
                }

                try {
                    // get the lock for the resource
                    lock = getCms().getLock(file);
                } catch (CmsException e) {
                    lock = CmsLock.getNullLock();

                    if (LOG.isErrorEnabled()) {
                        LOG.error(e.getLocalizedMessage(), e);
                    }
                }

                if (!lock.isNullLock()) {
                    // determine if resource is editable...
                    if (lock.isExclusiveOwnedBy(getCms().getRequestContext().currentUser())
                        || (lock.isDirectlyInherited() && lock.isOwnedBy(getCms().getRequestContext().currentUser()))) {
                        // lock is exclusive and belongs to the current user
                        if (lock.isInProject(getCms().getRequestContext().currentProject())
                            || Boolean.valueOf(getParamUsetempfileproject()).booleanValue()) {
                            // resource is locked in the current project or the tempfileproject is used
                            m_isEditable = Boolean.TRUE;
                            return m_isEditable.booleanValue();
                        }
                    }
                } else if (OpenCms.getWorkplaceManager().autoLockResources()) {
                    if ((file == null) || file.isFolder()) {
                        // check locked resources in folder
                        try {
                            List lockedResources = getCms().getLockedResources(
                                resourceName,
                                CmsLockFilter.FILTER_ALL.filterNotOwnedByUserId(getCms().getRequestContext().currentUser().getId()));
                            if (!lockedResources.isEmpty()) {
                                m_isEditable = Boolean.FALSE;
                                return m_isEditable.booleanValue();
                            }
                        } catch (CmsException e1) {
                            // should usually never happen
                            if (LOG.isErrorEnabled()) {
                                LOG.error(e1.getLocalizedMessage(), e1);
                            }
                        }
                    }
                    m_isEditable = Boolean.TRUE;
                    return m_isEditable.booleanValue();
                }
                // lock is null or belongs to other user and/or project, properties are not editable
                m_isEditable = Boolean.FALSE;
            }
        }
        return m_isEditable.booleanValue();
    }

    /**
     * Performs the definition of a new property.<p>
     * 
     * @return true, if the new property was created, otherwise false
     * @throws CmsException if creation is not successful
     */
    private boolean performDefineOperation() throws CmsException {

        boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
        try {
            if (useTempfileProject) {
                switchToTempProject();
            }
            String newProperty = getParamNewproperty();
            if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(newProperty)) {
                getCms().createPropertyDefinition(newProperty);
                return true;
            } else {
                throw new CmsException(Messages.get().container(Messages.ERR_INVALID_PROP_0));
            }
        } finally {
            if (useTempfileProject) {
                switchToCurrentProject();
            }
        }
    }

    /**
     * Performs the editing of the resources properties.<p>
     * 
     * @param request the HttpServletRequest
     * @return true, if the properties were successfully changed, otherwise false
     * @throws CmsException if editing is not successful
     */
    private boolean performDialogOperation(HttpServletRequest request) throws CmsException {

        List propertyDef = getCms().readAllPropertyDefinitions();
        boolean useTempfileProject = Boolean.valueOf(getParamUsetempfileproject()).booleanValue();
        try {
            if (useTempfileProject) {
                switchToTempProject();
            }
            Map activeProperties = getActiveProperties();
            String activeTab = getActiveTabName();
            List propertiesToWrite = new ArrayList();

            // check all property definitions of the resource for new values
            Iterator i = propertyDef.iterator();
            while (i.hasNext()) {
                CmsPropertyDefinition curPropDef = (CmsPropertyDefinition)i.next();
                String propName = CmsEncoder.escapeXml(curPropDef.getName());
                String valueStructure = null;
                String valueResource = null;

                if (key(Messages.GUI_PROPERTIES_INDIVIDUAL_0).equals(activeTab)) {
                    // get parameters from the structure tab
                    valueStructure = request.getParameter(PREFIX_VALUE + propName);
                    valueResource = request.getParameter(PREFIX_RESOURCE + propName);
                    if ((valueStructure != null)
                        && !"".equals(valueStructure.trim())
                        && valueStructure.equals(valueResource)) {
                        // the resource value was shown/entered in input field, set structure value to empty String
                        valueStructure = "";
                    }
                } else {
                    // get parameters from the resource tab
                    valueStructure = request.getParameter(PREFIX_STRUCTURE + propName);
                    valueResource = request.getParameter(PREFIX_VALUE + propName);
                }

                // check values for blanks and null
                if (valueStructure != null) {
                    valueStructure = valueStructure.trim();
                }

                if (valueResource != null) {
                    valueResource = valueResource.trim();
                }

                // create new CmsProperty object to store
                CmsProperty newProperty = new CmsProperty();
                newProperty.setName(curPropDef.getName());
                newProperty.setStructureValue(valueStructure);
                newProperty.setResourceValue(valueResource);

                // get the old property values
                CmsProperty oldProperty = (CmsProperty)activeProperties.get(curPropDef.getName());
                if (oldProperty == null) {
                    // property was not set, create new empty property object
                    oldProperty = new CmsProperty();
                    oldProperty.setName(curPropDef.getName());
                }

                boolean writeStructureValue = false;
                boolean writeResourceValue = false;
                String oldValue = oldProperty.getStructureValue();
                String newValue = newProperty.getStructureValue();

                // write the structure value if the existing structure value is not null and we want to delete the structure value
                writeStructureValue = ((oldValue != null) && newProperty.isDeleteStructureValue());
                // or if we want to write a value which is neither the delete value or an empty value
                writeStructureValue |= !newValue.equals(oldValue)
                    && !"".equalsIgnoreCase(newValue)
                    && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
                // set the structure value explicitly to null to leave it as is in the database
                if (!writeStructureValue) {
                    newProperty.setStructureValue(null);
                }

                oldValue = oldProperty.getResourceValue();
                newValue = newProperty.getResourceValue();

                // write the resource value if the existing resource value is not null and we want to delete the resource value
                writeResourceValue = ((oldValue != null) && newProperty.isDeleteResourceValue());
                // or if we want to write a value which is neither the delete value or an empty value
                writeResourceValue |= !newValue.equals(oldValue)
                    && !"".equalsIgnoreCase(newValue)
                    && !CmsProperty.DELETE_VALUE.equalsIgnoreCase(newValue);
                // set the resource value explicitly to null to leave it as is in the database
                if (!writeResourceValue) {
                    newProperty.setResourceValue(null);
                }

                if (writeStructureValue || writeResourceValue) {
                    // add property to list only if property values have changed
                    propertiesToWrite.add(newProperty);
                }
            }
            if (propertiesToWrite.size() > 0) {
                // lock resource if autolock is enabled
                checkLock(getParamResource());
                //write the new property values
                getCms().writePropertyObjects(getParamResource(), propertiesToWrite);
            }
        } finally {
            if (useTempfileProject) {
                switchToCurrentProject();
            }
        }
        return true;
    }

    /**
     * Sets the value of the dialogmode parameter.<p>
     * 
     * @param value the value to set
     */
    public void setParamDialogmode(String value) {

        m_paramDialogMode = value;
    }

    /**
     * Sets the paramIndexPageType.<p>
     *
     * @param paramIndexPageType the paramIndexPageType to set
     */
    public void setParamIndexPageType(String paramIndexPageType) {

        m_paramIndexPageType = paramIndexPageType;
    }

    /**
     * Sets the value of the new property parameter.<p>
     * 
     * @param value the value to set
     */
    public void setParamNewproperty(String value) {

        m_paramNewproperty = value;
    }

    /**
     * Sets the value of the usetempfileproject parameter.<p>
     * 
     * @param value the value to set
     */
    public void setParamUsetempfileproject(String value) {

        m_paramUseTempfileProject = value;
    }

}

⌨️ 快捷键说明

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