bruno       2003/07/22 04:52:35

  Added:       src/blocks/woody/java/org/apache/cocoon/woody/binding
                        AggregateJXPathBinding.java
                        AggregateJXPathBindingBuilder.java Binding.java
                        BindingManager.java ComposedJXPathBindingBase.java
                        ContextJXPathBinding.java
                        ContextJXPathBindingBuilder.java
                        DeleteNodeJXPathBinding.java
                        DeleteNodeJXPathBindingBuilder.java
                        FieldJXPathBinding.java
                        FieldJXPathBindingBuilder.java
                        InsertNodeJXPathBinding.java
                        InsertNodeJXPathBindingBuilder.java
                        JXPathBindingBase.java JXPathBindingManager.java
                        JXpathBindingBuilderBase.java
                        RepeaterJXPathBinding.java
                        RepeaterJXPathBindingBuilder.java
                        SetAttributeJXPathBinding.java
                        SetAttributeJXPathBindingBuilder.java
  Log:
  Binding framework patch by Marc Portier (see bugzilla 21671)
  
  Revision  Changes    Path
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/AggregateJXPathBinding.java
  
  Index: AggregateJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.AggregateField;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * AggregateJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that narrows the context towards provided childbindings. 
   * <p>
   * NOTES: <ol>
   * <li>This Binding assumes that the provided widget-id points to a widget 
   * that contains other widgets.</li>
   * </ol>
   */
  public class AggregateJXPathBinding extends ComposedJXPathBindingBase {
  
      private final String xpath;
  
      private final String widgetId;
  
      /**
       * Constructs AggregateJXPathBinding
       * @param widgetId
       * @param xpath
       * @param childBindings
       */
      public AggregateJXPathBinding(
          String widgetId,
          String xpath,
          JXPathBindingBase[] childBindings) {
          super(childBindings);
          this.widgetId = widgetId;
          this.xpath = xpath;
      }
  
      /**
       * Narrows the scope on the form-model to the member widget-field, and
       * narrows the scope on the object-model to the member xpath-context 
       * before continuing the binding over the child-bindings.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
  
          AggregateField aggregate =
              (AggregateField) frmModel.getWidget(this.widgetId);
          JXPathContext subContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
          super.loadFormFromModel(aggregate, subContext);
          getLogger().debug("done loading " + toString());
      }
  
      /**
       * Narrows the scope on the form-model to the member widget-field, and
       * narrows the scope on the object-model to the member xpath-context 
       * before continuing the binding over the child-bindings.
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
  
          AggregateField aggregate =
              (AggregateField) frmModel.getWidget(this.widgetId);
          JXPathContext subContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
          super.saveFormToModel(aggregate, subContext);
          getLogger().debug("done saving " + toString());
      }
  
      public String toString() {
          return "AggregateJXPathBinding [widget="
              + this.widgetId
              + ", xpath="
              + this.xpath
              + "]";
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/AggregateJXPathBindingBuilder.java
  
  Index: AggregateJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * AggregateJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] AggregateJXPathBinding} out of the configuration 
in the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:aggregate id="<i>widget-id</i>" path="<i>xpath-expression</i>"&gt;
   *   &lt;wb:field id="<i>sub-widget-id</i>" path="<i>relative-xpath</i>" />
   * &lt;/wb:aggregate&gt;
   * </code></pre>
   */
  public class AggregateJXPathBindingBuilder
      extends JXpathBindingBuilderBase {
  
      /**
       * @see 
org.outerj.woody.binding.BindingBuilder#buildBinding(org.w3c.dom.Element, 
org.outerj.woody.binding.BuilderAssistant)
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
          try {
              String xpath = DomHelper.getAttribute(bindingElm, "path");
              String widgetId = DomHelper.getAttribute(bindingElm, "id");
  
              JXPathBindingBase[] childBindings =
                  assistant.makeChildBindings(bindingElm);
  
              AggregateJXPathBinding aggregateBinding =
                  new AggregateJXPathBinding(widgetId, xpath, childBindings);
              return aggregateBinding;
          } catch (Exception e) {
              getLogger().warn(
                  "Error building an aggregate field binding.",
                  e);
              return null;
          }
      }
  }
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/Binding.java
  
  Index: Binding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.Widget;
  
  /**
   * Binding declares the methods to 'bind' (i.e. 'load' and 'save') 
   * information elements from some back-end model (2nd argument) to and from 
   * a existing Woody Widget.
   */
  public interface Binding {
      /** 
       * Loads the information-elements from the objModel to the frmModel.
       *  
       * @param frmModel
       * @param objModel
       */
      public void loadFormFromModel(Widget frmModel, Object objModel);
      
      /**
       * Saves the infortmation-elements to the objModel from the frmModel.
       * @param frmModel
       * @param objModel
       */
      public void saveFormToModel(Widget frmModel, Object objModel);
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/BindingManager.java
  
  Index: BindingManager.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.excalibur.source.Source;
  
  /**
   * BindingManager declares the factory method that produces actual Bindings.
   */
  public interface BindingManager {
  
      /**
       * Avalon Role for this service interface.
       */
      public static final String ROLE = BindingManager.class.getName();
  
      /**
       * Constant matching the namespace used for the Binding config files. 
       */
      public static final String NAMESPACE =
          "http://apache.org/cocoon/woody/binding/1.0";;
  
      /**
       * Creates a binding from the XML config found at source parameter.
       */
      public Binding createBinding(Source bindingFile)
          throws ProcessingException;
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/ComposedJXPathBindingBase.java
  
  Index: ComposedJXPathBindingBase.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * ComposedJXPathBindingBase provides a helper base class for subclassing 
   * into specific [EMAIL PROTECTED] JXPathBindingBase} implementations that 
have nested 
   * child-bindings.
   */
  public class ComposedJXPathBindingBase extends JXPathBindingBase {
      private final JXPathBindingBase[] subBindings;
  
      /**
       * Constructs ComposedJXPathBindingBase
       * 
       * @param childBindings sets the array of childBindings
       */
      protected ComposedJXPathBindingBase(JXPathBindingBase[] childBindings) {
          this.subBindings = childBindings;
      }
  
      /** 
       * Receives the logger to use for logging activity, and hands it over to
       * the nested children.
       */
      public void enableLogging(Logger logger) {
          super.enableLogging(logger);
          if (this.subBindings != null) {
              for (int i = 0; i < this.subBindings.length; i++) {
                  this.subBindings[i].enableLogging(logger);
              }
          }
      }
  
      /**
       * Actively performs the binding from the ObjectModel to the Woody-form
       * by passing the task onto it's children.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          if (this.subBindings != null) {
              int size = this.subBindings.length;
              for (int i = 0; i < size; i++) {
                  this.subBindings[i].loadFormFromModel(frmModel, jxpc);
              }
          }
      }
  
      /**
       * Actively performs the binding from the Woody-form to the ObjectModel 
       * by passing the task onto it's children.
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          if (this.subBindings != null) {
              int size = this.subBindings.length;
              for (int i = 0; i < size; i++) {
                  this.subBindings[i].saveFormToModel(frmModel, jxpc);
              }
          }
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/ContextJXPathBinding.java
  
  Index: ContextJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * ContextJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that narrows the binding scope to some xpath-context on the target 
   * objectModel to load and save from. 
   */
  public class ContextJXPathBinding extends ComposedJXPathBindingBase {
  
      /** 
       * the relative contextPath for the sub-bindings of this context */
      private final String xpath;
  
      /**
       * Constructs ContextJXPathBinding for the specified xpath sub-context
       * 
       * @param contextPath
       * @param childBindings
       */
      public ContextJXPathBinding(
          String contextPath,
          JXPathBindingBase[] childBindings) {
          super(childBindings);
          this.xpath = contextPath;
      }
  
      /**
       * Actively performs the binding from the ObjectModel wrapped in a jxpath 
       * context to the Woody-form.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          JXPathContext subContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
          super.loadFormFromModel(frmModel, subContext);
          getLogger().debug("done loading " + toString());
      }
  
      /**
       * Actively performs the binding from the Woody-form to the ObjectModel 
       * wrapped in a jxpath context.
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          JXPathContext subContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
          super.saveFormToModel(frmModel, subContext);
          getLogger().debug("done saving " + toString());
      }
  
      public String toString() {
          return "ContextJXPathBinding [xpath=" + this.xpath + "]";
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/ContextJXPathBindingBuilder.java
  
  Index: ContextJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * ContextJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] ContextJXPathBinding} out of the configuration in 
the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:context path="<i>xpath expression</i>"&gt;
   *   &lt;!-- in here come the nested child bindings on the sub-context --&gt;
   * &lt;/wb:context&gt;
   * </code></pre>
   */
  public class ContextJXPathBindingBuilder extends JXpathBindingBuilderBase {
  
      /**
       * Creates an instance of ContextJXPathBinding with the configured 
       * path and nested child bindings from the declarations in the bindingElm
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
  
          try {
              String xpath = DomHelper.getAttribute(bindingElm, "path");
  
              JXPathBindingBase[] childBindings =
                  assistant.makeChildBindings(bindingElm);
  
              ContextJXPathBinding contextBinding =
                  new ContextJXPathBinding(xpath, childBindings);
              return contextBinding;
          } catch (Exception e) {
              getLogger().warn("Error building a field binding.", e);
              return null;
          }
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/DeleteNodeJXPathBinding.java
  
  Index: DeleteNodeJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * DeleteNodeJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that deletes the current context-bean from the target
   * back-end model upon save. 
   * <p>
   * NOTES: <ol>
   * <li>This Binding does not perform any actions when loading.</li>
   * </ol>
   */
  public class DeleteNodeJXPathBinding extends JXPathBindingBase {
  
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          // doesn't do a thing when loading.
      }
  
  
      /** 
       * Removes the current context-bean from the jxpath context.
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          // get rid of the contextbean
          jxpc.removePath(".");
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/DeleteNodeJXPathBindingBuilder.java
  
  Index: DeleteNodeJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.binding.JXPathBindingManager.Assistant;
  import org.w3c.dom.Element;
  
  /**
   * DeleteNodeJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] DeleteNodeJXPathBinding} out of the configuration 
in the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:delete-node /&gt;
   * </code></pre>
   * 
   */
  public class DeleteNodeJXPathBindingBuilder
      extends JXpathBindingBuilderBase {
  
      /**
       * Creates an instance of [EMAIL PROTECTED] DeleteNodeJXPathBinding}.
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          Assistant assistant) {
  
          return new DeleteNodeJXPathBinding();
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/FieldJXPathBinding.java
  
  Index: FieldJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.cocoon.woody.formmodel.Field;
  import org.apache.commons.jxpath.JXPathContext;
  
  ///**
  // * Represents a Binding class for the Woody block that maps onto
  // * a &lt;bnd:field&gt; element of the binding config.
  // * The purpose of a this is to map a specific widget's value to a jxpath
  // * accessible property of the objectModel. 
  // */
  
  /**
   * FieldJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that loads and saves the information behind a specific xpath expresion 
   * (pointing to an attribute or text-node) to and from a specific Woody
   * widget as identified by its id. 
   */
  public class FieldJXPathBinding extends JXPathBindingBase {
  
      /** 
       * The xpath expression to the objectModel property     */
      private final String xpath;
  
      /** 
       * The id of the Woody form-widget     */
      private final String fieldId;
  
      /** 
       * Flag indicating if the objectModel-property can be altered or not */
      private final boolean readonly;
  
      /** 
       * Flag indicating if the objectModel-property can be altered or not */
      private final JXPathBindingBase updateBinding;
  
      /**
       * Constructs FieldJXPathBinding
       */
      public FieldJXPathBinding(
          String widgetId,
          String xpath,
          boolean readonly,
          JXPathBindingBase[] updateBindings) {
          this.fieldId = widgetId;
          this.xpath = xpath;
          this.readonly = readonly;
          this.updateBinding = new ComposedJXPathBindingBase(updateBindings);
      }
  
      /**
       * Actively performs the binding from the ObjectModel wrapped in a jxpath 
       * context to the Woody-form-widget specified in this object.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          try {
              Field fld = (Field) frmModel.getWidget(this.fieldId);
              // TODO here we need to use the dataconversion in the future
              String value = (String) jxpc.getValue(this.xpath);
              fld.setValue(value);
              getLogger().debug(
                  "done loading " + toString() + " -- value= " + value);
          } catch (Exception e) {
              getLogger().warn(
                  "JXPath failed to find value for " + this.xpath,
                  e);
          }
      }
  
      /**
       * Actively performs the binding from the Woody-form to the ObjectModel 
       * wrapped in a jxpath context
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          if (!this.readonly) {
              try {
                  Field fld = (Field) frmModel.getWidget(this.fieldId);
                  // TODO here we need some dataconversion in the future
                  String value = (String) fld.getValue();
                  String oldValue = (String) jxpc.getValue(this.xpath);
                  getLogger().debug(
                      "value= " + value + "-- oldvalue=" + oldValue);
                  boolean update = false;
  
                  if (value != oldValue
                      && value != null
                      && !value.equals(oldValue)) {
                      jxpc.setValue(this.xpath, value);
                      JXPathContext subContext =
                          jxpc.getRelativeContext(
                              jxpc.getPointer(this.xpath));
                      this.updateBinding.saveFormToModel(
                          frmModel,
                          subContext);
                      update = true;
                  }
                  getLogger().debug(
                      "done saving "
                          + toString()
                          + " -- value= "
                          + value
                          + " -- on-update == "
                          + update);
              } catch (Exception e) {
                  getLogger().warn(
                      "JXPath failed to find value for " + this.xpath,
                      e);
              }
          }
      }
  
      public String toString() {
          return "FieldJXPathBinding [widget="
              + this.fieldId
              + ", xpath="
              + this.xpath
              + "]";
      }
  
      public void enableLogging(Logger logger) {
          super.enableLogging(logger);
          this.updateBinding.enableLogging(logger);
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/FieldJXPathBindingBuilder.java
  
  Index: FieldJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * FieldJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] FieldJXPathBinding} out of the configuration in 
the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:field id="<i>widget-id</i>" path="<i>xpath-expression</i>"&gt;
   *   &lt;!-- optional child binding to be executed upon 'save' of changed 
value --&gt;
   *   &lt;wb:on-update&gt;
   *     &lt;!-- any childbinding --&gt;
   *   &lt;/wb:on-update&gt;
   * &lt;/wb:field&gt;
   * </code></pre>
   */
  public class FieldJXPathBindingBuilder extends JXpathBindingBuilderBase {
  
  
      /**
       * Creates an instance of [EMAIL PROTECTED] FieldJXPathBinding} based on 
the attributes
       * and nested configuration of the provided bindingElm.
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
  
          try {
              boolean readonly =
                  DomHelper.getAttributeAsBoolean(
                      bindingElm,
                      "readonly",
                      false);
              String xpath = DomHelper.getAttribute(bindingElm, "path");
              String widgetId = DomHelper.getAttribute(bindingElm, "id");
  
              Element updateWrapElement =
                  DomHelper.getChildElement(
                      bindingElm,
                      BindingManager.NAMESPACE,
                      "on-update");
              JXPathBindingBase[] updateBindings =
                  assistant.makeChildBindings(updateWrapElement);
  
              FieldJXPathBinding fieldBinding =
                  new FieldJXPathBinding(
                      widgetId,
                      xpath,
                      readonly,
                      updateBindings);
  
              return fieldBinding;
          } catch (Exception e) {
              getLogger().warn("Error building a field binding.", e);
              return null;
          }
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/InsertNodeJXPathBinding.java
  
  Index: InsertNodeJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.AbstractFactory;
  import org.apache.commons.jxpath.JXPathContext;
  import org.apache.commons.jxpath.Pointer;
  import org.w3c.dom.Document;
  import org.w3c.dom.DocumentFragment;
  import org.w3c.dom.Node;
  
  /**
   * InsertNodeJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that inserts a clone of some 'template document-fragment' into the target
   * back-end model upon save. 
   * <p>
   * NOTES: <ol>
   * <li>This Binding does not perform any actions when loading.</li>
   * <li>This expects the back-end model to be an XML file.</li>
   * </ol>
   */
  public class InsertNodeJXPathBinding extends JXPathBindingBase {
  
      private final DocumentFragment template;
      
      /**
       * Constructs InsertNodeJXPathBinding
       * @param domTemplate
       */
      public InsertNodeJXPathBinding(DocumentFragment domTemplate) {       
          this.template = domTemplate;
      }
  
      /**
       * Do-nothing implementation of the interface.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          // doesn't do a thing when loading.
      }
  
      /**
       * Registers a JXPath Factory on the JXPath Context.
       * <p>
       * The factory will inserts a clone of the 'template' DocumentFragment 
       * inside this object into the target objectmodel.
       */
      public void saveFormToModel(
          Widget frmModel,
          JXPathContext jxpc) {
  
          jxpc.setFactory(new AbstractFactory() {
              public boolean createObject(JXPathContext context, Pointer 
pointer,
                  Object parent, String name, int index) {
  
                  Node parentNode = (Node) parent;
                  Document targetDoc = parentNode.getOwnerDocument();
                  Node toInsert = 
targetDoc.importNode(InsertNodeJXPathBinding.this.template, true);
                  parentNode.appendChild(toInsert);
                  
                  InsertNodeJXPathBinding.this.getLogger().debug("InsertNode 
jxpath factory executed for index." + index);
                  return true;
              }
          });
          
          getLogger().debug("done registered factory for inserting node -- " + 
toString());
      }
      
      public String toString() {
          return "InsertNodeJXPathBinding [for nested template]";
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/InsertNodeJXPathBindingBuilder.java
  
  Index: InsertNodeJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.w3c.dom.DocumentFragment;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  
  /**
   * InsertNodeJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] InsertNodeJXPathBinding} out of the configuration 
in the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:insert-node&gt;
   *   &lt;!-- in here comes a template that will be inserted in the target 
   *           document --&gt;
   * &lt;/wb:insert-node&gt;
   * </code></pre>
   */
  public class InsertNodeJXPathBindingBuilder
      extends JXpathBindingBuilderBase {
  
      /**
       * Creates an instance of [EMAIL PROTECTED] InsertNodeJXPathBinding} 
configured 
       * with the nested template of the bindingElm. 
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
              
          try {
              // TODO have src attribute to point to extermal template in stead 
of 
              // inline definition through nested elements.
              // This will require to ask Assistant for parser 
              // (from component-manager)!
              DocumentFragment domTemplate =
                  bindingElm.getOwnerDocument().createDocumentFragment();
              NodeList nested = bindingElm.getChildNodes();
              int size = nested.getLength();
              for (int i = 0; i < size; i++) {
                  domTemplate.appendChild(nested.item(i).cloneNode(true));
              }
  
              return new InsertNodeJXPathBinding(domTemplate);
          } catch (Exception e) {
              getLogger().warn("Error building a insert-node binding.", e);
              return null;
          }
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JXPathBindingBase.java
  
  Index: JXPathBindingBase.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * Provides a base class for hooking up Binding implementations that use the 
   * Jakarta Commons <a 
href="http://jakarta.apache.org/commons/jxpath/index.html";>
   * JXPath package</a>.
   */
  public abstract class JXPathBindingBase implements Binding, LogEnabled {
  
      /** 
       * Avalon Logger to use in all subclasses.     */
      private Logger logger;
  
      /**
       * Redefines the Binding action as working on a JXPathContext Type rather 
       * then on generic objects.
       * Abstract method that subclasses need to implement for specific 
activity.
       */
      public abstract void loadFormFromModel(
          Widget frmModel,
          JXPathContext jxpc);
  
      /**
       * Hooks up with the more generic Binding of any objectModel by wrapping
       * it up in a JXPathContext object and then transfering control over to
       * the new overloaded version of this method.
       */
      public final void loadFormFromModel(Widget frmModel, Object objModel) {
          JXPathContext jxpc;
          if (!(objModel instanceof JXPathContext)) {
              jxpc = JXPathContext.newContext(objModel);
          } else {
              jxpc = (JXPathContext) objModel;
          }
          loadFormFromModel(frmModel, jxpc);
      }
  
      /**
       * Redefines the Binding action as working on a JXPathContext Type rather 
       * then on generic objects.
       * Abstract method that subclasses need to implement for specific 
activity.
       */
      public abstract void saveFormToModel(
          Widget frmModel,
          JXPathContext jxpc);
  
      /**
       * Hooks up with the more generic Binding of any objectModel by wrapping
       * it up in a JXPathContext object and then transfering control over to
       * the new overloaded version of this method.
       */
      public void saveFormToModel(Widget frmModel, Object objModel) {
          JXPathContext jxpc;
          if (!(objModel instanceof JXPathContext)) {
              jxpc = JXPathContext.newContext(objModel);
          } else {
              jxpc = (JXPathContext) objModel;
          }
          saveFormToModel(frmModel, jxpc);
      }
  
      /**
       * Receives the Avalon logger to use.
       * Subclasses should always start with <code>super.enableLogging(logger)
       * </code> in possible overriding versions.
       */
      public void enableLogging(Logger logger) {
          this.logger = logger;
      }
  
      protected Logger getLogger() {
          return logger;
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JXPathBindingManager.java
  
  Index: JXPathBindingManager.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.woody.util.DomHelper;
  import org.apache.excalibur.source.Source;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.xml.sax.InputSource;
  
  /**
   * JXPathBindingManager provides an implementation of [EMAIL PROTECTED] 
BindingManager}
   * by usage of the <a 
href="http://jakarta.apache.org/commons/jxpath/index.html";>
   * JXPath package</a>. 
   */
  public class JXPathBindingManager implements BindingManager, LogEnabled {
  
      //TODO caching of the Bindings. 
  
      /**
       * Avalon logger to use.     */
      private Logger logger;
  
      /**
       * Map of specific builders for the different elements in the 
       * Binding config.
       */
      private final Map bindingBuilders = new HashMap();
      {
          //TODO make this configurable
  
          this.bindingBuilders.put("field", new FieldJXPathBindingBuilder());
          this.bindingBuilders.put(
              "context",
              new ContextJXPathBindingBuilder());
          this.bindingBuilders.put(
              "repeater",
              new RepeaterJXPathBindingBuilder());
          this.bindingBuilders.put(
              "aggregate",
              new AggregateJXPathBindingBuilder());
          this.bindingBuilders.put(
              "set-attribute",
              new SetAttributeJXPathBindingBuilder());
          this.bindingBuilders.put(
              "insert-node",
              new InsertNodeJXPathBindingBuilder());
          this.bindingBuilders.put(
              "delete-node",
              new DeleteNodeJXPathBindingBuilder());
      }
  
      public Binding createBinding(Source bindSrc)
          throws ProcessingException {
          try {
              Document doc =
                  DomHelper.parse(new InputSource(bindSrc.getURI()));
              Element rootElm = doc.getDocumentElement();
              JXPathBindingBase newBinding = null;
              if (BindingManager
                  .NAMESPACE
                  .equals(rootElm.getNamespaceURI())) {
                  newBinding =
                      getBuilderAssistant()
                          .getBindingForConfigurationElement(
                          rootElm);
  
                  newBinding.enableLogging(getLogger());
                  getLogger().debug(
                      "Creation of new Binding finished. " + newBinding);
              } else {
                  getLogger().debug(
                      "Root Element of said binding file is in wrong 
namespace.");
              }
              return newBinding;
          } catch (Exception e) {
              throw new ProcessingException("Could not create binding.", e);
          }
      }
  
      public void enableLogging(Logger l) {
          this.logger = l;
          l.debug("Got logger, passing to the bindingBuilders");
          Iterator iter = this.bindingBuilders.values().iterator();
          while (iter.hasNext()) {
              Object builder = iter.next();
              if (builder instanceof LogEnabled) {
                  ((LogEnabled) builder).enableLogging(l);
              }
          }
      }
  
      protected Logger getLogger() {
          return logger;
      }
  
      private Assistant getBuilderAssistant() {
          return new Assistant();
      }
  
      /** 
       * Assistant Inner class discloses enough features to the created 
       * childBindings to recursively 
       * 
       * This patterns was chosen to prevent Inversion Of Control between
       * this factory and its builder classes (that could be provided by third
       * parties)  
       */
      public class Assistant {
  
          private JXpathBindingBuilderBase getBindingBuilder(String 
bindingType) {
              return (JXpathBindingBuilderBase) JXPathBindingManager
                  .this
                  .bindingBuilders
                  .get(bindingType);
          }
  
          /**
           * Creates a [EMAIL PROTECTED] Binding} folowing the specification in 
the 
           * provided config element.
           * 
           * @param configElm
           * @return
           */
          public JXPathBindingBase getBindingForConfigurationElement(Element 
configElm) {
              String bindingType = configElm.getLocalName();
              JXPathBindingManager.this.getLogger().debug(
                  "build binding for config elm " + bindingType);
              JXpathBindingBuilderBase bindingBuilder =
                  getBindingBuilder(bindingType);
              JXPathBindingBase childBinding =
                  (JXPathBindingBase) bindingBuilder.buildBinding(
                      configElm,
                      this);
              return childBinding;
          }
  
          /**
           * Makes an array of childBindings for the child-elements of the 
           * provided cinfiguration element.
           * 
           * @param parentElement
           * @return
           */
          public JXPathBindingBase[] makeChildBindings(Element parentElement) {
              if (parentElement == null) {
                  return null;
              }
  
              Element[] childElements =
                  DomHelper.getChildElements(
                      parentElement,
                      BindingManager.NAMESPACE);
              if (childElements != null) {
                  JXPathBindingBase[] childBindings =
                      new JXPathBindingBase[childElements.length];
                  for (int i = 0; i < childElements.length; i++) {
                      childBindings[i] =
                          getBindingForConfigurationElement(childElements[i]);
                  }
                  return childBindings;
              } else {
                  return null;
              }
          }
  
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/JXpathBindingBuilderBase.java
  
  Index: JXpathBindingBuilderBase.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.w3c.dom.Element;
  
  /**
   * Abstract base class enabling the logging.
   */
  public abstract class JXpathBindingBuilderBase implements LogEnabled {
  
      private Logger logger;
  
      /**
       * Receives the Avalon logger to use.
       */
      public void enableLogging(Logger logger) {
          this.logger = logger;
          logger.debug("JXpathBindingBuilderBase got logger...");
      }
  
      /**
       * Makes the logger available to the subclasses.
       * @return
       */
      protected Logger getLogger() {
          return this.logger;
      }
  
      /**
       * Builds a configured binding object based on the configuration as 
       * described in the bindingElement.  The BuilderMap can be used to 
       * find appropriate builders for possible subBinders.  
       * 
       * @param bindingElm
       * @param assistant
       * @return
       */
      public abstract JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant);
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBinding.java
  
  Index: RepeaterJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import java.util.ArrayList;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Set;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.cocoon.woody.formmodel.Repeater;
  import org.apache.commons.jxpath.JXPathContext;
  import org.apache.commons.jxpath.Pointer;
  
  /**
   * RepeaterJXPathBinding provides an implementation of a [EMAIL PROTECTED] 
Binding} 
   * that allows for bidirectional binding of a repeater-widget to/from
   * repeating structures in the back-end object model. 
   */
  public class RepeaterJXPathBinding extends JXPathBindingBase {
  
      private final String repeaterId;
      private final String repeaterPath;
      private final String rowPath;
      private final String uniqueRowId;
      private final String uniqueRowPath;
      private final FieldJXPathBinding uniqueFieldBinding;
      private final JXPathBindingBase rowBinding;
      private final JXPathBindingBase insertRowBinding;
      private final JXPathBindingBase deleteRowBinding;
  
      /**
       * Constructs RepeaterJXPathBinding
       */
      public RepeaterJXPathBinding(
          String repeaterId,
          String repeaterPath,
          String rowPath,
          String uniqueRowId,
          String uniqueRowPath,
          JXPathBindingBase[] childBindings,
          JXPathBindingBase insertBinding,
          JXPathBindingBase[] deleteBindings) {
          this.repeaterId = repeaterId;
          this.repeaterPath = repeaterPath;
          this.rowPath = rowPath;
          this.uniqueRowId = uniqueRowId;
          this.uniqueRowPath = uniqueRowPath;
          this.uniqueFieldBinding =
              new FieldJXPathBinding(uniqueRowId, uniqueRowPath, true, null);
          this.rowBinding = new ComposedJXPathBindingBase(childBindings);
          this.insertRowBinding = insertBinding;
          this.deleteRowBinding =
              new ComposedJXPathBindingBase(deleteBindings);
      }
  
  
      /**
       * Binds the unique-id of the repeated rows, and narrows the context on 
       * objectModelContext and Repeater to the repeated rows before handing 
       * over to the actual binding-children.
       *   
       * @param frmModel
       * @param jxpc
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          // Find the repeater
          Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
  
          // build a jxpath iterator for pointers
          JXPathContext repeaterContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
          Iterator rowPointers =
              repeaterContext.iteratePointers(this.rowPath);
  
          //iterate through it
          while (rowPointers.hasNext()) {
              // create a new row, take that as the frmModelSubContext
              Repeater.RepeaterRow thisRow = repeater.addRow();
  
              // make a jxpath ObjectModelSubcontext on the iterated element
              Pointer jxp = (Pointer) rowPointers.next();
              JXPathContext rowContext =
                  repeaterContext.getRelativeContext(jxp);
  
              // hand it over to children
              this.uniqueFieldBinding.loadFormFromModel(thisRow, rowContext);
              this.rowBinding.loadFormFromModel(thisRow, rowContext);
          }
          getLogger().debug("done loading rows " + toString());
      }
  
  
      /**
       * Uses the mapped unique-id of each row to detect if rows have been 
       * updated, inserted or removed.  Depending on what happened the 
appropriate
       * child-bindings are alowed to visit the narrowed contexts.
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          // Find the repeater
          Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
  
          // and his context
          JXPathContext repeaterContext =
              jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
  
          // create set of updatedRowIds
          Set updatedRowIds = new HashSet();
          //create list of rows to insert at end 
          List rowsToInsert = new ArrayList();
  
          // iterate rows...        
          int formRowCount = repeater.getSize();
          for (int i = 0; i < formRowCount; i++) {
              Repeater.RepeaterRow thisRow = repeater.getRow(i);
  
              //TODO future might need data-conversion here
              Widget rowIdWidget = thisRow.getWidget(this.uniqueRowId);
              String rowIdValue = (String) rowIdWidget.getValue();
  
              if (rowIdValue != null) {
                  //if rowIdValue != null --> iterate nodes to find match 
                  Iterator rowPointers =
                      repeaterContext.iteratePointers(this.rowPath);
                  while (rowPointers.hasNext()) {
                      Pointer jxp = (Pointer) rowPointers.next();
                      JXPathContext rowContext =
                          repeaterContext.getRelativeContext(jxp);
  
                      //TODO future might need data-conversion here
                      String matchId =
                          (String) rowContext.getValue(this.uniqueRowPath);
                      if (rowIdValue.equals(matchId)) {
                          // match! --> bind to children
                          this.rowBinding.saveFormToModel(
                              thisRow,
                              rowContext);
                          //        --> store rowIdValue in list of 
updatedRowIds
                          updatedRowIds.add(rowIdValue);
                          break;
                      }
                  }
              } else {
                  //if rowId == null --> remember to insert this one later
                  rowsToInsert.add(thisRow);
              }
          }
  
          //again iterate nodes for deletion  
          Iterator rowPointers =
              repeaterContext.iteratePointers(this.rowPath);
          while (rowPointers.hasNext()) {
              Pointer jxp = (Pointer) rowPointers.next();
              JXPathContext rowContext =
                  repeaterContext.getRelativeContext(jxp);
              //TODO future might need data-conversion here
              String matchId =
                  (String) rowContext.getValue(this.uniqueRowPath);
  
              // check if matchPath was in list of updates, if not --> bind for 
delete
              if (!updatedRowIds.contains(matchId)) {
                  this.deleteRowBinding.saveFormToModel(frmModel, rowContext);
              }
          }
  
          // count how many we have now
          int indexCount = 1;
          rowPointers = repeaterContext.iteratePointers(this.rowPath);
          while (rowPointers.hasNext()) {
              rowPointers.next();
              indexCount++;
          }
  
          // end with rows to insert (to make sure they don't get deleted!)
          Iterator rowIterator = rowsToInsert.iterator();
          //register the factory!
          this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
          while (rowIterator.hasNext()) {
              Repeater.RepeaterRow thisRow =
                  (Repeater.RepeaterRow) rowIterator.next();
              // -->  create the path to let the context be created
              Pointer newRowContextPointer =
                  repeaterContext.createPath(
                      this.rowPath + "[" + indexCount + "]");
              JXPathContext newRowContext =
                  repeaterContext.getRelativeContext(newRowContextPointer);
              getLogger().debug(
                  "inserted row at " + newRowContextPointer.asPath());
              //    + rebind to children for update
              this.rowBinding.saveFormToModel(thisRow, newRowContext);
              getLogger().debug("bound new row");
              indexCount++;
          }
  
          getLogger().debug("done saving rows " + toString());
      }
  
      public String toString() {
          return "RepeaterJXPathBinding [widget="
              + this.repeaterId
              + ", xpath="
              + this.repeaterPath
              + "]";
      }
  
      public void enableLogging(Logger logger) {
          super.enableLogging(logger);
          this.uniqueFieldBinding.enableLogging(logger);
          this.deleteRowBinding.enableLogging(logger);
          this.insertRowBinding.enableLogging(logger);
          this.rowBinding.enableLogging(logger);
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBindingBuilder.java
  
  Index: RepeaterJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * RepeaterJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] RepeaterJXPathBinding} out of the configuration 
in the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:repeater 
   *   id="contacts"
   *   parent-path="contacts"
   *   row-path="contact"
   *   unique-row-id="id"
   *   unique-path="@id"   &gt;
   * 
   *   &lt;wb:on-bind&gt;
   *      &lt;!-- nested bindings executed on updates AND right after the 
insert --&gt;
   *   &lt;/wb:on-bind&gt;
   * 
   *   &lt;wb:on-delete-row&gt;
   *      &lt;!-- nested bindings executed on deletion of row --&gt;
   *   &lt;/wb:on-delete-row&gt;
   * 
   *   &lt;wb:on-insert-row&gt;
   *      &lt;!-- nested bindings executed to prepare the insertion of a row 
--&gt;
   *   &lt;/wb:on-insert-row&gt;
   * 
   * &lt;/wb:repeater&gt;
   * </code></pre>
   */
  public class RepeaterJXPathBindingBuilder
      extends JXpathBindingBuilderBase {
  
      /**
       * Creates an instance of [EMAIL PROTECTED] RepeaterJXPathBinding} 
according to the 
       * attributes and nested comfiguration elements of the bindingElm.
       * 
       * @param bindingElm
       * @param assistant
       * @return
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
  
          try {
              String repeaterId = DomHelper.getAttribute(bindingElm, "id");
              String parentPath =
                  DomHelper.getAttribute(bindingElm, "parent-path");
              String rowPath = DomHelper.getAttribute(bindingElm, "row-path");
              String uniqueRowId =
                  DomHelper.getAttribute(bindingElm, "unique-row-id");
              String uniquePath =
                  DomHelper.getAttribute(bindingElm, "unique-path");
  
              Element childWrapElement =
                  DomHelper.getChildElement(
                      bindingElm,
                      BindingManager.NAMESPACE,
                      "on-bind");
              JXPathBindingBase[] childBindings =
                  assistant.makeChildBindings(childWrapElement);
  
              Element deleteWrapElement =
                  DomHelper.getChildElement(
                      bindingElm,
                      BindingManager.NAMESPACE,
                      "on-delete-row");
              JXPathBindingBase[] deleteBindings =
                  assistant.makeChildBindings(deleteWrapElement);
  
              Element insertWrapElement =
                  DomHelper.getChildElement(
                      bindingElm,
                      BindingManager.NAMESPACE,
                      "on-insert-row");
              JXPathBindingBase insertBinding =
                  assistant.makeChildBindings(insertWrapElement)[0];
  
              RepeaterJXPathBinding repeaterBinding =
                  new RepeaterJXPathBinding(
                      repeaterId,
                      parentPath,
                      rowPath,
                      uniqueRowId,
                      uniquePath,
                      childBindings,
                      insertBinding,
                      deleteBindings);
  
              return repeaterBinding;
          } catch (Exception e) {
              getLogger().warn("Error building a repeater field binding.", e);
              return null;
          }
      }
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SetAttributeJXPathBinding.java
  
  Index: SetAttributeJXPathBinding.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.formmodel.Widget;
  import org.apache.commons.jxpath.JXPathContext;
  
  /**
   * SetAttributeJXPathBinding provides an implementation of a [EMAIL 
PROTECTED] Binding} 
   * that sets a particular attribute to a fixed value upon save. 
   * <p>
   * NOTES: <ol>
   * <li>This Binding does not perform any actions when loading.</li>
   * </ol>
   */
  public class SetAttributeJXPathBinding extends JXPathBindingBase {
  
      private final String name;
      private final String value;
  
      /**
       * Constructs SetAttributeJXPathBinding
       * 
       * @param attName
       * @param attValue
       */
      public SetAttributeJXPathBinding(String attName, String attValue) {
          this.name = attName;
          this.value = attValue;
      }
  
      /**
       * Do-Nothing implementation.
       */
      public void loadFormFromModel(Widget frmModel, JXPathContext jxpc) {
          //this does nothing in the loading of things
      }
  
      /**
       * Sets the attribute value on the passed JXPathContext
       * 
       * @param frmModel
       * @param jxpc
       */
      public void saveFormToModel(Widget frmModel, JXPathContext jxpc) {
          jxpc.setValue("@" + this.name, this.value);
          getLogger().debug("done saving " + toString());
      }
  
      /**
       * @see java.lang.Object#toString()
       */
      public String toString() {
          return "SetAttributeJXPathBinding [attName="
              + this.name
              + ", attValue="
              + this.value
              + "]";
      }
  
  }
  
  
  
  1.1                  
cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/SetAttributeJXPathBindingBuilder.java
  
  Index: SetAttributeJXPathBindingBuilder.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
      [EMAIL PROTECTED]
  
   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  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.woody.binding;
  
  import org.apache.cocoon.woody.util.DomHelper;
  import org.w3c.dom.Element;
  
  /**
   * SetAttributeJXPathBindingBuilder provides a helper class for the Factory 
   * implemented in [EMAIL PROTECTED] JXPathBindingManager} that helps 
construct the 
   * actual [EMAIL PROTECTED] SetAttributeJXPathBinding} out of the 
configuration in the 
   * provided configElement which looks like:
   * <pre><code>
   * &lt;wb:set-attribute name="<i>attribute-name to set to</i>" 
   *                      value="<i>attribute-value</i>"/&gt;
   * </code></pre>
   */
  public class SetAttributeJXPathBindingBuilder
      extends JXpathBindingBuilderBase {
  
   
      /**
       * Creates an instance of [EMAIL PROTECTED] SetAttributeJXPathBinding} 
according to 
       * the attributes of the provided bindingElm. 
       * 
       * @param bindingElm
       * @param assistant
       * @return
       */
      public JXPathBindingBase buildBinding(
          Element bindingElm,
          JXPathBindingManager.Assistant assistant) {
  
          try {
              String attName = DomHelper.getAttribute(bindingElm, "name");
              String attValue = DomHelper.getAttribute(bindingElm, "value");
  
              SetAttributeJXPathBinding attBinding =
                  new SetAttributeJXPathBinding(attName, attValue);
  
              return attBinding;
          } catch (Exception e) {
              getLogger().warn("Error building a field binding.", e);
              return null;
          }
      }
  
  }
  
  
  

Reply via email to