cmscaptchasettings.java
来自「找了很久才找到到源代码」· Java 代码 · 共 935 行 · 第 1/3 页
JAVA
935 行
/**
* Returns the image height.<p>
*
* @return the image height
*/
public int getImageHeight() {
return m_imageHeight;
}
/**
* Returns the image width.<p>
*
* @return the image width
*/
public int getImageWidth() {
return m_imageWidth;
}
/**
* Returns the max. font size.<p>
*
* @return the max. font size
*/
public int getMaxFontSize() {
return m_maxFontSize;
}
/**
* Returns the max. phrase length.<p>
*
* @return the max. phrase length
*/
public int getMaxPhraseLength() {
return m_maxPhraseLength;
}
/**
* Returns the min. font size.<p>
*
* @return the min. font size
*/
public int getMinFontSize() {
return m_minFontSize;
}
/**
* Returns the min. phrase length.<p>
*
* @return the min. phrase length
*/
public int getMinPhraseLength() {
return m_minPhraseLength;
}
/**
* Configures the instance with values overridden from the the request parameters.<p>
*
* @param jsp a Cms JSP page
*
* @see #C_PARAM_BACKGROUND_COLOR
* @see #C_PARAM_FILTER_AMPLITUDE
*/
public void init(CmsJspActionElement jsp) {
List mulipartFileItems = CmsRequestUtil.readMultipartFileItems(jsp.getRequest());
m_parameterMap = new HashMap();
if (mulipartFileItems != null) {
m_parameterMap = CmsRequestUtil.readParameterMapFromMultiPart(
jsp.getRequestContext().getEncoding(),
mulipartFileItems);
} else {
m_parameterMap = jsp.getRequest().getParameterMap();
}
// image width
String stringValue = getParameter(C_PARAM_IMAGE_WIDTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageWidth = Integer.parseInt(stringValue);
}
// image height
stringValue = getParameter(C_PARAM_IMAGE_HEIGHT);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageHeight = Integer.parseInt(stringValue);
}
// min. phrase length
stringValue = getParameter(C_PARAM_MIN_PHRASE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minPhraseLength = Integer.parseInt(stringValue);
}
// max. phrase length
stringValue = getParameter(C_PARAM_MAX_PHRASE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxPhraseLength = Integer.parseInt(stringValue);
}
// min. font size
stringValue = getParameter(C_PARAM_MIN_FONT_SIZE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minFontSize = Integer.parseInt(stringValue);
}
// max. font size
stringValue = getParameter(C_PARAM_MAX_FONT_SIZE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxFontSize = Integer.parseInt(stringValue);
}
// font color
stringValue = getParameter(C_PARAM_FONT_COLOR);
if (CmsStringUtil.isNotEmpty(stringValue)) {
stringValue = CmsEncoder.unescape(stringValue, jsp.getRequestContext().getEncoding());
setFontColor(stringValue);
}
// background color
stringValue = getParameter(C_PARAM_BACKGROUND_COLOR);
if (CmsStringUtil.isNotEmpty(stringValue)) {
stringValue = CmsEncoder.unescape(stringValue, jsp.getRequestContext().getEncoding());
}
setBackgroundColor(stringValue);
// holes per glyph
stringValue = getParameter(C_PARAM_HOLES_PER_GLYPH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setHolesPerGlyph(Integer.parseInt(stringValue));
}
// filter amplitude
stringValue = getParameter(C_PARAM_FILTER_AMPLITUDE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterAmplitude(Integer.parseInt(stringValue));
}
// filter wave length
stringValue = getParameter(C_PARAM_FILTER_WAVE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterWaveLength(Integer.parseInt(stringValue));
}
// flag for generation of background image (vs. background color)
stringValue = getParameter(C_PARAM_USE_BACKGROUND_IMAGE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setUseBackgroundImage(Boolean.valueOf(stringValue).booleanValue());
}
// characters to use for word generation:
stringValue = getParameter(C_PARAM_CHARACTERS);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setCharacterPool(stringValue);
}
// characters to use for word generation:
stringValue = getParameter(C_PARAM_CHARACTERS);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setCharacterPool(stringValue);
}
// just for logging comfort (find misconfigured presets):
stringValue = getParameter(C_PARAM_PRESET);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_presetPath = stringValue;
}
}
/**
* Configures the instance with overridden values from the given XML content.<p>
*
* <h3>Xmlcontent configuration notes</h3>
* <ol>
* <li>
* <ul>
* <li> If the xmlcontent contains no node for BackgroundColor ({@link CmsCaptchaSettings#NODE_CAPTCHAPRESET_BACKGROUNDCOLOR}),
* a background image will be used. </li>
* <li> If the xmlcontent node contains an empty node (trimmable to the empty String), the
* default background colour {@link Color#WHITE}) will be used as background. </li>
* <li> Else the chosen background color will be used. </li>
* </ul>
* </li>
* </ol>
* <p>
*
* @param cms the current user's Cms object
* @param content the XML content of the form
* @param locale the current locale
*/
public void init(CmsObject cms, CmsXmlContent content, Locale locale) {
try {
String captchaSettingsPath = content.getStringValue(
cms,
new StringBuffer(CmsForm.NODE_CAPTCHA).append("/").append(CmsForm.NODE_CAPTCHA_PRESET).toString(),
locale);
if (CmsStringUtil.isNotEmpty(captchaSettingsPath)) {
m_presetPath = captchaSettingsPath;
CmsFile captchaSettingsFile = cms.readFile(captchaSettingsPath);
CmsXmlContent preset = CmsXmlContentFactory.unmarshal(cms, captchaSettingsFile);
Locale captchaSettingsLocale = Locale.ENGLISH;
// image width
String stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_IMAGEWIDTH,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageWidth = Integer.parseInt(stringValue);
}
// image height
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_IMAGEHEIGHT,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageHeight = Integer.parseInt(stringValue);
}
// min. phrase length
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_MIN_PHRASE_LENGTH,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minPhraseLength = Integer.parseInt(stringValue);
}
// max. phrase length
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_MAX_PHRASE_LENGTH,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxPhraseLength = Integer.parseInt(stringValue);
}
// min. font size
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_MIN_FONT_SIZE,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minFontSize = Integer.parseInt(stringValue);
}
// max. font size
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_MAX_FONT_SIZE,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxFontSize = Integer.parseInt(stringValue);
}
// font color
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_FONTCOLOR,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFontColor(stringValue);
}
// background color
// if the field is defined but left blank, the default background color will be used
// if the field is not defined a gimpy background image will be used
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_BACKGROUNDCOLOR,
captchaSettingsLocale);
setBackgroundColor(stringValue);
// holes per glyph
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_HOLESPERGLYPH,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setHolesPerGlyph(Integer.parseInt(stringValue));
}
// filter amplitude
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_FILTER_AMPLITUDE,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterAmplitude(Integer.parseInt(stringValue));
}
// filter wave length
stringValue = preset.getStringValue(
cms,
CmsCaptchaSettings.NODE_CAPTCHAPRESET_FILTER_WAVELENGTH,
captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterWaveLength(Integer.parseInt(stringValue));
}
stringValue = preset.getStringValue(cms, CmsForm.NODE_CAPTCHA_CHARACTERS, captchaSettingsLocale);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setCharacterPool(stringValue);
}
if (CmsStringUtil.isNotEmpty(stringValue)) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?