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 2004/09/08 06:50:26 UTC

cvs commit: jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl TemplateTag.java StyleTag.java StylesheetTag.java JellyStylesheet.java

dion        2004/09/07 21:50:26

  Modified:    jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl
                        TemplateTag.java StyleTag.java StylesheetTag.java
                        JellyStylesheet.java
  Log:
  detab
  
  Revision  Changes    Path
  1.14      +38 -38    jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/TemplateTag.java
  
  Index: TemplateTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/TemplateTag.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TemplateTag.java	25 Feb 2004 01:32:00 -0000	1.13
  +++ TemplateTag.java	8 Sep 2004 04:50:26 -0000	1.14
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -27,9 +27,9 @@
   import org.dom4j.rule.Pattern;
   import org.dom4j.rule.Rule;
   
  -/** 
  +/**
    * This tag represents a declarative matching rule, similar to the template tag in XSLT.
  - * 
  + *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision$
    */
  @@ -37,40 +37,40 @@
   
       /** The Log to which logging calls will be made. */
       private Log log = LogFactory.getLog(TemplateTag.class);
  -    
  +
   
       /** Holds value of property name. */
       private String name;
  -    
  +
       /** Holds value of property mode. */
  -    private String mode;    
  -    
  +    private String mode;
  +
       /** Holds value of property priority. */
       private double priority;
  -    
  +
       /** The pattern to match */
       private Pattern match;
  -    
  +
       /** The source XPath context for any child tags */
       private Object xpathSource;
  -    
  -    
  +
  +
       public TemplateTag() {
       }
   
  -    
  +
       // Tag interface
  -    //------------------------------------------------------------------------- 
  +    //-------------------------------------------------------------------------
       public void doTag(XMLOutput output) throws JellyTagException {
           StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class );
           if (tag == null) {
               throw new JellyTagException( "This <template> tag must be used inside a <stylesheet> tag" );
           }
   
  -        if ( log.isDebugEnabled() ) {        
  +        if ( log.isDebugEnabled() ) {
               log.debug( "adding template rule for match: " + match );
           }
  -        
  +
           Rule rule = createRule(tag, output);
           if ( rule != null && tag != null) {
               rule.setMode( mode );
  @@ -79,7 +79,7 @@
       }
   
       // XPathSource interface
  -    //-------------------------------------------------------------------------                    
  +    //-------------------------------------------------------------------------
   
       /**
        * @return the current XPath value on which relative paths are evaluated
  @@ -87,78 +87,78 @@
       public Object getXPathSource() {
           return xpathSource;
       }
  -    
  +
   
       // Properties
  -    //-------------------------------------------------------------------------                
  +    //-------------------------------------------------------------------------
   
       public void setMatch(Pattern match) {
           this.match = match;
       }
  -    
  +
       /** Getter for property priority.
        * @return Value of property priority.
        */
       public double getPriority() {
           return priority;
       }
  -    
  +
       /** Sets the priority.
        * @param priority New value of property priority.
        */
       public void setPriority(double priority) {
           this.priority = priority;
       }
  -    
  +
       /** Getter for property name.
        * @return Value of property name.
        */
       public String getName() {
           return name;
       }
  -    
  +
       /** Sets the name.
        * @param name New value of property name.
        */
       public void setName(String name) {
           this.name = name;
       }
  -    
  -    
  +
  +
       /** Sets the mode.
        * @param mode New value of property mode.
        */
       public void setMode(String mode) {
           this.mode = mode;
       }
  -    
  -    
  +
  +
       // Implementation methods
  -    //------------------------------------------------------------------------- 
  +    //-------------------------------------------------------------------------
       protected Rule createRule(StylesheetTag tag, XMLOutput output) {
           return new Rule( match, createAction(tag, output) );
       }
  -    
  +
       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()) {
  -                    log.debug( "Firing template body for match: " + match + " and node: " + node );          
  +                    log.debug( "Firing template body for match: " + match + " and node: " + node );
                   }
  -                
  +
                   XMLOutput actualOutput = tag.getStylesheetOutput();
                   if (actualOutput == null) {
  -                	actualOutput = output;
  +                    actualOutput = output;
                   }
  -                
  +
                   invokeBody(actualOutput);
               }
  -        };                    
  +        };
       }
   }
  
  
  
  1.9       +35 -35    jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/StyleTag.java
  
  Index: StyleTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/StyleTag.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StyleTag.java	25 Feb 2004 01:32:00 -0000	1.8
  +++ StyleTag.java	8 Sep 2004 04:50:26 -0000	1.9
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -25,7 +25,7 @@
   import org.jaxen.JaxenException;
   import org.jaxen.XPath;
   
  -/** 
  +/**
    * This tag performs a JSL stylesheet which was previously
    * created via an &lt;stylesheet&gt; tag.
    *
  @@ -37,46 +37,46 @@
       /** 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. */    
  +
  +    /** The XPath expression to evaluate. */
       private XPath select;
  -    
  +
       public StyleTag() {
       }
  -        
  -	// Tag interface
  -	//-------------------------------------------------------------------------                    
  -	public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
  -		Stylesheet stylesheet = getStylesheet();
  -		if (stylesheet == null) {
  -			throw new MissingAttributeException("stylesheet");
  -		}
  +
  +    // Tag interface
  +    //-------------------------------------------------------------------------
  +    public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
  +        Stylesheet stylesheet = getStylesheet();
  +        if (stylesheet == null) {
  +            throw new MissingAttributeException("stylesheet");
  +        }
   
           if (stylesheet instanceof JellyStylesheet) {
  -			JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  -			jellyStyle.setOutput(output);
  -		}
  -        
  +            JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  +            jellyStyle.setOutput(output);
  +        }
  +
           // dom4j only seems to throw Exception
           try {
  -        	Object source = getSource();            
  -			if (log.isDebugEnabled()) {
  -				log.debug("About to evaluate stylesheet on source: " + source);
  -			}
  +            Object source = getSource();
  +            if (log.isDebugEnabled()) {
  +                log.debug("About to evaluate stylesheet on source: " + source);
  +            }
   
  -			stylesheet.run(source);
  +            stylesheet.run(source);
           } catch (Exception e) {
               throw new JellyTagException(e);
           }
  -	}
  -    
  -    
  +    }
  +
  +
       // Properties
  -    //-------------------------------------------------------------------------                
  -    
  +    //-------------------------------------------------------------------------
  +
       public Stylesheet getStylesheet() {
           return stylesheet;
       }
  @@ -86,15 +86,15 @@
        */
       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
        */
  @@ -104,5 +104,5 @@
               return select.evaluate(source);
           }
           return source;
  -    }    
  +    }
   }
  
  
  
  1.14      +81 -81    jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/StylesheetTag.java
  
  Index: StylesheetTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/StylesheetTag.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- StylesheetTag.java	25 Feb 2004 01:32:00 -0000	1.13
  +++ StylesheetTag.java	8 Sep 2004 04:50:26 -0000	1.14
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -27,8 +27,8 @@
   import org.jaxen.XPath;
   
   
  -/** 
  - * This tag implements a JSL stylesheet which is similar to an 
  +/**
  + * This tag implements a JSL stylesheet which is similar to an
    * XSLT stylesheet but can use Jelly tags inside it
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
  @@ -39,56 +39,56 @@
       /** 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;
  -    
  +
       /** Holds value of property mode. */
  -    private String mode;    
  +    private String mode;
   
       /** The variable which the stylesheet will be output as */
       private String var;
  -        
  -    /** The XPath expression to evaluate. */    
  +
  +    /** 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() {
       }
  -        
   
  -	/**
  -	 * @return the XMLOutput from the stylesheet if available
  -	 */
  -	public XMLOutput getStylesheetOutput() {
  -		if (stylesheet instanceof JellyStylesheet) {
  -			JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  -			return jellyStyle.getOutput();
  -		}
  -		return null;
  -	}
  -	
  -	/**
  -	 * Sets the XMLOutput to use by the current stylesheet
  -	 */
  -	public void setStylesheetOutput(XMLOutput output) {
  -		if (stylesheet instanceof JellyStylesheet) {
  -			JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  -			jellyStyle.setOutput(output);
  -		}
  -	}
  -	
  -    /** 
  +
  +    /**
  +     * @return the XMLOutput from the stylesheet if available
  +     */
  +    public XMLOutput getStylesheetOutput() {
  +        if (stylesheet instanceof JellyStylesheet) {
  +            JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  +            return jellyStyle.getOutput();
  +        }
  +        return null;
  +    }
  +
  +    /**
  +     * Sets the XMLOutput to use by the current stylesheet
  +     */
  +    public void setStylesheetOutput(XMLOutput output) {
  +        if (stylesheet instanceof JellyStylesheet) {
  +            JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
  +            jellyStyle.setOutput(output);
  +        }
  +    }
  +
  +    /**
        * Adds a new template rule to this stylesheet
  -     */    
  +     */
       public void addTemplate( Rule rule ) {
           getStylesheet().addRule( rule );
       }
  -    
  +
       // XPathSource interface
  -    //-------------------------------------------------------------------------                    
  +    //-------------------------------------------------------------------------
   
       /**
        * @return the current XPath iteration value
  @@ -97,76 +97,76 @@
       public Object getXPathSource() {
           return xpathSource;
       }
  -    
  -    
  +
  +
       // Tag interface
  -    //-------------------------------------------------------------------------                    
  -	public void doTag(XMLOutput output) throws JellyTagException {
  -		stylesheet = createStylesheet(output);
  -
  -		// run the body to add the rules
  -		invokeBody(output);
  -		stylesheet.setModeName(getMode());
  -
  -		if (var != null) {
  -			context.setVariable(var, stylesheet);
  -		} 
  +    //-------------------------------------------------------------------------
  +    public void doTag(XMLOutput output) throws JellyTagException {
  +        stylesheet = createStylesheet(output);
  +
  +        // run the body to add the rules
  +        invokeBody(output);
  +        stylesheet.setModeName(getMode());
  +
  +        if (var != null) {
  +            context.setVariable(var, stylesheet);
  +        }
           else {
  -            
  +
               //dom4j seems to only throw generic Exceptions
               try {
  -			    Object source = getSource();
  +                Object source = getSource();
   
  -				if (log.isDebugEnabled()) {
  -					log.debug("About to evaluate stylesheet on source: " + source);
  -				}
  +                if (log.isDebugEnabled()) {
  +                    log.debug("About to evaluate stylesheet on source: " + source);
  +                }
   
  -				stylesheet.run(source);
  -            } 
  +                stylesheet.run(source);
  +            }
               catch (Exception e) {
                   throw new JellyTagException(e);
               }
  -                
  -		}
  -	}
  -    
  -    
  +
  +        }
  +    }
  +
  +
       // Properties
  -    //-------------------------------------------------------------------------                
  -    
  -    /** 
  +    //-------------------------------------------------------------------------
  +
  +    /**
        * Getter for property mode.
        * @return Value of property mode.
        */
       public String getMode() {
           return mode;
       }
  -    
  -    /** 
  +
  +    /**
        * Sets the mode.
        * @param mode New value of property mode.
        */
       public void setMode(String mode) {
           this.mode = mode;
  -    }   
  +    }
   
       public Stylesheet getStylesheet() {
           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
        */
  @@ -176,18 +176,18 @@
               return select.evaluate(source);
           }
           return source;
  -    }    
  -    
  -    
  +    }
  +
  +
       /**
  -     * Factory method to create a new stylesheet 
  +     * Factory method to create a new stylesheet
        */
       protected Stylesheet createStylesheet(final XMLOutput output) {
  -    	JellyStylesheet answer = new JellyStylesheet();
  -    	answer.setOutput(output);
  -    	return answer;
  +        JellyStylesheet answer = new JellyStylesheet();
  +        answer.setOutput(output);
  +        return answer;
       }
  -        
  +
       /**
        * Sets the xpathSource.
        * @param xpathSource The xpathSource to set
  
  
  
  1.4       +30 -30    jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/JellyStylesheet.java
  
  Index: JellyStylesheet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/jelly/jelly-tags/jsl/src/java/org/apache/commons/jelly/tags/jsl/JellyStylesheet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JellyStylesheet.java	25 Feb 2004 01:32:00 -0000	1.3
  +++ JellyStylesheet.java	8 Sep 2004 04:50:26 -0000	1.4
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -24,7 +24,7 @@
   import org.dom4j.rule.Action;
   import org.dom4j.rule.Stylesheet;
   
  -/** 
  +/**
    * This class is a specialization of the Stylesheet from dom4j's rule engine
    * that adds some Jelly specific features.
    *
  @@ -36,38 +36,38 @@
       /** The Log to which logging calls will be made. */
       private Log log = LogFactory.getLog(JellyStylesheet.class);
   
  -	private XMLOutput output;
  -	
  -	public JellyStylesheet() {
  -        setValueOfAction( 
  +    private XMLOutput output;
  +
  +    public JellyStylesheet() {
  +        setValueOfAction(
               new Action() {
  -                public void run(Node node) throws Exception {                    
  +                public void run(Node node) throws Exception {
                       String text = node.getStringValue();
                       if ( text != null && text.length() > 0 ) {
                           getOutput().write( text );
                       }
                   }
               }
  -        );                    
  -	}
  -	
  -	// Properties
  -    //------------------------------------------------------------------------- 
  -	 
  -	/**
  -	 * Returns the output.
  -	 * @return XMLOutput
  -	 */
  -	public XMLOutput getOutput() {
  -		return output;
  -	}
  -
  -	/**
  -	 * Sets the output.
  -	 * @param output The output to set
  -	 */
  -	public void setOutput(XMLOutput output) {
  -		this.output = output;
  -	}
  +        );
  +    }
  +
  +    // Properties
  +    //-------------------------------------------------------------------------
  +
  +    /**
  +     * Returns the output.
  +     * @return XMLOutput
  +     */
  +    public XMLOutput getOutput() {
  +        return output;
  +    }
  +
  +    /**
  +     * Sets the output.
  +     * @param output The output to set
  +     */
  +    public void setOutput(XMLOutput output) {
  +        this.output = output;
  +    }
   
   }
  
  
  

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