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

📄 cmssecure.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsSecure.java,v $
 * Date   : $Date: 2006/04/28 15:20:57 $
 * Version: $Revision: 1.31 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.commons;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPermissionSet;
import org.opencms.site.CmsSite;
import org.opencms.site.CmsSiteManager;
import org.opencms.staticexport.CmsLinkManager;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplaceSettings;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;

/**
 * Provides methods for building the security and export settings dialog.<p> 
 * 
 * The following files use this class:
 * <ul>
 * <li>/commons/secure.jsp
 * </ul>
 * <p>
 *
 * @author  Jan Baudisch 
 * 
 * @version $Revision: 1.31 $ 
 * 
 * @since 6.0.0 
 */
public class CmsSecure extends CmsDialog {

    /** Value for the action: change the security and export setting. */
    public static final int ACTION_CHSECEXP = 100;

    /** The dialog type. */
    public static final String DIALOG_TYPE = "secure";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsSecure.class);

    /** Export parameter. */
    private String m_paramExport;

    /** Exportname parameter. */
    private String m_paramExportname;

    /** Intern parameter. */
    private String m_paramIntern;

    /** Secure parameter. */
    private String m_paramSecure;

    /**
     * Public constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsSecure(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsSecure(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * Performs the Security and Export Change.<p>
     * 
     * @throws JspException if including a JSP subelement is not successful
     */
    public void actionChangeSecureExport() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);

        String filename = getParamResource();

        try {
            // lock resource if autolock is enabled
            checkLock(getParamResource());

            // write the properties
            writeProperty(CmsPropertyDefinition.PROPERTY_EXPORT, getParamExport());
            writeProperty(CmsPropertyDefinition.PROPERTY_EXPORTNAME, getParamExportname());
            writeProperty(CmsPropertyDefinition.PROPERTY_SECURE, getParamSecure());

            // change the flag of the resource so that it is internal            
            CmsResource resource = getCms().readResource(filename, CmsResourceFilter.IGNORE_EXPIRATION);
            if (resource.isInternal() && !Boolean.valueOf(getParamIntern()).booleanValue()) {
                getCms().chflags(filename, resource.getFlags() & (~CmsResource.FLAG_INTERNAL));
            } else if (!resource.isInternal() && Boolean.valueOf(getParamIntern()).booleanValue()) {
                getCms().chflags(filename, resource.getFlags() | CmsResource.FLAG_INTERNAL);
            }

            actionCloseDialog();
        } catch (Throwable e) {
            // error during change of secure settings, show error dialog
            includeErrorpage(this, e);
        }

    }

    /**
     * Builds the radio input to set the export and secure property.
     *
     * @param propName the name of the property to build the radio input for
     * @return html for the radio input
     * @throws CmsException if the reading of a property fails
     */
    public String buildRadio(String propName) throws CmsException {

        String propVal = readProperty(propName);
        StringBuffer result = new StringBuffer("<table border=\"0\"><tr>");
        result.append("<td><input type=\"radio\" value=\"true\" onClick=\"checkNoIntern()\" name=\"").append(propName).append(
            "\" ").append(Boolean.valueOf(propVal).booleanValue() ? "checked=\"checked\"" : "").append("/></td><td id=\"tablelabel\">").append(
            key(Messages.GUI_LABEL_TRUE_0)).append("</td>");
        result.append("<td><input type=\"radio\" value=\"false\" onClick=\"checkNoIntern()\" name=\"").append(propName).append(
            "\" ").append(Boolean.valueOf(propVal).booleanValue() ? "" : "checked=\"checked\"").append("/></td><td id=\"tablelabel\">").append(
            key(Messages.GUI_LABEL_FALSE_0)).append("</td>");
        result.append("<td><input type=\"radio\" value=\"\" onClick=\"checkNoIntern()\" name=\"").append(propName).append(
            "\" ").append(CmsStringUtil.isEmpty(propVal) ? "checked=\"checked\"" : "").append(
            "/></td><td id=\"tablelabel\">").append(getPropertyInheritanceInfo(propName)).append("</td></tr></table>");
        return result.toString();
    }

    /**
     * Returns the value of the export parameter.<p>
     * 
     * @return the value of the export parameter
     */
    public String getParamExport() {

        return m_paramExport;
    }

    /**
     * Returns the value of the exportname parameter.<p>
     * 
     * @return the value of the exportname parameter
     */
    public String getParamExportname() {

        return m_paramExportname;
    }

    /**
     * Returns the value of the intern parameter.<p>
     * 
     * @return the value of the intern parameter
     */
    public String getParamIntern() {

        return m_paramIntern;
    }

    /**
     * Returns the value of the secure parameter.<p>
     * 
     * @return the value of the secure parameter
     */
    public String getParamSecure() {

        return m_paramSecure;
    }

    /**
     * Returns the information from which the property is inherited.<p>
     * 
     * @param propName the name of the property
     * @return a String containing the information from which the property is inherited and inherited value
     * @throws CmsException if the reading of the Property fails 
     */
    public String getPropertyInheritanceInfo(String propName) throws CmsException {

        String folderName = CmsResource.getParentFolder(getParamResource());
        String folderPropVal = null;
        while (CmsStringUtil.isNotEmpty(folderName)) {
            CmsProperty prop = getCms().readPropertyObject(folderName, propName, false);
            folderPropVal = prop.getValue();
            if (CmsStringUtil.isNotEmpty(folderPropVal)) {
                break;
            }
            folderName = CmsResource.getParentFolder(folderName);
        }

        if (CmsStringUtil.isNotEmpty(folderPropVal)) {
            return key(Messages.GUI_SECURE_INHERIT_FROM_2, new Object[] {folderPropVal, folderName});
        } else {
            return key(Messages.GUI_SECURE_NOT_SET_0);
        }
    }

    /**
     * Returns the path under which the resource is accessable.
     *  
     * @return the path under which the resource is accessable
     */
    public String getResourceUrl() {

        CmsObject cms = getCms();

⌨️ 快捷键说明

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