You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/08/12 21:10:38 UTC

cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl StylesheetTag.java ApplyTemplatesTag.java TemplateTag.java JSLTagSupport.java

jstrachan    2002/08/12 12:10:36

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/jsl
                        StylesheetTag.java ApplyTemplatesTag.java
                        TemplateTag.java
  Removed:     jelly/src/java/org/apache/commons/jelly/tags/jsl
                        JSLTagSupport.java
  Log:
  Patched the JSL implementation so that it no longer relies on the old Tag caching mechanism. Now JSL works whether Tag caching is enabled or disabled.
  
  Revision  Changes    Path
  1.6       +26 -13    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StylesheetTag.java	26 Jun 2002 09:24:36 -0000	1.5
  +++ StylesheetTag.java	12 Aug 2002 19:10:36 -0000	1.6
  @@ -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.XPathSource;
   import org.apache.commons.jelly.tags.xml.XPathTagSupport;
   
   import org.apache.commons.logging.Log;
  @@ -80,7 +81,7 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class StylesheetTag extends XPathTagSupport {
  +public class StylesheetTag extends XPathTagSupport implements XPathSource {
   
       /** The Log to which logging calls will be made. */
       private Log log = LogFactory.getLog(StylesheetTag.class);
  @@ -92,15 +93,15 @@
       /** Holds value of property mode. */
       private String mode;    
   
  -    /** store the current output instance for use by inner classes */
  -    private XMLOutput output;
  -
       /** The variable which the stylesheet will be output as */
       private String var;
           
       /** The XPath expression to evaluate. */    
       private XPath select;
       
  +    /** The XPath source used by TemplateTag and ApplyTemplatesTag to pass XPath contexts */
  +    private Object xpathSource;
  +    
       public StylesheetTag() {
       }
           
  @@ -112,15 +113,22 @@
           getStylesheet().addRule( rule );
       }
       
  +    // XPathSource interface
  +    //-------------------------------------------------------------------------                    
  +
  +    /**
  +     * @return the current XPath iteration value
  +     *  so that any other XPath aware child tags to use
  +     */
  +    public Object getXPathSource() {
  +        return xpathSource;
  +    }
  +    
       
       // Tag interface
       //-------------------------------------------------------------------------                    
   	public void doTag(XMLOutput output) throws Exception {
  -		// for use by inner classes
  -		this.output = output;
  -
  -		Stylesheet stylesheet = getStylesheet();
  -		stylesheet.clear();
  +		stylesheet = createStylesheet(output);
   
   		// run the body to add the rules
   		invokeBody(output);
  @@ -161,9 +169,6 @@
       }   
   
       public Stylesheet getStylesheet() {
  -        if ( stylesheet == null ) {
  -            stylesheet = createStylesheet();
  -        }
           return stylesheet;
       }
       
  @@ -195,7 +200,7 @@
       /**
        * Factory method to create a new stylesheet 
        */
  -    protected Stylesheet createStylesheet() {
  +    protected Stylesheet createStylesheet(final XMLOutput output) {
           // add default actions
           Stylesheet answer = new Stylesheet();
           answer.setValueOfAction( 
  @@ -213,4 +218,12 @@
           return answer;
       }
           
  +    /**
  +     * Sets the xpathSource.
  +     * @param xpathSource The xpathSource to set
  +     */
  +    void setXPathSource(Object xpathSource) {
  +        this.xpathSource = xpathSource;
  +    }
  +
   }
  
  
  
  1.3       +14 -6     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java
  
  Index: ApplyTemplatesTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/ApplyTemplatesTag.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ApplyTemplatesTag.java	22 Jun 2002 15:53:27 -0000	1.2
  +++ ApplyTemplatesTag.java	12 Aug 2002 19:10:36 -0000	1.3
  @@ -59,8 +59,12 @@
   
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
  +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.rule.Stylesheet;
   
   import org.jaxen.XPath;
  @@ -72,8 +76,11 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class ApplyTemplatesTag extends JSLTagSupport {
  +public class ApplyTemplatesTag extends TagSupport {
   
  +    /** The Log to which logging calls will be made. */
  +    private Log log = LogFactory.getLog(ApplyTemplatesTag.class);
  +    
       /** Holds value of property mode. */
       private String mode;    
   
  @@ -88,18 +95,19 @@
       //------------------------------------------------------------------------- 
       /** By default just evaluate the body */
       public void doTag(XMLOutput output) throws Exception {
  -        Stylesheet stylesheet = getStylesheet();        
  -        if ( stylesheet == null ) {
  +        StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class );
  +        if (tag == null) {
               throw new JellyException( 
                   "<applyTemplates> tag must be inside a <stylesheet> tag"
               );
           }
  -        Object context = getXPathContext();
  +        Stylesheet stylesheet = tag.getStylesheet();                
  +        Object source = tag.getXPathSource();
           if ( select != null ) {
  -            stylesheet.applyTemplates( context, select );
  +            stylesheet.applyTemplates( source, select );
           }
           else {
  -            stylesheet.applyTemplates( context );
  +            stylesheet.applyTemplates( source );
           }
           
           // #### should support MODE!!!
  
  
  
  1.5       +10 -46    jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/TemplateTag.java
  
  Index: TemplateTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/jsl/TemplateTag.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TemplateTag.java	26 Jun 2002 09:24:36 -0000	1.4
  +++ TemplateTag.java	12 Aug 2002 19:10:36 -0000	1.5
  @@ -60,8 +60,8 @@
   
   import org.apache.commons.jelly.JellyContext;
   import org.apache.commons.jelly.JellyException;
  +import org.apache.commons.jelly.TagSupport;
   import org.apache.commons.jelly.XMLOutput;
  -import org.apache.commons.jelly.tags.xml.XPathSource;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -77,7 +77,7 @@
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  -public class TemplateTag extends JSLTagSupport implements XPathSource {
  +public class TemplateTag extends TagSupport {
   
       /** The Log to which logging calls will be made. */
       private Log log = LogFactory.getLog(TemplateTag.class);
  @@ -92,18 +92,9 @@
       /** Holds value of property priority. */
       private double priority;
       
  -    /** Holds value of property rule. */
  -    private Rule rule;    
  -
  -    /** Holds value of property action. */
  -    private Action action;
  -
       /** The pattern to match */
       private Pattern match;
       
  -    /** store the current output instance for use by inner classes */
  -    private XMLOutput output;
  -
       /** The source XPath context for any child tags */
       private Object xpathSource;
       
  @@ -114,9 +105,6 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws Exception {
  -        // for use by inner classes
  -        this.output = output;
  -        
           StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class );
           if (tag == null) {
               throw new JellyException( "This <template> tag must be used inside a <stylesheet> tag" );
  @@ -126,7 +114,7 @@
               log.debug( "adding template rule for match: " + match );
           }
           
  -        Rule rule = getRule();
  +        Rule rule = createRule(tag, output);
           if ( rule != null && tag != null) {
               rule.setMode( mode );
               tag.addTemplate( rule );
  @@ -181,23 +169,6 @@
       }
       
       
  -    /** Getter for property action.
  -     * @return Value of property action.
  -     */
  -    public Action getAction() {
  -        if ( action == null ) {
  -            action = createAction();
  -        }
  -        return action;
  -    }
  -    
  -    /** Sets the action.
  -     * @param action New value of property action.
  -     */
  -    public void setAction(Action action) {
  -        this.action = action;
  -    }
  -    
       /** Sets the mode.
        * @param mode New value of property mode.
        */
  @@ -205,27 +176,20 @@
           this.mode = mode;
       }
       
  -    /** Getter for property rule.
  -     * @return Value of property rule.
  -     */
  -    public Rule getRule() {
  -        if ( rule == null ) {
  -            rule = createRule();
  -        }
  -        return rule;
  -    }
  -    
  -    
       
       // Implementation methods
       //------------------------------------------------------------------------- 
  -    protected Rule createRule() {
  -        return new Rule( match, getAction() );
  +    protected Rule createRule(StylesheetTag tag, XMLOutput output) {
  +        return new Rule( match, createAction(tag, output) );
       }
       
  -    protected Action createAction() {
  +    protected Action createAction(final StylesheetTag tag, final XMLOutput output) {
           return new Action() {
               public void run(Node node) throws Exception {
  +                
  +                // store the context for use by applyTemplates tag
  +                tag.setXPathSource( node );
  +                
                   xpathSource = node;
       
                   if (log.isDebugEnabled()) {
  
  
  

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