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

📄 cmscaptchasettings.java

📁 OpenCms 是一个J2EE的产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/frontend/templateone/form/CmsCaptchaSettings.java,v $
 * Date   : $Date: 2006/03/27 14:52:20 $
 * Version: $Revision: 1.6 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002 - 2004 Alkacon Software (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, 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.frontend.templateone.form;

import org.opencms.file.CmsFile;
import org.opencms.file.CmsObject;
import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;
import org.opencms.xml.content.CmsXmlContent;
import org.opencms.xml.content.CmsXmlContentFactory;

import java.awt.Color;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;

/**
 * Stores the settings to render captcha images.
 * <p>
 * 
 * @author Thomas Weckert
 * 
 * @author Achim Westermann
 * 
 * @version $Revision: 1.6 $
 */
public final class CmsCaptchaSettings implements Cloneable {

    /** Request parameter for the background color. */
    public static final String C_PARAM_BACKGROUND_COLOR = "bgcol";

    /** Request parameter for the min phrase length. */
    public static final String C_PARAM_CHARACTERS = "crs";

    /** Request parameter for the filter amplitude. */
    public static final String C_PARAM_FILTER_AMPLITUDE = "famplit";

    /** Request parameter for the filter amplitude. */
    public static final String C_PARAM_FILTER_WAVE_LENGTH = "fwavlen";

    /** Request parameter for the font color. */
    public static final String C_PARAM_FONT_COLOR = "fcol";

    /** Request parameter for the font color. */
    public static final String C_PARAM_HOLES_PER_GLYPH = "holes";

    /** Request parameter for the image height. */
    public static final String C_PARAM_IMAGE_HEIGHT = "h";

    /** Request parameter for the image width. */
    public static final String C_PARAM_IMAGE_WIDTH = "w";

    /** Request parameter for the max. font size. */
    public static final String C_PARAM_MAX_FONT_SIZE = "maxfs";

    /** Request parameter for the max phrase length. */
    public static final String C_PARAM_MAX_PHRASE_LENGTH = "maxpl";

    /** Request parameter for the min. font size. */
    public static final String C_PARAM_MIN_FONT_SIZE = "minfs";

    /** Request parameter for the min phrase length. */
    public static final String C_PARAM_MIN_PHRASE_LENGTH = "minpl";

    /** Request parameter for the min phrase length. */
    public static final String C_PARAM_PRESET = "prst";

    /** Request parameter for the min phrase length. */
    public static final String C_PARAM_USE_BACKGROUND_IMAGE = "bgimg";

    /** Configuration node name for the optional captcha background color. */
    public static final String NODE_CAPTCHAPRESET_BACKGROUNDCOLOR = "BackgroundColor";

    /** Configuration node name for the field value node. */
    public static final String NODE_CAPTCHAPRESET_FILTER_AMPLITUDE = "FilterAmplitude";

    /** Configuration node name for the optional captcha image holes per glyph. */
    public static final String NODE_CAPTCHAPRESET_FILTER_WAVELENGTH = "FilterWaveLength";

    /** Configuration node name for the optional captcha font color. */
    public static final String NODE_CAPTCHAPRESET_FONTCOLOR = "FontColor";

    /** Configuration node name for the optional captcha image holes per glyph. */
    public static final String NODE_CAPTCHAPRESET_HOLESPERGLYPH = "HolesPerGlyph";

    /** Configuration node name for the optional captcha image height. */
    public static final String NODE_CAPTCHAPRESET_IMAGEHEIGHT = "ImageHeight";

    /** Configuration node name for the optional captcha image width. */
    public static final String NODE_CAPTCHAPRESET_IMAGEWIDTH = "ImageWidth";

    /** Configuration node name for the optional captcha max. font size. */
    public static final String NODE_CAPTCHAPRESET_MAX_FONT_SIZE = "MaxFontSize";

    /** Configuration node name for the optional captcha max. phrase length. */
    public static final String NODE_CAPTCHAPRESET_MAX_PHRASE_LENGTH = "MaxPhraseLength";

    /** Configuration node name for the optional captcha min. font size. */
    public static final String NODE_CAPTCHAPRESET_MIN_FONT_SIZE = "MinFontSize";

    /** Configuration node name for the optional captcha min. phrase length. */
    public static final String NODE_CAPTCHAPRESET_MIN_PHRASE_LENGTH = "MinPhraseLength";

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

    /** The the background color. */
    private Color m_backgroundColor = Color.WHITE;

    /** The string containing the characters to use for word generation. */
    private String m_characterPool = "abcdefghiklmnoprstuvwxyz";

    /** The filter amplitude for the water filter that bends the text. */
    private int m_filterAmplitude = 2;

    /** The filter wave length for the water filter that bends the text. */
    private int m_filterWaveLength = 100;

    /** The font color. */
    private Color m_fontColor = Color.BLACK;

    /** The amount of holes per glyph. */
    private Integer m_holesPerGlyp = new Integer(0);

    /** The image height in pixels. */
    private int m_imageHeight = 50;

    /** The image width in pixels. */
    private int m_imageWidth = 150;

    /** The maximum font size in pixels. */
    private int m_maxFontSize = 40;

    /** The maximum phrase length. */
    private int m_maxPhraseLength = 5;

    /** minimum font size in pixels. */
    private int m_minFontSize = 30;

    /** The minimum phrase length. */
    private int m_minPhraseLength = 5;

    /**
     * The path to the preset configuration (captchapreset) that has been used to initialize these
     * settings. This is read only, as the path is internally read from a nested CmsForm/FormCaptcha
     * XML content.
     */
    private String m_presetPath = "factory defaults (classfile)";

    /** The flag that decides wethter a background image or a background color is used. */
    private boolean m_useBackgroundImage = true;

    /**
     * Private constructor for the clone method.
     * <p>
     * 
     * May only be called from {@link #clone()} as that method guarantees to install the default
     * value from the master captcha settings.
     * <p>
     */
    private CmsCaptchaSettings() {

        // nop
    }

    /**
     * Constructor that will use request parameters to init theses settings.
     * <p>
     */
    private CmsCaptchaSettings(CmsJspActionElement jsp) {

        init(jsp);
    }

    /**
     * Returns a clone of the singleton instance of the
     * <em>"master"</em>  <code>CmsCaptchaSettings</code> and potential overridden values from
     * the request context.
     * <p>
     * 
     * The <em>"master"</em>  <code>CmsCaptchaSettings</code> are read from an XML content that
     * contains the global defaults.
     * <p>
     * 
     * @param jsp used to potentially access the XML content with the default captcha settings and
     *            to read overriden values from the request parameters.
     * 
     * @return a clone of the singleton instance of the
     *         <em>"master"</em>  <code>CmsCaptchaSettings</code>.
     */
    public static CmsCaptchaSettings getInstance(CmsJspActionElement jsp) {

        CmsCaptchaSettings result = new CmsCaptchaSettings(jsp);
        return (CmsCaptchaSettings)result.clone();
    }

    /**
     * Returns the background color.
     * <p>
     * 
     * @return the background color
     */
    public Color getBackgroundColor() {

        return m_backgroundColor;
    }

    /**
     * Returns the background color as a hex string.
     * <p>
     * 
     * @return the background color as a hex string
     */
    public String getBackgroundColorString() {

        StringBuffer buf = new StringBuffer();

        buf.append("#");
        buf.append(toHexString(m_backgroundColor.getRed()));
        buf.append(toHexString(m_backgroundColor.getGreen()));
        buf.append(toHexString(m_backgroundColor.getBlue()));

        return buf.toString();
    }

    /**
     * Returns the filter amplitude for the water filter that bends the text.
     * <p>
     * 
     * @return the filter amplitude for the water filter that bends the text.
     */
    public int getFilterAmplitude() {

        return m_filterAmplitude;
    }

    /**
     * Returns the filter wave length for the water filter that bends the text.
     * <p>
     * 
     * @return the filter wave length for the water filter that bends the text.
     */
    public int getFilterWaveLength() {

        return m_filterWaveLength;
    }

    /**
     * Returns the font color.
     * <p>
     * 
     * @return the font color
     */
    public Color getFontColor() {

        return m_fontColor;
    }

    /**
     * Returns the font color as a hex string.
     * <p>
     * 
     * @return the font color as a hex string
     */
    public String getFontColorString() {

        StringBuffer buf = new StringBuffer();

        buf.append("#");
        buf.append(toHexString(m_fontColor.getRed()));
        buf.append(toHexString(m_fontColor.getGreen()));
        buf.append(toHexString(m_fontColor.getBlue()));

        return buf.toString();
    }

    /**
     * Returns the holes per glyph for a captcha image text (distortion).
     * 
     * @return the holes per glyph for a captcha image text
     */
    public Integer getHolesPerGlyph() {

        return m_holesPerGlyp;
    }

⌨️ 快捷键说明

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