Package org.zkoss.zul

Class Captcha

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Scope, ComponentCtrl

    public class Captcha
    extends Image
    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:
    Serialized Form
    • Constructor Detail

      • Captcha

        public Captcha()
    • Method Detail

      • getFonts

        public java.util.List<java.awt.Font> getFonts()
        Gets fonts list, default provide two fonts.
      • getDefaultFonts

        public java.awt.Font[] getDefaultFonts()
        Gets the default font list.
      • getFont

        public java.awt.Font getFont​(int j)
        Get nth Font.
      • addFont

        public void addFont​(java.awt.Font font)
        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

        public void setFontColor​(java.lang.String color)
        Set font color. Allowed value format: #RRGGBB
      • getFontColor

        public java.lang.String getFontColor()
        Gets font color.
      • getFontRGB

        public int getFontRGB()
        Get the font color in int array (0: red, 1: green, 2:blue).
      • setBgColor

        public void setBgColor​(java.lang.String color)
        Set the background color of the chart.
        Parameters:
        color - in #RRGGBB format (hexadecimal).
      • getBgColor

        public java.lang.String 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.
      • getIntWidth

        public int getIntWidth()
        Get the captcha int width in pixel; to be used by the derived subclass.
      • setHeight

        public void setHeight​(java.lang.String h)
        Override super class to prepare the int height.
        Overrides:
        setHeight in class HtmlBasedComponent
      • getIntHeight

        public int getIntHeight()
        Get the captcha int height in pixel; to be used by the derived subclass.
      • getValue

        public java.lang.String 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

        public void setValue​(java.lang.String text)
                      throws WrongValueException
        Sets the text value to be shown as the distortion captcha.
        Parameters:
        text - the captcha text value
        Throws:
        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

        public void setExclude​(java.lang.String exclude)
        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

        public java.lang.String 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

        public java.lang.String randomValue()
        Regenerates new captcha text value and redraw.
      • setEngine

        public void setEngine​(java.lang.String clsnm)
                       throws java.lang.ClassNotFoundException,
                              java.lang.NoSuchMethodException,
                              java.lang.IllegalAccessException,
                              java.lang.InstantiationException,
                              java.lang.reflect.InvocationTargetException
        Sets the captcha engine by use of a class name. It creates an instance automatically.
        Throws:
        java.lang.ClassNotFoundException
        java.lang.NoSuchMethodException
        java.lang.IllegalAccessException
        java.lang.InstantiationException
        java.lang.reflect.InvocationTargetException
      • setEngine

        public void setEngine​(CaptchaEngine engine)
        Set the captcha engine.
      • newCaptchaEngine

        protected CaptchaEngine newCaptchaEngine()
                                          throws UiException
        Instantiates the default captcha engine. It is called, if setEngine(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, UiException is thrown.

        Derived class might override this method to provide your own default class.

        Throws:
        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.