You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by an...@apache.org on 2003/12/31 12:41:41 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel WidgetDefinitionBuilder.java Field.java WidgetDefinition.java Widget.java

antonio     2003/12/31 03:41:41

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/formmodel
                        WidgetDefinitionBuilder.java Field.java
                        WidgetDefinition.java Widget.java
  Log:
  Formatting code
  
  Revision  Changes    Path
  1.2       +2 -0      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinitionBuilder.java
  
  Index: WidgetDefinitionBuilder.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinitionBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WidgetDefinitionBuilder.java	22 Apr 2003 12:04:19 -0000	1.1
  +++ WidgetDefinitionBuilder.java	31 Dec 2003 11:41:41 -0000	1.2
  @@ -60,6 +60,8 @@
    *
    * <p>Implementations may implement Avalon's Composable interface to gain access
    * to other components.
  + * 
  + * @version CVS $Id$
    */
   public interface WidgetDefinitionBuilder {
   
  
  
  
  1.21      +25 -52    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Field.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Field.java	29 Dec 2003 06:14:49 -0000	1.20
  +++ Field.java	31 Dec 2003 11:41:41 -0000	1.21
  @@ -115,34 +115,27 @@
       public Object getValue() {
           // Parse the value
           if (this.needsParse) {
  -
               // Clear value, it will be recomputed
               this.value = null;
  -            if (this.enteredValue == null) {
  -                this.value = null;
  -                this.needsParse = false;
  -                this.needsValidate = true;
  -
  -            } else {
  +            if (this.enteredValue != null) {
                   // Parse the value
  -                this.value = definition.getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
  -
  -                if (this.value == null) {
  -                    // Conversion failed
  +                this.value = getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
  +                if (this.value != null) {       // Conversion successfull
  +                    this.needsParse = false;
  +                    this.needsValidate = true;
  +                } else {        // Conversion failed
                       this.validationError = new ValidationError(new I18nMessage(
                           "datatype.conversion-failed",
  -                        new String[] {"datatype." + definition.getDatatype().getDescriptiveName()},
  +                        new String[] {"datatype." + getDatatype().getDescriptiveName()},
                           new boolean[] { true },
                           Constants.I18N_CATALOGUE
                       ));
  -
                       // No need for further validation (and need to keep the above error)
                       this.needsValidate = false;
  -                } else {
  -                    // Conversion successfull
  -                    this.needsParse = false;
  -                    this.needsValidate = true;
                   }
  +            } else {
  +                this.needsParse = false;
  +                this.needsValidate = true;                
               }
           }
   
  @@ -158,53 +151,42 @@
               try {
                   // Clear error, it will be recomputed
                   this.validationError = null;
  -
  -                if (this.value == null) {
  -                    // No value : is it required ?
  +                if (this.value != null) {
  +                    this.validationError = getDatatype().validate(value, new ExpressionContextImpl(this));
  +                } else {        // No value : is it required ?
                       if (this.definition.isRequired()) {
                           this.validationError = new ValidationError(new I18nMessage("general.field-required", Constants.I18N_CATALOGUE));
                       }
  -
  -                } else {
  -                    this.validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
                   }
  -
                   this.needsValidate = false;
               } finally {
                   isValidating = false;
               }
           }
  -
           return this.validationError == null ? this.value : null;
       }
   
       public void setValue(Object newValue) {
  -        if (newValue != null && !definition.getDatatype().getTypeClass().isAssignableFrom(newValue.getClass())) {
  +        if (newValue != null && !getDatatype().getTypeClass().isAssignableFrom(newValue.getClass())) {
               throw new RuntimeException("Incorrect value type for \"" + getFullyQualifiedId() +
  -                                       "\" (expected " + definition.getDatatype().getTypeClass() +
  -                                       ", got " + newValue.getClass() + ".");
  +                           "\" (expected " + getDatatype().getTypeClass() +
  +                           ", got " + newValue.getClass() + ".");
           }
  -
           Object oldValue = this.value;
  -
           boolean changed = ! (oldValue == null ? "" : oldValue).equals(newValue == null ? "" : newValue);
  -
           // Do something only if value is different or null
           // (null allows to reset validation error)
           if (changed || newValue == null) {
               this.value = newValue;
  -
               this.needsParse = false;
               this.validationError = null;
               // Force validation, even if set by the application
               this.needsValidate = true;
  -
  -            if (newValue == null) {
  -                this.enteredValue = null;
  +            if (newValue != null) {
  +                this.enteredValue = getDatatype().convertToString(newValue, getForm().getLocale());
               } else {
  -                this.enteredValue = definition.getDatatype().convertToString(newValue, getForm().getLocale());
  +                this.enteredValue = null;
               }
  -
               if (changed) {
                   getForm().addWidgetEvent(new ValueChangedEvent(this, oldValue, newValue));
               }
  @@ -216,17 +198,14 @@
   
       public void readFromRequest(FormContext formContext) {
           String newEnteredValue = formContext.getRequest().getParameter(getFullyQualifiedId());
  -        
           // whitespace & empty field handling
           if (newEnteredValue != null) {
               // TODO make whitespace behaviour configurable !!
               newEnteredValue = newEnteredValue.trim();
  -
               if (newEnteredValue.length() == 0) {
                   newEnteredValue = null;
               }
           }
  -        
           // TODO: This cause validation to occur too early.
           getValue();
           this.oldValue = value;
  @@ -236,12 +215,10 @@
               // TODO: Hmmm...
               //getForm().addWidgetEvent(new DeferredValueChangedEvent(this, value));
               getForm().addWidgetEvent(new DeferredValueChangedEvent(this, getValue()));
  -
               enteredValue = newEnteredValue;
               validationError = null;
               value = null;
               needsParse = true;
  -
           }
           
           // Always revalidate, as validation may depend on the value of other fields
  @@ -289,31 +266,28 @@
           if (enteredValue != null || value != null) {
               contentHandler.startElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL, Constants.EMPTY_ATTRS);
               String stringValue;
  -            if (value != null)
  -                stringValue = definition.getDatatype().convertToString(value, locale);
  -            else
  +            if (value != null) {
  +                stringValue = getDatatype().convertToString(value, locale);
  +            } else {
                   stringValue = enteredValue;
  +            }
               contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
               contentHandler.endElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL);
           }
  -
           // validation message element: only present if the value is not valid
           if (validationError != null) {
               contentHandler.startElement(Constants.WI_NS, VALIDATION_MSG_EL, Constants.WI_PREFIX_COLON + VALIDATION_MSG_EL, Constants.EMPTY_ATTRS);
               validationError.generateSaxFragment(contentHandler);
               contentHandler.endElement(Constants.WI_NS, VALIDATION_MSG_EL, Constants.WI_PREFIX_COLON + VALIDATION_MSG_EL);
           }
  -
           // generate label, help, hint, etc.
           definition.generateDisplayData(contentHandler);
  -
           // the selection list, if any
           if (selectionList != null) {
               selectionList.generateSaxFragment(contentHandler, locale);
           } else if (definition.getSelectionList() != null) {
               definition.getSelectionList().generateSaxFragment(contentHandler, locale);
           }
  -
           contentHandler.endElement(Constants.WI_NS, FIELD_EL, Constants.WI_PREFIX_COLON + FIELD_EL);
       }
   
  @@ -328,8 +302,7 @@
       public void setSelectionList(SelectionList selectionList) {
           if (selectionList != null &&
               selectionList.getDatatype() != null &&
  -            selectionList.getDatatype() != definition.getDatatype()) {
  -
  +            selectionList.getDatatype() != getDatatype()) {
               throw new RuntimeException("Tried to assign a SelectionList that is not associated with this widget's datatype.");
           }
           this.selectionList = selectionList;
  
  
  
  1.4       +2 -0      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinition.java
  
  Index: WidgetDefinition.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinition.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WidgetDefinition.java	29 Dec 2003 06:14:49 -0000	1.3
  +++ WidgetDefinition.java	31 Dec 2003 11:41:41 -0000	1.4
  @@ -58,6 +58,8 @@
    * function is a lot like that of the class in Java. Users of the Woody framework
    * usually won't have to bother with the WidgetDefinition's, but will rather use
    * the Widget's themselves.
  + * 
  + * @version CVS $Id$
    */
   public interface WidgetDefinition {
   
  
  
  
  1.7       +2 -0      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Widget.java
  
  Index: Widget.java
  ===================================================================
  RCS file: /home/cvs//cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Widget.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Widget.java	19 Dec 2003 21:28:39 -0000	1.6
  +++ Widget.java	31 Dec 2003 11:41:41 -0000	1.7
  @@ -88,6 +88,8 @@
    * WidgetDefinition holds the data that is static accross all widgets. This
    * keeps the Widgets small and light to create. This mechanism is similar to
    * classes and objects in Java.
  + * 
  + * @version CVS $Id$
    */
   public interface Widget {