You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/08/10 23:38:24 UTC

svn commit: r231334 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel: AbstractWidget.java Action.java AggregateField.java BooleanField.java CaptchaField.java Field.java Form.java MultiValueField.java Repeater.java

Author: vgritsenko
Date: Wed Aug 10 14:38:15 2005
New Revision: 231334

URL: http://svn.apache.org/viewcvs?rev=231334&view=rev
Log:
cosmetic changes

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.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/Field.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java Wed Aug 10 14:38:15 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,12 +33,12 @@
 /**
  * Abstract base class for Widget implementations. Provides functionality
  * common to many widgets.
- * 
+ *
  * @version $Id$
  */
 public abstract class AbstractWidget implements Widget {
 
-    /** 
+    /**
      * Containing parent-widget to this widget.
      * NOTE: avoid directly accessing this member since subclasses can mask this
      * property through own implemented getParent()
@@ -70,6 +70,7 @@
      */
     protected boolean wasValid = true;
 
+
     protected AbstractWidget(AbstractWidgetDefinition definition) {
         this.state = definition.getState();
     }
@@ -90,29 +91,29 @@
         return getDefinition().getId();
     }
 
-    /** 
+    /**
      * Concrete subclasses should allow access to their underlaying Definition
      * through this method.
      *
-     * If subclasses decide to return <code>null</code> they should also organize 
+     * If subclasses decide to return <code>null</code> they should also organize
      * own implementations of {@link #getId()}, {@link #getLocation()},
      * {@link #validate()}, {@link #generateLabel(ContentHandler)} and
      * {@link #generateDisplayData(ContentHandler)} to avoid NPE's.
-     * 
-     * @return the widgetDefinition from which this widget was instantiated. 
+     *
+     * @return the widgetDefinition from which this widget was instantiated.
      *        (@link WidgetDefinition#createInstance()}
      */
     public abstract WidgetDefinition getDefinition();
 
     /**
-     * @return the location-information (file, line and column) where this widget was 
+     * @return the location-information (file, line and column) where this widget was
      * configured.
      */
     public String getLocation() {
         return getDefinition().getLocation();
     }
 
-    /** 
+    /**
      * @return The parent-widget of this widget.
      */
     // This method is final in order for other methods in this class to use this.parent
@@ -120,20 +121,22 @@
         return this.parent;
     }
 
-    /** 
+    /**
      * Sets the parent-widget of this widget.
      * This is a write-once property.
-     * 
+     *
      * @param widget the parent-widget of this one.
      * @throws IllegalStateException when the parent had already been set.
-     */    
+     */
     public void setParent(Widget widget) {
-        if (this.parent != null) throw new IllegalStateException("The parent of widget " + getRequestParameterName() + " should only be set once.");
+        if (this.parent != null) {
+            throw new IllegalStateException("The parent of widget " + getRequestParameterName() + " should only be set once.");
+        }
         this.parent = widget;
     }
 
     /**
-     * @return the form where this widget belongs to.  
+     * @return the form where this widget belongs to.
      */
     public Form getForm() {
         if (this.form == null) {
@@ -164,12 +167,12 @@
     public WidgetState getCombinedState() {
         if (this.parent == null) {
             return this.state;
-        } 
+        }
         return WidgetState.strictest(this.state, this.parent.getCombinedState());
     }
 
     public String getRequestParameterName() {
-        
+
         // Default if no parent or parent with empty id
         String requestParamName = getId();
 
@@ -187,11 +190,12 @@
 
     public Widget lookupWidget(String path) {
 
-        if (path == null || path.equals(""))
+        if (path == null || path.equals("")) {
             return this;
+        }
 
         Widget relativeWidget;
-        String relativePath = null;        
+        String relativePath = null;
         int sepPosition = path.indexOf("" + Widget.PATH_SEPARATOR);
 
         if (sepPosition < 0) {
@@ -208,7 +212,7 @@
                 relativePath = path.substring(3);
             } else {
                 String childId = path.substring(0, sepPosition );
-                relativeWidget = getChild(childId);            
+                relativeWidget = getChild(childId);
                 relativePath = path.substring(sepPosition+1);
             }
         }
@@ -218,9 +222,9 @@
     }
 
     /**
-     * Concrete widgets that contain actual child widgets should override to 
+     * Concrete widgets that contain actual child widgets should override to
      * return the actual child-widget.
-     * 
+     *
      * @param id of the child-widget
      * @return <code>null</code> if not overriden.
      */
@@ -247,7 +251,7 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * Abstract implementation throws a {@link UnsupportedOperationException}.
      * Concrete subclass widgets need to override when supporting event broadcasting.
      */
@@ -261,7 +265,7 @@
 
     /**
      * Add a validator to this widget instance.
-     * 
+     *
      * @param validator
      */
     public void addValidator(WidgetValidator validator) {
@@ -273,7 +277,7 @@
 
     /**
      * Remove a validator from this widget instance
-     * 
+     *
      * @param validator
      * @return <code>true</code> if the validator was found.
      */
@@ -299,14 +303,14 @@
             // Failed
             this.wasValid = false;
             return false;
-        } 
+        }
         // Definition successful, test local validators
         if (this.validators == null) {
             // No local validators
             this.wasValid = true;
             return true;
         }
-        
+
         // Iterate on local validators
         Iterator iter = this.validators.iterator();
         while(iter.hasNext()) {
@@ -316,7 +320,7 @@
                 return false;
             }
         }
-        
+
         // All local iterators successful
         this.wasValid = true;
         return true;
@@ -331,13 +335,13 @@
 
     /**
      * {@inheritDoc}
-     * 
+     *
      * Delegates to the {@link #getDefinition()} to generate the 'label' part of
-     * the display-data of this widget.  
-     * 
+     * the display-data of this widget.
+     *
      * Subclasses should override if the getDefinition can return <code>null</code>
      * to avoid NPE's
-     * 
+     *
      * @param contentHandler
      * @throws SAXException
      */
@@ -348,12 +352,12 @@
     }
 
     /**
-     * Generates nested additional content nested inside the main element for this 
+     * Generates nested additional content nested inside the main element for this
      * widget which is generated by {@link #generateSaxFragment(ContentHandler, Locale)}
-     * 
+     *
      * The implementation on the AbstractWidget level inserts no additional XML.
      * Subclasses need to override to insert widget specific content.
-     * 
+     *
      * @param contentHandler to send the SAX events to
      * @param locale in which context potential content needs to be put.
      * @throws SAXException
@@ -362,26 +366,26 @@
         // Do nothing
     }
 
-    /** 
+    /**
      * The XML element name used in {@link #generateSaxFragment(ContentHandler, Locale)}
      * to produce the wrapping element for all the XML-instance-content of this Widget.
-     * 
-     * @return the main elementname for this widget's sax-fragment. 
+     *
+     * @return the main elementname for this widget's sax-fragment.
      */
     protected abstract String getXMLElementName();
 
-    /** 
+    /**
      * The XML attributes used in {@link #generateSaxFragment(ContentHandler, Locale)}
      * to be placed on the wrapping element for all the XML-instance-content of this Widget.
-     * 
+     *
      * This automatically adds @id={@link #getRequestParameterName()} to that element.
      * Concrete subclasses should call super.getXMLElementAttributes and possibly
      * add additional attributes.
-     * 
-     * Note: the @id is not added for those widgets who's getId() returns <code>null</code> 
+     *
+     * Note: the @id is not added for those widgets who's getId() returns <code>null</code>
      * (e.g. top-level container widgets like 'form').  The contract of returning a non-null
      * {@link AttributesImpl} is however maintained.
-     * 
+     *
      * @return the attributes for the main element for this widget's sax-fragment.
      */
     protected AttributesImpl getXMLElementAttributes() {
@@ -403,14 +407,14 @@
     /**
      * Delegates to the {@link #getDefinition()} of this widget to generate a common
      * set of 'display' data. (i.e. help, label, hint,...)
-     * 
+     *
      * Subclasses should override if the getDefinition can return <code>null</code>
      * to avoid NPE's.
-     * 
+     *
      * @param contentHandler where to send the SAX events to.
      * @throws SAXException
-     * 
-     * @see WidgetDefinition#generateDisplayData(ContentHandler) 
+     *
+     * @see WidgetDefinition#generateDisplayData(ContentHandler)
      */
     protected void generateDisplayData(ContentHandler contentHandler) throws SAXException {
         getDefinition().generateDisplayData(contentHandler);
@@ -418,26 +422,26 @@
 
     /**
      * {@inheritDoc}
-     * 
-     * This will generate some standard XML consisting of a simple wrapper 
+     *
+     * This will generate some standard XML consisting of a simple wrapper
      * element (name provided by {@link #getXMLElementName()}) with attributes
-     * (provided by {@link #getXMLElementAttributes()} around anything injected 
+     * (provided by {@link #getXMLElementAttributes()} around anything injected
      * in by both {@link #generateDisplayData(ContentHandler)} and
      * {@link #generateItemSaxFragment(ContentHandler, Locale)}.
-     * 
+     *
      * <pre>
      * &lt;fi:{@link #getXMLElementName()} {@link #getXMLElementAttributes()} &gt;
      *   {@link #generateDisplayData(ContentHandler)} (i.e. help, label, ...)
-     * 
+     *
      *   {@link #generateItemSaxFragment(ContentHandler, Locale)}
-     * &lt;/fi:{@link #getXMLElementName()} &gt; 
+     * &lt;/fi:{@link #getXMLElementName()} &gt;
      * </pre>
-     * 
+     *
      * @param contentHandler to send the SAX events to
      * @param locale in which context potential content needs to be put.
-     * @throws SAXException 
+     * @throws SAXException
      */
-    public void generateSaxFragment(ContentHandler contentHandler, Locale locale)    
+    public void generateSaxFragment(ContentHandler contentHandler, Locale locale)
     throws SAXException {
 
         if (getCombinedState().isDisplayingValues()) {
@@ -463,13 +467,17 @@
 
 	public Object getAttribute(String name) {
         Object result = null;
-        
+
         // First check locally
-        if (this.attributes != null) result = this.attributes.get(name);
-        
+        if (this.attributes != null) {
+            result = this.attributes.get(name);
+        }
+
         // Fall back to the definition's attributes
-        if (result == null) result = getDefinition().getAttribute(name);
-        
+        if (result == null) {
+            result = getDefinition().getAttribute(name);
+        }
+
         return result;
     }
 
@@ -485,7 +493,7 @@
             this.attributes.remove(name);
         }
     }
-    
+
     public String toString() {
         String className = this.getClass().getName();
         int last = className.lastIndexOf('.');

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java Wed Aug 10 14:38:15 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,14 +27,16 @@
  * or as a hidden field which gets its value set by javascript. The Action widget will generate its associated
  * ActionEvent when a requestparameter is present with as name the id of this Action widget, and as
  * value a non-empty value.
- * 
+ *
  * @version $Id$
  */
 public class Action extends AbstractWidget implements ActionListenerEnabled {
+
     private final ActionDefinition definition;
     /** Additional listeners to those defined as part of the widget definition (if any). */
     private ActionListener listener;
 
+
     public Action(ActionDefinition definition) {
         super(definition);
         this.definition = definition;
@@ -45,8 +47,9 @@
     }
 
     public void readFromRequest(final FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         Form form = getForm();
 
@@ -73,7 +76,6 @@
 
         if (form.getSubmitWidget() == this) {
             form.addWidgetEvent(new ActionEvent(this, definition.getActionCommand()));
-
             handleActivate();
         }
     }
@@ -89,8 +91,8 @@
 
     /**
      * Always return <code>true</code> (an action has no validation)
-     * 
-     * TODO is there a use case for actions having validators?
+     *
+     * <br>TODO is there a use case for actions having validators?
      */
     public boolean validate() {
         return true;
@@ -102,15 +104,15 @@
     public boolean isValid() {
         return true;
     }
-    
+
     private static final String ACTION_EL = "action";
 
     /**
      * @return "action"
      */
-    public String getXMLElementName() {        
+    public String getXMLElementName() {
         return ACTION_EL;
-    }  
+    }
 
     /**
      * Adds a ActionListener to this widget instance. Listeners defined
@@ -140,5 +142,4 @@
             super.broadcastEvent(event);
         }
     }
-
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java Wed Aug 10 14:38:15 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,6 +53,8 @@
  */
 public class AggregateField extends Field implements ContainerWidget {
 
+    private static final String AGGREGATEFIELD_EL = "aggregatefield";
+
     /**
      * List of nested fields
      */
@@ -71,7 +73,7 @@
     public final AggregateFieldDefinition getAggregateFieldDefinition() {
         return (AggregateFieldDefinition)getDefinition();
     }
-    
+
     public void initialize() {
         this.selectionList = getAggregateFieldDefinition().getSelectionList();
     }
@@ -99,8 +101,9 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
         if (newEnteredValue != null) {
@@ -198,6 +201,7 @@
             this.wasValid = true;
             return true;
         }
+
         if (enteredValue != null && !fieldsHaveValues()) {
             XMLizable failMessage = getAggregateFieldDefinition().getSplitFailMessage();
             if (failMessage != null) {
@@ -229,8 +233,6 @@
 
         return super.validate();
     }
-
-    private static final String AGGREGATEFIELD_EL = "aggregatefield";
 
     /**
      * @return "aggregatefield"

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java Wed Aug 10 14:38:15 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,10 +38,11 @@
  * has no purpose here (there would always be only 2 choices: true or false),
  * and the manner in which the request parameter of this widget is interpreted
  * is different (missing or empty request parameter means 'false', rather than null value).
- * 
+ *
  * @version $Id$
  */
-public class BooleanField extends AbstractWidget implements ValidationErrorAware, ValueChangedListenerEnabled {
+public class BooleanField extends AbstractWidget
+                          implements ValidationErrorAware, ValueChangedListenerEnabled {
 
     private static final String BOOLEAN_FIELD_EL = "booleanfield";
     private static final String VALUE_EL = "value";
@@ -55,6 +56,7 @@
     private ValueChangedListener listener;
     protected ValidationError validationError;
 
+
     public BooleanField(BooleanFieldDefinition definition) {
         super(definition);
         this.definition = definition;
@@ -63,7 +65,7 @@
     public WidgetDefinition getDefinition() {
         return this.definition;
     }
-    
+
     public void initialize() {
         Boolean value = this.definition.getInitialValue();
         if (value != null) {
@@ -76,6 +78,7 @@
         if (!getCombinedState().isAcceptingInputs()) {
             return;
         }
+
         validationError = null;
         Object oldValue = value;
         String param = formContext.getRequest().getParameter(getRequestParameterName());

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=231334&r1=231333&r2=231334&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 Aug 10 14:38:15 2005
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
 
 /**
  * A {@link Field} for CAPTCHA validation. Upon generation, a secret random string is stored
- * in a session attribute having a randomly generated name, for use by a 
+ * in a session attribute having a randomly generated name, for use by a
  * {@link org.apache.cocoon.forms.validation.impl.CaptchaValidator}.
  * <br>
  * Usage sample:
@@ -46,8 +46,8 @@
       &lt;/fd:validation>
     &lt;/fd:captcha>
  * </pre>
- * 
- * @see http://www.captcha.net/
+ *
+ * @see <a href="http://www.captcha.net/">captcha.net</a>
  * @version CVS $Id$
  */
 public class CaptchaField extends Field {
@@ -57,7 +57,7 @@
     private static final String IMAGE_EL = "captcha-image";
     private static final String SECRET_CHARS = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
     private static final int SESSION_ATTR_NAME_LENGTH = 6;
-    
+
     private Context avalonContext;
     private int length;
 
@@ -85,12 +85,12 @@
         this.avalonContext = avalonContext;
         this.length = fieldDefinition.getLength();
     }
-    
+
     private String generateSecret() {
         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)); 
+            secret.append(SECRET_CHARS.charAt(randomnumber));
         }
         return secret.toString();
     }
@@ -116,5 +116,4 @@
         contentHandler.startElement(Constants.INSTANCE_NS, IMAGE_EL, Constants.INSTANCE_PREFIX_COLON + IMAGE_EL, attrs);
         contentHandler.endElement(Constants.INSTANCE_NS, IMAGE_EL, Constants.INSTANCE_PREFIX_COLON + IMAGE_EL);
     }
-    
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java Wed Aug 10 14:38:15 2005
@@ -45,8 +45,8 @@
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
  * @version $Id$
  */
-public class Field extends AbstractWidget implements ValidationErrorAware, DataWidget, SelectableWidget,
-        ValueChangedListenerEnabled {
+public class Field extends AbstractWidget
+                   implements ValidationErrorAware, DataWidget, SelectableWidget, ValueChangedListenerEnabled {
 
     private static final String FIELD_EL = "field";
     private static final String VALUE_EL = "value";
@@ -107,13 +107,12 @@
 
     // At startup, we have no value to parse (both enteredValue and value are null),
     // but need to validate (e.g. error if field is required)
-    protected int valueState = VALUE_PARSED;
-
-
     /**
      * Transient widget processing state indicating that the widget is currently validating
      * (used to avoid endless loops when a validator calls getValue)
      */
+    protected int valueState = VALUE_PARSED;
+
     protected ValidationError validationError;
 
 
@@ -129,7 +128,7 @@
     public WidgetDefinition getDefinition() {
         return this.fieldDefinition;
     }
-    
+
     public void initialize() {
         Object value = this.fieldDefinition.getInitialValue();
         if (value != null) {
@@ -193,7 +192,7 @@
             // Do we need to call listeners? If yes, keep (and parse if needed) old value.
             boolean callListeners = changed && hasValueChangedListeners();
             Object oldValue = callListeners ? getValue() : null;
-            
+
             this.value = newValue;
             this.validationError = null;
             // Force validation, even if set by the application
@@ -212,8 +211,9 @@
     }
 
     public void readFromRequest(FormContext formContext) {
-        if (!getCombinedState().isAcceptingInputs())
+        if (!getCombinedState().isAcceptingInputs()) {
             return;
+        }
 
         String newEnteredValue = formContext.getRequest().getParameter(getRequestParameterName());
         // FIXME: Should we consider only non-null values?
@@ -224,7 +224,6 @@
         //if (newEnteredValue != null) {
         readFromRequest(newEnteredValue);
         //}
-
     }
 
     protected void readFromRequest(String newEnteredValue) {
@@ -245,14 +244,15 @@
         } else {
             changed = !enteredValue.equals(newEnteredValue);
         }
+
         if (changed) {
             ValidationError oldError = this.validationError;
-            
+
             // If we have some value-changed listeners, we must make sure the current value has been
             // parsed, to fill the event. Otherwise, we don't need to spend that extra CPU time.
             boolean hasListeners = hasValueChangedListeners();
             Object oldValue = hasListeners ? getValue() : null;
-            
+
             enteredValue = newEnteredValue;
             validationError = null;
             value = null;
@@ -302,7 +302,7 @@
         }
 
         this.wasValid = this.validationError == null;
-        return this.validationError == null;
+        return this.wasValid;
     }
 
     /**
@@ -318,9 +318,11 @@
         if (this.valueState != VALUE_UNPARSED) {
             throw new IllegalStateException("Field is not in UNPARSED state (" + this.valueState + ")");
         }
+
         // Clear value, it will be recomputed
         this.value = null;
         this.validationError = null;
+
         if (this.enteredValue != null) {
             // Parse the value
             ConversionResult conversionResult = getDatatype().convertFromString(this.enteredValue, getForm().getLocale());
@@ -346,7 +348,6 @@
      * validation failed.
      */
     private void doValidate() {
-
         if (this.valueState != VALUE_PARSED) {
             throw new IllegalStateException("Field is not in PARSED state (" + this.valueState + ")");
         }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java Wed Aug 10 14:38:15 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -41,7 +41,10 @@
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
  * @version $Id$
  */
-public class Form extends AbstractContainerWidget implements ValidationErrorAware {
+public class Form extends AbstractContainerWidget
+                  implements ValidationErrorAware {
+
+    private static final String FORM_EL = "form";
 
     private final FormDefinition definition;
 
@@ -57,15 +60,16 @@
     //to read their value before events get fired.
     private boolean bufferEvents = false;
     private CursorableLinkedList events;
-    
+
     // Widgets that need to be updated in the client when in AJAX mode
     private Set updatedWidgets;
 
+
     public Form(FormDefinition definition) {
         super(definition);
         this.definition = definition;
     }
-    
+
     /**
      * Initialize the form by recursively initializing all its children. Any events occuring within the
      * initialization phase are buffered and fired after initialization is complete, so that any action
@@ -110,13 +114,13 @@
             event.getSourceWidget().broadcastEvent(event);
         }
     }
-    
+
     public void addWidgetUpdate(Widget widget) {
         if (this.updatedWidgets != null) {
             this.updatedWidgets.add(widget.getRequestParameterName());
         }
     }
-    
+
     public Set getUpdatedWidgets() {
         return this.updatedWidgets == null ? Collections.EMPTY_SET : this.updatedWidgets;
     }
@@ -235,7 +239,7 @@
         if (formContext.getRequest().getParameter("cocoon-ajax") != null) {
             this.updatedWidgets = new HashSet();
         }
-        
+
         // Fire the binding phase events
         fireEvents();
 
@@ -323,7 +327,7 @@
         // let all individual widgets read their value from the request object
         super.readFromRequest(formContext);
     }
-    
+
     /**
      * Set a validation error on this field. This allows the form to be externally marked as invalid by
      * application logic.
@@ -340,7 +344,7 @@
     public void setValidationError(ValidationError error) {
         this.validationError = error;
     }
-    
+
     /**
      * Performs validation phase of form processing.
      */
@@ -369,8 +373,6 @@
         this.wasValid = this.isValid && this.validationError == null;
         return this.wasValid;
     }
-
-    private static final String FORM_EL = "form";
 
     public String getXMLElementName() {
         return FORM_EL;

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java Wed Aug 10 14:38:15 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -49,7 +49,8 @@
  *
  * @version $Id$
  */
-public class MultiValueField extends AbstractWidget implements ValidationErrorAware, SelectableWidget, DataWidget {
+public class MultiValueField extends AbstractWidget
+                             implements ValidationErrorAware, SelectableWidget, DataWidget {
 
     private static final String MULTIVALUEFIELD_EL = "multivaluefield";
     private static final String VALUES_EL = "values";
@@ -67,7 +68,7 @@
         super(definition);
         this.definition = definition;
     }
-    
+
     public void initialize() {
         this.selectionList = this.definition.getSelectionList();
         super.initialize();
@@ -121,10 +122,10 @@
 
         if (values != null) {
             validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
-        }
-        else {
+        } else {
             validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed", Constants.I18N_CATALOGUE));
         }
+
         this.wasValid = validationError == null ? super.validate() : false;
         return this.wasValid;
     }
@@ -200,7 +201,7 @@
         if (selectionList == null) {
             throw new IllegalArgumentException("An MultiValueField's selection list cannot be null.");
         }
-        
+
         if (selectionList.getDatatype() != null &&
             selectionList.getDatatype() != definition.getDatatype()) {
 

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java?rev=231334&r1=231333&r2=231334&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java Wed Aug 10 14:38:15 2005
@@ -1,12 +1,12 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,15 +40,23 @@
  *
  * <p>Using the methods {@link #getSize()} and {@link #getWidget(int, java.lang.String)}
  * you can access all of the repeated widget instances.
- * 
+ *
  * @version $Id$
  */
-public class Repeater extends AbstractWidget implements ValidationErrorAware //, ContainerWidget 
-{
+public class Repeater extends AbstractWidget
+                      implements ValidationErrorAware {
+
+    private static final String REPEATER_EL = "repeater";
+    private static final String HEADINGS_EL = "headings";
+    private static final String HEADING_EL = "heading";
+    private static final String LABEL_EL = "label";
+    private static final String REPEATER_SIZE_EL = "repeater-size";
+
     private final RepeaterDefinition definition;
     private final List rows = new ArrayList();
     protected ValidationError validationError;
 
+
     public Repeater(RepeaterDefinition repeaterDefinition) {
         super(repeaterDefinition);
         this.definition = repeaterDefinition;
@@ -62,7 +70,7 @@
     public WidgetDefinition getDefinition() {
         return definition;
     }
-    
+
     public void initialize() {
         for (int i = 0; i < this.rows.size(); i++) {
             ((RepeaterRow)rows.get(i)).initialize();
@@ -81,7 +89,7 @@
         getForm().addWidgetUpdate(this);
         return repeaterRow;
     }
-    
+
     public RepeaterRow addRow(int index) {
         RepeaterRow repeaterRow = new RepeaterRow(definition);
         if (index >= this.rows.size()) {
@@ -97,30 +105,33 @@
     public RepeaterRow getRow(int index) {
         return (RepeaterRow)rows.get(index);
     }
-    
+
     /**
-     * Overrides {@link AbstractWidget#getChild(String)} to return the 
+     * Overrides {@link AbstractWidget#getChild(String)} to return the
      * repeater-row indicated by the index in 'id'
-     * 
+     *
      * @param id index of the row as a string-id
      * @return the repeater-row at the specified index
      */
     public Widget getChild(String id) {
-        int rowIndex = -1;
+        int rowIndex;
         try {
             rowIndex = Integer.parseInt(id);
         } catch (NumberFormatException nfe) {
             // Not a number
             return null;
         }
-        if (rowIndex < 0 || rowIndex >= getSize()) 
+
+        if (rowIndex < 0 || rowIndex >= getSize()) {
             return null;
+        }
+
         return getRow(rowIndex);
     }
-    
+
     /**
      * Crawls up the parents of a widget up to finding a repeater row.
-     * 
+     *
      * @param widget the widget whose row is to be found
      * @return the repeater row
      */
@@ -129,14 +140,14 @@
         while(result != null && ! (result instanceof Repeater.RepeaterRow)) {
             result = result.getParent();
         }
-        
+
         if (result == null) {
             throw new RuntimeException("Could not find a parent row for widget " + widget);
 
         }
         return (Repeater.RepeaterRow)result;
     }
-    
+
     /**
      * Get the position of a row in this repeater.
      * @param row the row which we search the index for
@@ -153,7 +164,7 @@
         rows.remove(index);
         getForm().addWidgetUpdate(this);
     }
-    
+
     public void moveRowLeft(int index) {
         if (index == 0 || index >= this.rows.size()) {
             // do nothing
@@ -175,7 +186,7 @@
         }
         getForm().addWidgetUpdate(this);
     }
-    
+
     /**
      * @deprecated {@see #clear()}
      *
@@ -184,13 +195,13 @@
         clear();
         getForm().addWidgetUpdate(this);
     }
-    
+
     /**
      * Clears all rows from the repeater and go back to the initial size
      */
     public void clear() {
         rows.clear();
-        
+
         // and reset to initial size
         for (int i = 0; i < this.definition.getInitialSize(); i++) {
             addRow();
@@ -208,7 +219,7 @@
         RepeaterRow row = (RepeaterRow)rows.get(rowIndex);
         return row.getChild(id);
     }
-    
+
     public void readFromRequest(FormContext formContext) {
         if (!getCombinedState().isAcceptingInputs())
             return;
@@ -256,33 +267,33 @@
             this.wasValid = true;
             return true;
         }
+
         boolean valid = true;
         Iterator rowIt = rows.iterator();
         while (rowIt.hasNext()) {
             RepeaterRow row = (RepeaterRow)rowIt.next();
             valid = valid & row.validate();
         }
-        this.wasValid = (valid ? super.validate() : false) && this.validationError == null;
+
+        if (!valid) {
+            valid = super.validate();
+        }
+
+        this.wasValid = valid && this.validationError == null;
         return this.wasValid;
     }
 
 
-    private static final String REPEATER_EL = "repeater";
-    private static final String HEADINGS_EL = "headings";
-    private static final String HEADING_EL = "heading";
-    private static final String LABEL_EL = "label";
-    private static final String REPEATER_SIZE_EL = "repeater-size";
-    
 
     /**
      * @return "repeater"
      */
     public String getXMLElementName() {
         return REPEATER_EL;
-    }   
-    
-    
-    
+    }
+
+
+
 	/**
 	 * Adds @size attribute
 	 */
@@ -291,8 +302,8 @@
         attrs.addCDATAAttribute("size", String.valueOf(getSize()));
 		return attrs;
 	}
-    
-        
+
+
 	public void generateDisplayData(ContentHandler contentHandler)
 			throws SAXException {
         // the repeater's label
@@ -311,8 +322,8 @@
         }
         contentHandler.endElement(Constants.INSTANCE_NS, HEADINGS_EL, Constants.INSTANCE_PREFIX_COLON + HEADINGS_EL);
 	}
-    
-    
+
+
     public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
         // the actual rows in the repeater
         Iterator rowIt = rows.iterator();
@@ -337,11 +348,11 @@
      * Generates a repeater-size element with a size attribute indicating the size of this repeater.
      */
     public void generateSize(ContentHandler contentHandler) throws SAXException {
-        AttributesImpl attrs = getXMLElementAttributes(); 
+        AttributesImpl attrs = getXMLElementAttributes();
         contentHandler.startElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_SIZE_EL, attrs);
         contentHandler.endElement(Constants.INSTANCE_NS, REPEATER_SIZE_EL, Constants.INSTANCE_PREFIX_COLON + REPEATER_SIZE_EL);
     }
-    
+
     /**
      * Set a validation error on this field. This allows repeaters be externally marked as invalid by
      * application logic.
@@ -361,16 +372,14 @@
 
     public class RepeaterRow extends AbstractContainerWidget {
 
+        private static final String ROW_EL = "repeater-row";
+
         public RepeaterRow(RepeaterDefinition definition) {
             super(definition);
             setParent(Repeater.this);
-            ((ContainerDefinition)definition).createWidgets(this);
+            definition.createWidgets(this);
         }
 
-//        public String getLocation() {
-//            return Repeater.this.getLocation();
-//        }
-//        
         public WidgetDefinition getDefinition() {
             return Repeater.this.definition;
         }
@@ -383,7 +392,7 @@
         public Form getForm() {
             return Repeater.this.getForm();
         }
-        
+
         public void initialize() {
             // Initialize children but don't call super.initialize() that would call the repeater's
             // on-create handlers for each row.
@@ -398,9 +407,6 @@
             // Validate only child widtgets, as the definition's validators are those of the parent repeater
             return widgets.validate();
         }
-        
-        private static final String ROW_EL = "repeater-row";
-
 
         /**
          * @return "repeater-row"
@@ -411,16 +417,15 @@
 
         public void generateLabel(ContentHandler contentHandler) throws SAXException {
             // this widget has its label generated in the context of the repeater
-        }     
-        
+        }
+
         public void generateDisplayData(ContentHandler contentHandler)
                 throws SAXException {
             // this widget has its display-data generated in the context of the repeater
         }
-        
+
         public void broadcastEvent(WidgetEvent event) {
             throw new UnsupportedOperationException("Widget " + this.getRequestParameterName() + " doesn't handle events.");
         }
     }
-
 }