📄 cmscaptchasettings.java
字号:
}
} else {
// the optional preset selector is missing...
}
} catch (Exception ex) {
if (LOG.isErrorEnabled()) {
LOG.error(ex.getLocalizedMessage());
}
}
}
/**
* Returns the flag that decides wethter a background image or a background color is used.
* <p>
*
* @return the flag that decides wethter a background image or a background color is used
*/
public boolean isUseBackgroundImage() {
return m_useBackgroundImage;
}
/**
* Sets the background color.
* <p>
*
* @param backgroundColor the background color to set
*/
public void setBackgroundColor(Color backgroundColor) {
m_backgroundColor = backgroundColor;
}
/**
* Sets the background color as a hex string.
* <p>
*
* @param backgroundColor the background color to set as a hex string
*/
public void setBackgroundColor(String backgroundColor) {
if (CmsStringUtil.isNotEmpty(backgroundColor)) {
if (backgroundColor.startsWith("#")) {
backgroundColor = backgroundColor.substring(1);
}
m_backgroundColor = new Color(Integer.valueOf(backgroundColor, 16).intValue());
m_useBackgroundImage = false;
} else if (backgroundColor != null) {
// not totally empty but consists of whitespaces only: use default value
// this happens e.g. if the XML content to configure did contain the node but left the
// value empty
// in this case the default background color will be used
m_useBackgroundImage = false;
m_backgroundColor = Color.WHITE;
} else {
// really empty and null - not even defined in XML content:
// don't use background color but a gimpy background image
m_useBackgroundImage = true;
// the color is not used but we have to avoid NPE in getBackgroundColorString()
m_backgroundColor = Color.WHITE;
}
}
/**
* Sets the filter amplitude for the water filter that will bend the text.
*
* @param i the filter amplitude for the water filter that will bend the text to set.
*/
public void setFilterAmplitude(int i) {
m_filterAmplitude = i;
}
/**
* Sets the filter wave length for the water filter that bends the text.
* <p>
*
* @param filterWaveLength the filter wave length for the water filter that bends the text to
* set
*/
public void setFilterWaveLength(int filterWaveLength) {
m_filterWaveLength = filterWaveLength;
}
/**
* Sets the font color.
* <p>
*
* @param fontColor the font color to set
*/
public void setFontColor(Color fontColor) {
m_fontColor = fontColor;
}
/**
* Sets the font color as a hex string.
* <p>
*
* @param fontColor the font color to set as a hex string
*/
public void setFontColor(String fontColor) {
if (CmsStringUtil.isNotEmpty(fontColor)) {
if (fontColor.startsWith("#")) {
fontColor = fontColor.substring(1);
}
m_fontColor = new Color(Integer.valueOf(fontColor, 16).intValue());
} else {
m_fontColor = Color.BLACK;
}
}
/**
* Sets the holes per glyph for a captcha image text (distortion).
*
* @param holes the holes per glyph for a captcha image text to set.
*/
public void setHolesPerGlyph(int holes) {
m_holesPerGlyp = new Integer(holes);
}
/**
* Sets the image height.
* <p>
*
* @param imageHeight the image height to set
*/
public void setImageHeight(int imageHeight) {
m_imageHeight = imageHeight;
}
/**
* Sets the image width.
* <p>
*
* @param imageWidth the image width to set
*/
public void setImageWidth(int imageWidth) {
m_imageWidth = imageWidth;
}
/**
* Sets the max. font size.
* <p>
*
* @param maxFontSize the max. font size to set
*/
public void setMaxFontSize(int maxFontSize) {
m_maxFontSize = maxFontSize;
}
/**
* Sets the max. phrase length.
* <p>
*
* @param maxPhraseLength the max. phrase length to set
*/
public void setMaxPhraseLength(int maxPhraseLength) {
m_maxPhraseLength = maxPhraseLength;
}
/**
* Sets the min. font size.
* <p>
*
* @param minFontSize the min. font size to set
*/
public void setMinFontSize(int minFontSize) {
m_minFontSize = minFontSize;
}
/**
* Sets the min. phrase length.
* <p>
*
* @param minPhraseLength the min. phrase length to set
*/
public void setMinPhraseLength(int minPhraseLength) {
m_minPhraseLength = minPhraseLength;
}
/**
* Returns the flag that decides wethter a background image or a background color is used.
* <p>
*
* @param useBackgroundImage the flag that decides wethter a background image or a background
* color is used.
*/
public void setUseBackgroundImage(boolean useBackgroundImage) {
m_useBackgroundImage = useBackgroundImage;
}
/**
* Creates a request parameter string from including all captcha settings.
* <p>
*
* @param cms needed for the context / encoding
* @return a request parameter string from including all captcha settings
*/
public String toRequestParams(CmsObject cms) {
StringBuffer buf = new StringBuffer();
buf.append(C_PARAM_IMAGE_WIDTH).append("=").append(m_imageWidth);
buf.append("&").append(C_PARAM_IMAGE_HEIGHT).append("=").append(m_imageHeight);
buf.append("&").append(C_PARAM_MIN_FONT_SIZE).append("=").append(m_minFontSize);
buf.append("&").append(C_PARAM_MAX_FONT_SIZE).append("=").append(m_maxFontSize);
buf.append("&").append(C_PARAM_MIN_PHRASE_LENGTH).append("=").append(m_minPhraseLength);
buf.append("&").append(C_PARAM_MAX_PHRASE_LENGTH).append("=").append(m_maxPhraseLength);
buf.append("&").append(C_PARAM_FONT_COLOR).append("=").append(
CmsEncoder.escape(getFontColorString(), cms.getRequestContext().getEncoding()));
buf.append("&").append(C_PARAM_BACKGROUND_COLOR).append("=").append(
CmsEncoder.escape(getBackgroundColorString(), cms.getRequestContext().getEncoding()));
buf.append("&").append(C_PARAM_HOLES_PER_GLYPH).append("=").append(m_holesPerGlyp);
buf.append("&").append(C_PARAM_FILTER_AMPLITUDE).append("=").append(m_filterAmplitude);
buf.append("&").append(C_PARAM_FILTER_WAVE_LENGTH).append("=").append(m_filterWaveLength);
buf.append("&").append(C_PARAM_CHARACTERS).append("=").append(m_characterPool);
buf.append("&").append(C_PARAM_PRESET).append("=").append(m_presetPath);
buf.append("&").append(C_PARAM_USE_BACKGROUND_IMAGE).append("=").append(Boolean.toString(m_useBackgroundImage));
return buf.toString();
}
/**
* @see java.lang.Object#clone()
*/
protected Object clone() {
CmsCaptchaSettings result = new CmsCaptchaSettings();
// copy all members here:
result.m_backgroundColor = m_backgroundColor;
result.m_filterAmplitude = m_filterAmplitude;
result.m_filterWaveLength = m_filterWaveLength;
result.m_fontColor = m_fontColor;
result.m_holesPerGlyp = m_holesPerGlyp;
result.m_imageHeight = m_imageHeight;
result.m_imageWidth = m_imageWidth;
result.m_maxFontSize = m_maxFontSize;
result.m_maxPhraseLength = m_maxPhraseLength;
result.m_minFontSize = m_minFontSize;
result.m_useBackgroundImage = m_useBackgroundImage;
result.m_minPhraseLength = m_minPhraseLength;
result.m_characterPool = m_characterPool;
result.m_presetPath = m_presetPath;
return result;
}
/**
* Returns the characterPool.
* <p>
*
* @return the characterPool
*/
String getCharacterPool() {
return m_characterPool;
}
/**
* Returns the preset path that was used to configure these settings.
* <p>
*
* This is read only, as the path is internally read from a nested CmsForm/FormCaptcha XML
* content.
* <p>
*
* @return the preset path that was used to configure these settings
*/
String getPresetPath() {
return m_presetPath;
}
/**
* Sets the characterPool.
* <p>
*
* @param characterPool the characterPool to set
*/
void setCharacterPool(String characterPool) {
m_characterPool = characterPool;
}
/**
* Converts a color range of a color into a hex string.
* <p>
*
* @param colorRange the color range of a color
* @return the hex string of the color range
*/
private String toHexString(int colorRange) {
if (colorRange < 10) {
return "0" + Integer.toHexString(colorRange);
} else {
return Integer.toHexString(colorRange);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -