Package org.zkoss.zul
Class Captcha
java.lang.Object
org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zul.impl.XulElement
org.zkoss.zul.Image
org.zkoss.zul.Captcha
- All Implemented Interfaces:
Serializable,Cloneable,org.zkoss.zk.ui.Component,org.zkoss.zk.ui.ext.Scope,org.zkoss.zk.ui.sys.ComponentCtrl
The generic captcha component.
Captcha requires an implementation of an engine (CaptchaEngine).
The default engine is based on JHLabs and available in ZK PE and ZK EE.
- Author:
- henrichen
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.zul.Image
Image.ExtraCtrlNested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo -
Field Summary
Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
_zclassFields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPEFields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd fonts into fonts list.Get the background color of the captcha box (in string as #RRGGBB).intgetBgRGB()Get the background color in int array (0: red, 1: green, 2:blue).Get the captcha engine.Font[]Gets the default font list.Get exclude characters.getFont(int j) Get nth Font.Gets font color.intGet the font color in int array (0: red, 1: green, 2:blue).getFonts()Gets fonts list, default provide two fonts.intGet the captcha int height in pixel; to be used by the derived subclass.intGet the captcha int width in pixel; to be used by the derived subclass.intGet length of the autogenerated text value; default to 5.getValue()Returns the text value of this captcha.booleanisFrame()Returns whether generate border.booleanisNoise()Returns whether generate noise; default to false.protected CaptchaEngineInstantiates the default captcha engine.Regenerates new captcha text value and redraw.voidsetBgColor(String color) Set the background color of the chart.voidSets the captcha engine by use of a class name.voidsetEngine(CaptchaEngine engine) Set the captcha engine.voidsetExclude(String exclude) Set exclude characters that will not be generated.voidsetFontColor(String color) Set font color.voidsetFrame(boolean frame) Sets whether generate border.voidOverride super class to prepare the int height.voidOverrides the method in HtmlBasedComponent, not to check using hflex and width at the same timevoidsetLength(int len) Set length of the autogenerated text value; default to 5.voidsetNoise(boolean b) Sets whether generate noise; default to false.voidSets the text value to be shown as the distortion captcha.voidOverrides the method in HtmlBasedComponent, not to check using vflex and height at the same timevoidOverride super class to prepare the int width.protected voidmark a draw flag to inform that this Chart needs update.Methods inherited from class org.zkoss.zul.Image
getContent, getExtraCtrl, getHover, getSrc, isChildable, renderProperties, setContent, setContent, setHover, setHoverContent, setHoverContent, setSrcMethods inherited from class org.zkoss.zul.impl.XulElement
clone, getContext, getCtrlKeys, getPopup, getPropertyAccess, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributesMethods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZindex, getZIndex, removeSclass, removeSclass, service, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight0, setHeightDirectly, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setSkeleton, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex0, setVflexDirectly, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectlyMethods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
Constructor Details
-
Captcha
public Captcha()
-
-
Method Details
-
getFonts
Gets fonts list, default provide two fonts. -
getDefaultFonts
Gets the default font list. -
getFont
Get nth Font. -
addFont
Add fonts into fonts list. If you did not add fonts, the default implementation would use the default fonts; i.e. bold Arial 35, and bold courier 35. -
setFontColor
Set font color. Allowed value format: #RRGGBB -
getFontColor
Gets font color. -
getFontRGB
public int getFontRGB()Get the font color in int array (0: red, 1: green, 2:blue). -
setBgColor
Set the background color of the chart.- Parameters:
color- in #RRGGBB format (hexadecimal).
-
getBgColor
Get the background color of the captcha box (in string as #RRGGBB). null means default. -
getBgRGB
public int getBgRGB()Get the background color in int array (0: red, 1: green, 2:blue). null means default. -
setWidth
Override super class to prepare the int width.- Overrides:
setWidthin classorg.zkoss.zk.ui.HtmlBasedComponent
-
setHflex
Overrides the method in HtmlBasedComponent, not to check using hflex and width at the same time- Overrides:
setHflexin classorg.zkoss.zk.ui.HtmlBasedComponent- Since:
- 8.0.1
-
getIntWidth
public int getIntWidth()Get the captcha int width in pixel; to be used by the derived subclass. -
setHeight
Override super class to prepare the int height.- Overrides:
setHeightin classorg.zkoss.zk.ui.HtmlBasedComponent
-
setVflex
Overrides the method in HtmlBasedComponent, not to check using vflex and height at the same time- Overrides:
setVflexin classorg.zkoss.zk.ui.HtmlBasedComponent- Since:
- 8.0.1
-
getIntHeight
public int getIntHeight()Get the captcha int height in pixel; to be used by the derived subclass. -
getValue
Returns the text value of this captcha.Default: an empty string.
Deriving class can override it to return whatever it wants other than null.
-
setValue
Sets the text value to be shown as the distortion captcha.- Parameters:
text- the captcha text value- Throws:
org.zkoss.zk.ui.WrongValueException
-
setLength
public void setLength(int len) Set length of the autogenerated text value; default to 5. -
getLength
public int getLength()Get length of the autogenerated text value; default to 5. -
setExclude
Set exclude characters that will not be generated. Note that only digit and character is used in generating text value. If you leave exclude null, the default exclude list will be applied; i.e., 0123456789IilOo (only character (no digits) are used except I, i, l, O(big O), o(small o)) -
getExclude
Get exclude characters. -
setNoise
public void setNoise(boolean b) Sets whether generate noise; default to false. (@since 5.0.0) -
isNoise
public boolean isNoise()Returns whether generate noise; default to false. (@since 5.0.0) -
setFrame
public void setFrame(boolean frame) Sets whether generate border.Default to false.
- Since:
- 5.0.4
-
isFrame
public boolean isFrame()Returns whether generate border.Default to false.
- Since:
- 5.0.4
-
randomValue
Regenerates new captcha text value and redraw. -
setEngine
public void setEngine(String clsnm) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException Sets the captcha engine by use of a class name. It creates an instance automatically. -
setEngine
Set the captcha engine. -
getCaptchaEngine
Get the captcha engine.- Throws:
org.zkoss.zk.ui.UiException- if failed to load the engine.
-
newCaptchaEngine
Instantiates the default captcha engine. It is called, ifsetEngine(java.lang.String)is not called with non-null engine.By default, it looks up the library property called org.zkoss.zul.captcha.engine.class. If found, the value is assumed to be the class name of the captcha engine (it must implement
CaptchaEngine. If not found,UiExceptionis thrown.Derived class might override this method to provide your own default class.
- Throws:
org.zkoss.zk.ui.UiException- if failed to instantiate the engine- Since:
- 3.0.0
-
smartDrawCaptcha
protected void smartDrawCaptcha()mark a draw flag to inform that this Chart needs update.
-