Return-Path: Delivered-To: apmail-xml-cocoon-cvs-archive@xml.apache.org Received: (qmail 13187 invoked by uid 500); 8 Sep 2002 23:02:58 -0000 Mailing-List: contact cocoon-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: cocoon-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list cocoon-cvs@xml.apache.org Received: (qmail 13174 invoked by uid 500); 8 Sep 2002 23:02:58 -0000 Delivered-To: apmail-xml-cocoon2-cvs@apache.org Date: 8 Sep 2002 23:02:57 -0000 Message-ID: <20020908230257.18494.qmail@icarus.apache.org> From: ivelin@apache.org To: xml-cocoon2-cvs@apache.org Subject: cvs commit: xml-cocoon2/src/java/org/apache/cocoon/transformation XMLFormTransformer.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N ivelin 2002/09/08 16:02:57 Modified: src/java/org/apache/cocoon/transformation XMLFormTransformer.java Log: update for itemset Revision Changes Path 1.11 +157 -42 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XMLFormTransformer.java 7 Aug 2002 10:52:13 -0000 1.10 +++ XMLFormTransformer.java 8 Sep 2002 23:02:57 -0000 1.11 @@ -173,6 +173,8 @@ 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_ITEMSET = "itemset"; + public final static String TAG_ITEM = "item"; public final static String TAG_VALUE = "value"; public final static String TAG_HIDDEN = "hidden"; @@ -375,10 +377,10 @@ // just record the SAX event super.startElement( uri, name, raw, attributes); } - // when a new repeat tag is discovered - // start recording - // the repeat will be unrolled after the repeat tag ends - else if (TAG_REPEAT.equals( name) ) + // when a new repeat tag is discovered + // start recording + // the repeat will be unrolled after the repeat tag ends + else if (TAG_REPEAT.equals( name )) { repeatTagDepth = currentTagDepth; isRecording = true; @@ -396,6 +398,27 @@ // and start recording its content startRecording(); } + // when a new itemset tag (used within select) is discovered + // start recording + // the itemset will be unrolled after the tag ends + // The difference with the repeat tag is that itemset if + // unrolled in multiple item tags. + else if ( TAG_ITEMSET.equals( name ) ) + { + repeatTagDepth = currentTagDepth; + isRecording = true; + + // get the nodeset selector string + nodeset = attributes.getValue(TAG_REPEAT_ATTR_NODESET); + + if (nodeset == null) + { + throw new SAXException( name + " element should provide a '" + TAG_REPEAT_ATTR_NODESET + "' attribute" ); + } + + // start recording its content + startRecording(); + } else // if not a repeat tag { // if this tag has a "ref" attribute, then @@ -434,11 +457,6 @@ { startElementOutput( uri, name, raw, attributes ); } // end if TAG_OUTPUT - else if ( TAG_CAPTION.equals( name ) ) - { - super.startElement( uri, name, raw, attributes); - this.ignoreHooksCount = 0; - } else if (TAG_INSERTVIOLATIONS.equals(name)) { startElementViolations( uri, name, raw, attributes ); @@ -466,15 +484,20 @@ TAG_TEXTAREA.equals(name) || TAG_PASSWORD.equals(name) || TAG_SELECTBOOLEAN.equals(name) || - TAG_SELECTONE.equals(name)) - { - startElementSimpleField( uri, name, raw, attributes, currentForm ); - } - else if (TAG_SELECTMANY.equals(name)) + TAG_SELECTONE.equals(name) || + TAG_SELECTMANY.equals(name) + ) { startElementSimpleField( uri, name, raw, attributes, currentForm ); } else if ( + TAG_CAPTION.equals(name) || + TAG_VALUE.equals(name) + ) + { + startElementWithOptionalRefAndSimpleContent( uri, name, raw, attributes, currentForm ); + } + else if ( TAG_SUBMIT.equals(name) || TAG_CANCEL.equals(name) || TAG_RESET.equals(name) ) @@ -486,8 +509,8 @@ // 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 ); + isHiddenTag = true; + startElementSimpleField( uri, name, raw, attributes, currentForm ); } else { @@ -683,6 +706,39 @@ } // end of startElementSimpleField + protected void startElementWithOptionalRefAndSimpleContent(String uri, String name, String raw, Attributes attributes, Form form) + throws SAXException + { + String ref = attributes.getValue(TAG_COMMON_ATTR_REF); + + if (ref == null) // ref attribute is not provided + { + this.startElement( uri, name, raw, attributes ); + return; + } + + if ( form == null) + { + throw new SAXException( name + " element should be either nested within a form tag or provide a form attribute" ); + } + + getLogger().debug("[" + String.valueOf( name ) + "] getting value from form [id=" + form.getId() + ", ref=" + String.valueOf(ref) + "]"); + + value_ = form.getValue( ref ); + + // we will only forward the SAX event once we know + // that the value of the tag is available + super.startElement(uri, name, raw, attributes); + + getLogger().debug("Value of form [id=" + form.getId() + ", ref=" + String.valueOf(ref) + "] = [" + value_ + "]") ; + + // Now render the character data inside the tag + String v = String.valueOf( value_ ); + super.characters(v.toCharArray(),0,v.length()); + + } // end of startElementSimpleFieldWithOptionalRef + + /** * Renders one or more xf:value elements * depending on whether _value is a @@ -768,7 +824,8 @@ // stop recording, unroll the repeat tag content // for each node in the node set, // then close the repeat tag - if (TAG_REPEAT.equals( name) && (repeatTagDepth == currentTagDepth)) + if ( (TAG_REPEAT.equals( name ) ) + && (repeatTagDepth == currentTagDepth)) { isRecording = false; DocumentFragment docFragment = endRecording(); @@ -777,6 +834,15 @@ // close the repeat tag super.endElement(uri, name, raw); } + // similarly for an itemset tag + else if ( (TAG_ITEMSET.equals( name )) + && (repeatTagDepth == currentTagDepth)) + { + isRecording = false; + DocumentFragment docFragment = endRecording(); + unrollItemSetTag( docFragment ); + nodeset = null; + } // if within a repeat tag, keep recording // when recording, nothing is actively processed else if (isRecording) @@ -810,39 +876,33 @@ currentForm = null; super.endElement(uri, name, raw); } - else if (TAG_OUTPUT.equals(name) || + else if ( + TAG_OUTPUT.equals(name) || TAG_TEXTBOX.equals(name) || TAG_PASSWORD.equals(name) || TAG_SELECTBOOLEAN.equals(name) || - TAG_SELECTONE.equals(name) ) - { - super.endElement(uri, name, raw); - } - else if (TAG_SELECTMANY.equals(name)) - { - super.endElement(uri, name, raw); - } - else if (TAG_SUBMIT.equals(name)) - { - super.endElement(uri, name, raw); - } - else if ( TAG_CAPTION.equals( name ) ) + TAG_SELECTONE.equals(name) || + TAG_SELECTMANY.equals(name) || + TAG_SUBMIT.equals(name) || + TAG_CAPTION.equals( name ) || + TAG_VALUE.equals( name ) + ) { 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(); - } + 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 @@ -919,6 +979,61 @@ ignoreHooksCount = oldIgnoreHooksCount; } } // unrollRepeatTag + + + + + /** + * Unroll the itemset tag. + * For each node in the itemset tag's nodeset selector result, + * render a item tag with a ref + * attribute which points to the location of the current node + * in the nodeset. + * Within each item tag, + * output the content of the itemset tag, + * by resolving all model references within nested caption and value tags, + * relative to the ref attribute of the item element. + * + * @param docFragment the content of the repeat tag + * @param nodeset the nodeset selector string + */ + protected void unrollItemSetTag( DocumentFragment docFragment ) + throws SAXException + { + int oldIgnoreHooksCount = ignoreHooksCount; + try + { + // reset ignore hooks counter + this.ignoreHooksCount = 0; + + Collection locations = currentForm.locate( nodeset ); + Iterator iter = locations.iterator(); + // iterate over each node in the nodeset + while ( iter.hasNext() ) + { + String nextNodeLocation = (String) iter.next (); + + // set the ref attribute to point to the current node + AttributesImpl atts = new AttributesImpl(); + atts.addAttribute( null, TAG_COMMON_ATTR_REF, TAG_COMMON_ATTR_REF, "CDATA", nextNodeLocation); + + super.startElement(NS, TAG_ITEM, NS_PREFIX + ":" + TAG_ITEM, atts); + if (value_ != null) + { + // stream back the recorder repeat content + DOMStreamer streamer = new DOMStreamer( this, this); + streamer.stream( docFragment ); + } + + super.endElement( NS, TAG_ITEM, NS_PREFIX + ":" + TAG_ITEM ); + + } + } + finally + { + ignoreHooksCount = oldIgnoreHooksCount; + } + } // unrollItemSetTag ---------------------------------------------------------------------- In case of troubles, e-mail: webmaster@xml.apache.org To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org For additional commands, e-mail: cocoon-cvs-help@xml.apache.org