commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml SetTag.java
Date Tue, 18 Jun 2002 12:30:10 GMT
jstrachan    2002/06/18 05:30:10

  Modified:    jelly    build.xml
               jelly/src/test/org/apache/commons/jelly/jsl example.jelly
                        example2.jelly
               jelly/src/java/org/apache/commons/jelly jelly.properties
               jelly/src/java/org/apache/commons/jelly/tags/jsl
                        JSLTagSupport.java StylesheetTag.java
                        JSLTagLibrary.java
               jelly/src/script makeTagDoc.jelly
               jelly/xdocs navigation.xml
               jelly/src/java/org/apache/commons/jelly/tags/xml SetTag.java
  Added:       jelly/src/java/org/apache/commons/jelly/tags/jsl
                        StyleTag.java
  Log:
  Patched the JSL library so that <stylesheet> can now output a Stylesheet variable
that can be repeatedly used by the <style> tag.
  
  Used this new capability in the jelly script to generate the tag documentation, src/script/makeTagDoc.jelly.
  The script is close to being useful but needs a bit more hacking yet.
  
  Revision  Changes    Path
  1.50      +1 -0      jakarta-commons-sandbox/jelly/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/build.xml,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- build.xml	18 Jun 2002 08:37:02 -0000	1.49
  +++ build.xml	18 Jun 2002 12:30:09 -0000	1.50
  @@ -231,6 +231,7 @@
   	
      <target name="doc-tags" depends="compile" 
         description="Generates the tag documentation">
  +    <mkdir dir="target/generated-xdocs"/>
   	<jelly file="src/script/makeTagDoc.jelly" output="target/generated-xdocs/tags.xml"/>

      </target>
   <!-- ========== Specific Test cases ======================================= -->
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/example.jelly
  
  Index: example.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/example.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- example.jelly	3 Jun 2002 05:14:30 -0000	1.2
  +++ example.jelly	18 Jun 2002 12:30:10 -0000	1.3
  @@ -21,7 +21,7 @@
   <h1>Output</h1>
   
   
  -<jsl:stylesheet source="${doc}">
  +<jsl:stylesheet select="$doc">
   
     <jsl:template match="/">
       <jsl:applyTemplates/>
  
  
  
  1.3       +1 -1      jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/example2.jelly
  
  Index: example2.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/jsl/example2.jelly,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- example2.jelly	3 Jun 2002 04:17:04 -0000	1.2
  +++ example2.jelly	18 Jun 2002 12:30:10 -0000	1.3
  @@ -20,7 +20,7 @@
   
   <h1>Output of first stylesheet1</h1>
   
  -<jsl:stylesheet source="${doc}">
  +<jsl:stylesheet select="$doc">
   
     <jsl:template match="/">
       <jsl:applyTemplates/>
  
  
  
  1.12      +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- jelly.properties	11 Jun 2002 22:59:22 -0000	1.11
  +++ jelly.properties	18 Jun 2002 12:30:10 -0000	1.12
  @@ -5,6 +5,7 @@
   sql         = org.apache.commons.jelly.tags.sql.SqlTagLibrary
   jsl			= org.apache.commons.jelly.tags.jsl.JSLTagLibrary
   ant			= org.apache.commons.jelly.tags.ant.AntTagLibrary
  +log			= org.apache.commons.jelly.tags.log.LogTagLibrary
   werkz		= org.apache.commons.jelly.tags.werkz.WerkzTagLibrary
   
   # optional taglibs
  
  
  
  1.2       +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/JSLTagSupport.java
  
  Index: JSLTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/JSLTagSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JSLTagSupport.java	25 May 2002 18:27:21 -0000	1.1
  +++ JSLTagSupport.java	18 Jun 2002 12:30:10 -0000	1.2
  @@ -82,6 +82,7 @@
           StylesheetTag tag  = (StylesheetTag) findAncestorWithClass( 
               this, StylesheetTag.class 
           );
  +
           if ( tag != null ) {
               return tag.getStylesheet();
           }
  
  
  
  1.3       +84 -47    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/StylesheetTag.java
  
  Index: StylesheetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/StylesheetTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StylesheetTag.java	7 Jun 2002 09:00:36 -0000	1.2
  +++ StylesheetTag.java	18 Jun 2002 12:30:10 -0000	1.3
  @@ -60,6 +60,7 @@
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
   import org.apache.commons.jelly.XMLOutput;
  +import org.apache.commons.jelly.tags.xml.XPathTagSupport;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -69,21 +70,24 @@
   import org.dom4j.rule.Rule;
   import org.dom4j.rule.Stylesheet;
   
  +import org.jaxen.XPath;
  +
  +
   /** 
    * This tag implements a JSL stylesheet which is similar to an 
  - * XSLT stylesheet but can use Jelly tags inside it. a JSP include.
  + * XSLT stylesheet but can use Jelly tags inside it
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class StylesheetTag extends JSLTagSupport {
  +public class StylesheetTag extends XPathTagSupport {
   
       /** The Log to which logging calls will be made. */
       private Log log = LogFactory.getLog(StylesheetTag.class);
   
       
       /** Holds the stylesheet which will be applied to the source context. */
  -    private Stylesheet stylesheet = new Stylesheet();
  +    private Stylesheet stylesheet;
       
       /** Holds value of property mode. */
       private String mode;    
  @@ -91,61 +95,50 @@
       /** store the current output instance for use by inner classes */
       private XMLOutput output;
   
  -    /** the source on which the stylesheet will operate */
  -    private Object source;
  -    
       /** The variable which the stylesheet will be output as */
       private String var;
           
  +    /** The XPath expression to evaluate. */    
  +    private XPath select;
  +    
       public StylesheetTag() {
  -        // add default actions
  -        stylesheet.setValueOfAction( 
  -            new Action() {
  -                public void run(Node node) throws Exception {
  -                    String text = node.getStringValue();
  -                    if ( text != null && text.length() > 0 ) {
  -                        output.write( text );
  -                    }
  -                }
  -            }
  -        );                    
  -        
       }
           
   
  -
       /** 
        * Adds a new template rule to this stylesheet
        */    
       public void addTemplate( Rule rule ) {
  -        stylesheet.addRule( rule );
  +        getStylesheet().addRule( rule );
       }
       
       
       // Tag interface
       //-------------------------------------------------------------------------       
            
  -    public void doTag(XMLOutput output) throws Exception {
  -        // for use by inner classes
  -        this.output = output;
  -        
  -        try {        
  -            // run the body to add the rules
  -            getBody().run(context, output);
  -            
  -            if ( log.isDebugEnabled() ) {
  -                log.debug( "About to evaluate stylesheet on source: " + source );
  -            }
  -            
  -            stylesheet.setModeName( getMode() );
  -            stylesheet.run( source );
  -        }
  -        finally {
  -            
  -            // help the GC
  -            this.output = null;
  -            stylesheet.clear();        
  -        }
  -    }
  +	public void doTag(XMLOutput output) throws Exception {
  +		// for use by inner classes
  +		this.output = output;
  +
  +		Stylesheet stylesheet = getStylesheet();
  +		stylesheet.clear();
  +
  +		// run the body to add the rules
  +		getBody().run(context, output);
  +		stylesheet.setModeName(getMode());
  +
  +		if (var != null) {
  +			context.setVariable(var, stylesheet);
  +		} 
  +        else {
  +			Object source = getSource();
  +
  +			if (log.isDebugEnabled()) {
  +				log.debug("About to evaluate stylesheet on source: " + source);
  +			}
  +
  +			stylesheet.run(source);
  +		}
  +	}
       
       
       // Properties
  @@ -167,13 +160,57 @@
           this.mode = mode;
       }   
   
  -    /** Sets the source on which the stylesheet will run
  +    public Stylesheet getStylesheet() {
  +        if ( stylesheet == null ) {
  +            stylesheet = createStylesheet();
  +        }
  +        return stylesheet;
  +    }
  +    
  +    /** 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;
  +    }
  +    
  +    // Implementation methods
  +    //-------------------------------------------------------------------------       
        
  +
  +    /** @return the source on which the stylesheet should run
        */
  -    public void setSource(Object source) {
  -        this.source = source;
  +    protected Object getSource() throws Exception {
  +        Object source = getXPathContext();
  +        if ( select != null ) {
  +            return select.evaluate(source);
  +        }
  +        return source;
       }    
       
  -    public Stylesheet getStylesheet() {
  -        return stylesheet;
  +    
  +    /**
  +     * Factory method to create a new stylesheet 
  +     */
  +    protected Stylesheet createStylesheet() {
  +        // add default actions
  +        Stylesheet answer = new Stylesheet();
  +        answer.setValueOfAction( 
  +            new Action() {
  +                public void run(Node node) throws Exception {                    
  +                    String text = node.getStringValue();
  +                    if ( text != null && text.length() > 0 ) {
  +                        // #### should use an 'output' property
  +                        // when this variable gets reused
  +                        output.write( text );
  +                    }
  +                }
  +            }
  +        );                    
  +        return answer;
       }
  +        
   }
  
  
  
  1.3       +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/JSLTagLibrary.java
  
  Index: JSLTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/JSLTagLibrary.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JSLTagLibrary.java	30 May 2002 11:03:20 -0000	1.2
  +++ JSLTagLibrary.java	18 Jun 2002 12:30:10 -0000	1.3
  @@ -97,6 +97,7 @@
       
       public JSLTagLibrary() {
           registerTag("stylesheet", StylesheetTag.class);
  +        registerTag("style", StyleTag.class);
           registerTag("template", TemplateTag.class);
           registerTag("applyTemplates", ApplyTemplatesTag.class);
           registerTag("valueOf", ExprTag.class);
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/StyleTag.java
  
  Index: StyleTag.java
  ===================================================================
  /*
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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", "Tomcat", 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/>.
   *
   */
  package org.apache.commons.jelly.tags.jsl;
  
  import org.apache.commons.jelly.JellyContext;
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.XMLOutput;
  import org.apache.commons.jelly.tags.xml.XPathTagSupport;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  import org.dom4j.rule.Stylesheet;
  
  import org.jaxen.XPath;
  
  /** 
   * This tag performs a JSL stylesheet which was previously
   * created via an &lt;stylesheet&gt; tag.
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class StyleTag extends XPathTagSupport {
  
      /** The Log to which logging calls will be made. */
      private Log log = LogFactory.getLog(StyleTag.class);
  
      
      /** Holds the stylesheet which will be applied to the source context. */
      private Stylesheet stylesheet;
      
      /** The XPath expression to evaluate. */    
      private XPath select;
      
      public StyleTag() {
      }
          
  	// Tag interface
  	//-------------------------------------------------------------------------           
        
  	public void doTag(XMLOutput output) throws Exception {
  		Stylesheet stylesheet = getStylesheet();
  		if (stylesheet == null) {
  			throw new MissingAttributeException("stylesheet");
  		}
          
          Object source = getSource();            
  		if (log.isDebugEnabled()) {
  			log.debug("About to evaluate stylesheet on source: " + source);
  		}
  
  		stylesheet.run(source);
  	}
      
      
      // Properties
      //-------------------------------------------------------------------------        
       
      
      public Stylesheet getStylesheet() {
          return stylesheet;
      }
  
      /**
       * Sets the stylesheet to use to style this tags body
       */
      public void setStylesheet(Stylesheet stylesheet) {
          this.stylesheet = stylesheet;
      }    
      
      /** Sets the XPath expression to evaluate. */
      public void setSelect(XPath select) {
          this.select = select;
      }
      
      // Implementation methods
      //-------------------------------------------------------------------------        
       
  
      /** @return the source on which the stylesheet should run
       */
      protected Object getSource() throws Exception {
          Object source = getXPathContext();
          if ( select != null ) {
              return select.evaluate(source);
          }
          return source;
      }    
  }
  
  
  
  1.2       +24 -9     jakarta-commons-sandbox/jelly/src/script/makeTagDoc.jelly
  
  Index: makeTagDoc.jelly
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/script/makeTagDoc.jelly,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- makeTagDoc.jelly	18 Jun 2002 08:37:02 -0000	1.1
  +++ makeTagDoc.jelly	18 Jun 2002 12:30:10 -0000	1.2
  @@ -1,9 +1,28 @@
   <?xml version="1.0"?>
  -<j:jelly xmlns:j="jelly:core" xmlns:x="jelly:xml">
  +<j:jelly 
  +	xmlns:j="jelly:core" 
  +	xmlns:x="jelly:xml" 
  +	xmlns:jsl="jelly:jsl" 
  +	xmlns:log="jelly:log">
   
   <x:parse var="doc" xml="target/javadoc.xml"/>
   <x:set var="packages" select="$doc/javadoc/package[class/implements/interfaceref/@name
= 'org.apache.commons.jelly.Tag']"/>    	
   
  +<!-- lets create a JSL stylesheet that we'll use later -->
  +<jsl:stylesheet var="docStylesheet">
  +
  +  <!-- don't output <doc> element but output its contents -->
  +  <jsl:template match="doc">
  +  	<jsl:applyTemplates/>	
  +  </jsl:template>
  +
  +  <!-- ignore javadoc tags-->
  +  <jsl:template match="authortag"/>
  +  <jsl:template match="versiontag"/>
  +
  +  <!-- let other text and elements pass through via default rules-->
  +</jsl:stylesheet>
  +
   <document>
   
       <properties>
  @@ -39,10 +58,8 @@
       <x:set var="name" select="string(@name)"/>
       <tr>
         <td><a href="#${name}">${name}</a></td>
  -      	
  -	  <!-- #### should use <x:copyOf> -->      		
         <td>
  -      	<x:copyOf select="doc/*|doc/text()"/>
  +      	  <jsl:style stylesheet="${docStylesheet}" select="doc"/>
   	  </td>
       </tr>
       </x:forEach>
  @@ -59,14 +76,12 @@
         <th>Description</th>
       </tr>
       
  -    <x:forEach select="class[@extensiblity!='abstract' and implements/interfaceref/@name
= 'org.apache.commons.jelly.Tag']">
  +    <x:forEach select="class[@extensibility!='abstract' and implements/interfaceref/@name
= 'org.apache.commons.jelly.Tag']">
       <x:set var="tagName" select="string(@name)"/>
   	<tr>
       	<td><a href="#${tagName}">${tagName}</a></td>
  -        <td>
  -        
  -	  	  <!-- #### should use <x:copyOf> -->      		
  -      	  <x:copyOf select="doc/*|doc/text()"/>
  +        <td>        
  +      	  <jsl:style stylesheet="${docStylesheet}" select="doc"/>
   		</td>
   	</tr>
       </x:forEach>
  
  
  
  1.6       +1 -0      jakarta-commons-sandbox/jelly/xdocs/navigation.xml
  
  Index: navigation.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/xdocs/navigation.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- navigation.xml	30 May 2002 18:26:19 -0000	1.5
  +++ navigation.xml	18 Jun 2002 12:30:10 -0000	1.6
  @@ -9,6 +9,7 @@
         <item name="Overview"                href="/index.html"/>
         <item name="FAQ"                     href="/faq.html"/>
         <item name="Detail"                  href="/overview.html"/>
  +      <item name="Tags"                    href="/tags.html"/>
         <item name="Download"                href="/dist/"/>
         <item name="To Do List"              href="/todo.html"/>
       </menu>
  
  
  
  1.8       +6 -5      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java
  
  Index: SetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/xml/SetTag.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SetTag.java	17 May 2002 15:18:13 -0000	1.7
  +++ SetTag.java	18 Jun 2002 12:30:10 -0000	1.8
  @@ -119,6 +119,7 @@
       public void setVar(String var) {
           this.var = var;
       }
  +    
       /** Sets the XPath expression to evaluate. */
       public void setSelect(XPath select) {
           this.select = select;
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message