ivelin      2002/06/08 10:57:38

  Modified:    src/java/org/apache/cocoon/transformation
                        XMLFormTransformer.java
  Log:
  This patch will check to see if an xf:hidden element already has an
  xf:value child and will add the value from the model if not.
  
  by Andrew Timberlake
  
  Revision  Changes    Path
  1.7       +98 -30    
xml-cocoon2/src/java/org/apache/cocoon/transformation/XMLFormTransformer.java
  
  Index: XMLFormTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/XMLFormTransformer.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- XMLFormTransformer.java   6 Jun 2002 14:43:41 -0000       1.6
  +++ XMLFormTransformer.java   8 Jun 2002 17:57:38 -0000       1.7
  @@ -89,12 +89,12 @@
    * but with populated values for the XPath references
    * to the form's model attributes
    *
  - * The original code was built by Torsten Curdt as
  - * part of the Preceptor API
    *
  - * @author Ivelin Ivanov <[EMAIL PROTECTED]>, May 2002
  - * @author Michael Ratliff, [EMAIL PROTECTED] <[EMAIL PROTECTED]>, May 
2002
  - * @author Torsten Curdt <[EMAIL PROTECTED]>, March 2002
  + * @author: Ivelin Ivanov <[EMAIL PROTECTED]>, June 2002
  + * @author: Andrew Timberlake <[EMAIL PROTECTED]>, June 2002
  + * @author: Michael Ratliff, [EMAIL PROTECTED] <[EMAIL PROTECTED]>, May 
2002
  + * @author: Torsten Curdt <[EMAIL PROTECTED]>, March 2002
  +
    */
   
   public class XMLFormTransformer extends AbstractSAXTransformer
  @@ -174,7 +174,9 @@
     public final static String TAG_SELECTBOOLEAN = "selectBoolean";
     public final static String TAG_SELECTONE = "selectOne";
     public final static String TAG_SELECTMANY = "selectMany";
  -
  +  public final static String TAG_VALUE = "value";
  +  public final static String TAG_HIDDEN = "hidden";
  +   
     /**
      * grouping tag
      *
  @@ -246,6 +248,19 @@
   
   
     /**
  +   * Flag to let us know if the transformer is working
  +   * on a hidden tag
  +   */
  +  private boolean isHiddenTag = false;
  +
  +  /**
  +   * Flag to let us know that the hidden element contains
  +   * a value child element.
  +   */
  +  private boolean hasHiddenTagValue = false;
  +
  +  
  +  /**
      * the ref value of the current field
      * used by the violations tag
      */
  @@ -416,6 +431,18 @@
             super.startElement( uri, name, raw, attributes);
             this.ignoreHooksCount = 0;
           }
  +        // if we're within a xf:hidden element
  +        // and a value sub-element has been provided 
  +        // in the markup, then it will be left
  +        // unchanged. Otherwise we will 
  +        // render the value of the referenced model
  +        // attribute
  +        else if ( isHiddenTag && TAG_VALUE.equals( name ) )
  +        {
  +                     hasHiddenTagValue = true;
  +            super.startElement( uri, name, raw, attributes);
  +        }
  +         
           // if the currentForm is still not available
           // then we can't process nested form tags
           else if (currentForm != null)
  @@ -445,6 +472,14 @@
             {
               super.startElement(uri, name, raw, attributes);
             }
  +          else if (TAG_HIDDEN.equals(name))
  +          {
  +            // raise the flag that we're within a hidden element
  +            // since there are intricacies in 
  +            // handling the value sub-element
  +                       isHiddenTag = true;
  +                       startElementSimpleField( uri, name, raw, attributes, 
currentForm );
  +          }          
             else
             {
                 getLogger().error("unknown element [" + String.valueOf(name) + "]");
  @@ -613,30 +648,48 @@
   
         getLogger().debug("Value of form [id=" + form.getId() + ", ref=" + 
String.valueOf(ref) + "] = [" + value_ + "]") ;
   
  -      // render the value subelement(s)
  -      if (value_ instanceof Collection)
  -      {
  -        Iterator i=((Collection) value_).iterator();
  -        while (i.hasNext())
  -        {
  -          renderValueSubElement( i.next() );
  -        }
  -      }
  -      else if ( value_ != null && value_.getClass().isArray () )
  -      {
  -        int len = Array.getLength ( value_ );
  -        for (int i = 0; i < len; i++ )
  -        {
  -          renderValueSubElement( Array.get ( value_, i ) );
  -        }
  -      }
  -      else
  -      {
  -        renderValueSubElement( value_ );
  -      }
  -  } // end of startElementSimpleField
  -
  -
  +       // Only render value sub-elements
  +      // at this point
  +      // if this is not a xf:hidden element.
  +       if(! isHiddenTag) renderValueSubElements();
  +     } // end of startElementSimpleField
  +
  +
  +     /**
  +      * Renders one or more xf:value elements 
  +     * depending on whether _value is a
  +      * collection, array or not.
  +      *
  +      * @throws SAXException
  +      */
  +     private void renderValueSubElements() throws SAXException
  +     {
  +             // render the value subelement(s)
  +             if (value_ instanceof Collection)
  +             {
  +               Iterator i=((Collection) value_).iterator();
  +               while (i.hasNext())
  +               {
  +                     renderValueSubElement( i.next() );
  +               }
  +             }
  +             else if ( value_ != null && value_.getClass().isArray () )
  +             {
  +               int len = Array.getLength ( value_ );
  +               for (int i = 0; i < len; i++ )
  +               {
  +                     renderValueSubElement( Array.get ( value_, i ) );
  +               }
  +             }
  +             else
  +             {
  +               renderValueSubElement( value_ );
  +             }
  +     }
  +
  + 
  +  
  +  
     /**
      * Outputs a <xf:value> element.
      * Used when transforming XMLForm elements
  @@ -749,6 +802,21 @@
           {
             super.endElement(uri, name, raw);
           }
  +        else if (TAG_HIDDEN.equals(name))
  +        {
  +                     isHiddenTag = false;
  +                     hasHiddenTagValue = false;
  +            // if value sub-element was not 
  +            // provided in the markup
  +            // then render the value of the referenced
  +            // model attribute, like normally done
  +            // for other elements
  +            if(! hasHiddenTagValue)
  +                     {
  +                             renderValueSubElements();
  +                     }
  +            super.endElement(uri, name, raw);
  +         }
           else
           {
             getLogger().error("unknown element [" + String.valueOf(name) + "]");
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to