1 10 package org.mmbase.datatypes; 11 12 import java.util.*; 13 import org.mmbase.bridge.*; 14 import org.mmbase.datatypes.processors.Processor; 15 import org.mmbase.util.*; 16 import org.mmbase.util.logging.*; 17 18 26 public class ConfirmPasswordDataType extends StringDataType { 27 private static final Logger log = Logging.getLoggerInstance(ConfirmPasswordDataType.class); 28 29 private static final long serialVersionUID = 1L; 31 protected PasswordRestriction passwordRestriction = new PasswordRestriction("password"); 32 33 37 public ConfirmPasswordDataType(String name) { 38 super(name); 39 } 40 41 protected void inheritRestrictions(BasicDataType origin) { 42 super.inheritRestrictions(origin); 43 if (origin instanceof ConfirmPasswordDataType) { 44 ConfirmPasswordDataType dataType = (ConfirmPasswordDataType) origin; 45 passwordRestriction.inherit(dataType.passwordRestriction); 46 } 47 } 48 protected void cloneRestrictions(BasicDataType origin) { 49 super.cloneRestrictions(origin); 50 if (origin instanceof ConfirmPasswordDataType) { 51 ConfirmPasswordDataType dataType = (ConfirmPasswordDataType) origin; 52 passwordRestriction = new PasswordRestriction(dataType.passwordRestriction); 53 } 54 } 55 56 protected Collection validateCastValue(Collection errors, Object castValue, Object value, Node node, Field field) { 57 errors = super.validateCastValue(errors, castValue, value, node, field); 58 errors = passwordRestriction.validate(errors, castValue, node, field); 59 return errors; 60 } 61 65 public void setField(String field) { 66 passwordRestriction.setValue(field); 67 } 68 71 public String getField() { 72 edit(); 73 return passwordRestriction.getField(); 74 } 75 76 protected StringBuffer toStringBuffer() { 77 StringBuffer buf = super.toStringBuffer(); 78 buf.append(" confirm(").append(passwordRestriction.getValue()).append(")"); 79 return buf; 80 } 81 82 protected class PasswordRestriction extends AbstractRestriction { 83 PasswordRestriction(PasswordRestriction source) { 84 super(source); 85 } 86 PasswordRestriction(String field) { 87 super("confirmpassword", field); 88 } 89 protected final String getField() { 90 return (String ) value; 91 } 92 93 protected boolean simpleValid(final Object v, final Node node, final Field field) { 94 if (node != null && field != null && v != null) { 95 if (! node.isChanged(getField())) return true; 96 97 Field passwordField = node.getNodeManager().getField(getField()); 98 Processor setProcessor = passwordField.getDataType().getProcessor(PROCESS_SET); 99 Object processedValue = setProcessor.process(node, field, v); 100 String passwordValue = (String ) node.getObjectValue(getField()); 101 if (log.isDebugEnabled()) { 102 log.debug("Password checking " + (node.isNew() ? "new" : "existing") + " node. Password field " + passwordField + " set-processor " + setProcessor); 103 log.debug("Offered value '" + v + "' --> '" + processedValue); 104 log.debug("Comparing '" + passwordValue + "' with '" + processedValue + "'(" + v + ")"); 105 } 106 return passwordValue.equals(v) || passwordValue.equals(processedValue); 107 } else { 108 return true; 109 } 110 } 111 } 112 113 } 114 | Popular Tags |