You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by br...@apache.org on 2003/04/22 14:04:22 UTC

cvs commit: cocoon-2.1/src/blocks/woody/samples/xsl/html woody-default.xsl

bruno       2003/04/22 05:04:22

  Added:       src/blocks/woody/conf woody-datatype.xroles
                        woody-expression.xroles woody.xroles woody.xsamples
               src/blocks/woody/java/org/apache/cocoon/woody Constants.java
                        DefaultFormManager.java FormManager.java
               src/blocks/woody/java/org/apache/cocoon/woody/acting
                        AbstractWoodyAction.java
                        HandleFormSubmitAction.java MakeFormAction.java
               src/blocks/woody/java/org/apache/cocoon/woody/datatype
                        Datatype.java DatatypeBuilder.java
                        DatatypeManager.java DefaultDatatypeManager.java
                        SelectionList.java SelectionListBuilder.java
                        StaticSelectionList.java ValidationError.java
                        ValidationRule.java ValidationRuleBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl
                        AbstractDatatype.java AbstractDatatypeBuilder.java
                        LongType.java LongTypeBuilder.java StringType.java
                        StringTypeBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl
                        AbstractValidationRule.java
                        AbstractValidationRuleBuilder.java
                        AssertValidationRule.java
                        AssertValidationRuleBuilder.java
                        EmailValidationRule.java
                        EmailValidationRuleBuilder.java
                        LengthValidationRule.java
                        LengthValidationRuleBuilder.java
                        RangeValidationRule.java
                        RangeValidationRuleBuilder.java
                        ValueCountValidationRule.java
                        ValueCountValidationRuleBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/expression
                        DefaultExpressionManager.java
                        ExpressionManager.java
               src/blocks/woody/java/org/apache/cocoon/woody/formmodel
                        AbstractWidget.java AbstractWidgetDefinition.java
                        AbstractWidgetDefinitionBuilder.java
                        BooleanField.java BooleanFieldDefinition.java
                        BooleanFieldDefinitionBuilder.java
                        CannotYetResolveWarning.java ContainerWidget.java
                        DuplicateIdException.java
                        ExpressionContextImpl.java Field.java
                        FieldDefinition.java FieldDefinitionBuilder.java
                        Form.java FormDefinition.java
                        FormDefinitionBuilder.java MultiValueField.java
                        MultiValueFieldDefinition.java
                        MultiValueFieldDefinitionBuilder.java Repeater.java
                        RepeaterDefinition.java
                        RepeaterDefinitionBuilder.java Widget.java
                        WidgetDefinition.java WidgetDefinitionBuilder.java
               src/blocks/woody/java/org/apache/cocoon/woody/generation
                        WoodyGenerator.java
               src/blocks/woody/java/org/apache/cocoon/woody/samples
                        InitForm1Action.java
               src/blocks/woody/java/org/apache/cocoon/woody/transformation
                        WidgetReplacingPipe.java
                        WoodyTemplateTransformer.java
               src/blocks/woody/java/org/apache/cocoon/woody/util
                        DomHelper.java
               src/blocks/woody/lib xreporter-expression-20030418.jar
               src/blocks/woody/samples sitemap.xmap welcome.html
               src/blocks/woody/samples/forms a-choices.xml form1.xml
                        form1_success.xsp form1_template.xml
                        registration.xml registration_success.xsp
                        registration_template.xml
               src/blocks/woody/samples/messages OtherMessages.xml
                        WoodyMessages.xml
               src/blocks/woody/samples/xsl/html woody-default.xsl
  Log:
  initial commit
  (mail with more info comming...)
  
  Revision  Changes    Path
  1.1                  cocoon-2.1/src/blocks/woody/conf/woody-datatype.xroles
  
  Index: woody-datatype.xroles
  ===================================================================
  <?xml version="1.0"?>
  <xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.woody.datatype.DatatypeManager']">
  
    <role name="org.apache.cocoon.woody.datatype.DatatypeManager"
      shorthand="woody-datatype"
      default-class="org.apache.cocoon.woody.datatype.DefaultDatatypeManager"/>
  </xroles>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/conf/woody-expression.xroles
  
  Index: woody-expression.xroles
  ===================================================================
  <?xml version="1.0"?>
  <xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.woody.expression.ExpressionManager']">
  
    <role name="org.apache.cocoon.woody.expression.ExpressionManager"
      shorthand="woody-expression"
      default-class="org.apache.cocoon.woody.expression.DefaultExpressionManager"/>
  </xroles>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/conf/woody.xroles
  
  Index: woody.xroles
  ===================================================================
  <?xml version="1.0"?>
  <xroles xpath="/role-list" unless="role[@name='org.apache.cocoon.woody.FormManager']">
  
    <role name="org.apache.cocoon.woody.FormManager"
      shorthand="woody"
      default-class="org.apache.cocoon.woody.DefaultFormManager"/>
  </xroles>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/conf/woody.xsamples
  
  Index: woody.xsamples
  ===================================================================
  <?xml version="1.0"?>
  <xsamples xpath="/samples" unless="group[@name='woody']">
  
    <group name="woody">
      <sample name="Woody" href="woody/">
        Woody (a form framework) examples.
     </sample>
    </group>
  </xsamples>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/Constants.java
  
  Index: Constants.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.helpers.AttributesImpl;
  
  /**
   * Various constants used in the Woody form framework.
   */
  public final class Constants {
      /** Namespace for Woody Template elements */
      public static final String WT_NS = "http://cocoon.apache.org/woody/template/1.0";
      public static final String WT_PREFIX = "wt";
      public static final String WT_PREFIX_COLON = "wt:";
  
      /** Namespace for Woody Instance elements */
      public static final String WI_NS = "http://cocoon.apache.org/woody/instance/1.0";
      public static final String WI_PREFIX = "wi";
      public static final String WI_PREFIX_COLON = "wi:";
  
      /** Namespace for Woody Definition elements */
      public static final String WD_NS = "http://cocoon.apache.org/woody/definition/1.0";
      public static final String WD_PREFIX = "wd";
      public static final String WD_PREFIX_COLON = "wd:";
  
      public static final Attributes EMPTY_ATTRS = new AttributesImpl();
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/DefaultFormManager.java
  
  Index: DefaultFormManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody;
  
  import org.apache.cocoon.woody.formmodel.*;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.components.LifecycleHelper;
  import org.apache.excalibur.source.Source;
  import org.apache.avalon.framework.CascadingException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.xml.sax.InputSource;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * Component implementing the {@link FormManager} role.
   *
   * <p>Some important TODO's: cache FormDefiniton's (now they are reparsed and recreated each
   * on each request), and make the list of widget implementations configurable instead of hardcoded.
   */
  public class DefaultFormManager implements FormManager, ThreadSafe, Composable {
      private ComponentManager componentManager;
      private Map widgetDefinitionBuilders = new HashMap();
      private FormDefinitionBuilder formDefinitionBuilder;
      private boolean initialized = false;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.componentManager = componentManager;
      }
  
      public void lazyInitialize() throws Exception {
          // Initialisation is only done after the FormManager has been fully created, because
          // the WidgetDefinitionBuilders that we create here need themselves access to
          // the FormManager (which they can only lookup after the FormManager itself has
          // passed all lifecycle stages).
  
          if (initialized)
              return;
  
          LifecycleHelper lifecycleHelper = new LifecycleHelper(null, null, componentManager, null, null, null);
  
          // TODO the stuff below must be done based on external configuration information
  
          // Setup all the widget definition builders
          WidgetDefinitionBuilder widgetDefinitionBuilder;
  
          widgetDefinitionBuilder = new FieldDefinitionBuilder();
          lifecycleHelper.setupComponent(widgetDefinitionBuilder);
          widgetDefinitionBuilders.put("field", widgetDefinitionBuilder);
  
          widgetDefinitionBuilder = new RepeaterDefinitionBuilder();
          lifecycleHelper.setupComponent(widgetDefinitionBuilder);
          widgetDefinitionBuilders.put("repeater", widgetDefinitionBuilder);
  
          widgetDefinitionBuilder = new BooleanFieldDefinitionBuilder();
          lifecycleHelper.setupComponent(widgetDefinitionBuilder);
          widgetDefinitionBuilders.put("booleanfield", widgetDefinitionBuilder);
  
          widgetDefinitionBuilder = new MultiValueFieldDefinitionBuilder();
          lifecycleHelper.setupComponent(widgetDefinitionBuilder);
          widgetDefinitionBuilders.put("multivaluefield", widgetDefinitionBuilder);
  
          // special case
          formDefinitionBuilder = new FormDefinitionBuilder();
          lifecycleHelper.setupComponent(formDefinitionBuilder);
  
          initialized = true;
      }
  
      public FormDefinition getFormDefinition(Source source) throws Exception {
          lazyInitialize();
  
          // TODO caching!!
          Document formDocument;
          try {
              InputSource inputSource = new InputSource(source.getInputStream());
              inputSource.setSystemId(source.getURI());
              formDocument = DomHelper.parse(inputSource);
          }
          catch (Exception exc) {
              throw new CascadingException("Could not parse form definition from " + source.getURI(), exc);
          }
  
          Element formElement = formDocument.getDocumentElement();
  
          // check that the root element is a wd:form element
          if (!(formElement.getLocalName().equals("form") || Constants.WD_NS.equals(formElement.getNamespaceURI())))
              throw new Exception("Expected a Woody form element at " + DomHelper.getLocation(formElement));
  
          FormDefinition formDefinition = (FormDefinition)formDefinitionBuilder.buildWidgetDefinition(formElement);
          return formDefinition;
      }
  
      public WidgetDefinition buildWidgetDefinition(Element widgetDefinition) throws Exception {
          lazyInitialize();
  
          String widgetName = widgetDefinition.getLocalName();
          WidgetDefinitionBuilder builder = (WidgetDefinitionBuilder)widgetDefinitionBuilders.get(widgetName);
          if (builder == null)
              throw new Exception("Unkown kind of widget \"" + widgetName + "\" specified at " + DomHelper.getLocation(widgetDefinition));
          return builder.buildWidgetDefinition(widgetDefinition);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/FormManager.java
  
  Index: FormManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody;
  
  import org.apache.cocoon.woody.formmodel.FormDefinition;
  import org.apache.cocoon.woody.formmodel.WidgetDefinition;
  import org.apache.excalibur.source.Source;
  import org.w3c.dom.Element;
  
  /**
   * Work interface for the component that can create {@link FormDefinition}'s.
   */
  public interface FormManager {
      public static final String ROLE = "org.apache.cocoon.woody.FormManager";
  
      public FormDefinition getFormDefinition(Source source) throws Exception;
  
      public WidgetDefinition buildWidgetDefinition(Element widgetDefinition) throws Exception;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/AbstractWoodyAction.java
  
  Index: AbstractWoodyAction.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.acting;
  
  import org.apache.cocoon.woody.FormManager;
  import org.apache.cocoon.acting.Action;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * Abstract base class for Woody actions.
   */
  public abstract class AbstractWoodyAction implements Action, ThreadSafe, Composable {
      protected FormManager formManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          formManager = (FormManager)componentManager.lookup(FormManager.ROLE);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/HandleFormSubmitAction.java
  
  Index: HandleFormSubmitAction.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.acting;
  
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.woody.FormManager;
  import org.apache.cocoon.woody.formmodel.FormDefinition;
  import org.apache.cocoon.woody.formmodel.Form;
  
  import java.util.Map;
  import java.util.Collections;
  import java.util.Locale;
  
  /**
   * An action that will create a form instance, let it handle the current request (and
   * do validation), and will return null if validation was successfully or not-null when
   * validation failed. In both cases, the created form instance is stored in a request attribute,
   * so that it can be picked up later on by other components.
   *
   * <p>Required parameters:
   * <ul>
   *  <li><strong>form-definition</strong>: filename (URL) pointing to the form definition file
   *  <li><strong>attribute-name</strong>: name of the request attribute in which the form instance should be stored
   * </ul>
   */
  public class HandleFormSubmitAction implements Action, ThreadSafe, Composable {
  
      FormManager formManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          formManager = (FormManager)componentManager.lookup(FormManager.ROLE);
      }
  
      public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)
              throws Exception {
          String formSource = parameters.getParameter("form-definition");
          String formAttribute = parameters.getParameter("attribute-name");
  
          FormDefinition formDefinition = formManager.getFormDefinition(resolver.resolveURI(formSource));
          Form form = (Form)formDefinition.createInstance();
  
          Request request = ObjectModelHelper.getRequest(objectModel);
          form.readFromRequest(request, Locale.US);
          boolean validationSuccess = form.validate(Locale.US);
          request.setAttribute(formAttribute, form);
  
          if (validationSuccess)
              return Collections.EMPTY_MAP;
          else
              return null;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/acting/MakeFormAction.java
  
  Index: MakeFormAction.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.acting;
  
  import org.apache.cocoon.acting.Action;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.woody.FormManager;
  import org.apache.cocoon.woody.formmodel.FormDefinition;
  import org.apache.cocoon.woody.formmodel.Form;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  
  import java.util.Map;
  
  /**
   * An action that creates a new form instance and stores it in a request attribute.
   *
   * <p>Required parameters:
   * <ul>
   *  <li><strong>form-definition</strong>: filename (URL) of the form definition file
   *  <li><strong>attribute-name</strong>: name of the request attribute in which to store the form instance
   * </ul>
   */
  public class MakeFormAction implements Action, ThreadSafe, Composable {
  
      FormManager formManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          formManager = (FormManager)componentManager.lookup(FormManager.ROLE);
      }
  
      public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)
              throws Exception {
          String formSource = parameters.getParameter("form-definition");
          String formAttribute = parameters.getParameter("attribute-name");
  
          FormDefinition formDefinition = formManager.getFormDefinition(resolver.resolveURI(formSource));
          Form form = (Form)formDefinition.createInstance();
  
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(formAttribute, form);
  
          return null;
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/Datatype.java
  
  Index: Datatype.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.outerj.expression.ExpressionContext;
  
  import java.util.Locale;
  
  /**
   * A Datatype encapsulates the functionality for working with specific
   * kinds of data like integers, deciamals or dates.
   *
   * <p>I provides:
   * <ul>
   *  <li>Methods for converting between String and Object representation of the data
   *  <li>For validating the data (usually against a set of validation rules)
   *  <li>optionally a selection list
   * </ul>
   *
   * <p>Each datatype can be marked as an "arraytype". Currently, this only has an
   * influence on the {@link #validate} method, which should in that case be passed
   * an array of objects. See also {@link #isArrayType}.
   */
  public interface Datatype {
      public Object convertFromString(String value);
      public Object convertFromStringLocalized(String value, Locale locale);
      public String convertToString(Object value);
      public String convertToStringLocalized(Object value, Locale locale);
      // TODO validate moet wellicht ook nog een context meekrijgen
  
      /**
       * Returns null if validation is successful, otherwise returns the failmessage key.
       *
       * @param value an Object of the correct type for this datatype (see {@link #getTypeClass}, or
       * if {@link #isArrayType} returns true, an array of objects of that type.
       */
      public ValidationError validate(Object value, ExpressionContext expressionContext);
  
      /**
       * Gets the class object for the type represented by this datatype. E.g. Long, String, ...
       * The objects returned from the convertFromString* methods are of this type, and the object
       * passed to the convertToString* or validate methods should be of this type.
       */
      public Class getTypeClass();
  
      /**
       * Returns a descriptive name for the base type of this datatype,
       * i.e. something like 'string', 'long', 'decimal', ...
       */
      public String getDescriptiveName();
  
      /**
       * Returns the selection list associated with this datatype, or null if it has none.
       */
      public SelectionList getSelectionList();
  
      /**
       * Indicates wether this datatype represents an array type. This approach has been
       * chosen instead of creating a seperate ArrayDatatype interface (and corresponding
       * implementations), since almost all functionality is the same between the scalar
       * and array types. The main difference is that the validate() method will be passed
       * arrays instead of single values, and hence different validation rules will be
       * required.
       */
      public boolean isArrayType();
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DatatypeBuilder.java
  
  Index: DatatypeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.w3c.dom.Element;
  
  /**
   * Implementations of this class build a Datatype from an XML description
   * (a DOM Element).
   *
   * <p>These builders should be threadsafe, only one instance of them will be created.
   *
   * <p>Implementations may implement Avalon's Composable interface to get access to
   * other components.
   */
  public interface DatatypeBuilder {
      public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DatatypeManager.java
  
  Index: DatatypeManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.w3c.dom.Element;
  
  /**
   * Work interface for the component that manages the datatypes.
   *
   * <p>See also {@link Datatype} and {@link DefaultDatatypeManager}.
   */
  public interface DatatypeManager {
      public static final String ROLE = "org.apache.cocoon.woody.datatype.DatatypeManager";
  
      /**
       * Creates a datatype from an XML description.
       */
      public Datatype createDatatype(Element datatypeElement, boolean arrayType) throws Exception;
  
      /**
       * Creates a validation rule from an XML description. This will usually be used by the
       * {@link DatatypeBuilder}s while building a {@link Datatype}.
       */
      public ValidationRule createValidationRule(Element validationRuleElement) throws Exception;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/DefaultDatatypeManager.java
  
  Index: DefaultDatatypeManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.cocoon.woody.datatype.typeimpl.StringTypeBuilder;
  import org.apache.cocoon.woody.datatype.typeimpl.LongTypeBuilder;
  import org.apache.cocoon.woody.datatype.validationruleimpl.*;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.components.LifecycleHelper;
  import org.w3c.dom.Element;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * Implementation of the {@link DatatypeManager} component.
   *
   * <p>It supports an extensible number of datatype and validation rule implementations
   * by delegating the creation of them to {@link DatatypeBuilder}s and {@link ValidationRuleBuilder}s.
   * Currently the list of datatype and validationrule builders is hardcoded, but this will
   * become externally configurable in the future.
   *
   */
  public class DefaultDatatypeManager implements DatatypeManager, Initializable, ThreadSafe, Composable {
      private Map typeBuilderMap = new HashMap();
      private Map validationRuleBuilderMap = new HashMap();
      private ComponentManager componentManager;
  
      public void initialize() throws Exception {
          LifecycleHelper lifecycleHelper = new LifecycleHelper(null, null, componentManager, null, null, null);
  
          // TODO all the stuff below should come from a configuration file, so that this is extensible
  
          // Setup the type builders
          Object typeBuilder;
  
          typeBuilder = new StringTypeBuilder();
          lifecycleHelper.setupComponent(typeBuilder);
          typeBuilderMap.put("string", typeBuilder);
  
          typeBuilder = new LongTypeBuilder();
          lifecycleHelper.setupComponent(typeBuilder);
          typeBuilderMap.put("long", typeBuilder);
  
  
          // Setup the validation rule builders
          Object validationRuleBuilder;
  
          validationRuleBuilder = new LengthValidationRuleBuilder();
          lifecycleHelper.setupComponent(validationRuleBuilder);
          validationRuleBuilderMap.put("length", validationRuleBuilder);
  
          validationRuleBuilder = new EmailValidationRuleBuilder();
          lifecycleHelper.setupComponent(validationRuleBuilder);
          validationRuleBuilderMap.put("email", validationRuleBuilder);
  
          validationRuleBuilder = new ValueCountValidationRuleBuilder();
          lifecycleHelper.setupComponent(validationRuleBuilder);
          validationRuleBuilderMap.put("value-count", validationRuleBuilder);
  
          validationRuleBuilder = new RangeValidationRuleBuilder();
          lifecycleHelper.setupComponent(validationRuleBuilder);
          validationRuleBuilderMap.put("range", validationRuleBuilder);
  
          validationRuleBuilder = new AssertValidationRuleBuilder();
          lifecycleHelper.setupComponent(validationRuleBuilder);
          validationRuleBuilderMap.put("assert", validationRuleBuilder);
      }
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.componentManager = componentManager;
      }
  
      public Datatype createDatatype(Element datatypeElement, boolean arrayType) throws Exception {
          String typeName = DomHelper.getAttribute(datatypeElement, "base");
          DatatypeBuilder builder = (DatatypeBuilder)typeBuilderMap.get(typeName);
          if (builder == null)
              throw new Exception("Unknown datatype '" + typeName + "' specified at " + DomHelper.getLocation(datatypeElement));
          else
              return builder.build(datatypeElement, arrayType, this);
      }
  
      public ValidationRule createValidationRule(Element validationRuleElement) throws Exception {
          String name  = validationRuleElement.getLocalName();
          ValidationRuleBuilder builder = (ValidationRuleBuilder)validationRuleBuilderMap.get(name);
          if (builder == null)
              throw new Exception("Unknown validation rule + \"" + name + "\" specified at " + DomHelper.getLocation(validationRuleElement));
          else
              return builder.build(validationRuleElement);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/SelectionList.java
  
  Index: SelectionList.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  import java.util.Locale;
  
  /**
   * Interface to be implemented by selection lists.
   */
  public interface SelectionList {
      Datatype getDatatype();
  
      void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/SelectionListBuilder.java
  
  Index: SelectionListBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.util.DomHelper;
  
  /**
   * Builds {@link SelectionList}s from an XML description.
   */
  public class SelectionListBuilder {
  
      public static SelectionList build(Element selectionListElement, Datatype datatype) throws Exception {
          StaticSelectionList selectionList = new StaticSelectionList(datatype);
  
          NodeList children = selectionListElement.getChildNodes();
          for (int i = 0; children.item(i) != null; i++) {
              Node node = children.item(i);
              if (node instanceof Element && Constants.WD_NS.equals(node.getNamespaceURI()) && "item".equals(node.getLocalName())) {
                  Element element = (Element)node;
                  String stringValue = element.getAttribute("value");
                  Object value = datatype.convertFromString(stringValue);
                  if (value == null)
                      throw new Exception("Could not convert the value \"" + stringValue + "\" to the type " + datatype.getDescriptiveName() + ", defined at " + DomHelper.getLocation(element));
  
                  Object label = null;
                  Element labelEl = DomHelper.getChildElement(element, Constants.WD_NS, "label");
                  if (labelEl != null) {
                      label = DomHelper.compileElementContent(labelEl);
                  }
                  selectionList.addItem(value, label);
              }
          }
  
          return selectionList;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/StaticSelectionList.java
  
  Index: StaticSelectionList.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.Locale;
  
  /**
   * An implementation of a SelectionList. Create instances of this class by using
   * the {@link SelectionListBuilder}. This implementation is called "Static" because
   * the list of items is not retrieved dynamically, but only ones and shared for
   * all users of the {@link Datatype}.
   */
  public class StaticSelectionList implements SelectionList {
      /** The datatype to which this selection list belongs */
      private Datatype datatype;
      private List items = new ArrayList();
      private XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
  
      private static final String SELECTION_LIST_EL = "selection-list";
      private static final String ITEM_EL = "item";
      private static final String LABEL_EL = "label";
  
      public StaticSelectionList(Datatype datatype) {
          this.datatype = datatype;
      }
  
      public Datatype getDatatype() {
          return datatype;
      }
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL, Constants.EMPTY_ATTRS);
          Iterator itemIt = items.iterator();
          while (itemIt.hasNext()) {
              SelectionListItem item = (SelectionListItem)itemIt.next();
              item.generateSaxFragment(contentHandler, locale);
          }
          contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL);
      }
  
      /**
       * Adds a new item to this selection list.
       * @param value a value of the correct type (i.e. the type with which this selectionlist is associated)
       * @param label a SAX-fragment created using the XMLByteStreamCompiler, can be null
       */
      public void addItem(Object value, Object label) {
          items.add(new SelectionListItem(value, label));
      }
  
      private final class SelectionListItem {
          private final Object value;
          private final Object label;
  
          public SelectionListItem(Object value, Object label) {
              this.value = value;
              this.label = label;
          }
  
          public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException
          {
              AttributesImpl itemAttrs = new AttributesImpl();
              itemAttrs.addAttribute("", "value", "value", "CDATA", datatype.convertToString(value));
              contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL, itemAttrs);
              contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
              if (label != null) {
                  interpreter.recycle();
                  interpreter.setContentHandler(contentHandler);
                  interpreter.deserialize(label);
              } else {
                  String formattedLabel = datatype.convertToStringLocalized(value, locale);
                  contentHandler.characters(formattedLabel.toCharArray(), 0, formattedLabel.length());
              }
              contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
              contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/ValidationError.java
  
  Index: ValidationError.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
  import org.apache.cocoon.transformation.I18nTransformer;
  import org.apache.cocoon.woody.Constants;
  
  /**
   * An object that holds a validation error message. The error message can
   * be a simple string (which should be a message bundle key) or a piece of XML.
   */
  public class ValidationError {
      /** Holds the error message compiled using the {@link org.apache.cocoon.components.sax.XMLByteStreamCompiler}. */
      private Object saxFragment;
      /** Holds a simple string error message. */
      private String errorMessage;
      /** Should the errorMessage be interpreted as a resource bundle key? */
      private boolean i18n;
      private String[] errorMessageParameters;
      private boolean[] keys;
  
      /**
       * @param i18n should the errorMessage be interpreted as an i18n key?
       */
      public ValidationError(String errorMessage, boolean i18n) {
          this.errorMessage = errorMessage;
          this.i18n = i18n;
      }
  
      /**
       * @param errorMessageKey a message key, to be translated by the I18nTransformer
       */
      public ValidationError(String errorMessageKey) {
          this.errorMessage = errorMessageKey;
          this.i18n = true;
      }
  
      /**
       * @param parameters parameters to be substituted in the errorMessage (will be
       * done by the I18nTransformer)
       */
      public ValidationError(String errorMessageKey, String[] parameters) {
          this.errorMessage = errorMessageKey;
          this.errorMessageParameters = parameters;
          this.keys = null;
          this.i18n = true;
      }
  
      /**
       * @param keys Each element in the keys array corresponds to a string in the parameters array
       * and indicates whether that parameter is in itself again a key.
       */
      public ValidationError(String errorMessageKey, String[] parameters, boolean[] keys) {
          this.errorMessage = errorMessageKey;
          this.errorMessageParameters = parameters;
          this.keys = keys;
          this.i18n = true;
      }
  
      public ValidationError(Object errorMessage) {
          this.saxFragment = errorMessage;
      }
  
      /**
       * Generates SAX events for this ValidationError. In case of the constructors where
       * a String error message key was supplied, the necessary I18n tags will be generated.
       */
      public void generateSaxFragment(ContentHandler contentHandler) throws SAXException {
          if (saxFragment != null) {
              XMLByteStreamInterpreter byteStreamInterpreter = new XMLByteStreamInterpreter();
              byteStreamInterpreter.setContentHandler(contentHandler);
              byteStreamInterpreter.deserialize(saxFragment);
          } else if (errorMessageParameters != null) {
              contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI);
  
              contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT, Constants.EMPTY_ATTRS);
  
              // the i18n:text element
              AttributesImpl i18nAttrs = new AttributesImpl();
              i18nAttrs.addAttribute(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "i18n:" + I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "CDATA", "woody");
  
              contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs);
              contentHandler.characters(errorMessage.toCharArray(), 0, errorMessage.length());
              contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT);
  
              // the parameters
              for (int i = 0; i < errorMessageParameters.length; i++) {
                  contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT, Constants.EMPTY_ATTRS);
                  if (keys != null && keys[i])
                      contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs);
                  contentHandler.characters(errorMessageParameters[i].toCharArray(), 0, errorMessageParameters[i].length());
                  if (keys != null && keys[i])
                      contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT);
                  contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT);
              }
  
              contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT);
  
              contentHandler.endPrefixMapping("i18n");
          } else if (i18n) {
              contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI);
  
              AttributesImpl i18nAttrs = new AttributesImpl();
              i18nAttrs.addAttribute(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "i18n:" + I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "CDATA", "woody");
  
              contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs);
              contentHandler.characters(errorMessage.toCharArray(), 0, errorMessage.length());
              contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT);
  
              contentHandler.endPrefixMapping("i18n");
          } else {
              contentHandler.characters(errorMessage.toCharArray(), 0, errorMessage.length());
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/ValidationRule.java
  
  Index: ValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.outerj.expression.ExpressionContext;
  
  /**
   * Interface for validation rules. Most {@link Datatype} implementations will
   * perform their validation by checking a number of these validation rules
   * (though strictly spoken this is not required).
   */
  public interface ValidationRule {
      /**
       *
       * @param value a value of a class supported by the ValidationRule implementation
       * @param expressionContext many validation rules use the xReporter expression interpreter,
       * the expressionContext allows to resolve variables used in these expressions.
       */
      public ValidationError validate(Object value, ExpressionContext expressionContext);
  
      /**
       * Returns true if this ValidationRule supports the given Datatype.
       * Implementations will want to check both {@link Datatype#getTypeClass} and
       * {@link Datatype#isArrayType}.
       */
      public boolean supportsType(Datatype datatype);
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/ValidationRuleBuilder.java
  
  Index: ValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype;
  
  import org.w3c.dom.Element;
  
  /**
   * Interface for classes that can build ValidationRules from an XML description.
   * A ValidationRuleBuilder can be Composable.
   * A ValidationRuleBuilder should be thread safe, only one instance of it
   * will be created.
   */
  public interface ValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/AbstractDatatype.java
  
  Index: AbstractDatatype.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.outerj.expression.ExpressionContext;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.datatype.SelectionList;
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.ValidationRule;
  
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Iterator;
  
  /**
   * Abstract base class for Datatype implementations. Most concreate datatypes
   * will derive from this class.
   */
  public abstract class AbstractDatatype implements Datatype {
      private List validationRules = new ArrayList();
      private SelectionList selectionList;
      private boolean arrayType = false;
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          Iterator validationRulesIt = validationRules.iterator();
          while (validationRulesIt.hasNext()) {
              ValidationRule validationRule = (ValidationRule)validationRulesIt.next();
              ValidationError result = validationRule.validate(value, expressionContext);
              if (result != null)
                  return result;
          }
          return null;
      }
  
      public void addValidationRule(ValidationRule validationRule) {
          validationRules.add(validationRule);
      }
  
      public void setSelectionList(SelectionList selectionList) {
          if (selectionList.getDatatype() != this)
              throw new RuntimeException("Error in AbstractDatatype.setSelectionList: tried to assign a StaticSelectionList that is not associated with this datatype.");
          this.selectionList = selectionList;
      }
  
      public SelectionList getSelectionList() {
          return selectionList;
      }
  
      public boolean isArrayType() {
          return arrayType;
      }
  
      protected void setArrayType(boolean arrayType) {
          this.arrayType = arrayType;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/AbstractDatatypeBuilder.java
  
  Index: AbstractDatatypeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.apache.cocoon.woody.datatype.*;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.excalibur.source.Source;
  import org.apache.excalibur.source.SourceResolver;
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.xml.sax.InputSource;
  
  import java.io.IOException;
  
  /**
   * Abstract base class for datatype builders, most concrete datatype builders
   * will derive from this class.
   */
  public abstract class AbstractDatatypeBuilder implements DatatypeBuilder, Composable {
      protected ComponentManager componentManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          this.componentManager = componentManager;
      }
  
      protected Source resolve(String src) throws ComponentException, IOException {
          SourceResolver resolver = null;
          try {
              resolver = (SourceResolver)componentManager.lookup(SourceResolver.ROLE);
              return resolver.resolveURI(src);
          } finally {
              if (resolver != null)
                  componentManager.release(resolver);
          }
      }
  
      protected void buildSelectionList(Element datatypeElement, AbstractDatatype datatype) throws Exception {
          Element selectionListElement = DomHelper.getChildElement(datatypeElement, Constants.WD_NS, "selection-list");
          if (selectionListElement != null) {
              String src = selectionListElement.getAttribute("src");
              if (src.length() > 0)
                  selectionListElement = readSelectionList(src);
              SelectionList selectionList = SelectionListBuilder.build(selectionListElement, datatype);
              datatype.setSelectionList(selectionList);
          }
      }
  
      private Element readSelectionList(String src) throws Exception {
          Source source = resolve(src);
          InputSource inputSource = new InputSource(source.getInputStream());
          inputSource.setSystemId(source.getURI());
          Document document = DomHelper.parse(inputSource);
          Element selectionListElement = document.getDocumentElement();
          if (!Constants.WD_NS.equals(selectionListElement.getNamespaceURI()) || !"selection-list".equals(selectionListElement.getLocalName()))
              throw new Exception("Excepted a wd:selection-list element at " + DomHelper.getLocation(selectionListElement));
          return selectionListElement;
      }
  
      protected void buildValidationRules(Element datatypeElement, AbstractDatatype datatype, DatatypeManager datatypeManager) throws Exception {
          Element validationElement = DomHelper.getChildElement(datatypeElement, Constants.WD_NS, "validation");
          if (validationElement != null) {
              Element[] validationElements = DomHelper.getChildElements(validationElement, Constants.WD_NS);
              for (int i = 0; i < validationElements.length; i++) {
                  ValidationRule rule = datatypeManager.createValidationRule(validationElements[i]);
                  if (!rule.supportsType(datatype)) {
                      throw new Exception("Validation rule \"" + validationElements[i].getLocalName() + "\" cannot be used with strings, error at " + DomHelper.getLocation(validationElements[i]));
                  }
                  datatype.addValidationRule(rule);
              }
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/LongType.java
  
  Index: LongType.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.outerj.i18n.DecimalFormat;
  import org.outerj.i18n.I18nSupport;
  
  import java.util.Locale;
  import java.text.ParseException;
  
  /**
   * A {@link org.apache.cocoon.woody.datatype.Datatype Datatype} implementation
   * for whole numbers.
   */
  public class LongType extends AbstractDatatype {
      public Object convertFromString(String value) {
          try {
              return new Long(Long.parseLong(value));
          } catch (NumberFormatException e) {
              return null;
          }
      }
  
      public Object convertFromStringLocalized(String value, Locale locale) {
          DecimalFormat numberFormat = I18nSupport.getInstance().getIntegerFormat(locale);
          // TODO numberFormat.applyPattern(...)
          try {
              return new Long(numberFormat.parse(value).longValue());
          } catch (ParseException e) {
              return null;
          }
      }
  
      public String convertToString(Object value) {
          return value.toString();
      }
  
      public String convertToStringLocalized(Object value, Locale locale) {
          DecimalFormat numberFormat = I18nSupport.getInstance().getIntegerFormat(locale);
          // TODO numberFormat.applyPattern(...)
          return numberFormat.format(value);
      }
  
      public Class getTypeClass() {
          return Long.class;
      }
  
      public String getDescriptiveName() {
          return "long";
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/LongTypeBuilder.java
  
  Index: LongTypeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.apache.cocoon.woody.datatype.*;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link LongType}s.
   */
  public class LongTypeBuilder extends AbstractDatatypeBuilder {
      public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
          LongType type = new LongType();
          type.setArrayType(arrayType);
  
          buildValidationRules(datatypeElement, type, datatypeManager);
  
          // TODO number formatting patterns
  
          // TODO default value
  
          buildSelectionList(datatypeElement, type);
  
          return type;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/StringType.java
  
  Index: StringType.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import java.util.Locale;
  
  /**
   * A {@link org.apache.cocoon.woody.datatype.Datatype Datatype} implementation
   * for strings.
   */
  public class StringType extends AbstractDatatype {
      public Object convertFromString(String value) {
          return value;
      }
  
      public Object convertFromStringLocalized(String value, Locale locale) {
          return value;
      }
  
      public String convertToString(Object value) {
          return (String)value;
      }
  
      public String convertToStringLocalized(Object value, Locale locale) {
          return (String)value;
      }
  
      public Class getTypeClass() {
          return String.class;
      }
  
      public String getDescriptiveName() {
          return "string";
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/typeimpl/StringTypeBuilder.java
  
  Index: StringTypeBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.typeimpl;
  
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.datatype.DatatypeManager;
  import org.apache.cocoon.woody.datatype.typeimpl.StringType;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link StringType}s.
   */
  public class StringTypeBuilder extends AbstractDatatypeBuilder {
  
      public Datatype build(Element datatypeElement, boolean arrayType, DatatypeManager datatypeManager) throws Exception {
          StringType type = new StringType();
          type.setArrayType(arrayType);
  
          buildValidationRules(datatypeElement, type, datatypeManager);
          buildSelectionList(datatypeElement, type);
  
          return type;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AbstractValidationRule.java
  
  Index: AbstractValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
  import org.outerj.expression.Expression;
  import org.outerj.expression.ExpressionContext;
  import org.outerj.expression.ExpressionException;
  
  import java.math.BigDecimal;
  
  /**
   * Abstract base class providing common functionality for many {@link ValidationRule}
   * implementations.
   */
  public abstract class AbstractValidationRule implements ValidationRule {
      private Object failMessage;
  
      /**
       * Sets the failmessage to use for this validation rule, this will be used
       * instead of the validation rules' built-in message. The message itself should
       * be an object obtained from Cocoon's XMLByteStreamCompiler. This
       * allows fail messages to contain mixed content (instead of just
       * being a string).
       */
      public void setFailMessage(Object object) {
          this.failMessage = object;
      }
  
      /**
       * Returns the failMessage wrapped in a ValidationError object.
       */
      public ValidationError getFailMessage() {
          return new ValidationError(failMessage);
      }
  
      /**
       * Returns true if this validation rule has a user-defined fail message.
       */
      public boolean hasFailMessage() {
          return failMessage != null;
      }
  
      /**
       * Helper method for evaluating expressions whose result is numeric.
       *
       * @param exprName a name for the expression that's descriptive for the user, e.g. the name of the attribute in which it was defined
       * @param ruleName a descriptive name for the validation rule, usually the rule's element name
       * @return either a ValidationError (because expression evaluation failed) or a CannotYetResolveWarning
       * (because another, required field referenced in the expression has not yet a value), or a BigDecimal.
       */
      protected Object evaluateNumeric(Expression expression, ExpressionContext expressionContext, String exprName, String ruleName) {
          Object expressionResult;
          try {
              expressionResult = expression.evaluate(expressionContext);
          } catch (CannotYetResolveWarning w) {
              return w;
          } catch (ExpressionException e) {
              return new ValidationError("Error evaluating \"" + exprName + "\" expression on \"" + ruleName + "\" validation rule", false);
          }
          if (!(expressionResult instanceof BigDecimal))
              return new ValidationError("Got non-numeric result from \"" + exprName + "\" expression on \"" + ruleName + "\" validation rule", false);
          return expressionResult;
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AbstractValidationRuleBuilder.java
  
  Index: AbstractValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRuleBuilder;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.expression.ExpressionManager;
  import org.apache.avalon.framework.CascadingException;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  import org.w3c.dom.Element;
  import org.outerj.expression.Expression;
  import org.outerj.expression.TokenMgrError;
  
  /**
   * Abstract base class for ValidationRuleBuilder implementations.
   */
  public abstract class AbstractValidationRuleBuilder implements ValidationRuleBuilder, Composable {
      protected ExpressionManager expressionManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          expressionManager = (ExpressionManager)componentManager.lookup(ExpressionManager.ROLE);
      }
  
      /**
       * Checks if the validation rule configuration contains a custom failmessage, and if so,
       * sets it one the ValidationRule.
       */
      protected void buildFailMessage(Element validationRuleElement, AbstractValidationRule rule) {
          Element failMessageElement = DomHelper.getChildElement(validationRuleElement, Constants.WD_NS, "failmessage");
          if (failMessageElement != null) {
              Object failMessage = DomHelper.compileElementContent(failMessageElement);
              rule.setFailMessage(failMessage);
          }
      }
  
      /**
       * Parses an expression and throws a nice error message if this fails.
       */
      protected Expression parseExpression(String exprString, Element element, String attrName) throws Exception {
          try {
              return expressionManager.parse(exprString);
          } catch (TokenMgrError e) {
              throw new CascadingException("Error in expression \"" + exprString + "\" in attribute \"" + attrName + "\" at " + DomHelper.getLocation(element), e);
          } catch (Exception e) {
              throw new CascadingException("Error in expression \"" + exprString + "\" in attribute \"" + attrName + "\" at " + DomHelper.getLocation(element), e);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AssertValidationRule.java
  
  Index: AssertValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
  import org.outerj.expression.ExpressionContext;
  import org.outerj.expression.ExpressionException;
  import org.outerj.expression.Expression;
  
  /**
   * Generic validation rule that evaluates an expression. If the outcome of the expression is true,
   * the validation is successful, otherwise not.
   */
  public class AssertValidationRule extends AbstractValidationRule {
      private Expression testExpression;
  
      public AssertValidationRule(Expression testExpression) {
          this.testExpression = testExpression;
      }
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          Object expressionResult;
          try {
              expressionResult = testExpression.evaluate(expressionContext);
          } catch (CannotYetResolveWarning w) {
              return null;
          } catch (ExpressionException e) {
              return new ValidationError("Error evaluating expression on assert validation rule.");
          }
  
          if (!(expressionResult instanceof Boolean))
              return new ValidationError("Got non-boolean result from expression on assert validation rule.");
  
          if (((Boolean)expressionResult).booleanValue())
              return null;
          else
              return hasFailMessage() ? getFailMessage() : new ValidationError("Assertion validation rule failed.");
      }
  
      public boolean supportsType(Datatype datatype) {
          return true;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/AssertValidationRuleBuilder.java
  
  Index: AssertValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  import org.outerj.expression.Expression;
  
  /**
   * Builds {@link AssertValidationRule}s.
   */
  public class AssertValidationRuleBuilder extends AbstractValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception {
          String exprStr = validationRuleElement.getAttribute("test");
          if (exprStr.length() == 0)
              throw new Exception("assert validation rule requires a \"test\" attribute at " + DomHelper.getLocation(validationRuleElement));
          Expression testExpression = parseExpression(exprStr, validationRuleElement, "test");
          if (testExpression.getResultType() != null && !Boolean.class.isAssignableFrom(testExpression.getResultType()))
              throw new Exception("Expression should evaluate to a boolean on assert validation rule at " + DomHelper.getLocation(validationRuleElement));
          AssertValidationRule rule = new AssertValidationRule(testExpression);
          buildFailMessage(validationRuleElement, rule);
          return rule;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/EmailValidationRule.java
  
  Index: EmailValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.outerj.expression.ExpressionContext;
  
  /**
   * ValidationRule that checks that a string is an email address.
   */
  public class EmailValidationRule extends AbstractValidationRule {
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          String email = (String)value;
  
          if (isEmail(email))
              return null;
          else
              return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.invalidemail");
      }
  
      public boolean supportsType(Datatype datatype) {
          return datatype.getTypeClass().isAssignableFrom(String.class) && !datatype.isArrayType();
      }
  
      private boolean isEmail(String email) {
          // TODO there's room for improvement here
  
          // check that the email address does not contain spaces
          int space = email.indexOf(' ');
          if (space != -1)
              return false;
  
          // check that there is an @, and that there's at least one character before the @
          int atpos = email.indexOf('@');
          if (atpos < 1)
              return false;
  
          atpos++;
  
          // check there's not second at
          int anotheratpos = email.indexOf('@', atpos);
          if (anotheratpos != -1)
              return false;
  
          // check there's at least one dot after the at
          int dotAfterAt = email.indexOf('.', atpos);
          if (dotAfterAt == -1)
              return false;
  
          return true;
      }
  }
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/EmailValidationRuleBuilder.java
  
  Index: EmailValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link EmailValidationRule}s.
   */
  public class EmailValidationRuleBuilder extends AbstractValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception {
          EmailValidationRule rule = new EmailValidationRule();
          buildFailMessage(validationRuleElement, rule);
          return rule;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/LengthValidationRule.java
  
  Index: LengthValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
  import org.outerj.expression.ExpressionContext;
  import org.outerj.expression.Expression;
  
  import java.math.BigDecimal;
  
  /**
   * Checks the length of a String.
   *
   * <p>This validation rule can perform 4 different checks:
   * <ul>
   *  <li>check exact string length
   *  <li>check minimum string length
   *  <li>check maximum string length
   *  <li>check min and max string length
   * </ul>
   */
  public class LengthValidationRule extends AbstractValidationRule {
      private Expression exactExpr;
      private Expression minExpr;
      private Expression maxExpr;
  
      public void setExactExpr(Expression exactExpr) {
          this.exactExpr = exactExpr;
      }
  
      public void setMinExpr(Expression minExpr) {
          this.minExpr = minExpr;
      }
  
      public void setMaxExpr(Expression maxExpr) {
          this.maxExpr = maxExpr;
      }
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          String string = (String)value;
  
          if (exactExpr != null) {
              Object result = evaluateNumeric(exactExpr, expressionContext, "exact", "length");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (string.length() != length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.exact-length", new String[] {String.valueOf(length)});
              return null;
          } else if (minExpr != null && maxExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "length");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int minLength = ((BigDecimal)result).intValue();
  
              result = evaluateNumeric(maxExpr, expressionContext, "max", "length");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int maxLength = ((BigDecimal)result).intValue();
  
              if (string.length() < minLength || string.length() > maxLength)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.range-length", new String[] {String.valueOf(minLength), String.valueOf(maxLength)});
              return null;
          } else if (minExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "length");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (string.length() < length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.min-length", new String[] {String.valueOf(length)});
              return null;
          } else if (maxExpr != null) {
              Object result = evaluateNumeric(maxExpr, expressionContext, "max", "length");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (string.length() > length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.string.max-length", new String[] {String.valueOf(length)});
              return null;
          }
          return null;
      }
  
      public boolean supportsType(Datatype datatype) {
          return datatype.getTypeClass().isAssignableFrom(String.class) && !datatype.isArrayType();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/LengthValidationRuleBuilder.java
  
  Index: LengthValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.outerj.expression.Expression;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link LengthValidationRule}s.
   */
  public class LengthValidationRuleBuilder extends AbstractValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception {
          LengthValidationRule rule = new LengthValidationRule();
  
          String exactExprString = validationRuleElement.getAttribute("exact");
          String minExprString = validationRuleElement.getAttribute("min");
          String maxExprString = validationRuleElement.getAttribute("max");
  
          if (exactExprString.length() > 0) {
              Expression expression = parseExpression(exactExprString, validationRuleElement, "exact");
              rule.setExactExpr(expression);
          } else if (minExprString.length() > 0 && maxExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
              expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else if (minExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
          } else if (maxExprString.length() > 0) {
              Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else {
              throw new Exception("length validation rule requires a min and/or max, or exact attribute at " + DomHelper.getLocation(validationRuleElement));
          }
  
          buildFailMessage(validationRuleElement, rule);
  
          return rule;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RangeValidationRule.java
  
  Index: RangeValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
  import org.outerj.expression.ExpressionContext;
  import org.outerj.expression.Expression;
  
  import java.math.BigDecimal;
  
  /**
   * Checks numeric ranges. Works both for Long and BigDecimal values.
   *
   * <p>This validation rule can perform 3 different checks:
   * <ul>
   *  <li>check minimum value
   *  <li>check maximum value
   *  <li>check min and max values (range check)
   * </ul>
   */
  public class RangeValidationRule extends AbstractValidationRule {
      private Expression minExpr;
      private Expression maxExpr;
  
      public void setMinExpr(Expression minExpr) {
          this.minExpr = minExpr;
      }
  
      public void setMaxExpr(Expression maxExpr) {
          this.maxExpr = maxExpr;
      }
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          BigDecimal decimal = null;
          if (value instanceof Long)
              decimal = new BigDecimal(((Long) value).longValue());
          else
              decimal = (BigDecimal) value;
  
          if (minExpr != null && maxExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "range");
              if (result instanceof ValidationError)
                  return (ValidationError) result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              BigDecimal min = (BigDecimal) result;
  
              result = evaluateNumeric(maxExpr, expressionContext, "max", "range");
              if (result instanceof ValidationError)
                  return (ValidationError) result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              BigDecimal max = (BigDecimal) result;
  
              if (decimal.compareTo(min) < 0 || decimal.compareTo(max) > 0)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.range", new String[]{min.toString(), max.toString()});
              return null;
          } else if (minExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "range");
              if (result instanceof ValidationError)
                  return (ValidationError) result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              BigDecimal min = (BigDecimal) result;
              if (decimal.compareTo(min) < 0)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.min", new String[]{min.toString()});
              return null;
          } else if (maxExpr != null) {
              Object result = evaluateNumeric(maxExpr, expressionContext, "max", "range");
              if (result instanceof ValidationError)
                  return (ValidationError) result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              BigDecimal max = (BigDecimal) result;
              if (decimal.compareTo(max) > 0)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.numeric.max", new String[]{max.toString()});
              return null;
          }
          return null;
      }
  
      public boolean supportsType(Datatype datatype) {
          return (datatype.getTypeClass().isAssignableFrom(Long.class) || datatype.getTypeClass().isAssignableFrom(BigDecimal.class)) && !datatype.isArrayType();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/RangeValidationRuleBuilder.java
  
  Index: RangeValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  import org.outerj.expression.Expression;
  
  /**
   * Builds {@link RangeValidationRule}s.
   */
  public class RangeValidationRuleBuilder extends AbstractValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception {
          RangeValidationRule rule = new RangeValidationRule();
  
          String minExprString = validationRuleElement.getAttribute("min");
          String maxExprString = validationRuleElement.getAttribute("max");
  
          if (minExprString.length() > 0 && maxExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
              expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else if (minExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
          } else if (maxExprString.length() > 0) {
              Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else {
              throw new Exception("range validation rule requires a min and/or max attribute at " + DomHelper.getLocation(validationRuleElement));
          }
  
          buildFailMessage(validationRuleElement, rule);
  
          return rule;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/ValueCountValidationRule.java
  
  Index: ValueCountValidationRule.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.formmodel.CannotYetResolveWarning;
  import org.outerj.expression.ExpressionContext;
  import org.outerj.expression.Expression;
  
  import java.math.BigDecimal;
  
  /**
   * Checks the number of values (i.e. the size of the array). This only works for Datatypes
   * for which {@link org.apache.cocoon.woody.datatype.Datatype#isArrayType isArrayType} returns
   * true.
   *
   * <p>This validation rule can perform 4 different checks:
   * <ul>
   *  <li>check exact array size
   *  <li>check minimum array size
   *  <li>check maximum array size
   *  <li>check min and max array size
   * </ul>
   */
  public class ValueCountValidationRule extends AbstractValidationRule {
      private Expression exactExpr;
      private Expression minExpr;
      private Expression maxExpr;
  
      public void setExactExpr(Expression exactExpr) {
          this.exactExpr = exactExpr;
      }
  
      public void setMinExpr(Expression minExpr) {
          this.minExpr = minExpr;
      }
  
      public void setMaxExpr(Expression maxExpr) {
          this.maxExpr = maxExpr;
      }
  
      public ValidationError validate(Object value, ExpressionContext expressionContext) {
          Object[] array = (Object[])value;
  
          if (exactExpr != null) {
              Object result = evaluateNumeric(exactExpr, expressionContext, "exact", "value-count");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (array.length != length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.array.exact-valuecount", new String[] {String.valueOf(length)});
              return null;
          } else if (minExpr != null && maxExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "value-count");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int minLength = ((BigDecimal)result).intValue();
  
              result = evaluateNumeric(maxExpr, expressionContext, "max", "value-count");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int maxLength = ((BigDecimal)result).intValue();
  
              if (array.length < minLength || array.length > maxLength)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.array.range-valuecount", new String[] {String.valueOf(minLength), String.valueOf(maxLength)});
              return null;
          } else if (minExpr != null) {
              Object result = evaluateNumeric(minExpr, expressionContext, "min", "value-count");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (array.length < length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.array.min-valuecount", new String[] {String.valueOf(length)});
              return null;
          } else if (maxExpr != null) {
              Object result = evaluateNumeric(maxExpr, expressionContext, "max", "value-count");
              if (result instanceof ValidationError)
                  return (ValidationError)result;
              else if (result instanceof CannotYetResolveWarning)
                  return null;
              int length = ((BigDecimal)result).intValue();
              if (array.length > length)
                  return hasFailMessage() ? getFailMessage() : new ValidationError("validation.array.max-valuecount", new String[] {String.valueOf(length)});
              return null;
          }
          return null;
      }
  
      public boolean supportsType(Datatype datatype) {
          return datatype.isArrayType();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/datatype/validationruleimpl/ValueCountValidationRuleBuilder.java
  
  Index: ValueCountValidationRuleBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.datatype.validationruleimpl;
  
  import org.apache.cocoon.woody.datatype.ValidationRule;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  import org.outerj.expression.Expression;
  
  /**
   * Builds {@link ValueCountValidationRule}s.
   */
  public class ValueCountValidationRuleBuilder extends AbstractValidationRuleBuilder {
      public ValidationRule build(Element validationRuleElement) throws Exception {
          ValueCountValidationRule rule = new ValueCountValidationRule();
  
          String exactExprString = validationRuleElement.getAttribute("exact");
          String minExprString = validationRuleElement.getAttribute("min");
          String maxExprString = validationRuleElement.getAttribute("max");
  
          if (exactExprString.length() > 0) {
              Expression expression = parseExpression(exactExprString, validationRuleElement, "exact");
              rule.setExactExpr(expression);
          } else if (minExprString.length() > 0 && maxExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
              expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else if (minExprString.length() > 0) {
              Expression expression = parseExpression(minExprString, validationRuleElement, "min");
              rule.setMinExpr(expression);
          } else if (maxExprString.length() > 0) {
              Expression expression = parseExpression(maxExprString, validationRuleElement, "max");
              rule.setMaxExpr(expression);
          } else {
              throw new Exception("value-count validation rule requires a min and/or max, or exact attribute at " + DomHelper.getLocation(validationRuleElement));
          }
  
          buildFailMessage(validationRuleElement, rule);
  
          return rule;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/expression/DefaultExpressionManager.java
  
  Index: DefaultExpressionManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.expression;
  
  import org.outerj.expression.Expression;
  import org.outerj.expression.ExpressionException;
  import org.outerj.expression.ParseException;
  import org.outerj.expression.FormulaParser;
  import org.apache.avalon.framework.thread.ThreadSafe;
  
  /**
   * Implementation of the {@link ExpressionManager} role.
   *
   * <p>In the future, this component should become configurable so that new, user-defined
   * functions can be registered.
   */
  public class DefaultExpressionManager implements ExpressionManager, ThreadSafe {
      public Expression parse(String expressionString) throws ParseException, ExpressionException
      {
          FormulaParser parser = new FormulaParser(new java.io.StringReader(expressionString)); //, functionFactory);
          parser.sum();
  
          Expression expression = parser.getExpression();
          expression.check();
  
          return expression;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/expression/ExpressionManager.java
  
  Index: ExpressionManager.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.expression;
  
  import org.outerj.expression.Expression;
  import org.outerj.expression.ParseException;
  import org.outerj.expression.ExpressionException;
  
  /**
   * Work interface for the component that creates Expression objects.
   * The reason for centralising the creation of expressions is so that
   * new functions can be registered in one place.
   */
  public interface ExpressionManager {
      public static final String ROLE = "org.apache.cocoon.woody.expression.ExpressionManager";
  
      public Expression parse(String expression) throws ParseException, ExpressionException;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidget.java
  
  Index: AbstractWidget.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * Abstract base class for Widget implementations. Provides functionality
   * common to many widgets.
   */
  public abstract class AbstractWidget implements Widget {
      private ContainerWidget parent;
  
      public ContainerWidget getParent() {
          return parent;
      }
  
      public void setParent(ContainerWidget widget) {
          this.parent = widget;
      }
  
      public String getNamespace() {
          if (getParent() != null && getParent().getNamespace().length() > 0)
              return getParent().getNamespace() + "." + getId();
          else
              return getId();
      }
  
      public String getFullyQualifiedId() {
          if (parent != null) {
              String namespace = parent.getNamespace();
              if (namespace.length() > 0)
                  return namespace + "." + getId();
          }
          return getId();
      }
  
      public Object getValue() {
          return null;
      }
  
      public boolean isRequired() {
          return false;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidgetDefinition.java
  
  Index: AbstractWidgetDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
  
  /**
   * Provides functionality that is common across many WidgetDefinition implementations.
   */
  public abstract class AbstractWidgetDefinition implements WidgetDefinition {
      private String id;
      private Object label;
  
      public String getId() {
          return id;
      }
  
      protected void setId(String id) {
          this.id = id;
      }
  
      /**
       * Sets the label for this widget. The label must be a SAX fragment generated
       * with Cocoon's XMLByteStreamCompiler. This approach allows to have
       * mixed content in labels.
       */
      public void setLabel(Object label) {
          this.label = label;
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          if (label != null) {
              XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
              interpreter.setContentHandler(contentHandler);
              interpreter.deserialize(label);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractWidgetDefinitionBuilder.java
  
  Index: AbstractWidgetDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.w3c.dom.Element;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.FormManager;
  import org.apache.cocoon.woody.datatype.DatatypeManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.ComponentException;
  
  /**
   * Abstract base class for WidgetDefinitionBuilders. Provides functionality
   * common to many implementations.
   */
  public abstract class AbstractWidgetDefinitionBuilder implements WidgetDefinitionBuilder, Composable {
      protected FormManager formManager;
      protected DatatypeManager datatypeManager;
  
      public void compose(ComponentManager componentManager) throws ComponentException {
          formManager = (FormManager)componentManager.lookup(FormManager.ROLE);
          datatypeManager = (DatatypeManager)componentManager.lookup(DatatypeManager.ROLE);
      }
  
      protected void setId(Element widgetElement, AbstractWidgetDefinition widgetDefinition) throws Exception {
          String id = DomHelper.getAttribute(widgetElement, "id");
          if (id.length() < 1)
              throw new Exception("Missing id attribute on element \"" + widgetElement.getTagName() + "\" at " + DomHelper.getLocation(widgetElement));
          widgetDefinition.setId(id);
      }
  
      protected void setLabel(Element widgetElement, AbstractWidgetDefinition widgetDefinition) {
          Element labelElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "label");
          if (labelElement != null) {
              Object label = DomHelper.compileElementContent(labelElement);
              widgetDefinition.setLabel(label);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/BooleanField.java
  
  Index: BooleanField.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.woody.Constants;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.util.Locale;
  
  /**
   * A widget to select a boolean value. Usually rendered as a checkbox.
   *
   * <p>You may wonder why we don't use a {@link Field} widget with an associated
   * Boolean Datatype instead. The reason is that many of the features of the Field
   * widget are overkill for a Boolean: validation is unnecessary (if the field is
   * not true it is false), the selectionlist associated with a Datatype also
   * 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).
   */
  public class BooleanField extends AbstractWidget {
      private Boolean value = Boolean.FALSE;
      private BooleanFieldDefinition definition;
  
      public BooleanField(BooleanFieldDefinition definition) {
          this.definition = definition;
      }
  
      public String getId() {
          return definition.getId();
      }
  
      public void readFromRequest(Request request, Locale locale) {
          String param = request.getParameter(getFullyQualifiedId());
          if (param != null && param.equalsIgnoreCase("true"))
              value = Boolean.TRUE;
          else
              value = Boolean.FALSE;
      }
  
      public boolean validate(Locale locale) {
          // a boolean field is always valid
          return true;
      }
  
      private static final String BOOLEAN_FIELD_EL = "booleanfield";
      private static final String VALUE_EL = "value";
      private static final String LABEL_EL = "label";
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          AttributesImpl fieldAttrs = new AttributesImpl();
          fieldAttrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
          contentHandler.startElement(Constants.WI_NS, BOOLEAN_FIELD_EL, Constants.WI_PREFIX_COLON + BOOLEAN_FIELD_EL, fieldAttrs);
  
          // value element
          contentHandler.startElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL, Constants.EMPTY_ATTRS);
          String stringValue = String.valueOf(value != null && value.booleanValue() == true? "true": "false");
          contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length());
          contentHandler.endElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL);
  
          contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
          definition.generateLabel(contentHandler);
          contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
  
          contentHandler.endElement(Constants.WI_NS, BOOLEAN_FIELD_EL, Constants.WI_PREFIX_COLON + BOOLEAN_FIELD_EL);
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          definition.generateLabel(contentHandler);
      }
  
      public Object getValue() {
          return value;
      }
  
      public void setValue(Object object) {
          if (!(object instanceof Boolean))
              throw new RuntimeException("Cannot set value of boolean field \"" + getFullyQualifiedId() + "\" to a non-Boolean value.");
          value = (Boolean)object;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/BooleanFieldDefinition.java
  
  Index: BooleanFieldDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * The {@link WidgetDefinition} part of a BooleanField widget, see {@link BooleanField} for more information.
   */
  public class BooleanFieldDefinition extends AbstractWidgetDefinition {
      public Widget createInstance() {
          return new BooleanField(this);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/BooleanFieldDefinitionBuilder.java
  
  Index: BooleanFieldDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link BooleanFieldDefinition}s.
   */
  public class BooleanFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
      public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
          BooleanFieldDefinition definition = new BooleanFieldDefinition();
          setId(widgetElement, definition);
          setLabel(widgetElement, definition);
          // TODO default value
          return definition;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/CannotYetResolveWarning.java
  
  Index: CannotYetResolveWarning.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * This exception is thrown by {@link ExpressionContextImpl} when it asked for
   * the value of a required field, when that required field does not yet have
   * a value.
   */
  public class CannotYetResolveWarning extends  RuntimeException {
      public String getMessage() {
          return "An expression variable could not yet be resolved.";
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ContainerWidget.java
  
  Index: ContainerWidget.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * A container widget is a widget that contains other widgets.
   * If a widget has a parent, then this parent should always be a ContainerWidget.
   */
  public interface ContainerWidget extends Widget {
      public Widget getWidget(String id);
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/DuplicateIdException.java
  
  Index: DuplicateIdException.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * This exception is thrown by WidgetDefinitions that contain other WidgetDefinitions,
   * such as the {@link FormDefinition} or the {@link RepeaterDefinition}, in case
   * one tries to add a WidgetDefinition that has the same id as another,
   * previously added, WidgetDefinition..
   */
  public class DuplicateIdException extends Exception {
      public DuplicateIdException(String message) {
          super(message);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ExpressionContextImpl.java
  
  Index: ExpressionContextImpl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.outerj.expression.ExpressionContext;
  
  import java.math.BigDecimal;
  
  /**
   * Implementation of the ExpressionContext required for the evaluation of
   * expressions by xReporter expression interpreter.
   */
  public class ExpressionContextImpl implements ExpressionContext {
      private Widget widget;
  
      public ExpressionContextImpl(Widget widget) {
          this.widget = widget;
      }
  
      /**
       * Variables refer to other widgets.
       *
       * <p>The current implementation only allows access to sibling widgets.
       *
       * <p>In case the value of a widget is null but the widget is required, then a special
       * exception will be thrown, the {@link CannotYetResolveWarning}. This is because in
       * that case, you'll probably want to re-evaluate the expression at a later time (since
       * the widget is required, it will eventually get a value).
       *
       * <p>In case the value of the widget is null but the field is not required, then simply
       * null is returned. (TODO: a function IsNull() will provided in the expression library
       * so that expression writers can check for the likely condition where a non-required field
       * is null).
       *
       * <p>If the variable name does not refer to an existing widget, null is returned (TODO: this
       * behaviour will probably change in the future)
       */
      public Object resolveVariable(String name) {
          // TODO allow to access other widgets instead of only siblings (allow going up with ../ notation or something)
          Widget widget = this.widget.getParent().getWidget(name);
          if (widget != null) {
              Object value = widget.getValue();
  
              if (value == null && widget.isRequired()) {
                  // the widget currently has not yet a value, but since it is required, it will get a value sooner
                  // or later. Therefore, we throw an exception here indicating that this expression can currenlty
                  // not yet be evaluated, but will be at a later time.
                  throw new CannotYetResolveWarning();
              }
  
              // do some type conversions:
              //   * the expression library only knows about BigDecimals as being numbers, so convert Longs first to BigDecimals
              //   * ...
              if (value instanceof Long)
                  return new BigDecimal(((Long)value).longValue());
              else
                  return value;
          }
          return null;
      }
  
      public Object get(String s) {
          return null;
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Field.java
  
  Index: Field.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.util.Locale;
  
  /**
   * A general-purpose Widget that can hold one value. A Field widget can be associated
   * with a {@link org.apache.cocoon.woody.datatype.Datatype Datatype}, and thus
   * a Field widget can be used to edit different kinds of data, such as strings,
   * numbers and dates. A Datatype can also have an associated SelectionList, so
   * that the value for the Field can be selected from a list, rather than being
   * entered in a textbox. The validation of the field is delegated to its associated
   * Datatype.
   */
  public class Field extends AbstractWidget {
      private FieldDefinition definition;
      private String enteredValue;
      private Object value;
      private boolean conversionFailed;
      private ValidationError validationError;
  
      public Field(FieldDefinition fieldDefinition) {
          this.definition = fieldDefinition;
      }
  
      public String getId() {
          return definition.getId();
      }
  
      public Object getValue() {
          return value;
      }
  
      public void setValue(Object object) {
          if (!definition.getDatatype().getTypeClass().isAssignableFrom(object.getClass()))
              throw new RuntimeException("Tried to set value of field \"" + getFullyQualifiedId() + "\" with an object of an incorrect type.");
  
          value = object;
          validationError = null;
          conversionFailed = false;
      }
  
      public void readFromRequest(Request request, Locale locale) {
          enteredValue = request.getParameter(getFullyQualifiedId());
          validationError = null;
          conversionFailed = false;
  
          // whitespace & empty field handling
          if (enteredValue != null) {
              // TODO make whitespace behaviour configurable !!
              enteredValue.trim();
  
              if (enteredValue.equals(""))
                  enteredValue = null;
          }
  
          // try to convert entered string to the field's native datatype
          if (enteredValue != null) {
              value = definition.getDatatype().convertFromStringLocalized(enteredValue, locale);
              if (value == null)
                  conversionFailed = true;
          } else
              value = null;
      }
  
      public boolean validate(Locale locale) {
          if (value != null)
              validationError = definition.getDatatype().validate(value, new ExpressionContextImpl(this));
          else if (conversionFailed)
              validationError = new ValidationError("datatype.conversion-failed", new String[] {"datatype." + definition.getDatatype().getDescriptiveName()}, new boolean[] { true });
          else if (definition.isRequired())
              validationError = new ValidationError("general.field-required");
  
          return validationError == null;
      }
  
      public boolean isRequired() {
          return definition.isRequired();
      }
  
      private static final String FIELD_EL = "field";
      private static final String VALUE_EL = "value";
      private static final String VALIDATION_MSG_EL = "validation-message";
      private static final String LABEL_EL = "label";
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          AttributesImpl fieldAttrs = new AttributesImpl();
          fieldAttrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
          fieldAttrs.addAttribute("", "required", "required", "CDATA", String.valueOf(definition.isRequired()));
          contentHandler.startElement(Constants.WI_NS, FIELD_EL, Constants.WI_PREFIX_COLON + FIELD_EL, fieldAttrs);
  
          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().convertToStringLocalized(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);
          }
  
          // the label
          contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
          definition.generateLabel(contentHandler);
          contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
  
          // the selection list, if any
          if (definition.getDatatype().getSelectionList() != null) {
              definition.getDatatype().getSelectionList().generateSaxFragment(contentHandler, locale);
          }
  
          contentHandler.endElement(Constants.WI_NS, FIELD_EL, Constants.WI_PREFIX_COLON + FIELD_EL);
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          definition.generateLabel(contentHandler);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FieldDefinition.java
  
  Index: FieldDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.woody.datatype.Datatype;
  
  /**
   * The {@link WidgetDefinition} part of a Field widget, see {@link Field} for more information.
   */
  public class FieldDefinition extends AbstractWidgetDefinition {
      private Datatype datatype;
      private boolean required;
  
      public Widget createInstance() {
          Field field = new Field(this);
          return field;
      }
  
      public Datatype getDatatype() {
          return datatype;
      }
  
      public void setDatatype(Datatype datatype) {
          this.datatype = datatype;
      }
  
      public boolean isRequired() {
          return required;
      }
  
      public void setRequired(boolean required) {
          this.required = required;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FieldDefinitionBuilder.java
  
  Index: FieldDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.woody.datatype.Datatype;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.w3c.dom.Element;
  
  /**
   * Builds {FieldDefinition}s.
   */
  public class FieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
  
      public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
          FieldDefinition fieldDefinition = new FieldDefinition();
          setId(widgetElement, fieldDefinition);
  
          Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "datatype");
          if (datatypeElement == null)
              throw new Exception("A nested datatype element is required for the widget specified at " + DomHelper.getLocation(widgetElement));
  
          Datatype datatype = datatypeManager.createDatatype(datatypeElement, false);
          fieldDefinition.setDatatype(datatype);
  
          setLabel(widgetElement, fieldDefinition);
  
          boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false);
          fieldDefinition.setRequired(required);
  
          return fieldDefinition;
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Form.java
  
  Index: Form.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.woody.Constants;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.util.*;
  
  /**
   * A widget that serves as a container for other widgets, the top-level widget in
   * a form description file.
   */
  public class Form extends AbstractWidget implements ContainerWidget {
      private List widgets;
      private Map widgetsById;
      private FormDefinition definition;
  
      public Form(FormDefinition definition) {
          widgets = new ArrayList();
          widgetsById = new HashMap();
          this.definition = definition;
      }
  
      protected void addWidget(Widget widget) {
          widgets.add(widget);
          widget.setParent(this);
          widgetsById.put(widget.getId(), widget);
      }
  
      public void readFromRequest(Request request, Locale locale) {
          // let all individual widgets read their value from the request object
          Iterator widgetIt = widgets.iterator();
          while (widgetIt.hasNext()) {
              Widget widget = (Widget)widgetIt.next();
              widget.readFromRequest(request, locale);
          }
      }
  
      public boolean validate(Locale locale) {
          boolean allValid = true;
          Iterator widgetIt = widgets.iterator();
          while (widgetIt.hasNext()) {
              Widget widget = (Widget)widgetIt.next();
              allValid = allValid & widget.validate(locale);
          }
          return allValid;
      }
  
      public Widget getWidget(String id) {
          return (Widget)widgetsById.get(id);
      }
  
      public String getId() {
          return definition.getId();
      }
  
      private static final String FORM_EL = "form";
      private static final String CHILDREN_EL = "children";
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          AttributesImpl formAttrs = new AttributesImpl();
          formAttrs.addAttribute("", "id", "id", "CDATA", definition.getId());
  
          contentHandler.startElement(Constants.WI_NS, FORM_EL, Constants.WI_PREFIX_COLON + FORM_EL, Constants.EMPTY_ATTRS);
          definition.generateLabel(contentHandler);
  
          contentHandler.startElement(Constants.WI_NS, CHILDREN_EL, Constants.WI_PREFIX_COLON + CHILDREN_EL, Constants.EMPTY_ATTRS);
          Iterator widgetIt = widgets.iterator();
          while (widgetIt.hasNext()) {
              Widget widget = (Widget)widgetIt.next();
              widget.generateSaxFragment(contentHandler, locale);
          }
          contentHandler.endElement(Constants.WI_NS, CHILDREN_EL, Constants.WI_PREFIX_COLON + CHILDREN_EL);
  
          contentHandler.endElement(Constants.WI_NS, FORM_EL, Constants.WI_PREFIX_COLON + FORM_EL);
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          definition.generateLabel(contentHandler);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FormDefinition.java
  
  Index: FormDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import java.util.*;
  
  /**
   * The {@link WidgetDefinition} part of a Form widget, see {@link Form} for more information.
   */
  public class FormDefinition extends AbstractWidgetDefinition {
      private List widgetDefinitions = new ArrayList();
      private Map widgetDefinitionsById = new HashMap();
  
      public void addWidgetDefinition(WidgetDefinition widgetDefinition) throws DuplicateIdException {
          if (widgetDefinitionsById.containsKey(widgetDefinition.getId()))
              throw new DuplicateIdException("Duplicate widget id detected: form " + getId() + " already has a widget with id \"" + widgetDefinition.getId() + "\"");
          widgetDefinitions.add(widgetDefinition);
          widgetDefinitionsById.put(widgetDefinition.getId(), widgetDefinition);
      }
  
      public Widget createInstance() {
          Form form = new Form(this);
  
          Iterator widgetDefinitionIt = widgetDefinitions.iterator();
          while (widgetDefinitionIt.hasNext()) {
              WidgetDefinition widgetDefinition = (WidgetDefinition)widgetDefinitionIt.next();
              form.addWidget(widgetDefinition.createInstance());
          }
  
          return form;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/FormDefinitionBuilder.java
  
  Index: FormDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link FormDefinition}s.
   */
  public class FormDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
  
      public WidgetDefinition buildWidgetDefinition(Element formElement) throws Exception {
          FormDefinition formDefinition = new FormDefinition();
  
          formDefinition.setId("");
          setLabel(formElement, formDefinition);
  
          // all child elements of the form element, that are in woody's namespace, are supposed
          // to be widgets
          Element[] widgetElements = DomHelper.getChildElements(formElement, Constants.WD_NS);
          for (int i = 0; i < widgetElements.length; i++) {
              Element widgetElement = widgetElements[i];
              WidgetDefinition widgetDefinition = formManager.buildWidgetDefinition(widgetElement);
              formDefinition.addWidgetDefinition(widgetDefinition);
          }
  
          return formDefinition;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/MultiValueField.java
  
  Index: MultiValueField.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.woody.datatype.ValidationError;
  import org.apache.cocoon.woody.Constants;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.util.Locale;
  
  /**
   * A MultiValueField is mostly the same as a normal {@link Field}, but can
   * hold multiple values. A MultiValueField should have a Datatype which
   * has a SelectionList, because the user will always select the values
   * from a list. A MultiValueField has no concept of "required", you should
   * instead use the ValueCountValidationRule to check how many items the user
   * has selected.
   *
   * <p>A MultiValueField also has a {@link org.apache.cocoon.woody.datatype.Datatype Datatype}
   * associated with it. In case of MultiValueFields, this Datatype will always be an array
   * type, thus {@link org.apache.cocoon.woody.datatype.Datatype#isArrayType Datatype#isArrayType} will
   * always return true, and this in return has an influence on the kind of validation rules that
   * can be used with the Datatype (see {@link org.apache.cocoon.woody.datatype.Datatype Datatype}
   * description for more information).
   */
  public class MultiValueField extends AbstractWidget {
      private MultiValueFieldDefinition definition;
      private String[] enteredValues;
      private Object[] values;
      private ValidationError validationError;
  
      public MultiValueField(MultiValueFieldDefinition definition) {
          this.definition = definition;
      }
  
      public String getId() {
          return definition.getId();
      }
  
      public void readFromRequest(Request request, Locale locale) {
          enteredValues = request.getParameterValues(getFullyQualifiedId());
          validationError = null;
          values = null;
  
          boolean conversionFailed = false;
          if (enteredValues != null) {
              // Normally, for MultiValueFields, the user selects the values from
              // a SelectionList, and the values in a SelectionList are garanteed to
              // be valid, so the conversion from String to native datatype should
              // never fail. But it could fail if users start messing around with
              // request parameters.
              Object[] tempValues = new Object[enteredValues.length];
              for (int i = 0; i < enteredValues.length; i++) {
                  String param = enteredValues[i];
                  tempValues[i] = definition.getDatatype().convertFromStringLocalized(param, locale);
                  if (tempValues[i] == null) {
                      conversionFailed = true;
                      break;
                  }
              }
  
              if (!conversionFailed)
                  values = tempValues;
              else
                  values = null;
          } else {
              values = new Object[0];
          }
      }
  
      public boolean validate(Locale locale) {
          if (values != null)
              validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
          else
              validationError = new ValidationError("multivaluefield.conversionfailed");
  
          return validationError == null;
      }
  
      private static final String MULTIVALUEFIELD_EL = "multivaluefield";
      private static final String VALUES_EL = "values";
      private static final String VALUE_EL = "value";
      private static final String LABEL_EL = "label";
      private static final String VALIDATION_MSG_EL = "validation-message";
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          AttributesImpl attrs = new AttributesImpl();
          attrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
          contentHandler.startElement(Constants.WI_NS, MULTIVALUEFIELD_EL, Constants.WI_PREFIX_COLON + MULTIVALUEFIELD_EL, attrs);
  
          contentHandler.startElement(Constants.WI_NS, VALUES_EL, Constants.WI_PREFIX_COLON + VALUES_EL, Constants.EMPTY_ATTRS);
          if (values != null) {
              for (int i = 0; i < values.length; i++) {
                  contentHandler.startElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL, Constants.EMPTY_ATTRS);
                  // Note: by intent not convertToStringLocalized
                  String value = definition.getDatatype().convertToString(values[i]);
                  contentHandler.characters(value.toCharArray(), 0, value.length());
                  contentHandler.endElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL);
              }
          } else if (enteredValues != null) {
              for (int i = 0; i < enteredValues.length; i++) {
                  contentHandler.startElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL, Constants.EMPTY_ATTRS);
                  // Note: by intent not convertToStringLocalized
                  String value = definition.getDatatype().convertToString(enteredValues[i]);
                  contentHandler.characters(value.toCharArray(), 0, value.length());
                  contentHandler.endElement(Constants.WI_NS, VALUE_EL, Constants.WI_PREFIX_COLON + VALUE_EL);
              }
          }
          contentHandler.endElement(Constants.WI_NS, VALUES_EL, Constants.WI_PREFIX_COLON + VALUES_EL);
  
          // the label
          contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
          definition.generateLabel(contentHandler);
          contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
  
          // the selection list (a MultiValueField has per definition always a SelectionList)
          definition.getDatatype().getSelectionList().generateSaxFragment(contentHandler, locale);
  
          // validation message element
          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);
          }
  
          contentHandler.endElement(Constants.WI_NS, MULTIVALUEFIELD_EL, Constants.WI_PREFIX_COLON + MULTIVALUEFIELD_EL);
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          definition.generateLabel(contentHandler);
      }
  
      public Object getValue() {
          return values;
      }
  
      public void setValues(Object[] values) {
          // check that all the objects in the array correspond to the datatype
          for (int i = 0; i < values.length; i++) {
              if (!definition.getDatatype().getTypeClass().isAssignableFrom(values[i].getClass()))
                  throw new RuntimeException("Cannot set value of field \"" + getFullyQualifiedId() + "\" with an object of type " + values[i].getClass().getName());
          }
          this.values = values;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/MultiValueFieldDefinition.java
  
  Index: MultiValueFieldDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  /**
   * The {@link WidgetDefinition} part of a MultiValueField widget, see {@link MultiValueField} for more information.
   */
  public class MultiValueFieldDefinition extends FieldDefinition {
      public Widget createInstance() {
          return new MultiValueField(this);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/MultiValueFieldDefinitionBuilder.java
  
  Index: MultiValueFieldDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.w3c.dom.Element;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.woody.datatype.Datatype;
  
  /**
   * Builds {@link MultiValueFieldDefinition}s.
   */
  public class MultiValueFieldDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
      public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
          MultiValueFieldDefinition definition = new MultiValueFieldDefinition();
  
          setId(widgetElement, definition);
          setLabel(widgetElement, definition);
  
          Element datatypeElement = DomHelper.getChildElement(widgetElement, Constants.WD_NS, "datatype");
          if (datatypeElement == null)
              throw new Exception("A nested datatype element is required for the widget specified at " + DomHelper.getLocation(widgetElement));
  
          Datatype datatype = datatypeManager.createDatatype(datatypeElement, true);
          if (datatype.getSelectionList() == null)
              throw new Exception("Error: multivaluefields always require a selectionlist at " + DomHelper.getLocation(datatypeElement));
          definition.setDatatype(datatype);
  
          boolean required = DomHelper.getAttributeAsBoolean(widgetElement, "required", false);
          definition.setRequired(required);
  
          return definition;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Repeater.java
  
  Index: Repeater.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.woody.Constants;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  import java.util.*;
  
  /**
   * A repeater is a widget that repeats a number of other widgets.
   *
   * <p>Technically, the Repeater widget is a ContainerWidget whose children are
   * {@link RepeaterRow}s, and the RepeaterRows in turn are ContainerWidgets
   * containing the actual repeated widgets. However, in practice, you won't need
   * to use the RepeaterRow widget directly.
   *
   * <p>Using the methods {@link #getSize} and {@link #getWidget(int, java.lang.String)}
   * you can access all of the repeated widget instances.
   */
  public class Repeater extends AbstractWidget implements ContainerWidget {
      private RepeaterDefinition definition;
      private List rows = new ArrayList();
  
      public Repeater(RepeaterDefinition repeaterDefinition) {
          this.definition = repeaterDefinition;
      }
  
      public String getId() {
          return definition.getId();
      }
  
      public int getSize() {
          return rows.size();
      }
  
      public void addRow() {
          rows.add(new RepeaterRow());
      }
  
      public RepeaterRow getRow(int index) {
          return (RepeaterRow)rows.get(index);
      }
  
      /**
       * Gets a widget on a certain row.
       * @param rowIndex startin from 0
       * @param id a widget id
       * @return null if there's no such widget
       */
      public Widget getWidget(int rowIndex, String id) {
          RepeaterRow row = (RepeaterRow)rows.get(rowIndex);
          return row.getWidget(id);
      }
  
      public Widget getWidget(String id) {
          // TODO catch numberformatexception and throw something nice in that case
          int row = Integer.parseInt(id);
          return (RepeaterRow)rows.get(row);
      }
  
      public void readFromRequest(Request request, Locale locale) {
          // read number of rows from request, and make an according number of rows
          String sizeParameter = request.getParameter(getFullyQualifiedId() + ".size");
          if (sizeParameter != null) {
              int size = 0;
              try {
                  size = Integer.parseInt(sizeParameter);
              } catch (NumberFormatException exc) {
                  // do nothing
              }
              for (int i = 0; i < size; i++) {
                  // TODO: a person with bad intents could pass a very large size parameter, maybe we should
                  // check for a built-in limit or something.
                  addRow();
              }
          } else {
              rows.clear();
          }
  
          // let the rows read their data from the request
          Iterator rowIt = rows.iterator();
          while (rowIt.hasNext()) {
              RepeaterRow row = (RepeaterRow)rowIt.next();
              row.readFromRequest(request, locale);
          }
      }
  
      public boolean validate(Locale locale) {
          boolean valid = true;
          Iterator rowIt = rows.iterator();
          while (rowIt.hasNext()) {
              RepeaterRow row = (RepeaterRow)rowIt.next();
              valid = valid & row.validate(locale);
          }
          return valid;
      }
  
      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";
  
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
          AttributesImpl repeaterAttrs = new AttributesImpl();
          repeaterAttrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
          repeaterAttrs.addAttribute("", "size", "size", "CDATA", String.valueOf(getSize()));
          contentHandler.startElement(Constants.WI_NS, REPEATER_EL, Constants.WI_PREFIX_COLON + REPEATER_EL, repeaterAttrs);
  
          // the repeater's label
          contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS);
          definition.generateLabel(contentHandler);
          contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL);
  
          // heading element -- currently contains the labels of each widget in the repeater
          contentHandler.startElement(Constants.WI_NS, HEADINGS_EL, Constants.WI_PREFIX_COLON + HEADINGS_EL, Constants.EMPTY_ATTRS);
          Iterator widgetDefinitionIt = definition.getWidgetDefinitions().iterator();
          while (widgetDefinitionIt.hasNext()) {
              WidgetDefinition widgetDefinition = (WidgetDefinition)widgetDefinitionIt.next();
              contentHandler.startElement(Constants.WI_NS, HEADING_EL, Constants.WI_PREFIX_COLON + HEADING_EL, Constants.EMPTY_ATTRS);
              widgetDefinition.generateLabel(contentHandler);
              contentHandler.endElement(Constants.WI_NS, HEADING_EL, Constants.WI_PREFIX_COLON + HEADING_EL);
          }
          contentHandler.endElement(Constants.WI_NS, HEADINGS_EL, Constants.WI_PREFIX_COLON + HEADINGS_EL);
  
          // the actual rows in the repeater
          Iterator rowIt = rows.iterator();
          while (rowIt.hasNext()) {
              RepeaterRow row = (RepeaterRow)rowIt.next();
              row.generateSaxFragment(contentHandler, locale);
          }
          contentHandler.endElement(Constants.WI_NS, REPEATER_EL, Constants.WI_PREFIX_COLON + REPEATER_EL);
      }
  
      public void generateLabel(ContentHandler contentHandler) throws SAXException {
          definition.generateLabel(contentHandler);
      }
  
      /**
       * Generates the label of a certain widget in this repeater.
       */
      public void generateWidgetLabel(String widgetId, ContentHandler contentHandler) throws SAXException {
          WidgetDefinition widgetDefinition = definition.getWidgetDefinition(widgetId);
          if (widgetDefinition == null)
              throw new SAXException("Repeater \"" + getFullyQualifiedId() + "\" contains no widget with id \"" + widgetId + "\".");
          widgetDefinition.generateLabel(contentHandler);
      }
  
      /**
       * Generates a repeater-size element with a size attribute indicating the size of this repeater.
       */
      public void generateSize(ContentHandler contentHandler) throws SAXException {
          AttributesImpl attrs = new AttributesImpl();
          attrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
          attrs.addAttribute("", "size", "size", "CDATA", String.valueOf(getSize()));
          contentHandler.startElement(Constants.WI_NS, REPEATER_SIZE_EL, Constants.WI_PREFIX_COLON + REPEATER_SIZE_EL, attrs);
          contentHandler.endElement(Constants.WI_NS, REPEATER_SIZE_EL, Constants.WI_PREFIX_COLON + REPEATER_SIZE_EL);
      }
  
      public class RepeaterRow implements ContainerWidget {
          private List widgets;
          private Map widgetsById;
  
          public RepeaterRow() {
              this.widgets = new ArrayList();
              this.widgetsById = new HashMap();
  
              // make instances of all the widgets
              Iterator widgetDefinitionIt = definition.getWidgetDefinitions().iterator();
              while (widgetDefinitionIt.hasNext()) {
                  WidgetDefinition widgetDefinition = (WidgetDefinition)widgetDefinitionIt.next();
                  Widget widget = widgetDefinition.createInstance();
                  widget.setParent(this);
                  widgets.add(widget);
                  widgetsById.put(widget.getId(), widget);
              }
          }
  
          public String getId() {
              // id of a RepeaterRow is the position of the row in the list of rows.
              return String.valueOf(rows.indexOf(this));
          }
  
          public ContainerWidget getParent() {
              return Repeater.this;
          }
  
          public String getNamespace() {
              return getParent().getNamespace() + "." + getId();
          }
  
          public String getFullyQualifiedId() {
              return getParent().getNamespace() + "." + getId();
          }
  
          public void setParent(ContainerWidget widget) {
              throw new RuntimeException("Parent of RepeaterRow is fixed, and cannot be set.");
          }
  
          public Widget getWidget(String id) {
              return (Widget)widgetsById.get(id);
          }
  
          public void readFromRequest(Request request, Locale locale) {
              Iterator widgetIt = widgets.iterator();
              while (widgetIt.hasNext()) {
                  Widget widget = (Widget)widgetIt.next();
                  widget.readFromRequest(request, locale);
              }
          }
  
          public boolean validate(Locale locale) {
              boolean valid = true;
              Iterator widgetIt = widgets.iterator();
              while (widgetIt.hasNext()) {
                  Widget widget = (Widget)widgetIt.next();
                  valid = valid & widget.validate(locale);
              }
              return valid;
          }
  
          public Object getValue() {
              return null;
          }
  
          public boolean isRequired() {
              return false;
          }
  
          public void generateLabel(ContentHandler contentHandler) throws SAXException {
              // this widget has no label
          }
  
          private static final String ROW_EL = "repeater-row";
  
          public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
              AttributesImpl rowAttrs = new AttributesImpl();
              rowAttrs.addAttribute("", "id", "id", "CDATA", getFullyQualifiedId());
              contentHandler.startElement(Constants.WI_NS, ROW_EL, Constants.WI_PREFIX_COLON + ROW_EL, rowAttrs);
              Iterator widgetIt = widgets.iterator();
              while (widgetIt.hasNext()) {
                  Widget widget = (Widget)widgetIt.next();
                  widget.generateSaxFragment(contentHandler, locale);
              }
              contentHandler.endElement(Constants.WI_NS, ROW_EL, Constants.WI_PREFIX_COLON + ROW_EL);
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/RepeaterDefinition.java
  
  Index: RepeaterDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import java.util.*;
  
  /**
   * The {@link WidgetDefinition} part of a Repeater widget, see {@link Repeater} for more information.
   */
  public class RepeaterDefinition extends AbstractWidgetDefinition {
      private List widgetDefinitions = new ArrayList();
      private Map widgetDefinitionsById = new HashMap();
  
      protected void addWidget(WidgetDefinition widgetDefinition) throws DuplicateIdException {
          if (widgetDefinitionsById.containsKey(widgetDefinition.getId()))
              throw new DuplicateIdException("Duplicate widget id detected: repeater " + getId() + " already has a widget with id \"" + widgetDefinition.getId() + "\"");
          widgetDefinitions.add(widgetDefinition);
          widgetDefinitionsById.put(widgetDefinition.getId(), widgetDefinition);
      }
  
      public Collection getWidgetDefinitions() {
          return widgetDefinitions;
      }
  
      public WidgetDefinition getWidgetDefinition(String id) {
          return (WidgetDefinition)widgetDefinitionsById.get(id);
      }
  
      public Widget createInstance() {
          return new Repeater(this);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/RepeaterDefinitionBuilder.java
  
  Index: RepeaterDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.cocoon.woody.Constants;
  import org.w3c.dom.Element;
  
  /**
   * Builds {@link RepeaterDefinition}s.
   */
  public class RepeaterDefinitionBuilder extends AbstractWidgetDefinitionBuilder {
  
      public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception {
          RepeaterDefinition repeaterDefinition = new RepeaterDefinition();
          setId(widgetElement, repeaterDefinition);
          setLabel(widgetElement, repeaterDefinition);
  
          // the children of the repeater element are widget configuration elements
          Element[] widgetElements = DomHelper.getChildElements(widgetElement, Constants.WD_NS);
          for (int i = 0; i < widgetElements.length; i++) {
              WidgetDefinition widgetDefinition = formManager.buildWidgetDefinition(widgetElements[i]);
              repeaterDefinition.addWidget(widgetDefinition);
          }
  
          return repeaterDefinition;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/Widget.java
  
  Index: Widget.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.apache.cocoon.environment.Request;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  import java.util.Locale;
  
  /**
   * Interface to be implemented by Widgets. In Woody, a form consists of a number
   * of widgets. Each widget can hold a (possibly strongly-typed) value, can validate
   * itself, can generate an XML representation of itself, can read its value
   * from the Request object, and so on.
   *
   * <p>A Widget is created by calling the createInstance method on the a
   * {@link WidgetDefinition}. A Widget holds all the data that is specific for
   * a certain use of the widget (its value, validationerrors, ...), while the
   * WidgetDefinition holds the data that is static accross all widgets. This
   * keeps the Widgets small and light to create.
   */
  public interface Widget {
      /**
       * Returns the id of this widget.
       */
      public String getId();
  
      /**
       * Gets the parent of this widget. If this widget is the root widget,
       * this method returns null.
       */
      public ContainerWidget getParent();
  
      /**
       * This method is called on a widget when it is added to a container.
       * Unless you're implementing a {@link ContainerWidget}, you should not use
       * this method.
       */
      public void setParent(ContainerWidget widget);
  
      /**
       * Gets the namespace of this widget. The combination of a widget's namespace
       * with its id (see {@link #getId} gives the widget a form-wide unique name.
       * In practice, the namespace consists of the id's of the widget's parent widgets,
       * separated by dots.
       */
      public String getNamespace();
  
      /**
       * Returns the id prefixed with the namespace, this name should be unique
       * accross all widgets on the form.
       */
      public String getFullyQualifiedId();
  
      /**
       * Lets this widget read its data from a request. At this point the Widget
       * may try to convert the request parameter to its native datatype (if it
       * is not a string), but it should not yet generate any validation errors.
       */
      public void readFromRequest(Request request, Locale locale);
  
      /**
       * Validates this widget and returns the outcome. Possible error messages are
       * remembered by the widget itself and will be part of the XML produced by
       * this widget in its {@link #generateSaxFragment} method.
       */
      public boolean validate(Locale locale);
  
      /**
       * Generates an XML representation of this widget. The startDocument and endDocument
       * SAX events will not be called. It is assumed that the prefix for the Woody namespace
       * mentioned in Constants.WI_PREFIX is already declared (by the caller or otherwise).
       */
      public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException;
  
      /**
       * Generates SAX events for the label of this widget. The label will not be wrapped
       * inside another element.
       */
      public void generateLabel(ContentHandler contentHandler) throws SAXException;
  
      /**
       * Returns the value of the widget. For some widgets (notably ContainerWidgets) this may not make sense, those
       * should then simply return null here.
       */
      public Object getValue();
  
      /**
       * Returns wether this widget is required to be filled in. As with {@link #getValue}, for some
       * widgets this may not make sense, those should return false here.
       */
      public boolean isRequired();
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinition.java
  
  Index: WidgetDefinition.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * A WidgetDefinition holds all the static information about a Widget. It's
   * 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.
   */
  public interface WidgetDefinition {
      public String getId();
      public Widget createInstance();
  
      /**
       * Generates SAX events for the label of this widget.
       */
      public void generateLabel(ContentHandler contentHandler) throws SAXException;
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/WidgetDefinitionBuilder.java
  
  Index: WidgetDefinitionBuilder.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.formmodel;
  
  import org.w3c.dom.Element;
  
  /**
   * Interface for classes that can build widgets from an XML description.
   *
   * <p>These builder classes should be thread safe, only a single instance of them
   * will be created.
   *
   * <p>Implementations may implement Avalon's Composable interface to gain access
   * to other components.
   */
  public interface WidgetDefinitionBuilder {
  
      public WidgetDefinition buildWidgetDefinition(Element widgetElement) throws Exception;
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/generation/WoodyGenerator.java
  
  Index: WoodyGenerator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.generation;
  
  import org.apache.cocoon.generation.AbstractGenerator;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.woody.formmodel.Form;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.util.Map;
  import java.util.Locale;
  
  /**
   * A generator that streams an XML representation of a Woody {@link Form}. This will
   * recursively contain the XML for all widgets on the form. This can then be styled
   * using an XSLT.
   *
   * <p>An alternative approach that requires less (or even none) XSLT work is offered by
   * the {@link org.apache.cocoon.woody.transformation.WoodyTemplateTransformer WoodyTemplateTransformer}.
   *
   * <p>The Form whose XML should be produced should reside in a request attribute, whose
   * name should be provided to this generator as a sitemap parameter called "attribute-name".
   */
  public class WoodyGenerator extends AbstractGenerator {
      private Form form;
  
      public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
              throws ProcessingException, SAXException, IOException {
          super.setup(resolver, objectModel, src, par);
          // get the form from a request attribute
          String formAttribute;
          try {
              formAttribute = parameters.getParameter("attribute-name");
          } catch (ParameterException e) {
              throw new ProcessingException("Missing 'attribute-name' parameter for WoodyTemplateTransformer.");
          }
          Request request = ObjectModelHelper.getRequest(objectModel);
          form = (Form)request.getAttribute(formAttribute);
          if (form == null) {
              throw new ProcessingException("WoodyTemplateTransformer cannot find a form in the request attribute named " + formAttribute);
          }
      }
  
      public void recycle() {
          super.recycle();
          form = null;
      }
  
      public void generate() throws IOException, SAXException, ProcessingException {
          contentHandler.startDocument();
          contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS);
          form.generateSaxFragment(contentHandler, Locale.US);
          contentHandler.endPrefixMapping(Constants.WI_PREFIX);
          contentHandler.endDocument();
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/samples/InitForm1Action.java
  
  Index: InitForm1Action.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.samples;
  
  import org.apache.cocoon.woody.acting.AbstractWoodyAction;
  import org.apache.cocoon.woody.formmodel.FormDefinition;
  import org.apache.cocoon.woody.formmodel.Form;
  import org.apache.cocoon.woody.formmodel.Repeater;
  import org.apache.cocoon.woody.formmodel.Field;
  import org.apache.cocoon.environment.Redirector;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.avalon.framework.parameters.Parameters;
  
  import java.util.Map;
  
  /**
   * An action that creates an instance of a specific example form included with Woody,
   * and adds some rows to its repeater widget. This example is meant to illustrate
   * how you can prepopulate a Form instance before its initial display.
   */
  public class InitForm1Action extends AbstractWoodyAction {
      public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters parameters)
              throws Exception {
          String formSource = parameters.getParameter("form-definition");
          String formAttribute = parameters.getParameter("attribute-name");
  
          FormDefinition formDefinition = formManager.getFormDefinition(resolver.resolveURI(formSource));
          Form form = (Form)formDefinition.createInstance();
  
          Repeater repeater = (Repeater)form.getWidget("contacts");
          repeater.addRow();
          Field field = (Field)repeater.getWidget(0, "firstname");
          field.setValue("Jules");
  
          repeater.addRow();
          field = (Field)repeater.getWidget(1, "firstname");
          field.setValue("Lucien");
  
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(formAttribute, form);
  
          return null;
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WidgetReplacingPipe.java
  
  Index: WidgetReplacingPipe.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.transformation;
  
  import org.apache.cocoon.xml.AbstractXMLPipe;
  import org.apache.cocoon.woody.formmodel.ContainerWidget;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.cocoon.woody.formmodel.Repeater;
  import org.apache.cocoon.woody.Constants;
  import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
  import org.apache.cocoon.components.sax.XMLByteStreamInterpreter;
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.xml.sax.SAXException;
  import org.xml.sax.Attributes;
  
  import java.util.Locale;
  
  /**
   * The basic operation of this Pipe is that it replaces wi:widget tags (having an id attribute)
   * by the XML representation of the corresponding widget instance.
   *
   * <p>These XML fragments (normally all in the {@link Constants#WI_NS "Woody Instance"} namespace, can
   * then be translated to a HTML presentation by an XSL. This XSL will then only have to style
   * individual widget, and will not need to do the whole page layout.
   *
   * <p>The content of the &lt;widget&gt; element will be re-inserted in the XML generated by the Widget
   * (as a child of its root element, before the closing tag), and wrapped inside a &lt;wi:styling&gt;
   * element. This allows to pass extra information to the XSLT that will render the widgets. For example,
   * this could be used to define the textbox width or the listbox style (dropdown or normal), ...</p>
   *
   * <p>Additionally, this transformer supports the following tags:
   * <ul>
   *  <li><strong>widget-label</strong>: used to insert the label of a widget. Requires an "id" attribute.
   *  <li><strong>repeater-widget</strong>: provides special treatement for repeater widgets. The content
   *   of the repeater-widget element will be used as a template to generate each of the rows of the repeater.
   *  The repeater-widget element requires an "id" attribute.
   *  <li><strong>repeater-widget-label</strong>: inserts the label of a widget contained by the repeater.
   *  Requires an "id" attribute (identifying the repeater) and a "widget-id" attribute (identifying the widget
   *  in the repeater).
   *  <li><strong>repeater-size</strong>: inserts an element &lt;repeater-size id="" size=""/> containing the
   *   size (number of rows) in the repeater.
   * </ul>
   *
   * <p>Woody ships with an XSL that can style all the widgets that are provided by the core Woody framework.
   */
  public class WidgetReplacingPipe extends AbstractXMLPipe {
      private ContainerWidget contextWidget;
      /** Indicates whether we're currently in a widget element. */
      private boolean inWidgetElement;
      /** Compiler used to record the XML inside wi:widget elements. */
      private XMLByteStreamCompiler xmlCompiler = new XMLByteStreamCompiler();
      /** Counts the element nesting. */
      private int elementNestingCounter;
      /**
       * Contains the value of the {@link #elementNestingCounter} on the moment the transformer
       * encountered a wi:widget element. Used to detect the corresponding endElement call
       * for the wi:widget element.
       */
      private int widgetElementNesting;
      /**
       * If {@link #inWidgetElement} = true, then this contains the widget currenlty being handled.
       */
      private Widget widget;
      /** Boolean indicating wether the current widget requires special repeater-treatement. */
      private boolean repeaterWidget;
      private WoodyTemplateTransformer.InsertStylingContentHandler stylingHandler = new WoodyTemplateTransformer.InsertStylingContentHandler();
  
      private static final String STYLING_EL = "styling";
  
      public void init(ContainerWidget contextWidget) {
          this.contextWidget = contextWidget;
          inWidgetElement = false;
          elementNestingCounter = 0;
      }
  
      public void startElement(String namespaceURI, String localName, String qName, Attributes attributes)
              throws SAXException {
          elementNestingCounter++;
          if (!inWidgetElement && namespaceURI.equals(Constants.WT_NS)
                  && (localName.equals("widget") || localName.equals("repeater-widget"))) {
              inWidgetElement = true;
              widgetElementNesting = elementNestingCounter;
              xmlCompiler.recycle();
  
              // retrieve widget here, but its XML will only be streamed in the endElement call
              widget = getWidget(attributes);
              repeaterWidget = localName.equals("repeater-widget");
              if (repeaterWidget && !(widget instanceof Repeater))
                  throw new SAXException("WoodyTemplateTransformer: the element \"repeater-widget\" can only be used for repeater widgets.");
          } else if (inWidgetElement) {
              xmlCompiler.startElement(namespaceURI, localName, qName, attributes);
          } else if (namespaceURI.equals(Constants.WT_NS)) {
              if (localName.equals("widget-label")) {
                  Widget widget = getWidget(attributes);
                  widget.generateLabel(contentHandler);
              } else if (localName.equals("repeater-widget-label")) {
                  Widget widget = getWidget(attributes);
                  if (!(widget instanceof Repeater))
                      throw new SAXException("WoodyTemplateTransformer: the element \"repeater-widget-label\" can only be used for repeater widgets.");
                  String widgetId = attributes.getValue("widget-id");
                  if (widgetId == null || widgetId.equals(""))
                      throw new SAXException("WoodyTemplateTransformer: the element \"repeater-widget-label\" requires a \"widget-id\" attribute.");
                  ((Repeater)widget).generateWidgetLabel(widgetId, contentHandler);
              } else if (localName.equals("repeater-size")) {
                  Widget widget = getWidget(attributes);
                  if (!(widget instanceof Repeater))
                      throw new SAXException("WoodyTemplateTransformer: the element \"repeater-size\" can only be used for repeater widgets.");
                  contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS);
                  ((Repeater)widget).generateSize(contentHandler);
                  contentHandler.endPrefixMapping(Constants.WI_PREFIX);
              } else {
                  throw new SAXException("Unsupported WoodyTemplateTransformer element: " + localName);
              }
          } else {
              super.startElement(namespaceURI, localName, qName, attributes);
          }
      }
  
      protected Widget getWidget(Attributes attributes) throws SAXException {
          String widgetId = attributes.getValue("id");
          if (widgetId == null || widgetId.equals(""))
              throw new SAXException("WoodyTemplateTransformer: missing id attribute on a woody element.");
          Widget widget = contextWidget.getWidget(widgetId);
          if (widget == null)
              throw new SAXException("WoodyTemplateTransformer: widget with id \"" + widgetId + "\" does not exist in the container " + contextWidget.getFullyQualifiedId());
          return widget;
      }
  
      public void endElement(String namespaceURI, String localName, String qName)
              throws SAXException {
          if (inWidgetElement && elementNestingCounter == widgetElementNesting &&
                  namespaceURI.equals(Constants.WT_NS)
                  && (localName.equals("widget") || localName.equals("repeater-widget"))) {
  
              if (repeaterWidget) {
                  Repeater repeater = (Repeater)widget;
                  WidgetReplacingPipe rowPipe = new WidgetReplacingPipe();
                  XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
                  int rowCount = repeater.getSize();
                  Object saxFragment = xmlCompiler.getSAXFragment();
                  for (int i = 0; i < rowCount; i++) {
                      Repeater.RepeaterRow row = repeater.getRow(i);
                      rowPipe.init(row);
                      rowPipe.setContentHandler(contentHandler);
                      rowPipe.setLexicalHandler(lexicalHandler);
                      interpreter.setConsumer(rowPipe);
                      interpreter.deserialize(saxFragment);
                      interpreter.recycle();
                      rowPipe.recycle();
                  }
              } else {
                  stylingHandler.recycle();
                  stylingHandler.setSaxFragment(xmlCompiler.getSAXFragment());
                  stylingHandler.setContentHandler(contentHandler);
                  stylingHandler.setLexicalHandler(lexicalHandler);
                  contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS);
                  widget.generateSaxFragment(stylingHandler, Locale.US /* TODO take locale from transformer parameter */);
                  contentHandler.endPrefixMapping(Constants.WI_PREFIX);
              }
  
              inWidgetElement = false;
              widget = null;
          } else if (inWidgetElement) {
              xmlCompiler.endElement(namespaceURI, localName, qName);
          } else if (namespaceURI.equals(Constants.WT_NS) &&
                  (localName.equals("widget-label") || localName.equals("repeater-widget-label")
                  || localName.equals("repeater-size"))) {
              // do nothing
          } else {
              super.endElement(namespaceURI, localName, qName);
          }
          elementNestingCounter--;
      }
  
      public void startPrefixMapping(String prefix, String uri)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.startPrefixMapping(prefix, uri);
          else
              super.startPrefixMapping(prefix, uri);
      }
  
      public void endPrefixMapping(String prefix)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.endPrefixMapping(prefix);
          else
              super.endPrefixMapping(prefix);
      }
  
      public void characters(char c[], int start, int len)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.characters(c, start, len);
          else
              super.characters(c, start, len);
      }
  
      public void ignorableWhitespace(char c[], int start, int len)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.ignorableWhitespace(c, start, len);
          else
              super.ignorableWhitespace(c, start, len);
      }
  
      public void processingInstruction(String target, String data)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.processingInstruction(target, data);
          else
              super.processingInstruction(target, data);
      }
  
      public void skippedEntity(String name)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.skippedEntity(name);
          else
              super.skippedEntity(name);
      }
  
      public void startEntity(String name)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.startEntity(name);
          else
              super.startEntity(name);
      }
  
      public void endEntity(String name)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.endEntity(name);
          else
              super.endEntity(name);
      }
  
      public void startCDATA()
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.startCDATA();
          else
              super.startCDATA();
      }
  
      public void endCDATA()
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.endCDATA();
          else
              super.endCDATA();
      }
  
      public void comment(char ch[], int start, int len)
              throws SAXException {
          if (inWidgetElement)
              xmlCompiler.comment(ch, start, len);
          else
              super.comment(ch, start, len);
      }
  
      /**
       * This ContentHandler helps in inserting SAX events before the closing tag of the root
       * element.
       */
      public class InsertStylingContentHandler extends AbstractXMLPipe implements Recyclable {
          private int elementNesting = 0;
          private XMLByteStreamInterpreter interpreter = new XMLByteStreamInterpreter();
          private Object saxFragment;
  
          public void setSaxFragment(Object saxFragment) {
              this.saxFragment = saxFragment;
          }
  
          public void recycle() {
              super.recycle();
              elementNesting = 0;
              interpreter.recycle();
              saxFragment = null;
          }
  
          public void startElement(String uri, String loc, String raw, Attributes a)
                  throws SAXException {
              elementNesting++;
              super.startElement(uri, loc, raw, a);
          }
  
          public void endElement(String uri, String loc, String raw)
                  throws SAXException {
              elementNesting--;
              if (elementNesting == 0 && saxFragment != null) {
                  interpreter.setContentHandler(contentHandler);
                  interpreter.setLexicalHandler(lexicalHandler);
                  contentHandler.startElement(Constants.WI_NS, STYLING_EL, Constants.WI_PREFIX_COLON + STYLING_EL, Constants.EMPTY_ATTRS);
                  interpreter.deserialize(saxFragment);
                  contentHandler.endElement(Constants.WI_NS, STYLING_EL, Constants.WI_PREFIX_COLON + STYLING_EL);
              }
              super.endElement(uri, loc, raw);
          }
      }
  
      public void recycle() {
          super.recycle();
          contextWidget = null;
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/transformation/WoodyTemplateTransformer.java
  
  Index: WoodyTemplateTransformer.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.transformation;
  
  import org.apache.cocoon.transformation.Transformer;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.woody.formmodel.Form;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.excalibur.pool.Poolable;
  import org.xml.sax.SAXException;
  
  import java.util.Map;
  import java.io.IOException;
  
  /**
   * See description of {@link WidgetReplacingPipe}.
   */
  public class WoodyTemplateTransformer extends WidgetReplacingPipe implements Transformer, Poolable {
      public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException,
              SAXException, IOException {
  
          // get the form from a request attribute
          String formAttribute;
          try {
              formAttribute = parameters.getParameter("attribute-name");
          } catch (ParameterException e) {
              throw new ProcessingException("Missing 'attribute-name' parameter for WoodyTemplateTransformer.");
          }
          Request request = ObjectModelHelper.getRequest(objectModel);
          Form form = (Form)request.getAttribute(formAttribute);
          if (form == null) {
              throw new ProcessingException("WoodyTemplateTransformer cannot find a form in the request attribute named " + formAttribute);
          }
          init(form);
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/util/DomHelper.java
  
  Index: DomHelper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.util;
  
  import org.apache.xerces.parsers.DOMParser;
  import org.apache.xerces.xni.*;
  import org.apache.xerces.dom.NodeImpl;
  import org.apache.cocoon.components.sax.XMLByteStreamCompiler;
  import org.apache.cocoon.xml.dom.DOMStreamer;
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXNotSupportedException;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.util.ArrayList;
  
  /**
   * Helper class to create and retrieve information from DOM-trees. It provides
   * some functionality comparable to what's found in Avalon's Configuration objects. These
   * lasts one could however not be used by Woody because they don't provide an
   * accurate model of an XML file (no mixed content, no namespaced attributes, no namespace declarations, ...).
   *
   * <p>This class depends specifically on the Xerces DOM implementation to be able to provide
   * information about the location of elements in their source XML file. See the {@link #getLocation} method.
   */
  public class DomHelper {
  
      /**
       * Retrieves the location of an element node in the source file from which the Document was created.
       * This will only work for Document's created with the method {@link #parse} of this class.
       */
      public static String getLocation(Element element) {
          String location = null;
          if (element instanceof NodeImpl)
              location = (String)((NodeImpl)element).getUserData("location");
  
          if (location != null)
              return location;
          else
              return "(location unknown)";
      }
  
      /**
       * Returns all Element children of an Element that belong to the given namespace.
       */
      public static Element[] getChildElements(Element element, String namespace) {
          ArrayList elements = new ArrayList();
          NodeList nodeList = element.getChildNodes();
          for (int i = 0; i < nodeList.getLength(); i++) {
              Node node = nodeList.item(i);
              if (node instanceof Element && namespace.equals(node.getNamespaceURI()))
                  elements.add(node);
          }
          return (Element[])elements.toArray(new Element[0]);
      }
  
      /**
       * Returns the first child element with the given namespace and localName, or null
       * if there is no such element.
       */
      public static Element getChildElement(Element element, String namespace, String localName) {
          NodeList nodeList = element.getChildNodes();
          for (int i = 0; i < nodeList.getLength(); i++) {
              Node node = nodeList.item(i);
              if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName()))
                  return (Element)node;
          }
          return null;
      }
  
      /**
       * Returns the value of an element's attribute, but throws an exception
       * if the element has no such attribute.
       */
      public static String getAttribute(Element element, String attributeName) throws Exception {
          String attrValue = element.getAttribute(attributeName);
          if (attrValue == null)
              throw new Exception("Missing attribute \"" + attributeName + "\" on element \"" + element.getTagName() + "\" at " + getLocation(element));
          return attrValue;
      }
  
      public static int getAttributeAsInteger(Element element, String attributeName) throws Exception {
          String attrValue = getAttribute(element, attributeName);
          try {
              return Integer.parseInt(attrValue);
          } catch (NumberFormatException e) {
              throw new Exception("Cannot parse the value \"" + attrValue + "\" as an integer in the attribute \"" + attributeName + "\" on the element \"" + element.getTagName() + "\" at " + getLocation(element));
          }
      }
  
      public static boolean getAttributeAsBoolean(Element element, String attributeName, boolean defaultValue) throws Exception {
          String attrValue = element.getAttribute(attributeName);
          if (attrValue.equals(""))
              return defaultValue;
          else if (attrValue.equalsIgnoreCase("true") || attrValue.equalsIgnoreCase("yes"))
              return true;
          else if (attrValue.equalsIgnoreCase("false") || attrValue.equalsIgnoreCase("no"))
              return false;
          else
              throw new Exception("Cannot parse the value \"" + attrValue + "\" as a boolean in the attribute \"" + attributeName + "\" on the element \"" + element.getTagName() + "\" at " + getLocation(element));
      }
  
      /**
       * Uses Cocoon's XMLByteStreamCompiler to convert the content of the given element to compiled
       * SAX events.
       */
      public static Object compileElementContent(Element element) {
          XMLByteStreamCompiler byteStreamCompiler = new XMLByteStreamCompiler();
          DOMStreamer domStreamer = new DOMStreamer();
          domStreamer.setContentHandler(byteStreamCompiler);
  
          NodeList childNodes = element.getChildNodes();
          for (int i = 0; i < childNodes.getLength(); i++) {
              try {
                  domStreamer.stream(childNodes.item(i));
              } catch (SAXException e) {
                  // It's unlikely that an exception will occur here, so use a runtime exception
                  throw new RuntimeException("Error in DomHelper.compileElementContent: " + e.toString());
              }
          }
          return byteStreamCompiler.getSAXFragment();
      }
  
      /**
       * Creates a W3C Document that remembers the location of each element in the source file.
       * The location of element nodes can then be retrieved using the {@link #getLocation} method.
       */
      public static Document parse(InputSource inputSource) throws SAXException, SAXNotSupportedException, IOException {
          DOMParser domParser = new LocationTrackingDOMParser();
          domParser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
          domParser.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes", false);
          domParser.parse(inputSource);
          return domParser.getDocument();
      }
  
      /**
       * An extension of the Xerces DOM parser that puts the location of each node in that
       * node's UserData.
       */
      public static class LocationTrackingDOMParser extends DOMParser {
          XMLLocator locator;
  
          public void startDocument(XMLLocator xmlLocator, String s, Augmentations augmentations) throws XNIException {
              super.startDocument(xmlLocator, s, augmentations);
              this.locator = xmlLocator;
              setLocation();
          }
  
          public void startElement(QName qName, XMLAttributes xmlAttributes, Augmentations augmentations) throws XNIException {
              super.startElement(qName, xmlAttributes, augmentations);
              setLocation();
          }
  
          private final void setLocation() {
              NodeImpl node = null;
              try {
                  node = (NodeImpl) this.getProperty("http://apache.org/xml/properties/dom/current-element-node");
              } catch (org.xml.sax.SAXException ex) {
                  System.err.println("except" + ex);
              }
              if (node != null) {
                  String location = locator.getLiteralSystemId() + ": line " + locator.getLineNumber();
                  node.setUserData("location", location, null);
              }
          }
      }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/lib/xreporter-expression-20030418.jar
  
  	<<Binary file>>
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  <?xml version="1.0"?>
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
  
   <map:components>
  
    <map:generators default="file">   
      <map:generator name="woody" src="org.apache.cocoon.woody.generation.WoodyGenerator"/>
    </map:generators>
  
    <map:transformers default="xslt">    
      <map:transformer name="woody" src="org.apache.cocoon.woody.transformation.WoodyTemplateTransformer"/>
      <map:transformer name="i18n" src="org.apache.cocoon.transformation.I18nTransformer">
        <catalogues default="other">
          <catalogue id="other" name="OtherMessages" location="messages"/>
          <catalogue id="woody" name="WoodyMessages" location="messages"/>
        </catalogues>
        <cache-at-startup>true</cache-at-startup>
      </map:transformer>
      <!-- be sure Xalan is used instead of XSLTC -->
      <map:transformer logger="sitemap.transformer.xslt" name="xslt" pool-grow="2" pool-max="32" pool-min="8" src="org.apache.cocoon.transformation.TraxTransformer">
        <use-request-parameters>false</use-request-parameters>
        <use-session-parameters>false</use-session-parameters>
        <use-cookie-parameters>false</use-cookie-parameters>
        <transformer-factory>org.apache.xalan.processor.TransformerFactoryImpl</transformer-factory>
      </map:transformer>
    </map:transformers>
  
    <map:readers default="resource">  
    </map:readers>
  
    <map:serializers default="html">     
    </map:serializers>
  
    <map:matchers default="wildcard">
    </map:matchers>
  
    <map:selectors default="browser">
      <map:selector name="request-method" src="org.apache.cocoon.selection.RequestMethodSelector"/>
    </map:selectors>
  
    <map:actions>
      <map:action name="woody-make-form" src="org.apache.cocoon.woody.acting.MakeFormAction"/>
      <map:action name="init-form1" src="org.apache.cocoon.woody.samples.InitForm1Action"/>
      <map:action name="woody-handle-form-submit" src="org.apache.cocoon.woody.acting.HandleFormSubmitAction"/>
    </map:actions>
  
    <map:pipes default="caching">
    </map:pipes>
  
   </map:components>
  
  <!-- =========================== Views =================================== -->
  
   <map:views>
    <map:view name="content" from-label="content">
     <map:serialize type="xml"/>
    </map:view>
  
    <map:view name="pretty-content" from-label="data">
      <map:transform src="context://stylesheets/system/xml2html.xsl"/>
      <map:serialize type="html"/>
    </map:view>
  
    <map:view name="links" from-position="last">
     <map:serialize type="links"/>
    </map:view>
    
   </map:views>
  
   <map:pipelines>
     <map:pipeline>
  
       <map:match pattern="">
         <map:read src="welcome.html"/>
       </map:match>
  
       <!--
          | "Form1" example, demonstrates all kinds of features
          -->
       <map:match pattern="form1">
         <!-- Here we use the HTTP method, GET or POST, to make distinction between
         the initial form display and a form submit. In both cases the same publishing
         pipeline will be used, which is below the selector. -->
         <map:select type="request-method">
           <map:when test="GET">
             <!-- Here we use an action especially created for the "form1" example
             which will initialise the form with some data. -->
             <map:act type="init-form1">
               <map:parameter name="form-definition" value="forms/form1.xml"/>
               <map:parameter name="attribute-name" value="form1"/>
             </map:act>
           </map:when>
           <map:when test="POST">
             <map:act type="woody-handle-form-submit">
               <map:parameter name="form-definition" value="forms/form1.xml"/>
               <map:parameter name="attribute-name" value="form1"/>
  
               <!-- the content of this action is only executed in case validation
                    succeeded, thus if the form handling is completed -->
               <map:generate type="serverpages" src="forms/form1_success.xsp"/>
               <map:serialize/>
             </map:act>
           </map:when>
           <map:otherwise>
             <!-- todo: do something here -->
           </map:otherwise>
         </map:select>
  
         <!-- pipeline to show the form -->
         <map:generate src="forms/form1_template.xml"/>
         <map:transform type="woody">
           <map:parameter name="attribute-name" value="form1"/>
         </map:transform>
         <map:transform type="i18n">
           <map:parameter name="locale" value="en-US"/>
         </map:transform>
         <map:transform src="xsl/html/woody-default.xsl"/>
         <map:transform type="i18n">
           <map:parameter name="locale" value="en-US"/>
         </map:transform>
         <map:serialize/>
       </map:match>
  
       <!--
          | Registration form example (used in the documentation)
          -->
       <map:match pattern="registration">
         <map:select type="request-method">
           <map:when test="GET">
             <map:act type="woody-make-form">
               <map:parameter name="form-definition" value="forms/registration.xml"/>
               <map:parameter name="attribute-name" value="registrationform"/>
             </map:act>
           </map:when>
           <map:otherwise>
             <map:act type="woody-handle-form-submit">
               <map:parameter name="form-definition" value="forms/registration.xml"/>
               <map:parameter name="attribute-name" value="registrationform"/>
  
               <map:generate type="serverpages" src="forms/registration_success.xsp"/>
               <map:serialize/>
             </map:act>
           </map:otherwise>
         </map:select>
  
         <map:generate src="forms/registration_template.xml"/>
         <map:transform type="woody">
           <map:parameter name="attribute-name" value="registrationform"/>
         </map:transform>
         <map:transform type="i18n">
           <map:parameter name="locale" value="en-US"/>
         </map:transform>
         <map:transform src="xsl/html/woody-default.xsl"/>
         <map:transform type="i18n">
           <map:parameter name="locale" value="en-US"/>
         </map:transform>
         <map:serialize/>
       </map:match>
     </map:pipeline>
   </map:pipelines>
  
  </map:sitemap>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/welcome.html
  
  Index: welcome.html
  ===================================================================
  <html>
    <head>
      <title>Woody samples</title>
    </head>
    <body>
      <h1>Woody</h1>
      <p>Woody is yet another form framework for Cocoon.</p>
  
      <p>Woody is currently still alpha software and in active development. Your
      feedback is very welcome on the Cocoon mailing lists.</p>
  
      <h1>Examples</h1>
      <ul>
        <li><a href="form1">Form1</a>: demonstrates various features</li>
        <li><a href="registration">Registration</a>: a simple registration form</li>
      </ul>
  
      <h1>Documentation</h1>
      <p>Todo: put a link to the documentation</p>
    </body>
  </html>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/a-choices.xml
  
  Index: a-choices.xml
  ===================================================================
  <wd:selection-list xmlns:wd="http://cocoon.apache.org/woody/definition/1.0">
    <wd:item value="a"/>
    <wd:item value="aa"/>
    <wd:item value="aaa"/>
    <wd:item value="aaaa"/>
    <wd:item value="aaaaa"/>
  </wd:selection-list>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form1.xml
  
  Index: form1.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <wd:form
    xmlns:wd="http://cocoon.apache.org/woody/definition/1.0"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
  
    <wd:field id="email" required="true">
      <wd:datatype base="string">
        <wd:validation>
          <wd:email/>
        </wd:validation>
      </wd:datatype>
      <wd:label>Enter an <b>email</b> address:</wd:label>
    </wd:field>
  
    <wd:booleanfield id="somebool">
      <wd:label>Put me <em>on</em> or <em>off</em>.</wd:label>
    </wd:booleanfield>
  
    <wd:field id="fourchars">
      <wd:label>Select something that's 4 characters long:</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:length exact='2*2'/>
        </wd:validation>
        <wd:selection-list src="forms/a-choices.xml"/>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="account">
      <wd:label>Indicate the size of your bank account (in m<sup>3</sup>):</wd:label>
      <wd:datatype base="long">
        <wd:selection-list>
          <wd:item value="1"/>
          <wd:item value="2"/>
          <wd:item value="3">
            <wd:label>three</wd:label>
          </wd:item>
          <wd:item value="4"/>
          <wd:item value="5"/>
        </wd:selection-list>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="cowheight">
      <wd:label>Indicate your height (in cows):</wd:label>
      <wd:datatype base="long">
        <wd:selection-list>
          <wd:item value="1"/>
          <wd:item value="2"/>
          <wd:item value="3">
            <wd:label>three</wd:label>
          </wd:item>
          <wd:item value="4"/>
          <wd:item value="5"/>
        </wd:selection-list>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="number1" required="true">
      <wd:label>Please enter a number:</wd:label>
      <wd:datatype base="long"/>
    </wd:field>
  
    <wd:field id="number2" required="true">
      <wd:label>Enter another number, larger than the other number:</wd:label>
      <wd:datatype base="long">
        <wd:validation>
          <wd:range min="number1 + 1">
            <wd:failmessage>This number should be larger than the first number.</wd:failmessage>
          </wd:range>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:multivaluefield id="drinks">
      <wd:label>Indicate which 2 of the following drinks you'd like to receive:</wd:label>
      <wd:datatype base="string">
        <wd:selection-list>
          <wd:item value="Maes"/>
          <wd:item value="Jupiler"/>
          <wd:item value="Leffe"/>
          <wd:item value="Hoegaarden"/>
          <wd:item value="Coca Cola"/>
        </wd:selection-list>
        <wd:validation>
          <wd:value-count exact="2"/>
        </wd:validation>
      </wd:datatype>
    </wd:multivaluefield>
  
    <wd:repeater id="contacts">
      <wd:field id="firstname">
        <wd:label>Firstname</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="lastname">
        <wd:label>Lastname</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="phone">
        <wd:label>Phone</wd:label>
        <wd:datatype base="string"/>
      </wd:field>
      <wd:field id="email">
        <wd:label>Email</wd:label>
        <wd:datatype base="string">
          <wd:validation>
            <wd:email/>
          </wd:validation>
        </wd:datatype>
      </wd:field>
    </wd:repeater>
  
  </wd:form>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form1_success.xsp
  
  Index: form1_success.xsp
  ===================================================================
  <?xml version="1.0"?>
  <xsp:page language="java"
    xmlns:xsp="http://apache.org/xsp">
  
    <xsp:structure>
      <xsp:include>org.apache.cocoon.woody.formmodel.*</xsp:include>
    </xsp:structure>
  
    <html>
      <body>
        <xsp:logic>
          // get reference to form and some of the widgets on it
          Form form = (Form)request.getAttribute("form1");
          Field field = (Field)form.getWidget("email");
          BooleanField booleanField = (BooleanField)form.getWidget("somebool");
          Field field2 = (Field)((Repeater)form.getWidget("contacts")).getWidget(1, "firstname");
        </xsp:logic>
  
        email has the following value:
        <xsp:expr>field.getValue()</xsp:expr>
        <br/>
        Second person has this firstname:
        <xsp:expr>field2.getValue()</xsp:expr>
        <br/>
        The value of the checkbox is:
        <xsp:expr>booleanField.getValue()</xsp:expr>
      </body>
    </html>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/form1_template.xml
  
  Index: form1_template.xml
  ===================================================================
  <?xml version="1.0"?>
  <html xmlns:wt="http://cocoon.apache.org/woody/template/1.0">
    <head>
      <title>Form 1 sample</title>
    </head>
    <body>
      <form action="form1" method="POST">
        <table border="1">
          <tr>
            <td valign="top"><wt:widget-label id="email"/></td>
            <td valign="top"><wt:widget id="email"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="fourchars"/></td>
            <td valign="top">
              <!-- The extra content inside the widget element will be
              used by the XSL to determine its behaviour -->
              <wt:widget id="fourchars">
                <list-style>listbox</list-style>
                <listbox-size>4</listbox-size>
              </wt:widget>
            </td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="number1"/></td>
            <td valign="top"><wt:widget id="number1"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="number2"/></td>
            <td valign="top"><wt:widget id="number2"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="account"/></td>
            <td valign="top"><wt:widget id="account"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="cowheight"/></td>
            <td valign="top">
              <wt:widget id="cowheight">
                <list-style>radio</list-style>
              </wt:widget>
            </td>
          </tr>
          <tr>
            <td/>
            <td><wt:widget id="somebool"/> <wt:widget-label id="somebool"/></td>
          </tr>
          <tr>
            <td valign="top"><wt:widget-label id="drinks"/></td>
            <td valign="top"><wt:widget id="drinks"/></td>
          </tr>
        </table>
  
        <wt:widget-label id="contacts"/><br/>
        <wt:repeater-size id="contacts"/>
        <table border="1">
          <tr>
            <th><wt:repeater-widget-label id="contacts" widget-id="firstname"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="lastname"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="phone"/></th>
            <th><wt:repeater-widget-label id="contacts" widget-id="email"/></th>
          </tr>
  
          <!-- The contents of the repeater-widget element is a template that will
          be applied to each row in the repeater. -->
          <wt:repeater-widget id="contacts">
            <tr>
              <td><wt:widget id="firstname"/></td>
              <td><wt:widget id="lastname"/></td>
              <td><wt:widget id="phone"/></td>
              <td><wt:widget id="email"/></td>
            </tr>
          </wt:repeater-widget>
        </table>
  
        <input type="submit"/>
      </form>
    </body>
  </html>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/registration.xml
  
  Index: registration.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <wd:form
    xmlns:wd="http://cocoon.apache.org/woody/definition/1.0"
    xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
  
    <wd:field id="name" required="true">
      <wd:label>Name:</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:length min="2"/>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="email" required="true">
      <wd:label>Email address:</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:email/>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="age">
      <wd:label>Your age:</wd:label>
      <wd:datatype base="long">
        <wd:validation>
          <wd:range min="0" max="150"/>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="password" required="true">
      <wd:label>Password:</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:length min="5" max="20"/>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:field id="confirmPassword" required="true">
      <wd:label>Re-enter password:</wd:label>
      <wd:datatype base="string">
        <wd:validation>
          <wd:assert test="password = confirmPassword">
            <wd:failmessage>The two passwords are not equal.</wd:failmessage>
          </wd:assert>
        </wd:validation>
      </wd:datatype>
    </wd:field>
  
    <wd:booleanfield id="spam">
      <wd:label>Send me spam</wd:label>
    </wd:booleanfield>
  
  </wd:form>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/registration_success.xsp
  
  Index: registration_success.xsp
  ===================================================================
  <?xml version="1.0"?>
  <xsp:page language="java"
    xmlns:xsp="http://apache.org/xsp">
  
    <xsp:structure>
      <xsp:include>org.apache.cocoon.woody.formmodel.*</xsp:include>
    </xsp:structure>
  
    <html>
      <body>
        <xsp:logic>
          // get reference to form and some of the widgets on it
          Form form = (Form)request.getAttribute("registrationform");
          Field name = (Field)form.getWidget("name");
        </xsp:logic>
  
        Registration was successful for <xsp:expr>name.getValue()</xsp:expr>
      </body>
    </html>
  </xsp:page>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/forms/registration_template.xml
  
  Index: registration_template.xml
  ===================================================================
  <?xml version="1.0"?>
  <html xmlns:wt="http://cocoon.apache.org/woody/template/1.0">
    <head>
      <title>Registration form</title>
    </head>
    <body>
      <h1>Registration</h1>
      <form action="registration" method="POST">
        <wt:widget-label id="name"/>
        <wt:widget id="name"/>
        <br/>
        <wt:widget-label id="email"/>
        <wt:widget id="email"/>
        <br/>
        <wt:widget-label id="age"/>
        <wt:widget id="age"/>
        <br/>
        <wt:widget-label id="password"/>
        <wt:widget id="password"/>
        <br/>
        <wt:widget-label id="confirmPassword"/>
        <wt:widget id="confirmPassword"/>
        <br/>
        <wt:widget id="spam"/>
        <wt:widget-label id="spam"/>
        <br/>
  
        <input type="submit"/>
      </form>
    </body>
  </html>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/messages/OtherMessages.xml
  
  Index: OtherMessages.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <catalogue>
  </catalogue>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/messages/WoodyMessages.xml
  
  Index: WoodyMessages.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <!-- This catalogue file contains translations for built-in YAFF messages. -->
  <catalogue>
    <message key="general.field-required">This field is required.</message>
  
    <message key="datatype.conversion-failed">Not a valid {0}.</message>
    <message key="datatype.long">integer number</message>
  
    <message key="validation.string.exact-length">Should be exactly {0} characters.</message>
    <message key="validation.string.range-length">Should contain from {0} to {1} characters.</message>
    <message key="validation.string.min-length">Should be at least {0} characters.</message>
    <message key="validation.string.max-length">Should be at most {0} characters.</message>
  
    <message key="validation.string.invalidemail">This field does not contain a valid email address</message>
  
    <message key="validation.array.exact-valuecount">Exactly {0} item(s) should be selected.</message>
    <message key="validation.array.range-valuecount">At least {0} item(s) and at most {1} items should be selected.</message>
    <message key="validation.array.min-valuecount">At least {0} item(s) should be selected.</message>
    <message key="validation.array.max-valuecount">At most {0} items should be selected.</message>
  
    <message key="multivaluefield.conversionfailed">One of the selected values is of an incorrect type.</message>
  
    <message key="validation.numeric.range">Number should be in the range from {0} to {1}.</message>
    <message key="validation.numeric.min">Number should be greater than or equal to {0}.</message>
    <message key="validation.numeric.max">Number should be less than or equal to {0}.</message>
  
  </catalogue>
  
  
  
  1.1                  cocoon-2.1/src/blocks/woody/samples/xsl/html/woody-default.xsl
  
  Index: woody-default.xsl
  ===================================================================
  <?xml version="1.0"?>
  <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wi="http://cocoon.apache.org/woody/instance/1.0">
  
    <xsl:template match="wi:field">
  
      <xsl:choose>
        <xsl:when test="wi:selection-list">
          <xsl:call-template name="field-with-selection-list">
            <xsl:with-param name="fieldelement" select="."/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="field">
            <xsl:with-param name="fieldelement" select="."/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
  
      <xsl:if test="wi:validation-message">
        <xsl:call-template name="validation-message">
          <xsl:with-param name="message" select="wi:validation-message"/>
        </xsl:call-template>
      </xsl:if>
      <xsl:if test="@required='true'">
        <b>*</b>
      </xsl:if>
    </xsl:template>
  
    <xsl:template name="field">
      <xsl:param name="fieldelement"/>
      <input name="{$fieldelement/@id}" value="{$fieldelement/wi:value}"/>
    </xsl:template>
  
    <xsl:template name="field-with-selection-list">
      <xsl:param name="fieldelement"/>
  
      <xsl:variable name="value" select="$fieldelement/wi:value"/>
      <xsl:variable name="liststyle" select="$fieldelement/wi:styling/list-style/text()"/>
  
      <xsl:choose>
        <xsl:when test="$liststyle='radio'">
          <xsl:for-each select="$fieldelement/wi:selection-list/wi:item">
            <input type="radio" name="{$fieldelement/@id}" value="{@value}">
              <xsl:if test="@value = $value">
                <xsl:attribute name="checked">true</xsl:attribute>
              </xsl:if>
            </input>
            <xsl:copy-of select="wi:label/node()"/><br/>
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <!-- default: dropdown box -->
          <select name="{$fieldelement/@id}">
            <xsl:if test="$liststyle='listbox'">
              <xsl:attribute name="size">
                <xsl:choose>
                  <xsl:when test="$fieldelement/wi:styling/listbox-size">
                    <xsl:value-of select="$fieldelement/wi:styling/listbox-size"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:text>5</xsl:text>
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
            </xsl:if>
            <xsl:for-each select="$fieldelement/wi:selection-list/wi:item">
              <option value="{@value}">
                <xsl:if test="@value = $value">
                  <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:copy-of select="wi:label/node()"/>
              </option>
            </xsl:for-each>
          </select>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>
  
    <xsl:template name="validation-message">
      <xsl:param name="message"/>
      <a href="#" style="color:red; font-weight: bold" onclick="alert('{normalize-space($message)}')">&#160;!&#160;</a>
    </xsl:template>
  
    <xsl:template match="wi:booleanfield">
      <input type="checkbox" value="true" name="{@id}">
        <xsl:if test="wi:value/text() = 'true'">
          <xsl:attribute name="checked">true</xsl:attribute>
        </xsl:if>
      </input>
    </xsl:template>
  
    <xsl:template match="wi:multivaluefield">
      <xsl:if test="wi:validation-message">
        <xsl:call-template name="validation-message">
          <xsl:with-param name="message" select="wi:validation-message"/>
        </xsl:call-template>
      </xsl:if>
      <xsl:variable name="id" select="@id"/>
      <xsl:variable name="values" select="wi:values/wi:value/text()"/>
      <xsl:for-each select="wi:selection-list/wi:item">
        <xsl:variable name="value" select="@value"/>
        <input type="checkbox" value="{@value}" name="{$id}">
          <xsl:if test="$values[.=$value]">
            <xsl:attribute name="checked">true</xsl:attribute>
          </xsl:if>
        </input>
        <xsl:copy-of select="wi:label/node()"/>
        <br/>
      </xsl:for-each>
    </xsl:template>
  
    <xsl:template match="wi:repeater">
      <input type="hidden" name="{@id}.size" value="{@size}"/>
      <table border="1">
        <tr>
          <xsl:for-each select="wi:headings/wi:heading">
            <th><xsl:value-of select="."/></th>
          </xsl:for-each>
        </tr>
        <xsl:apply-templates select="wi:repeater-row"/>
      </table>
    </xsl:template>
  
    <xsl:template match="wi:repeater-row">
      <tr>
        <xsl:for-each select="*">
          <td>
            <xsl:apply-templates select="."/>
          </td>
        </xsl:for-each>
      </tr>
    </xsl:template>
  
    <xsl:template match="wi:repeater-size">
      <input type="hidden" name="{@id}.size" value="{@size}"/>
    </xsl:template>
  
    <xsl:template match="wi:form">
      <table border="1">
        <xsl:for-each select="wi:children/*">
          <tr>
            <xsl:choose>
              <xsl:when test="local-name(.) = 'repeater'">
                <td valign="top" colspan="2">
                  <xsl:apply-templates select="."/>
                </td>
              </xsl:when>
              <xsl:when test="local-name(.) = 'booleanfield'">
                <td>&#160;</td>
                <td valign="top">
                  <xsl:apply-templates select="."/>
                  <xsl:text> </xsl:text>
                  <xsl:copy-of select="wi:label"/>
                </td>
              </xsl:when>
              <xsl:otherwise>
                <td valign="top">
                  <xsl:copy-of select="wi:label"/>
                </td>
                <td valign="top">
                  <xsl:apply-templates select="."/>
                </td>
              </xsl:otherwise>
            </xsl:choose>
          </tr>
        </xsl:for-each>
      </table>
    </xsl:template>
  
    <xsl:template match="@*|node()" priority="-1">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
  
  </xsl:stylesheet>