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

📄 cmscontentcheckproperty.java

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

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.tools.I_CmsToolHandler;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;

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

import org.apache.commons.logging.Log;

/**
 * This implementation of the I_CmsContentCheck interface implments a check for 
 * resource properties.<p>
 * 
 * The following items can be configured and checked:
 * <ul>
 * <li>Property not set</li>
 * <li>Property value contains filename</li>
 * <li>Property value is shorter than a minimum size</li>
 * <li>Property value contains a given value (with RegEx)</li>
 * <li>Property value does not contain a given value (with RegEx)</li>
 * </ul>
 *
 * @author  Michael Emmerich
 * 
 * @version $Revision: 1.3 $ 
 * 
 * @since 6.1.2
 */
public class CmsContentCheckProperty extends A_CmsContentCheck implements I_CmsContentCheck, I_CmsToolHandler {

    /** Path to the configuration file. */
    private static final String CONFIGURATION = CmsContentCheck.VFS_PATH_PLUGIN_FOLDER
        + "propertycheck/configuration.xml";

    /** Name of the dialog parameter. */
    private static final String DIALOG_PARAMETER = "property";

    /** Path to the configuration icon. */
    private static final String ICONPATH = "tools/contenttools/icons/big/contentcheck_property_configuration.png";

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

    /** Name of this content check. */
    private static final String NAME = "Property Check";

    /** The xpath for the empty configuration. */
    private static final String XPATH_EMPTY = "empty";

    /** The xpath for the error configuration. */
    private static final String XPATH_ERROR = "error";

    /** The xpath for the filename configuration. */
    private static final String XPATH_FILENAME = "filename";

    /** The xpath for the length configuration. */
    private static final String XPATH_LENGTH = "length";

    /** The xpath for the propertyname configuration. */
    private static final String XPATH_PROPERTYNAME = "propertyname";

    /** The xpath for the type configuration. */
    private static final String XPATH_TYPE = "type";

    /** The xpath for the value configuration. */
    private static final String XPATH_VALUE = "value";

    /** The xpath for the warning configuration. */
    private static final String XPATH_WARNUING = "warning";

    /** The active flag, signaling if this content check is active. */
    private boolean m_active = true;

    /** The CmsObject. */
    private CmsObject m_cms;

    /** List of all configured error checks. */
    private List m_configuredErrorChecks = null;

    /** List of all configured warning checks. */
    private List m_configuredWarningChecks = null;

    /** Locale to be used to extract xml content. */
    private Locale m_locale;

    /**
     * 
     * @see org.opencms.workplace.tools.content.check.I_CmsContentCheck#executeContentCheck(org.opencms.file.CmsObject, org.opencms.workplace.tools.content.check.CmsContentCheckResource)
     */
    public CmsContentCheckResource executeContentCheck(CmsObject cms, CmsContentCheckResource testResource)
    throws CmsException {

        getConfiguration();
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(
                Messages.LOG_DEBUG_PROPERTY_CONFIGURED_ERRORS_2,
                new Object[] {testResource.getResourceName(), m_configuredErrorChecks}));
        }
        // check for errors
        List errors = processProperties(m_configuredErrorChecks, testResource);
        if (errors.size() > 0) {
            testResource.addErrors(errors);
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug(Messages.get().getBundle().key(
                Messages.LOG_DEBUG_PROPERTY_CONFIGURED_WARNINGS_2,
                testResource.getResourceName(),
                m_configuredErrorChecks));
        }
        // check for warnings
        List warnings = processProperties(m_configuredWarningChecks, testResource);
        if (warnings.size() > 0) {
            testResource.addWarnings(warnings);
        }
        return testResource;
    }

    /**
     * 
     * @see org.opencms.workplace.tools.content.check.I_CmsContentCheck#getDialogParameterName()
     */
    public String getDialogParameterName() {

        return DIALOG_PARAMETER;
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getHelpText()
     */
    public String getHelpText() {

        return Messages.get().getBundle().key(Messages.GUI_CHECKCONTENT_CONFIGURATION_PROPERTY_HELP_0);
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getIconPath()
     */
    public String getIconPath() {

        return ICONPATH;
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getLink()
     */
    public String getLink() {

        return "/system/workplace/views/admin/admin-editor.jsp?resource=/system/workplace/admin/contenttools/check/plugin/propertycheck/configuration.xml";
    }

    /**
     * @see org.opencms.workplace.tools.content.check.I_CmsContentCheck#getMessageBundles()
     */
    public List getMessageBundles() {

        List messages = new ArrayList();
        messages.add(org.opencms.workplace.tools.content.check.Messages.get().getBundleName());
        return messages;
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getName()
     */
    public String getName() {

        return NAME;
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getPath()
     */
    public String getPath() {

        return "/contenttools/checkconfig/checkproperty";
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getPosition()
     */
    public float getPosition() {

        return 1;
    }

    /**
     * @see org.opencms.workplace.tools.I_CmsToolHandler#getShortName()
     */
    public String getShortName() {

        return NAME;
    }

    /**
     * @see org.opencms.workplace.tools.content.check.I_CmsContentCheck#init(org.opencms.file.CmsObject)
     */
    public void init(CmsObject cms) {

        m_cms = cms;
        m_locale = new Locale("en");
    }

    /**
     * Gets the active flag.<p>
     * 
     * @return true if this content check is active, false otherwise.
     */
    public boolean isActive() {

        return m_active;
    }

    /**
     * Sets the active flag.<p>
     * 
     * This method is required to build the widget dialog frontend.
     *
     * @param value true if this content check is set to be active, false otherwise.
     */
    public void setActive(boolean value) {

        m_active = value;
    }

    /**

⌨️ 快捷键说明

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