cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: r170781 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/forms: java/org/apache/cocoon/forms/formmodel/ samples/captcha/ samples/captcha/forms/
Date Wed, 18 May 2005 17:31:54 GMT
Author: ugo
Date: Wed May 18 10:31:52 2005
New Revision: 170781

URL: http://svn.apache.org/viewcvs?rev=170781&view=rev
Log:
Make CAPTCHA secret length configurable

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaDefinitionBuilder.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaFieldDefinition.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaDefinitionBuilder.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaDefinitionBuilder.java?rev=170781&r1=170780&r2=170781&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaDefinitionBuilder.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaDefinitionBuilder.java
Wed May 18 10:31:52 2005
@@ -49,5 +49,9 @@
         // parse "@required"
         boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false);
         definition.setRequired(required);
+        
+        // parse "@length"
+        int length = DomHelper.getAttributeAsInteger(widgetElement, "length", 7);
+        ((CaptchaFieldDefinition) definition).setLength(length);
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaField.java?rev=170781&r1=170780&r2=170781&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaField.java
Wed May 18 10:31:52 2005
@@ -56,10 +56,10 @@
 
     private static final String IMAGE_EL = "captcha-image";
     private static final String SECRET_CHARS = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
-    private static final int SECRET_LENGTH = 7;
     private static final int SESSION_ATTR_NAME_LENGTH = 6;
     
     private Context avalonContext;
+    private int length;
 
     /**
      * Random number generator used to create session attribute name.
@@ -80,14 +80,15 @@
         random.setSeed(System.currentTimeMillis());
     }
 
-    public CaptchaField(FieldDefinition fieldDefinition, Context avalonContext) {
+    public CaptchaField(CaptchaFieldDefinition fieldDefinition, Context avalonContext) {
         super(fieldDefinition);
         this.avalonContext = avalonContext;
+        this.length = fieldDefinition.getLength();
     }
     
     private String generateSecret() {
-        StringBuffer secret = new StringBuffer(SECRET_LENGTH);
-        for (int n = 0 ; n < SECRET_LENGTH ; n++) {
+        StringBuffer secret = new StringBuffer(length);
+        for (int n = 0 ; n < length ; n++) {
             int randomnumber = random.nextInt(SECRET_CHARS.length());
             secret.append(SECRET_CHARS.charAt(randomnumber)); 
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaFieldDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaFieldDefinition.java?rev=170781&r1=170780&r2=170781&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaFieldDefinition.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/CaptchaFieldDefinition.java
Wed May 18 10:31:52 2005
@@ -26,6 +26,7 @@
 public class CaptchaFieldDefinition extends FieldDefinition {
     
     private Context avalonContext;
+    private int length;
 
     public CaptchaFieldDefinition(Context avalonContext) {
         this.avalonContext = avalonContext;
@@ -34,6 +35,15 @@
     public Widget createInstance() {
         CaptchaField field = new CaptchaField(this, avalonContext);
         return field;
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    public void setLength(int length) {
+        checkMutable();
+        this.length = length;
     }
 
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml?rev=170781&r1=170780&r2=170781&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/captcha-image.xml Wed May
18 10:31:52 2005
@@ -15,7 +15,7 @@
   limitations under the License.
 -->
 
-<svg width="200" height="75">
+<svg width="210" height="75">
     <defs>
         <filter id="blur2">
             <feGaussianBlur stdDeviation="2"/>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml?rev=170781&r1=170780&r2=170781&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/samples/captcha/forms/captcha.def.xml Wed
May 18 10:31:52 2005
@@ -24,7 +24,7 @@
 
   <fd:widgets>
   
-    <fd:captcha id="f1" required="true">
+    <fd:captcha id="f1" required="true" length="8">
       <fd:label>Copy the string shown on the right into the input field</fd:label>
       <fd:datatype base="string"/>
       <fd:validation>



Mime
View raw message