📄 cmscaptchasettings.java
字号:
/**
* 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) {
HttpServletRequest request = jsp.getRequest();
// image width
String stringValue = request.getParameter(C_PARAM_IMAGE_WIDTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageWidth = Integer.parseInt(stringValue);
}
// image height
stringValue = request.getParameter(C_PARAM_IMAGE_HEIGHT);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_imageHeight = Integer.parseInt(stringValue);
}
// min. phrase length
stringValue = request.getParameter(C_PARAM_MIN_PHRASE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minPhraseLength = Integer.parseInt(stringValue);
}
// max. phrase length
stringValue = request.getParameter(C_PARAM_MAX_PHRASE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxPhraseLength = Integer.parseInt(stringValue);
}
// min. font size
stringValue = request.getParameter(C_PARAM_MIN_FONT_SIZE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_minFontSize = Integer.parseInt(stringValue);
}
// max. font size
stringValue = request.getParameter(C_PARAM_MAX_FONT_SIZE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
m_maxFontSize = Integer.parseInt(stringValue);
}
// font color
stringValue = request.getParameter(C_PARAM_FONT_COLOR);
if (CmsStringUtil.isNotEmpty(stringValue)) {
stringValue = CmsEncoder.unescape(stringValue, jsp.getRequestContext().getEncoding());
setFontColor(stringValue);
}
// background color
stringValue = request.getParameter(C_PARAM_BACKGROUND_COLOR);
if (CmsStringUtil.isNotEmpty(stringValue)) {
stringValue = CmsEncoder.unescape(stringValue, jsp.getRequestContext().getEncoding());
}
setBackgroundColor(stringValue);
// holes per glyph
stringValue = request.getParameter(C_PARAM_HOLES_PER_GLYPH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setHolesPerGlyph(Integer.parseInt(stringValue));
}
// filter amplitude
stringValue = request.getParameter(C_PARAM_FILTER_AMPLITUDE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterAmplitude(Integer.parseInt(stringValue));
}
// filter wave length
stringValue = request.getParameter(C_PARAM_FILTER_WAVE_LENGTH);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setFilterWaveLength(Integer.parseInt(stringValue));
}
// flag for generation of background image (vs. background color)
stringValue = request.getParameter(C_PARAM_USE_BACKGROUND_IMAGE);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setUseBackgroundImage(Boolean.valueOf(stringValue).booleanValue());
}
// characters to use for word generation:
stringValue = request.getParameter(C_PARAM_CHARACTERS);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setCharacterPool(stringValue);
}
// characters to use for word generation:
stringValue = request.getParameter(C_PARAM_CHARACTERS);
if (CmsStringUtil.isNotEmpty(stringValue)) {
setCharacterPool(stringValue);
}
// just for logging comfort (find misconfigured presets):
stringValue = request.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)) {
setCharacterPool(stringValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -