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

📄 cmspropertychange.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/CmsPropertyChange.java,v $
 * Date   : $Date: 2006/03/31 13:59:16 $
 * Version: $Revision: 1.14 $
 *
 * 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.tools.content;

import org.opencms.file.CmsObject;
import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.i18n.CmsEncoder;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

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 the change property values dialog.<p>
 *
 * @author  Andreas Zahner 
 * 
 * @version $Revision: 1.14 $ 
 * 
 * @since 6.0.0 
 */
public class CmsPropertyChange extends CmsDialog {

    /** Value for the action: show result. */
    public static final int ACTION_SHOWRESULT = 100;

    /** Request parameter value for the action: show result. */
    public static final String DIALOG_SHOWRESULT = "showresult";

    /** The dialog type. */
    public static final String DIALOG_TYPE = "propertychange";
    /** Request parameter name for the property name. */
    public static final String PARAM_NEWVALUE = "newvalue";
    /** Request parameter name for the property name. */
    public static final String PARAM_OLDVALUE = "oldvalue";
    /** Request parameter name for the property name. */
    public static final String PARAM_PROPERTYNAME = "propertyname";
    /** Request parameter name for the property name. */
    public static final String PARAM_RECURSIVE = "recursive";

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

    private List m_changedResources;

    /** The error message. */
    private String m_errorMessage;

    private String m_paramNewValue;
    private String m_paramOldValue;
    private String m_paramPropertyName;
    private String m_paramRecursive;

    private boolean m_validationErrors;

    /**
     * Public constructor with JSP action element.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsPropertyChange(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 CmsPropertyChange(PageContext context, HttpServletRequest req, HttpServletResponse res) {

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

    /**
     * Builds the html for the property definition select box.<p>
     * 
     * @param cms the CmsObject
     * @param selectValue the localized value for the "Please select" option
     * @param attributes optional attributes for the &lt;select&gt; tag
     * @param selectedValue the value that is currently selected
     * @return the html for the property definition select box
     */
    public static String buildSelectProperty(CmsObject cms, String selectValue, String attributes, String selectedValue) {

        List propertyDef = new ArrayList();
        try {
            // get all property definitions
            propertyDef = cms.readAllPropertyDefinitions();
        } catch (CmsException e) {
            // should usually never happen
            if (LOG.isInfoEnabled()) {
                LOG.info(e);
            }
        }

        int propertyCount = propertyDef.size();
        List options = new ArrayList(propertyCount + 1);
        List values = new ArrayList(propertyCount + 1);
        options.add(CmsEncoder.escapeXml(selectValue));
        values.add("");
        int selectedIndex = 0;
        int count = 1;

        for (int i = 0; i < propertyCount; i++) {
            // loop property definitions and get definition name
            CmsPropertyDefinition currDef = (CmsPropertyDefinition)propertyDef.get(i);
            if (currDef.getName().equals(selectedValue)) {
                selectedIndex = count;
            }
            options.add(CmsEncoder.escapeXml(currDef.getName()));
            values.add(CmsEncoder.escapeXml(currDef.getName()));
            count += 1;
        }

        CmsDialog wp = new CmsDialog(null);
        return wp.buildSelect(attributes, options, values, selectedIndex);
    }

    /**
     * Changes the property values on the specified resources.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionChange() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        try {
            boolean recursive = Boolean.valueOf(getParamRecursive()).booleanValue();
            if (performChangeOperation(recursive)) {
                // if no exception is caused and "true" is returned change property operation was successful
                setAction(ACTION_SHOWRESULT);
            } else {
                // "false" returned, display "please wait" screen
                getJsp().include(FILE_DIALOG_SCREEN_WAIT);
            }
        } catch (Throwable e) {
            // error while changing property values, show error dialog
            includeErrorpage(this, e);

        }
    }

    /**
     * Builds the html for the result list of resources where the property was changed.<p>
     * 
     * @return the html for the result list
     */
    public String buildResultList() {

        StringBuffer result = new StringBuffer(16);
        if (getChangedResources() != null && getChangedResources().size() > 0) {
            // at least one resource property value has been changed, show list
            for (int i = 0; i < getChangedResources().size(); i++) {
                CmsResource res = (CmsResource)getChangedResources().get(i);
                String resName = getCms().getSitePath(res);
                result.append(resName);
                result.append("<br>\n");
            }
        } else {
            // nothing was changed, show message
            result.append(Messages.get().getBundle(getLocale()).key(Messages.GUI_INPUT_PROPERTYCHANGE_RESULT_NONE_0));
        }
        return result.toString();
    }

    /**
     * Builds the html for the property definition select box.<p>
     * 
     * @param attributes optional attributes for the &lt;select&gt; tag
     * @return the html for the property definition select box
     */
    public String buildSelectProperty(String attributes) {

        return buildSelectProperty(
            getCms(),
            Messages.get().getBundle(getLocale()).key(Messages.GUI_PLEASE_SELECT_0),
            attributes,
            getParamPropertyName());
    }

    /**
     * Returns the error message.<p>
     *
     * @return the error message
     */
    public String getErrorMessage() {

        if (CmsStringUtil.isEmpty(m_errorMessage)) {
            return "";
        }

        return m_errorMessage;
    }

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

        if (m_paramNewValue != null) {
            return m_paramNewValue;

⌨️ 快捷键说明

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