You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by di...@apache.org on 2003/01/16 00:56:47 UTC

cvs commit: jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml CommentTag.java ParamTag.java XMLTagLibrary.java ParseTagSupport.java CopyTag.java package.html CopyOfTag.java SetTag.java SortTag.java ParseTag.java AttributeTag.java IfTag.java TransformTag.java ElementTag.java DoctypeTag.java ForEachTag.java ExprTag.java

dion        2003/01/15 15:56:47

  Added:       jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml
                        CommentTag.java ParamTag.java XMLTagLibrary.java
                        ParseTagSupport.java CopyTag.java package.html
                        CopyOfTag.java SetTag.java SortTag.java
                        ParseTag.java AttributeTag.java IfTag.java
                        TransformTag.java ElementTag.java DoctypeTag.java
                        ForEachTag.java ExprTag.java
  Log:
  Move xml taglib out of core
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CommentTag.java
  
  Index: CommentTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CommentTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CommentTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  
  /** 
   * A tag which outputs a comment to the underlying XMLOutput based on the
   * contents of its body.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class CommentTag extends XPathTagSupport {
  
      private String text;
      
      public CommentTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          String text = getText();
          if (text == null) {
              text = getBodyText(false);
          }
          char[] ch = text.toCharArray();
          output.comment(ch, 0, ch.length);
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      /**
       * Returns the text.
       * @return String
       */
      public String getText() {
          return text;
      }
  
      /**
       * Sets the comment text. If no text is specified then the body of the tag
       * is used instead.
       * 
       * @param text The comment text to use
       */
      public void setText(String text) {
          this.text = text;
      }
  
  }
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParamTag.java
  
  Index: ParamTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParamTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: ParamTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** Sets a parameter in the parent transform tag
    *
    * @author Robert Leftwich
    * @version $Revision: 1.1 $
    */
  public class ParamTag extends TagSupport {
  
      /** the name of the attribute. */
      private String name;
  
      /** the value of the attribute. */
      private Object value;
  
  
      public ParamTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
          TransformTag tag = (TransformTag) this.findAncestorWithClass( TransformTag.class );
          if ( tag == null ) {
              throw new JellyException( "<param> tag must be enclosed inside a <transform> tag" );
          }
          Object value = this.getValue();
          if (value == null) { 
              value = getBodyText();
          }
  
          tag.setParameterValue( getName(), value );
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /**
       * @return the name of the attribute.
       */
      public String getName() {
          return name;
      }
      /**
       * Sets the name of the attribute
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * @return the value of the attribute.
       */
      public Object getValue() {
          return value;
      }
      /**
       * Sets the value of the attribute
       */
      public void setValue(Object value) {
          this.value = value;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java
  
  Index: XMLTagLibrary.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/XMLTagLibrary.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: XMLTagLibrary.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.TagLibrary;
  import org.apache.commons.jelly.expression.Expression;
  import org.apache.commons.jelly.expression.ExpressionFactory;
  import org.apache.commons.jelly.expression.CompositeExpression;
  import org.apache.commons.jelly.expression.jexl.JexlExpressionFactory;
  import org.apache.commons.jelly.expression.xpath.XPathExpression;
  import org.apache.commons.jelly.impl.TagScript;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  
  /** Describes the Taglib. This class could be generated by XDoclet
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class XMLTagLibrary extends TagLibrary {
  
      /** The Log to which logging calls will be made. */
      private Log log = LogFactory.getLog(XMLTagLibrary.class);
  
      private JexlExpressionFactory jexlFactory;
  
      public XMLTagLibrary() {
          registerTag("out", ExprTag.class);
          registerTag("if", IfTag.class);
          registerTag("forEach", ForEachTag.class);
          registerTag("parse", ParseTag.class);
          registerTag("set", SetTag.class);
          registerTag("transform", TransformTag.class);
          registerTag("param", ParamTag.class);
  
          // extensions to JSTL
          registerTag("expr", ExprTag.class);
          registerTag("element", ElementTag.class);
          registerTag("attribute", AttributeTag.class);
          registerTag("copy", CopyTag.class);
          registerTag("copyOf", CopyOfTag.class);
          registerTag("comment", CommentTag.class);
          registerTag("doctype", DoctypeTag.class);
          registerTag("sort", SortTag.class);
  
          this.jexlFactory = new JexlExpressionFactory();
      }
  
      public Expression createExpression(
          ExpressionFactory factory,
          TagScript tagScript,
          String attributeName,
          String attributeValue) throws Exception {
  
          // #### may need to include some namespace URI information in the XPath instance?
  
          if (attributeName.equals("select") || attributeName.equals("sort")) {
              if ( log.isDebugEnabled() ) {
                  log.debug( "Parsing XPath expression: " + attributeValue );
              }
  
              Expression xpathExpr = createXPathTextExpression( attributeValue );
              
              return new XPathExpression(attributeValue,
                                         xpathExpr,
                                         tagScript);
          }
  
          // will use the default expression instead
          return super.createExpression(factory, tagScript, attributeName, attributeValue);
      }
  
      protected Expression createXPathTextExpression(String exprText) throws Exception {
          return CompositeExpression.parse( exprText,
                                            this.jexlFactory );
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParseTagSupport.java
  
  Index: ParseTagSupport.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParseTagSupport.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ParseTagSupport.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import java.io.File;
  import java.io.InputStream;
  import java.io.Reader;
  import java.net.URL;
  
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.dom4j.Document;
  import org.dom4j.io.SAXContentHandler;
  import org.dom4j.io.SAXReader;
  
  /** 
   * An abstract base class for any tag which parsers its body as XML.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public abstract class ParseTagSupport extends TagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(ParseTagSupport.class);
  
      /** The variable that will be generated for the document */
      private String var;
  
      /** The SAXReader used to parser the document */
      private SAXReader saxReader;
  
      public ParseTagSupport() {
      }
  
  
      // Properties
      //-------------------------------------------------------------------------                
      /** The variable name that will be used for the Document variable created
       */
      public String getVar() {
          return var;
      }
  
      /** Sets the variable name that will be used for the Document variable created
       */
      public void setVar(String var) {
          this.var = var;
      }
      
      /** @return the SAXReader used for parsing, creating one lazily if need be  */
      public SAXReader getSAXReader() throws Exception {
          if (saxReader == null) {
              saxReader = createSAXReader();
          }
          return saxReader;
      }
  
      /** Sets the SAXReader used for parsing */
      public void setSAXReader(SAXReader saxReader) {
          this.saxReader = saxReader;
      }
      
  
      // Implementation methods
      //-------------------------------------------------------------------------                
  
      /**
       * Factory method to create a new SAXReader
       */    
      protected abstract SAXReader createSAXReader() throws Exception;
      
      
      /**
       * Parses the body of this tag and returns the parsed document
       */
      protected Document parseBody(XMLOutput output) throws Exception {
          SAXContentHandler handler = new SAXContentHandler();
          XMLOutput newOutput = new XMLOutput(handler);
          handler.startDocument();
          invokeBody( newOutput);
          handler.endDocument();
          return handler.getDocument();
  
  /*
          // the following is inefficient as it requires a parse of the text
          // but is left here in the code to see how it could be done.
  
          String text = getBodyText();
          
          if ( log.isDebugEnabled() ) {
              log.debug( "About to parse: " + text );
          }
          return getSAXReader().read( new StringReader( text ) );
  */
      }
  
      /**
       * Parses the given source
       */    
      protected Document parse(Object source) throws Exception {
          // #### we should allow parsing to output XML events to
          // the output if no var is specified
          
          if (source instanceof String) {
              String uri = (String) source;
              source = context.getResource(uri);
          }
          
          if (source instanceof URL) {
              return getSAXReader().read((URL) source);
          }
          else if (source instanceof File) {
              return getSAXReader().read((File) source);
          }
          else if (source instanceof Reader) {
              return getSAXReader().read((Reader) source);
          }
          else if (source instanceof InputStream) {
              return getSAXReader().read((InputStream) source);
          }
          else {
              throw new IllegalArgumentException(
                  "Invalid source argument. Must be a String, Reader, InputStream or URL."
                      + " Was type; "
                      + source.getClass().getName()
                      + " with value: "
                      + source);
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyTag.java
  
  Index: CopyTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CopyTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  import org.dom4j.Element;
  import org.dom4j.io.SAXWriter;
  import org.jaxen.XPath;
  
  /** 
   * A tag which performs a copy operation like the XSLT tag, 
   * performing a shallow copy of the element and its attributes but no content.
   *
   * @author James Strachan
   */
  public class CopyTag extends XPathTagSupport {
  
      /** The XPath expression to evaluate. */
      private XPath select;
  
      public CopyTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
  	public void doTag(XMLOutput output) throws Exception {
  		Object xpathContext = getXPathContext();
  
          Object node = xpathContext;
          
  		if (select != null) {
              node = select.selectSingleNode(xpathContext);
  		}
  
          if ( node instanceof Element ) {
              Element element = (Element) node;
              
              SAXWriter saxWriter = new SAXWriter(output, output);
              
              saxWriter.writeOpen(element);
              invokeBody(output);
              saxWriter.writeClose(element);
          }
          else {
              invokeBody(output);
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
  </head>
  <body>
  
    <p>The XML Tags from the JSTL
    </p>
  </body>
  </html>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyOfTag.java
  
  Index: CopyOfTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/CopyOfTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: CopyOfTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  import org.dom4j.Node;
  import org.dom4j.io.SAXWriter;
  import org.jaxen.XPath;
  
  /** A tag which performs a copy-of operation like the XSLT tag
    *
    * @author James Strachan
    */
  public class CopyOfTag extends XPathTagSupport {
  
      /** The XPath expression to evaluate. */
      private XPath select;
  
      public CopyOfTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          Object xpathContext = getXPathContext();
          
          if (select == null) {
              throw new MissingAttributeException( "select" );
          }
  
          SAXWriter saxWriter = new SAXWriter(output, output);
          List nodes = select.selectNodes(xpathContext);
          for (Iterator iter = nodes.iterator(); iter.hasNext(); ) {
              Object object = iter.next();
              if ( object instanceof Node ) {
                  saxWriter.write( (Node) object );
              }
              else if (object != null ) {
                  output.write( object.toString() );
              }
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: SetTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathComparator;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.jaxen.XPath;
  import org.jaxen.JaxenException;
  
  import java.util.List;
  import java.util.Collections;
  
  /** A tag which defines a variable from an XPath expression 
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class SetTag extends XPathTagSupport {
  
      /** The Log to which logging calls will be made. */
      private Log log = LogFactory.getLog(SetTag.class);
      
      /** The variable name to export. */
      private String var;
      
      /** The XPath expression to evaluate. */    
      private XPath select;
      
      /** Xpath comparator for sorting */
      private XPathComparator xpCmp = null;
  
      public SetTag() {
  
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          if (var == null) {
              throw new MissingAttributeException( "var" );
          }
          if (select == null) {
              throw new MissingAttributeException( "select" );
          }
          
          Object xpathContext = getXPathContext();        
          Object value = select.evaluate(xpathContext);
  
          if (value instanceof List) {
              // sort the list if xpCmp is set.
              if (xpCmp != null && (xpCmp.getXpath() != null)) {
                  Collections.sort((List)value, xpCmp);
              }
          }
  
          //log.info( "Evaluated xpath: " + select + " as: " + value + " of type: " + value.getClass().getName() );
          
          context.setVariable(var, value);
      }
      
      // Properties
      //-------------------------------------------------------------------------                
      
      /** Sets the variable name to define for this expression
       */
      public void setVar(String var) {
          this.var = var;
      }
      
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
  
  
      /** Sets the xpath expression to use to sort selected nodes.
       */
      public void setSort(XPath sortXPath) throws JaxenException {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setXpath(sortXPath);
      }
  
      /**
       * Set whether to sort ascending or descending.
       */
      public void setDescending(boolean descending) {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setDescending(descending);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SortTag.java
  
  Index: SortTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/SortTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: SortTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.xpath.XPathComparator;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  import org.jaxen.XPath;
  import org.jaxen.JaxenException;
  
  import java.util.List;
  import java.util.Collections;
  
  /** A tag that can sort a list of xml nodes via an xpath expression.
    *
    * @author <a href="mailto:jason@jhorman.org">Jason Horman</a>
    * @version $Id: SortTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
    */
  
  public class SortTag extends XPathTagSupport {
  
      /** The list to sort */
      private List list = null;
  
      /** Xpath comparator for sorting */
      private XPathComparator xpCmp = null;
  
      public void doTag(XMLOutput output) throws Exception {
          if (xpCmp == null) {
              throw new MissingAttributeException( "xpCmp" );
          }
          if (list == null) {
              throw new MissingAttributeException( "list" );
          }
  
          Collections.sort(list, xpCmp);
      }
  
      /** Set the list to sort. */
      public void setList(List list) {
          this.list = list;
      }
  
      /** Sets the xpath expression to use to sort selected nodes.
       */
      public void setSort(XPath sortXPath) throws JaxenException {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setXpath(sortXPath);
      }
  
      /**
       * Set whether to sort ascending or descending.
       */
      public void setDescending(boolean descending) {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setDescending(descending);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java
  
  Index: ParseTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ParseTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: ParseTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.XMLOutput;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.dom4j.Document;
  import org.dom4j.io.SAXReader;
  
  /** A tag which parses some XML and defines a variable with the parsed Document.
    * The XML can either be specified as its body or can be passed in via the
    * xml property which can be a Reader, InputStream, URL or String URI.
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ParseTag extends ParseTagSupport {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(ParseTag.class);
  
      /** The xml to parse, either a String URI, a Reader or InputStream */
      private Object xml;
  
      // Optional properties not defined in JSTL
      /** whether XML validation is enabled or disabled */
      private boolean validate;
  
      public ParseTag() {
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
          if (getVar() == null) {
              throw new IllegalArgumentException("The var attribute cannot be null");
          }
          Document document = getXmlDocument(output);
          context.setVariable(getVar(), document);
      }
  
      // Properties
      //-------------------------------------------------------------------------
      /** Gets the source of the XML which is either a String URI, Reader or InputStream */
      public Object getXml() {
          return this.xml;
      }
  
      /** Sets the source of the XML which is either a String URI, a File, Reader or InputStream */
      public void setXml(Object xml) {
          this.xml = xml;
      }
  
      /** @return whether XML validation is enabled or disabled */
      public boolean getValidate() {
          return validate;
      }
  
      /** Sets whether XML validation is enabled or disabled */
      public void setValidate(boolean validate) {
          this.validate = validate;
      }
  
  
      // Implementation methods
      //-------------------------------------------------------------------------
  
      /**
       * Factory method to create a new SAXReader
       */
      protected SAXReader createSAXReader() throws Exception {
          return new SAXReader(validate);
      }
  
      protected Document getXmlDocument(XMLOutput output) throws Exception {
          Document document = null;
          Object xmlObj = this.getXml();
          if (xmlObj == null) {
              document = parseBody(output);
          }
          else {
              document = parse(xmlObj);
          }
          return document;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/AttributeTag.java
  
  Index: AttributeTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/AttributeTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: AttributeTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** Adds an XML attribute to the parent element tag like 
    * the <code>&lt;xsl:attribute&gt;</code> tag.
    *
    * @author James Strachan
    * @version $Revision: 1.1 $
    */
  public class AttributeTag extends TagSupport {
      
      /** the name of the attribute. */
      private String name;
      
  
      public AttributeTag() {
      }
      
      // Tag interface
      //-------------------------------------------------------------------------
      public void doTag(XMLOutput output) throws Exception {
          ElementTag tag = (ElementTag) findAncestorWithClass( ElementTag.class );
          if ( tag == null ) {
              throw new JellyException( "<attribute> tag must be enclosed inside an <element> tag" );
          }
          tag.setAttributeValue( getName(), getBodyText() );
      }
      
      // Properties
      //-------------------------------------------------------------------------
      
      /** 
       * @return the name of the attribute.
       */
      public String getName() {
          return name;
      }
      /** 
       * Sets the name of the attribute
       */
      public void setName(String name) {
          this.name = name;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/IfTag.java
  
  Index: IfTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/IfTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: IfTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  import org.jaxen.XPath;
  
  /** 
   * Evaluates the XPath expression to be a boolean and only evaluates the body
   * if the expression is true.    
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class IfTag extends XPathTagSupport {
  
      /** The XPath expression to evaluate. */
      private XPath select;
  
      public IfTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          if (select == null) {
              throw new MissingAttributeException( "select" );
          }
          
          Object xpathContext = getXPathContext();
          if ( select.booleanValueOf(xpathContext) ) {
              invokeBody(output);
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------   
                   
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------                
      protected Object getXPathContext() {
          ForEachTag tag = (ForEachTag) findAncestorWithClass( ForEachTag.class );    
          if ( tag != null ) {
              return tag.getXPathContext();
          }
          return null;
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java
  
  Index: TransformTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/TransformTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * $Id: TransformTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.Reader;
  import java.io.StringReader;
  import java.io.StringWriter;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.util.Iterator;
  import java.util.List;
  
  import javax.xml.transform.Result;
  import javax.xml.transform.Source;
  import javax.xml.transform.TransformerException;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.URIResolver;
  import javax.xml.transform.sax.SAXResult;
  import javax.xml.transform.sax.SAXSource;
  import javax.xml.transform.sax.SAXTransformerFactory;
  import javax.xml.transform.sax.TransformerHandler;
  import javax.xml.transform.stream.StreamSource;
  
  import org.apache.commons.jelly.Script;
  import org.apache.commons.jelly.Tag;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.impl.ScriptBlock;
  import org.apache.commons.jelly.impl.StaticTagScript;
  import org.apache.commons.jelly.impl.TagScript;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.dom4j.Document;
  import org.dom4j.io.DocumentResult;
  import org.dom4j.io.DocumentSource;
  import org.xml.sax.ContentHandler;
  import org.xml.sax.DTDHandler;
  import org.xml.sax.EntityResolver;
  import org.xml.sax.ErrorHandler;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXNotRecognizedException;
  import org.xml.sax.SAXNotSupportedException;
  import org.xml.sax.XMLReader;
  import org.xml.sax.ext.LexicalHandler;
  import org.xml.sax.helpers.XMLReaderFactory;
  
  /** A tag which parses some XML, applies an xslt transform to it
    * and defines a variable with the transformed Document.
    * The XML can either be specified as its body or can be passed in via the
    * xml property which can be a Reader, InputStream, URL or String URI.
    *
    * The XSL can be passed in via the
    * xslt property which can be a Reader, InputStream, URL or String URI.
    *
    * @author Robert Leftwich
    * @version $Revision: 1.1 $
    */
  public class TransformTag extends ParseTag {
  
      /** The Log to which logging calls will be made. */
      private static final Log log = LogFactory.getLog(TransformTag.class);
  
      /** Propert name for lexical handler */
      private static final String LEXICAL_HANDLER_PROPERTY =
          "http://xml.org/sax/properties/lexical-handler";
  
      /** The xslt to parse, either a String URI, a Reader or InputStream */
      private Object xslt;
  
      /** The xsl transformer factory */
      private SAXTransformerFactory tf;
  
      /** the transformer handler, doing the real work */
      private TransformerHandler transformerHandler;
  
      /**
       * Constructor for TransformTag.
       */
      public TransformTag() {
          super();
          this.tf = (SAXTransformerFactory) TransformerFactory.newInstance();
      }
  
      // Tag interface
      //-------------------------------------------------------------------------
  
      /**
       * Process this tag instance
       *
       * @param output The pipeline for xml events
       * @throws Exception - when required attributes are missing
       */
      public void doTag(XMLOutput output) throws Exception {
  
          if (null == this.getXslt()) {
              throw new IllegalArgumentException("The xslt attribute cannot be null");
          }
  
          // set a resolver to locate uri
          this.tf.setURIResolver(createURIResolver());
          this.transformerHandler =
              this.tf.newTransformerHandler(this.getObjAsSAXSource(this.getXslt()));
  
          // run any nested param tags
          this.doNestedParamTag(output);
  
          // get a reader to provide SAX events to transformer
          XMLReader xmlReader = this.createXMLReader();
          xmlReader.setContentHandler(this.transformerHandler);
          xmlReader.setProperty(LEXICAL_HANDLER_PROPERTY, this.transformerHandler);
  
          // handle result differently, depending on if var is specified
          String varName = this.getVar();
          if (null == varName) {
              // pass the result of the transform out as SAX events
              this.transformerHandler.setResult(this.createSAXResult(output));
              xmlReader.parse(this.getXMLInputSource());
          }
          else {
              // pass the result of the transform out as a document
              DocumentResult result = new DocumentResult();
              this.transformerHandler.setResult(result);
              xmlReader.parse(this.getXMLInputSource());
  
              // output the result as a variable
              Document transformedDoc = result.getDocument();
              this.context.setVariable(varName, transformedDoc);
          }
  
      }
  
      // Properties
      //-------------------------------------------------------------------------
  
      /**
       * Gets the source of the XSL which is either a String URI, Reader or
       * InputStream
       *
       * @returns xslt    The source of the xslt
       */
      public Object getXslt() {
          return this.xslt;
      }
  
      /**
       * Sets the source of the XSL which is either a String URI, Reader or
       * InputStream
       *
       * @param xslt    The source of the xslt
       */
      public void setXslt(Object xslt) {
          this.xslt = xslt;
      }
  
      public void setParameterValue(String name, Object value) {
          this.transformerHandler.getTransformer().setParameter(name, value);
      }
  
      // Implementation methods
      //-------------------------------------------------------------------------
  
      /**
       * Creates a new URI Resolver so that URIs inside the XSLT document can be
       * resolved using the JellyContext
       *
       * @return a URI Resolver for the JellyContext
       */
      protected URIResolver createURIResolver() {
          return new URIResolver() {
              public Source resolve(String href, String base)
                  throws TransformerException {
  
                  if (log.isDebugEnabled() ) {
                      log.debug( "base: " + base + " href: " + href );
                  }
  
                  // pass if we don't have a systemId
                  if (null == href)
                      return null;
  
                  // @todo
                  // #### this is a pretty simplistic implementation.
                  // #### we should really handle this better such that if
                  // #### base is specified as an absolute URL
                  // #### we trim the end off it and append href
                  return new StreamSource(context.getResourceAsStream(href));
              }
          };
      }
  
      /**
       * Factory method to create a new SAXResult for the given
       * XMLOutput so that the output of an XSLT transform will go
       * directly into the XMLOutput that we are given.
       *
       * @param output The destination of the transform output
       * @return A SAXResult for the transfrom output
       */
      protected Result createSAXResult(XMLOutput output) {
          SAXResult result = new SAXResult(output);
          result.setLexicalHandler(output);
          return result;
      }
  
      /**
       * Factory method to create a new XMLReader for this tag
       * so that the input of the XSLT transform comes from
       * either the xml var, the nested tag or the tag body.
       *
       * @return XMLReader for the transform input
       * @throws SAXException
       *             If the value of the "org.xml.sax.driver" system property
       *             is null, or if the class cannot be loaded and instantiated.
       */
      protected XMLReader createXMLReader() throws SAXException {
          XMLReader xmlReader = null;
          Object xmlReaderSourceObj = this.getXml();
          // if no xml source specified then get from body
          // otherwise convert it to a SAX source
          if (null == xmlReaderSourceObj) {
              xmlReader = new TagBodyXMLReader(this);
          }
          else {
              xmlReader = XMLReaderFactory.createXMLReader();
          }
  
          return xmlReader;
      }
  
      /**
       * Helper method to get the appropriate xml input source
       * so that the input of the XSLT transform comes from
       * either the xml var, the nested tag or the tag body.
       *
       * @return InputSource for the transform input
       */
      protected InputSource getXMLInputSource() {
          InputSource xmlInputSource = null;
          Object xmlInputSourceObj = this.getXml();
          // if no xml source specified then get from tag body
          // otherwise convert it to an input source
          if (null == xmlInputSourceObj) {
              xmlInputSource = new TagBodyInputSource();
          } else {
              xmlInputSource = this.getInputSourceFromObj(xmlInputSourceObj);
          }
          return xmlInputSource;
      }
  
      /**
       * Helper method to convert the specified object to a SAX source
       *
       * @return SAXSource from the source object or null
       */
      protected SAXSource getObjAsSAXSource(Object saxSourceObj)
      throws Exception {
          SAXSource saxSource = null;
          if (null != saxSourceObj) {
              if (saxSourceObj instanceof Document) {
                  saxSource =  new DocumentSource((Document) saxSourceObj);
              } else {
                  InputSource xmlInputSource =
                      this.getInputSourceFromObj(saxSourceObj);
                  saxSource = new SAXSource(xmlInputSource);
              }
          }
  
          return saxSource;
      }
  
      /**
       * Helper method to get an xml input source for the supplied object
       *
       * @return InputSource for the object or null
       */
      protected InputSource getInputSourceFromObj(Object sourceObj ) {
          InputSource xmlInputSource = null;
          if (sourceObj instanceof Document) {
              SAXSource saxSource = new DocumentSource((Document) sourceObj);
              xmlInputSource = saxSource.getInputSource();
          } else {
              if (sourceObj instanceof String) {
                  String uri = (String) sourceObj;
                  xmlInputSource = new InputSource(context.getResourceAsStream(uri));
              }
              else if (sourceObj instanceof Reader) {
                  xmlInputSource = new InputSource((Reader) sourceObj);
              }
              else if (sourceObj instanceof InputStream) {
                  xmlInputSource = new InputSource((InputStream) sourceObj);
              }
              else if (sourceObj instanceof URL) {
                  String uri = ((URL) sourceObj).toString();
                  xmlInputSource = new InputSource(context.getResourceAsStream(uri));
              }
              else if (sourceObj instanceof File) {
                  try {
                      String uri = ((File) sourceObj).toURL().toString();
                      xmlInputSource = new InputSource(context.getResourceAsStream(uri));
                  }
                  catch (MalformedURLException e) {
                      throw new IllegalArgumentException(
                          "This should never occur. We should always be able to convert a File to a URL" + e );
                  }
              }
              else {
                  throw new IllegalArgumentException(
                      "Invalid source argument. Must be a String, Reader, InputStream or URL."
                          + " Was type; "
                          + sourceObj.getClass().getName()
                          + " with value: "
                          + sourceObj);
              }
          }
  
          return xmlInputSource;
      }
  
      /**
       * Helper method to run any nested param tags
       *
      * @param output The destination for any SAX output (not actually used)
       */
      private void doNestedParamTag(XMLOutput output) throws Exception {
          // find any nested param tags and run them
          Script bodyScript = this.getBody();
          if (bodyScript instanceof ScriptBlock) {
              ScriptBlock scriptBlock = (ScriptBlock) bodyScript;
              List scriptList = scriptBlock.getScriptList();
              for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) {
                  Script script = (Script) iter.next();
                  if (script instanceof TagScript) {
                      Tag tag = ((TagScript) script).getTag();
                      if (tag instanceof ParamTag) {
                          script.run(context, output);
                      }
  
                  }
              }
          }
      }
  
      /** A helper class that converts a transform tag body to an XMLReader
        * to hide the details of where the input for the transform is obtained
        *
        * @author <a href="mailto:robert@leftwich.info">Robert Leftwich</a>
        * @version $Revision: 1.1 $
        */
      private class TagBodyXMLReader implements XMLReader {
  
          /** The tag whose body is to be read. */
          private Tag tag;
  
          /** The destination for the sax events generated by the reader. */
          private XMLOutput xmlOutput;
  
          /** Storage for a DTDHandler if set by the user of the reader. */
          private DTDHandler dtdHandler;
  
          /** Storage for a ErrorHandler if set by the user of the reader. */
          private ErrorHandler errorHandler;
  
          /** Storage for a EntityResolver if set by the user of the reader. */
          private EntityResolver entityResolver;
  
          /**
           * Construct an XMLReader for the specified Tag
           *
           * @param tag    The Tag to convert to an XMLReader
           */
          public TagBodyXMLReader(Tag tag)
          {
              this.tag = tag;
              this.xmlOutput = new XMLOutput();
          }
  
          // Methods
          //-------------------------------------------------------------------------
  
          /**
           * Parse an XML source.
           *
           * @param input  The source of the xml
           * @throws SAXException -
           *             Any SAX exception, possibly wrapping another exception.
           * @throws IOException -
           *             An IO exception from the parser, possibly from a byte
                         stream or character stream supplied by the application.
           */
          public void parse(InputSource input)
          throws IOException, SAXException
          {
              // safety check that we are being used correctly
              if (input instanceof TagBodyInputSource) {
                  this.doInvokeBody();
              } else {
                  throw new SAXException("Invalid input source");
              }
          }
  
          /**
           * Parse an XML source specified by a system id
           *
           * @param input  The system identifier (URI)
           * @throws SAXException -
           *             Any SAX exception, possibly wrapping another exception.
           * @throws IOException -
           *             An IO exception from the parser, possibly from a byte
                         stream or character stream supplied by the application.
           */
          public void parse(String systemId)
          throws IOException, SAXException
          {
              this.doInvokeBody();
          }
  
          // Helper methods
          //-------------------------------------------------------------------------
  
          /**
           * Actually invoke the tag body to generate the SAX events
           *
           * @throws SAXException -
           *             Any SAX exception, possibly wrapping another exception.
           */
          private void doInvokeBody() throws SAXException {
              try {
                  if (this.shouldParseBody()) {
                      XMLReader anXMLReader = XMLReaderFactory.createXMLReader();
                      anXMLReader.setContentHandler(this.xmlOutput);
                      anXMLReader.setProperty(LEXICAL_HANDLER_PROPERTY,this.xmlOutput);
                      StringWriter writer = new StringWriter();
                      this.tag.invokeBody(XMLOutput.createXMLOutput(writer));
                      Reader reader = new StringReader(writer.toString());
                      anXMLReader.parse(new InputSource(reader));
                  } else {
                      this.tag.invokeBody(this.xmlOutput);
                  }
              } catch (Exception ex) {
                  throw new SAXException(ex);
              }
          }
  
          /**
           * Helper method to determin if nested body needs to be parsed by (an
           * xml parser, i.e. its only text) to generate SAX events or not
           *
           * @return True if tag body should be parsed or false if invoked only
           */
          private boolean shouldParseBody() {
              boolean result = false;
              // check to see if we need to parse the body or just invoke it
              Script bodyScript = this.tag.getBody();
              if (bodyScript instanceof ScriptBlock) {
                  ScriptBlock scriptBlock = (ScriptBlock) bodyScript;
                  List scriptList = scriptBlock.getScriptList();
                  for (Iterator iter = scriptList.iterator(); iter.hasNext(); ) {
                      Script script = (Script) iter.next();
                      if (script instanceof StaticTagScript) {
                          result = true;
                           break;
                      }
                  }
              }
              return result;
          }
  
          // Properties
          //-------------------------------------------------------------------------
  
          /**
           * Gets the SAX ContentHandler to feed SAX events into
           *
           * @return the SAX ContentHandler to use to feed SAX events into
           */
          public ContentHandler getContentHandler() {
              return this.xmlOutput.getContentHandler();
          }
  
          /**
           * Sets the SAX ContentHandler to feed SAX events into
           *
           * @param contentHandler is the ContentHandler to use.
           *      This value cannot be null.
           */
          public void setContentHandler(ContentHandler contentHandler) {
              this.xmlOutput.setContentHandler(contentHandler);
              // often classes will implement LexicalHandler as well
              if (contentHandler instanceof LexicalHandler) {
                  this.xmlOutput.setLexicalHandler((LexicalHandler) contentHandler);
              }
          }
  
          /**
           * Gets the DTD Handler to feed SAX events into
           *
           * @return the DTD Handler to use to feed SAX events into
           */
          public DTDHandler getDTDHandler() {
              return this.dtdHandler;
          }
  
          /**
           * Sets the DTD Handler to feed SAX events into
           *
           * @param the DTD Handler to use to feed SAX events into
           */
          public void setDTDHandler(DTDHandler dtdHandler) {
              this.dtdHandler = dtdHandler;
          }
  
          /**
           * Gets the Error Handler to feed SAX events into
           *
           * @return the Error Handler to use to feed SAX events into
           */
          public ErrorHandler getErrorHandler() {
              return this.errorHandler;
          }
  
          /**
           * Sets the Error Handler to feed SAX events into
           *
           * @param the Error Handler to use to feed SAX events into
           */
          public void setErrorHandler(ErrorHandler errorHandler) {
              // save the error handler
              this.errorHandler = errorHandler;
          }
  
          /**
           * Gets the Entity Resolver to feed SAX events into
           *
           * @return the Entity Resolver to use to feed SAX events into
           */
          public EntityResolver getEntityResolver() {
              return this.entityResolver;
          }
  
          /**
           * Sets the Entity Resolver to feed SAX events into
           *
           * @param the Entity Resolver to use to feed SAX events into
           */
          public void setEntityResolver(EntityResolver entityResolver) {
              this.entityResolver = entityResolver;
          }
  
          /**
           * Lookup the value of a property
           *
           * @param name - The property name, which is a fully-qualified URI.
           * @return - The current value of the property.
           * @throws SAXNotRecognizedException -
           *            When the XMLReader does not recognize the property name.
           * @throws SAXNotSupportedException -
           *            When the XMLReader recognizes the property name but
           *            cannot determine its value at this time.
           */
          public Object getProperty(String name)
          throws SAXNotRecognizedException, SAXNotSupportedException
          {
              // respond to the lexical handler request
              if (name.equalsIgnoreCase(LEXICAL_HANDLER_PROPERTY)) {
                  return this.xmlOutput.getLexicalHandler();
              } else {
                  // do nothing
                  return null;
              }
          }
  
          /**
           * Set the value of a property
           *
           * @param name - The property name, which is a fully-qualified URI.
           * @param value - The property value
           * @throws SAXNotRecognizedException -
           *            When the XMLReader does not recognize the property name.
           * @throws SAXNotSupportedException -
           *            When the XMLReader recognizes the property name but
           *            cannot determine its value at this time.
           */
          public void setProperty(String name, Object value)
          throws SAXNotRecognizedException, SAXNotSupportedException
          {
              // respond to the lexical handler setting
              if (name.equalsIgnoreCase(LEXICAL_HANDLER_PROPERTY)) {
                  this.xmlOutput.setLexicalHandler((LexicalHandler) value);
              }
          }
  
          /**
           * Lookup the value of a feature
           *
           * @param name - The feature name, which is a fully-qualified URI.
           * @return - The current state of the feature (true or false)
           * @throws SAXNotRecognizedException -
           *            When the XMLReader does not recognize the feature name.
           * @throws SAXNotSupportedException -
           *            When the XMLReader recognizes the feature name but
           *            cannot determine its value at this time.
           */
          public boolean getFeature(String name)
          throws SAXNotRecognizedException, SAXNotSupportedException
          {
              // do nothing
              return false;
          }
  
          /**
           * Set the value of a feature
           *
           * @param name - The feature name, which is a fully-qualified URI.
           * @param value - The current state of the feature (true or false)
           * @throws SAXNotRecognizedException -
           *            When the XMLReader does not recognize the feature name.
           * @throws SAXNotSupportedException -
           *            When the XMLReader recognizes the feature name but
           *            cannot determine its value at this time.
           */
          public void setFeature(String name, boolean value)
          throws SAXNotRecognizedException, SAXNotSupportedException
          {
              // do nothing
          }
      }
  
      /** A marker class used by the TagBodyXMLReader as a sanity check
        * (i.e. The source is not actually used)
        *
        */
      private class TagBodyInputSource extends InputSource {
  
          /**
           * Construct an instance of this marker class
           */
          public TagBodyInputSource() {
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ElementTag.java
  
  Index: ElementTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ElementTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ElementTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.JellyException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.AttributesImpl;
  
  /** A tag to produce an XML element which can contain other attributes 
    * or elements like the <code>&lt;xsl:element&gt;</code> tag.
    *
    * @author James Strachan
    * @version $Revision: 1.1 $
    */
  public class ElementTag extends TagSupport {
      
      /** The namespace URI */
      private String namespace;
      
      /** The qualified name */
      private String name;
      
      /** The XML Attributes */
      private AttributesImpl attributes = new AttributesImpl();
  
  	/** flag set if attributes are output */
  	private boolean outputAttributes;
      
      public ElementTag() {
      }
  
  	/**
  	 * Sets the attribute of the given name to the specified value.
  	 * 
	 * @param name of the attribute
	 * @param value of the attribute
	 * @throws JellyException if the start element has already been output. 
  	 *   Attributes must be set on the outer element before any content 
  	 *   (child elements or text) is output
	 */
      public void setAttributeValue( String name, String value ) throws JellyException {
      	if (outputAttributes) {
      		throw new JellyException(
  				"Cannot set the value of attribute: " 
      			+ name + " as we have already output the startElement() SAX event"
  			);
      	}
      	
          // ### we'll assume that all attributes are in no namespace!
          // ### this is severely limiting!
          // ### we should be namespace aware
          int index = attributes.getIndex("", name);
          if (index >= 0) {
              attributes.removeAttribute(index);
          }
          // treat null values as no attribute 
          if (value != null) {
              attributes.addAttribute("", name, name, "CDATA", value);
          }
      }
  
      // Tag interface
      //-------------------------------------------------------------------------                    
      public void doTag(XMLOutput output) throws Exception {
          int idx = name.indexOf(':');
          final String localName = (idx >= 0) 
          	? name.substring(idx + 1)
          	: name;
          
          outputAttributes = false;
          
          XMLOutput newOutput = new XMLOutput(output) {
  
  			// add an initialize hook to the core content-generating methods
  			        	
  		    public void startElement(
  		        String uri,
  		        String localName,
  		        String qName,
  		        Attributes atts)
  		        throws SAXException {
  				initialize();        	
  		        super.startElement(uri, localName, qName, atts);
  		    }
  		
  		    public void endElement(String uri, String localName, String qName)
  		        throws SAXException {
  				initialize();        	
  		        super.endElement(uri, localName, qName);
  		    }
  		
  		    public void characters(char ch[], int start, int length) throws SAXException {
  				initialize();        	
  		        super.characters(ch, start, length);
  		    }
  		
  		    public void ignorableWhitespace(char ch[], int start, int length)
  		        throws SAXException {
  				initialize();        	
  		        super.ignorableWhitespace(ch, start, length);
  		    }
  		    public void processingInstruction(String target, String data)
  		        throws SAXException {
  				initialize();        	
  		        super.processingInstruction(target, data);
  		    }
  		
          	/** 
          	 * Ensure that the outer start element is generated 
          	 * before any content is output
        	 */ 
          	protected void initialize() throws SAXException {
          		if (!outputAttributes) {
  			        super.startElement(namespace, localName, name, attributes);
  			        outputAttributes = true;
          		}
          	}
          };
          
          invokeBody(newOutput);
          
          if (!outputAttributes) {
  	        output.startElement(namespace, localName, name, attributes);
  	        outputAttributes = true;
          }
          
          output.endElement(namespace, localName, name);
          attributes.clear();
      }
      
      // Properties
      //-------------------------------------------------------------------------
      
      /** 
       * @return the qualified name of the element
       */
      public String getName() {
          return name;
      }
      
      /** 
       * Sets the qualified name of the element
       */
      public void setName(String name) {
          this.name = name;
      }
      
      /**
       * @return the namespace URI of the element
       */
      public String getURI() {
          return namespace;
      }
      
      /**
       * Sets the namespace URI of the element
       */
      public void setURI(String namespace) {
          this.namespace = namespace;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/DoctypeTag.java
  
  Index: DoctypeTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/DoctypeTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: DoctypeTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  
  
  /** 
   * A tag which outputs a DOCTYPE declaration to the current XML output pipe.
   * Note that there should only be a single DOCTYPE declaration in any XML stream and
   * it should occur before any element content.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.1 $
   */
  public class DoctypeTag extends XPathTagSupport {
  
      private String name;
      private String publicId;
      private String systemId;
  
      public DoctypeTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          if (name == null) {
              throw new MissingAttributeException( "name" );
          }
          
          output.startDTD(name, publicId, systemId);
          invokeBody(output);
          output.endDTD();
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      /**
       * Returns the name.
       * @return String
       */
      public String getName() {
          return name;
      }
  
      /**
       * Returns the publicId.
       * @return String
       */
      public String getPublicId() {
          return publicId;
      }
  
      /**
       * Returns the systemId.
       * @return String
       */
      public String getSystemId() {
          return systemId;
      }
  
      /**
       * Sets the document type name of the DOCTYPE 
       */
      public void setName(String name) {
          this.name = name;
      }
  
      /**
       * Sets the declared public identifier for DTD 
       */
      public void setPublicId(String publicId) {
          this.publicId = publicId;
      }
  
      /**
       * Sets the declared system identifier for the DTD
       */
      public void setSystemId(String systemId) {
          this.systemId = systemId;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java
  
  Index: ForEachTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ForEachTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ForEachTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import java.util.Iterator;
  import java.util.List;
  import java.util.Collections;
  
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathComparator;
  import org.apache.commons.jelly.xpath.XPathSource;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  
  import org.jaxen.XPath;
  import org.jaxen.JaxenException;
  
  /** A tag which performs an iteration over the results of an XPath expression
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ForEachTag extends XPathTagSupport implements XPathSource {
  
      /** Holds the XPath selector. */
      private XPath select;
  
      /** Xpath comparator for sorting */
      private XPathComparator xpCmp = null;
  
      /** If specified then the current item iterated through will be defined
        * as the given variable name. */
      private String var;
  
      /** The current iteration value */
      private Object iterationValue;
  
  
      public ForEachTag() {
      }
      
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          if (select != null) {
              List nodes = select.selectNodes( getXPathContext() );
  
              // sort the list if xpCmp is set.
              if (xpCmp != null && (xpCmp.getXpath() != null)) {
                  Collections.sort(nodes, xpCmp);
              }
  
              Iterator iter = nodes.iterator();
              while (iter.hasNext()) {
                  iterationValue = iter.next();
                  if (var != null) {
                      context.setVariable(var, iterationValue);
                  }
                  invokeBody(output);
              }
          }
      }
      
      // XPathSource interface
      //-------------------------------------------------------------------------                    
  
      /**
       * @return the current XPath iteration value
       *  so that any other XPath aware child tags to use
       */
      public Object getXPathSource() {
          return iterationValue;
      }
      
      // Properties
      //-------------------------------------------------------------------------                    
      /** Sets the XPath selection expression
        */
      public void setSelect(XPath select) {
          this.select = select;
      }
  
      /** Sets the variable name to export for the item being iterated over
       */
      public void setVar(String var) {
          this.var = var;
      }
  
      /** Sets the xpath expression to use to sort selected nodes.
       */
      public void setSort(XPath sortXPath) throws JaxenException {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setXpath(sortXPath);
      }
  
      /**
       * Set whether to sort ascending or descending.
       */
      public void setDescending(boolean descending) {
          if (xpCmp == null) xpCmp = new XPathComparator();
          xpCmp.setDescending(descending);
      }
      
      /*
       * Override superclass so method can be access by IfTag
       */
      protected Object getXPathContext() {
          return super.getXPathContext();
      }
      
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java
  
  Index: ExprTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/xml/src/java/org/apache/commons/jelly/tags/xml/ExprTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   * $Revision: 1.1 $
   * $Date: 2003/01/15 23:56:45 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: ExprTag.java,v 1.1 2003/01/15 23:56:45 dion Exp $
   */
  package org.apache.commons.jelly.tags.xml;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.xpath.XPathTagSupport;
  import org.jaxen.XPath;
  
  /** A tag which performs a string XPath expression; similar to &lt;xsl:value-of&gt;
    * in XSLT
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class ExprTag extends XPathTagSupport {
  
      /** The XPath expression to evaluate. */
      private XPath select;
  
      public ExprTag() {
      }
  
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          Object xpathContext = getXPathContext();
          
          if (select == null) {
              throw new MissingAttributeException( "select" );
          }
          
          String text = select.stringValueOf(xpathContext);
          if ( text != null ) {
              output.write(text);
          }
      }
  
      // Properties
      //-------------------------------------------------------------------------                
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>