Update of /var/cvs/src/org/mmbase/datatypes
In directory james.mmbase.org:/tmp/cvs-serv10895

Modified Files:
        ConfirmPasswordDataType.java 
Log Message:
ConfirmPassword can now be a straigh-forward extension of CheckEqualityDataTye


See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/datatypes


Index: ConfirmPasswordDataType.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/datatypes/ConfirmPasswordDataType.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- ConfirmPasswordDataType.java        21 Jun 2007 07:32:31 -0000      1.14
+++ ConfirmPasswordDataType.java        28 Apr 2009 14:06:54 -0000      1.15
@@ -20,98 +20,19 @@
  * only sense as a field of a node).
  *
  * @author Michiel Meeuwissen
- * @version $Id: ConfirmPasswordDataType.java,v 1.14 2007/06/21 07:32:31 
pierre Exp $
+ * @version $Id: ConfirmPasswordDataType.java,v 1.15 2009/04/28 14:06:54 
michiel Exp $
  * @since MMBase-1.8
  */
-public class ConfirmPasswordDataType extends StringDataType {
-    private static final Logger log = 
Logging.getLoggerInstance(ConfirmPasswordDataType.class);
-
-    private static final long serialVersionUID = 1L; // increase this if 
object serialization changes (which we shouldn't do!)
-
-    protected PasswordRestriction  passwordRestriction =  new 
PasswordRestriction("password");
-
+public class ConfirmPasswordDataType extends CheckEqualityDataType {
     /**
      * Constructor for string data type.
      * @param name the name of the data type
      */
     public ConfirmPasswordDataType(String name) {
         super(name);
+        setField("password");
+        setPassword(true);
     }
 
-    protected void inheritRestrictions(BasicDataType origin) {
-        super.inheritRestrictions(origin);
-        if (origin instanceof ConfirmPasswordDataType) {
-            ConfirmPasswordDataType dataType = (ConfirmPasswordDataType) 
origin;
-            passwordRestriction.inherit(dataType.passwordRestriction);
-        }
-    }
-    protected void cloneRestrictions(BasicDataType origin) {
-        super.cloneRestrictions(origin);
-        if (origin instanceof ConfirmPasswordDataType) {
-            ConfirmPasswordDataType dataType = (ConfirmPasswordDataType) 
origin;
-            passwordRestriction = new 
PasswordRestriction(dataType.passwordRestriction);
-        }
-    }
-
-    public int getEnforceStrength() {
-        return Math.max(super.getEnforceStrength(), 
passwordRestriction.getEnforceStrength());
-    }
-
-    protected Collection<LocalizedString> 
validateCastValue(Collection<LocalizedString> errors, Object castValue, Object 
value, Node node, Field field) {
-        errors = super.validateCastValue(errors, castValue, value, node, 
field);
-        errors = passwordRestriction.validate(errors, castValue, node, field);
-        return errors;
-    }
-    /**
-     * The field property is the name of the other password field that this 
fields 'confirms'. It default to 'password'.
-     * In datatype XML it can be set with the generic &lt;property 
name="field" value="..." /&gt;
-     */
-    public void setField(String field) {
-        passwordRestriction.setValue(field);
-    }
-    /**
-     * Returns the name of the field which is 'confirmed' by this datatype.
-     */
-    public String getField() {
-        edit();
-        return passwordRestriction.getField();
-    }
-
-    protected StringBuilder toStringBuilder() {
-        StringBuilder buf = super.toStringBuilder();
-        buf.append(" 
confirm(").append(passwordRestriction.getValue()).append(")");
-        return buf;
-    }
-
-    protected class PasswordRestriction extends AbstractRestriction {
-        PasswordRestriction(PasswordRestriction source) {
-            super(source);
-        }
-        PasswordRestriction(String field) {
-            super("confirmpassword", field);
-        }
-        protected final String getField() {
-            return (String) value;
-        }
-
-        protected boolean simpleValid(final Object v, final Node node, final 
Field field) {
-            if (node != null && field != null && v != null) {
-                if (! node.isChanged(getField())) return true;
-
-                Field passwordField = 
node.getNodeManager().getField(getField());
-                Processor setProcessor = 
passwordField.getDataType().getProcessor(PROCESS_SET);
-                Object processedValue = setProcessor.process(node, field, v);
-                String passwordValue = (String) 
node.getObjectValue(getField());
-                if (log.isDebugEnabled()) {
-                    log.debug("Password checking " + (node.isNew() ? "new" : 
"existing") + " node. Password field " + passwordField + " set-processor " + 
setProcessor);
-                    log.debug("Offered value '" + v + "' --> '" + 
processedValue);
-                    log.debug("Comparing '" + passwordValue + "' with '" + 
processedValue + "'(" + v + ")");
-                }
-                return passwordValue.equals(v) || 
passwordValue.equals(processedValue);
-            } else {
-                return true;
-            }
-        }
-    }
 
 }
_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to