cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/acting FormValidatorAction.java ValidatorActionHelper.java ValidatorActionResult.java
Date Fri, 09 Aug 2002 08:27:18 GMT
haul        2002/08/09 01:27:18

  Modified:    src/java/org/apache/cocoon/acting FormValidatorAction.java
                        ValidatorActionHelper.java
                        ValidatorActionResult.java
  Added:       src/java/org/apache/cocoon/transformation
                        SimpleFormTransformer.java
  Log:
    <action dev="CH" type="add">
     Simple Formvalidation: FormValidatorAction sets attribute "*" to indicate
     overall validation status. Added SimpleFormTransformer that fills XHTML form
     fields with values from request parameters and allows conditional error tags
     depending on validation result. This removes the requirement for
     XSP. Changed ordering of error levels: "notpresent" (indicates that no
     validation result is present for this parameter) moves between "ok" and
     "error". New error level "maxerror" used in conjunction with the
     transformer, is never set, used as upper bound.
    </action>
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/java/org/apache/cocoon/transformation/SimpleFormTransformer.java
  
  Index: SimpleFormTransformer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.transformation;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.acting.ValidatorActionResult;
  import org.apache.cocoon.components.language.markup.xsp.XSPFormValidatorHelper;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.xml.AbstractXMLPipe;
  
  import org.xml.sax.SAXException;
  import org.xml.sax.Attributes;
  import org.xml.sax.helpers.AttributesImpl;
  
  import org.apache.cocoon.util.HashMap;
  import java.util.Map;
  import java.util.Stack;
  import java.io.IOException;
  
  /** Eliminates the need for XSP to use FormValidatorAction. Caveat:
   * Select options need a value attribute to work correctly.
   *
   * <p>This transformer fills all HTML 4 form elements with values from
   * parameters of the request object with the same name. It handles
   * select boxes, textareas, checkboxes, radio buttons, password and
   * text fields, and buttons.</p>
   *
   * <p>In addition, it handles FormValidatorAction results by
   * selectively omitting &lt;error/&gt; elements. These elements need a
   * "name" attribute corresponding to the name of the form element, and
   * either a "when" or a "when-ge" attribute.</p>
   *
   * <p>An error element is send down the pipeline if validation results
   * are available and either the results equals the "when" attribute or
   * the result is greater or equal to the "when-ge" attribute.</p>
   *
   * <p>Names for validation results are "ok", "not-present", "error",
   * "is-null", "too-small", "too-large", and "no-match" for the similar
   * named values from ValidatorActionResult.</p>
   *
   * <p>There need not to be an "error" element for every form element,
   * multiple error elements for the same form element may be
   * present.</p>
   *
   * <p>To use this transformer, add the following to your
   * transformation pipeline: <pre>
   *   &lt;map:transform type="simple-form"/&gt;
   * </pre></p>
   *
   * <p>Example:<pre>
   *     &lt;input name="user.name" size="50" maxlength="60"/&gt;
   *     &lt;error name="user.name" when-ge="error"&gt;required&lt;/error&gt;
   * </pre></p>
   *
   * @author <a href="mailto:haul@apache.org">Christian Haul</a>
   * @version CVS $Id: SimpleFormTransformer.java,v 1.1 2002/08/09 08:27:17 haul Exp $
   */
  public class SimpleFormTransformer extends AbstractTransformer 
      implements Composable, Configurable, Recyclable {
  
      /** Symbolic names for elements */
      /** unknown element */
      private static final int ELEMENT_DEFAULT = 0;
      /** input element */
      private static final int ELEMENT_INPUT = 1;
      /** select element */
      private static final int ELEMENT_SELECT = 2;
      /** option element */
      private static final int ELEMENT_OPTION = 3;
      /** textarea element */
      private static final int ELEMENT_TXTAREA = 4;
      /** error element */
      private static final int ELEMENT_ERROR = 5;
      /** default element as Integer (needed as default in org.apache.cocoon.util.HashMap.get())
*/
      private static final Integer defaultElement = new Integer(ELEMENT_DEFAULT);
  
      /** input type unknown */
      private static final int TYPE_DEFAULT = 0;
      /** input type checkbox */
      private static final int TYPE_CHECKBOX = 1;
      /** input type radio */
      private static final int TYPE_RADIO = 2;
      /** default input type as Integer (needed as default in org.apache.cocoon.util.HashMap.get())
*/
      private static final Integer defaultType = new Integer(TYPE_DEFAULT);
      
  
      /** map element name string to symbolic name */
      private static final HashMap elementNames;
      /** map input type string to symbolic name */
      private static final HashMap inputTypes;
      /** map ValidatorActionResult to name string */
      private static final HashMap validatorResults;
      /** map name string to ValidatorActionResult */
      private static final HashMap validatorResultLabel;
  
      /** setup mapping tables */
      static {
          HashMap names = new HashMap();
          names.put("input", new Integer(ELEMENT_INPUT));
          names.put("select", new Integer(ELEMENT_SELECT));
          names.put("option", new Integer(ELEMENT_OPTION));
          names.put("textarea", new Integer(ELEMENT_TXTAREA));
          names.put("error", new Integer(ELEMENT_ERROR));
          elementNames = names;
          names = null;
  
          names = new HashMap();
          names.put("checkbox", new Integer(TYPE_CHECKBOX));
          names.put("radio", new Integer(TYPE_RADIO));
          inputTypes = names;
          names = null;
  
          names = new HashMap();
          names.put("ok", ValidatorActionResult.OK);
          names.put("not-present", ValidatorActionResult.NOTPRESENT);
          names.put("error", ValidatorActionResult.ERROR);
          names.put("is-null", ValidatorActionResult.ISNULL);
          names.put("too-small", ValidatorActionResult.TOOSMALL);
          names.put("too-large", ValidatorActionResult.TOOLARGE);
          names.put("no-match", ValidatorActionResult.NOMATCH);
          validatorResultLabel = names;
  
          names = new HashMap();
          names.put(ValidatorActionResult.OK,"ok");
          names.put(ValidatorActionResult.NOTPRESENT,"not-present");
          names.put(ValidatorActionResult.ERROR,"error");
          names.put(ValidatorActionResult.ISNULL,"is-null");
          names.put(ValidatorActionResult.TOOSMALL,"too-small");
          names.put(ValidatorActionResult.TOOLARGE,"too-large");
          names.put(ValidatorActionResult.NOMATCH,"no-match");
          validatorResults = names;
          names = null;
      }
  
      /** nesting level of ignored elements */
      protected int ignoreCount;
      /** stack of ignored element names */
      protected Stack   stack = new Stack();
  
      /** name attribute of current select element */
      protected String selectName = null;
  
      /** current element's request parameter values */
      protected String[] values = null;
      
      /** current request's validation results (all validated elements) */
      protected Map validationResults = null;
  
      /** The current Request object */
      protected Request            request;
      /** The current objectModel of the environment */
      protected Map                objectModel;
      /** The parameters specified in the sitemap */
      protected Parameters         parameters;
      /** The Avalon ComponentManager for getting Components */
      protected ComponentManager   manager;
  
      /** Are we already initialized for the current request? */
      private boolean isInitialized;
  
      /** Empty attributes (for performance). This can be used
       *  do create own attributes, but make sure to clean them
       *  afterwords.
       */
      protected AttributesImpl emptyAttributes = new AttributesImpl();
  
      /** set per instance variables to defaults */
      private void reset(){
          this.objectModel = null;
          this.request = null;
          this.parameters = null;
          this.stack.clear();
          this.ignoreCount = 0;
          this.selectName = null;
          this.values = null;
          this.validationResults = null;
      }
  
  
      /**
       * Avalon Configurable Interface
       */
      public void configure(Configuration configuration)
      throws ConfigurationException {
      }
  
  
      /**
       * Setup the next round.
       * The instance variables are initialised.
       * @param resolver The current SourceResolver
       * @param objectModel The objectModel of the environment.
       * @param src The value of the src attribute in the sitemap.
       * @param par The parameters from the sitemap.
       */
      public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
      throws ProcessingException, SAXException, IOException {
  
          this.reset();
          this.objectModel = objectModel;
  
          this.request = ObjectModelHelper.getRequest(objectModel);
          if (request == null) {
              getLogger().debug("no request object");
              throw new ProcessingException("no request object");
          }
          this.parameters = par;
          this.isInitialized = false;
          this.validationResults = XSPFormValidatorHelper.getResults(objectModel);
      }
  
      /**
       *  Recycle this component.
       */
      public void recycle() {
          super.recycle();
          this.reset();
      }
  
      /**
       * Avalon Composable Interface
       * @param manager The Avalon Component Manager
       */
      public void compose(ComponentManager manager) {
          this.manager = manager;
      }
  
      /** 
       * Generate string representation of attributes. For debug only.
       */
      protected String printAttributes(Attributes attr){
          StringBuffer sb = new StringBuffer();
          sb.append('[');
          for (int i = 0; i<attr.getLength(); i++) {
              sb
                  .append('@')
                  .append(attr.getLocalName(i))
                  .append("='")
                  .append(attr.getValue(i))
                  .append("' ");
          }
          sb.append(']');
          return sb.toString();
      }
  
  
      /**
       * Handle input elements that may have a "checked" attributes,
       * i.e. checkbox and radio.
       * @param aName name of input element from "name" attribute.
       */
      protected void startCheckableElement(String uri, String name, String raw, AttributesImpl
attributes, String aName)
          throws SAXException {
  
          String checked = attributes.getValue("checked");
          String value = attributes.getValue("value");
          if (aName != null){
              boolean found = false;
              for (int i=0; i<this.values.length; i++) {
                  if (this.values[i].equals(String.valueOf(value))) {
                      found = true;
                      if (checked == null) {
                          attributes.addAttribute("","checked","checked","CDATA","");
                      }
                      break;
                  }
              }
              if (!found && checked != null) {
                  attributes.removeAttribute(attributes.getIndex("checked"));
              }
          }
          super.startElement(uri, name, raw, (Attributes)attributes);
      }
  
  
      /**
       * Handle input elements that may don't have a "checked"
       * attributes, e.g. text, password, button.
       * @param aName name of input element from "name" attribute.
       */
      protected void startNonCheckableElement(String uri, String name, String raw, AttributesImpl
attributes, String aName)
          throws SAXException {
  
          String value = attributes.getValue("value");
          this.values = (aName != null ? this.request.getParameterValues(aName) : null);
          if (this.values != null) {
              if (value != null) {
                  attributes.setValue(attributes.getIndex("value"), this.values[0]);
              } else {
                  attributes.addAttribute("", "value","value","CDATA",this.values[0]);
              }
          }
          super.startElement(uri, name, raw, (Attributes)attributes);
          this.values = null;
      }
  
      /**
       * Handle input elements. Calls startCheckableElement or
       * startNonCheckableElement.
       */
      protected void startInputElement(String uri, String name, String raw, Attributes attr)
          throws SAXException {
  
          // @value = request.getParameterValues(@name)
          String aName = attr.getValue("name");
          String fixed = attr.getValue("fixed");
  
          this.values = request.getParameterValues(aName);
          if (aName == null || this.values == null || (fixed != null && parseBoolean(fixed)))
{
              super.startElement(uri, name, raw, attr);
  
          } else {
          
              AttributesImpl attributes = null;
              if (attr instanceof AttributesImpl) {
                  attributes = (AttributesImpl) attr;
              } else {
                  attributes = new AttributesImpl(attr);
              }
              String type = attributes.getValue("type");
              switch (((Integer)inputTypes.get(type,defaultType)).intValue()) {
              case TYPE_CHECKBOX:
              case TYPE_RADIO:
                  this.startCheckableElement(uri, name, raw, attributes, aName);
                  break;
                  
              case TYPE_DEFAULT:
                  this.startNonCheckableElement(uri, name, raw, attributes, aName);
                  break;
              }
              this.values=null;
          }
      }
  
  
      /**
       * Handle select elements. Sets up some instance variables for
       * following option elements.
       */
      protected void startSelectElement(String uri, String name, String raw, Attributes attr)
          throws SAXException {
  
          // this.selectName = @name
          // this.values = request.getParameterValues(@name)
          String aName = attr.getValue("name");
          String fixed = attr.getValue("fixed");
          this.selectName = attr.getValue("name");
          if (aName != null && (this.selectName != null || (fixed != null &&
parseBoolean(fixed))))
              this.values = this.request.getParameterValues(this.selectName);
          super.startElement(uri, name, raw, attr);
      }
  
  
      /**
       * Handle option elements. Uses instance variables set up by
       * startSelectElement. Relies on option having a "value"
       * attribute, i.e. does not check following characters if "value"
       * is not present.
       */
      protected void startOptionElement(String uri, String name, String raw, Attributes attr)
          throws SAXException {
  
          // add @selected if @value in request.getParameterValues(@name)
          if (this.values == null) {
              super.startElement(uri, name, raw, attr);
          } else {
              AttributesImpl attributes = null;
              if (attr instanceof AttributesImpl) {
                  attributes = (AttributesImpl) attr;
              } else {
                  attributes = new AttributesImpl(attr);
              }
              String selected = attributes.getValue("selected");
              String value = attributes.getValue("value");
              boolean found = false;
              
              for (int i=0; i<this.values.length; i++) {
                  if (this.values[i].equals(String.valueOf(value))) {
                      found = true;
                      if (selected == null) {
                          attributes.addAttribute("","selected","selected","CDATA","");
                      }
                      break;
                  }
              }
              if (!found && selected != null) {
                  attributes.removeAttribute(attributes.getIndex("selected"));
              }
              
              super.startElement(uri, name, raw, (Attributes)attributes);
          }
      }
          
      /**
       * Handles textarea elements. Skips nested events if request
       * parameter with same name exists.
       */
      protected void startTextareaElement(String uri, String name, String raw, Attributes
attributes)
          throws SAXException {
  
          String aName = attributes.getValue("name");
          String fixed = attributes.getValue("fixed");
          String[] value = null;
          if (aName != null) 
              value = this.request.getParameterValues(aName);
          if (value!=null || (fixed != null && (parseBoolean(fixed)))) {
              this.ignoreCount++;
              this.stack.push(name);
              super.startElement(uri, name, raw, attributes);
              super.characters(value[0].toCharArray(), 0, value[0].length());
          } else {
              super.startElement(uri, name, raw, attributes);
          }
      }
  
  
      /**
       * Handle error elements. If validation results are available,
       * compares validation result for parameter with the same name as
       * the "name" attribute with the result names is "when" and
       * "when-ge". Drops element and all nested events when error
       * condition is not met.
       */
      protected void startErrorElement(String uri, String name, String raw, Attributes attr)
          throws SAXException {
          
          if (this.validationResults == null) {
              this.ignoreCount++;
              this.stack.push(name);
          } else {
              String aName = attr.getValue("name");
              if (aName == null) {
                  super.startElement(uri, name, raw, attr);
              } else {
                  ValidatorActionResult validation = XSPFormValidatorHelper.getParamResult(this.objectModel,
aName);
                  String when = attr.getValue("when");
                  String when_ge = attr.getValue("when-ge");
                  
                  if ((when != null && when.equals((String)validatorResults.get(validation)))
||
                      (when_ge != null && validation.ge((ValidatorActionResult) 
                                                        validatorResultLabel.get(when_ge,ValidatorActionResult.MAXERROR)))
                      ) {
                      AttributesImpl attributes=null;
                      if (attr instanceof AttributesImpl) {
                          attributes = (AttributesImpl) attr;
                      } else {
                          attributes = new AttributesImpl(attr);
                      }
                      // remove attributes not meant for client
                      attributes.removeAttribute(attributes.getIndex("name"));
                      if (when != null)    attributes.removeAttribute(attributes.getIndex("when"));
                      if (when_ge != null) attributes.removeAttribute(attributes.getIndex("when-ge"));
                      super.startElement(uri, name, raw, (Attributes)attributes);
                  } else {
                      this.ignoreCount++;
                      this.stack.push(name);
                  };
              }
          }
      }
  
  
  
      /**
       * Start processing elements of our namespace.
       * This hook is invoked for each sax event with our namespace.
       * @param uri The namespace of the element.
       * @param name The local name of the element.
       * @param raw The qualified name of the element.
       * @param attr The attributes of the element.
       */
      public void startElement(String uri, String name, String raw, Attributes attr)
          throws SAXException {
  
          if (this.ignoreCount == 0) {
              if (uri!="") {
                  super.startElement(uri, name, raw, attr);
              } else {
                  switch (((Integer)elementNames.get(name,defaultElement)).intValue()) {
                  case ELEMENT_INPUT:
                      this.startInputElement(uri,name,raw,attr);
                      break;
  
                  case ELEMENT_SELECT:
                      this.startSelectElement(uri,name,raw,attr);
                      break;
  
                  case ELEMENT_OPTION:
                      this.startOptionElement(uri,name,raw,attr);
                      break;
  
                  case ELEMENT_TXTAREA:
                      this.startTextareaElement(uri,name,raw,attr);
                      break;
  
                  case ELEMENT_ERROR:
                      this.startErrorElement(uri,name,raw,attr);
                      break;
  
                  default:
                      super.startElement(uri, name, raw, attr);
                  }
              }
          } else {
              this.ignoreCount++;
              this.stack.push(name);
              if (((Integer)elementNames.get(name,defaultElement)).intValue()==ELEMENT_ERROR){
              }
          }
      }
  
      /**
       * Start processing elements of our namespace.
       * This hook is invoked for each sax event with our namespace.
       * @param uri The namespace of the element.
       * @param name The local name of the element.
       * @param raw The qualified name of the element.
       */
      public void endElement(String uri, String name, String raw)
          throws SAXException {
  
          if (uri!="") {
              if (this.ignoreCount == 0) super.endElement(uri, name, raw);
          } else {
              if (this.ignoreCount>0){
                  if (((String)this.stack.peek()).equals(name)){
                      this.stack.pop();
                      this.ignoreCount--;
                  }
              } else {
                  switch (((Integer)elementNames.get(name,defaultElement)).intValue()) {
                  case ELEMENT_INPUT:
                      super.endElement(uri, name, raw);
                      break;
                  case ELEMENT_SELECT:
                      this.selectName = null;
                      this.values = null;
                      super.endElement(uri, name, raw);
                      break;
                  case ELEMENT_OPTION:
                      super.endElement(uri, name, raw);
                      break;
                  case ELEMENT_TXTAREA:
                      super.endElement(uri, name, raw);
                      break;
                  case ELEMENT_ERROR:
                      super.endElement(uri, name, raw);
                      break;
                  default:
                      super.endElement(uri, name, raw);
                  }
              }
          }
      }
  
      /**
       * Receive notification of character data.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void characters(char c[], int start, int len)
      throws SAXException {
          if (this.ignoreCount == 0) super.characters(c, start, len);
      }
  
      /**
       * Receive notification of ignorable whitespace in element content.
       *
       * @param c The characters from the XML document.
       * @param start The start position in the array.
       * @param len The number of characters to read from the array.
       */
      public void ignorableWhitespace(char c[], int start, int len)
      throws SAXException {
          if (this.ignoreCount == 0) super.ignorableWhitespace(c, start, len);
      }
  
      /**
       * Receive notification of a processing instruction.
       *
       * @param target The processing instruction target.
       * @param data The processing instruction data, or null if none was
       *             supplied.
       */
      public void processingInstruction(String target, String data)
      throws SAXException {
          if (this.ignoreCount == 0) super.processingInstruction(target, data);
      }
  
      /**
       * Receive notification of a skipped entity.
       *
       * @param name The name of the skipped entity.  If it is a  parameter
       *             entity, the name will begin with '%'.
       */
      public void skippedEntity(String name)
      throws SAXException {
          if (this.ignoreCount == 0) super.skippedEntity(name);
      }
  
      private static  boolean parseBoolean(String aBoolean){
          return "true".equalsIgnoreCase(aBoolean);
      }
  }
  
  
  
  1.10      +9 -4      xml-cocoon2/src/java/org/apache/cocoon/acting/FormValidatorAction.java
  
  Index: FormValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/FormValidatorAction.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FormValidatorAction.java	28 Apr 2002 19:03:10 -0000	1.9
  +++ FormValidatorAction.java	9 Aug 2002 08:27:18 -0000	1.10
  @@ -98,10 +98,13 @@
    * This action returns null when validation fails, otherwise it provides
    * all validated parameters to the sitemap via {name} expression.
    *
  - * In addition a request attribute <code>org.apache.cocoon.acting.FormValidatorAction.results</code>
  + * In addition a request attribute
  + * <code>org.apache.cocoon.acting.FormValidatorAction.results</code>
    * contains the validation results in both cases and make it available
  - * to XSPs. Mind you that redirections create new request objects and thus
  - * the result is not available for the target page.
  + * to XSPs. The special parameter "*" contains either the validation
  + * result "OK", if all parameters were validated successfully, or
  + * "ERROR" otherwise. Mind you that redirections create new request
  + * objects and thus the result is not available for the target page.
    *
    * All values for a parameter are read through the
    * getParameterValues() method and validated seperately.
  @@ -257,9 +260,11 @@
               if (!allOK) {
                   // if any validation failed return an empty map
                   actionMap = null;
  +                resultMap.put("*", new ValidatorActionHelper(null, ValidatorActionResult.ERROR));
                   if (getLogger().isDebugEnabled())
                       getLogger().debug ("All form params validated. An error occurred.");
               } else {
  +                resultMap.put("*", new ValidatorActionHelper(null, ValidatorActionResult.OK));
                   if (getLogger().isDebugEnabled())
                       getLogger().debug ("All form params successfully validated");
               }
  
  
  
  1.6       +10 -1     xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java
  
  Index: ValidatorActionHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ValidatorActionHelper.java	22 Feb 2002 06:59:26 -0000	1.5
  +++ ValidatorActionHelper.java	9 Aug 2002 08:27:18 -0000	1.6
  @@ -98,6 +98,15 @@
       }
   
       /**
  +     * Tests if the validation result is <code>NOTPRESENT</code>,
  +     * e.g. when the value is null and is allowed to be null.
  +     *
  +     */
  +    public boolean isNotPresent() {
  +    return (result.equals(ValidatorActionResult.NOTPRESENT));
  +    }
  +
  +    /**
        * Tests if the validation result is <code>ISNULL</code>,
        * e.g. when the value is null but is not supposed to be null.
        *
  
  
  
  1.6       +16 -10    xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java
  
  Index: ValidatorActionResult.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ValidatorActionResult.java	22 Feb 2002 06:59:26 -0000	1.5
  +++ ValidatorActionResult.java	9 Aug 2002 08:27:18 -0000	1.6
  @@ -68,46 +68,52 @@
       OK         = new ValidatorActionResult ("OK");          // 0
   
       /**
  +     * this is returned when the result of a validation is
  +     * requested but no such result is found in the request
  +     * attribute.
  +     */
  +    public static final ValidatorActionResult
  +    NOTPRESENT = new ValidatorActionResult ("NOTPRESENT");  // 1
  +
  +    /**
        * some error occurred, this is a result that is never set but
        * serves as a comparison target.
        */
       public static final ValidatorActionResult
  -    ERROR      = new ValidatorActionResult ("ERROR");       // 1
  +    ERROR      = new ValidatorActionResult ("ERROR");       // 2
   
       /**
        * the parameter is null but isn't allowed to.
        */
       public static final ValidatorActionResult
  -    ISNULL     = new ValidatorActionResult ("ISNULL");      // 2
  +    ISNULL     = new ValidatorActionResult ("ISNULL");      // 3
   
       /**
        * either value or length in case of a string is less than the
        * specified minimum.
        */
       public static final ValidatorActionResult
  -    TOOSMALL   = new ValidatorActionResult ("TOOSMALL");    // 3
  +    TOOSMALL   = new ValidatorActionResult ("TOOSMALL");    // 4
   
       /**
        * either value or length in case of a string is greater than
        * the specified maximum.
        */
       public static final ValidatorActionResult
  -    TOOLARGE   = new ValidatorActionResult ("TOOLARGE");    // 4
  +    TOOLARGE   = new ValidatorActionResult ("TOOLARGE");    // 5
   
       /**
        * a string parameter's value is not matched by the specified
        * regular expression.
        */
       public static final ValidatorActionResult
  -    NOMATCH    = new ValidatorActionResult ("NOMATCH");     // 5
  +    NOMATCH    = new ValidatorActionResult ("NOMATCH");     // 6
   
       /**
  -     * this is returned when the result of a validation is
  -     * requested but no such result is found in the request
  -     * attribute.
  +     * maximum error, only used for comparisons.
        */
       public static final ValidatorActionResult
  -    NOTPRESENT = new ValidatorActionResult ("NOTPRESENT");  // 6
  +    MAXERROR   = new ValidatorActionResult ("MAXERROR");    // 7
   
       /**
        * Make constructor private to inhibit creation outside.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message