Coverage report

  %line %branch
org.apache.commons.jelly.tags.jsl.StyleTag
85% 
96% 

 1  
 /*
 2  
  * Copyright 2002,2004 The Apache Software Foundation.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.apache.commons.jelly.tags.jsl;
 17  
 
 18  
 import org.apache.commons.jelly.JellyTagException;
 19  
 import org.apache.commons.jelly.MissingAttributeException;
 20  
 import org.apache.commons.jelly.XMLOutput;
 21  
 import org.apache.commons.jelly.xpath.XPathTagSupport;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 import org.dom4j.rule.Stylesheet;
 25  
 import org.jaxen.JaxenException;
 26  
 import org.jaxen.XPath;
 27  
 
 28  
 /**
 29  
  * This tag performs a JSL stylesheet which was previously
 30  
  * created via an <stylesheet> tag.
 31  
  *
 32  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 33  
  * @version $Revision: 155420 $
 34  
  */
 35  
 public class StyleTag extends XPathTagSupport {
 36  
 
 37  
     /** The Log to which logging calls will be made. */
 38  18
     private Log log = LogFactory.getLog(StyleTag.class);
 39  
 
 40  
 
 41  
     /** Holds the stylesheet which will be applied to the source context. */
 42  
     private Stylesheet stylesheet;
 43  
 
 44  
     /** The XPath expression to evaluate. */
 45  
     private XPath select;
 46  
 
 47  15
     public StyleTag() {
 48  15
     }
 49  
 
 50  
     // Tag interface
 51  
     //-------------------------------------------------------------------------
 52  
     public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
 53  18
         Stylesheet stylesheet = getStylesheet();
 54  18
         if (stylesheet == null) {
 55  0
             throw new MissingAttributeException("stylesheet");
 56  
         }
 57  
 
 58  18
         if (stylesheet instanceof JellyStylesheet) {
 59  18
             JellyStylesheet jellyStyle = (JellyStylesheet) stylesheet;
 60  18
             jellyStyle.setOutput(output);
 61  
         }
 62  
 
 63  
         // dom4j only seems to throw Exception
 64  
         try {
 65  18
             Object source = getSource();
 66  18
             if (log.isDebugEnabled()) {
 67  0
                 log.debug("About to evaluate stylesheet on source: " + source);
 68  
             }
 69  
 
 70  18
             stylesheet.run(source);
 71  0
         } catch (Exception e) {
 72  0
             throw new JellyTagException(e);
 73  18
         }
 74  18
     }
 75  
 
 76  
 
 77  
     // Properties
 78  
     //-------------------------------------------------------------------------
 79  
 
 80  
     public Stylesheet getStylesheet() {
 81  18
         return stylesheet;
 82  
     }
 83  
 
 84  
     /**
 85  
      * Sets the stylesheet to use to style this tags body
 86  
      */
 87  
     public void setStylesheet(Stylesheet stylesheet) {
 88  18
         this.stylesheet = stylesheet;
 89  18
     }
 90  
 
 91  
     /** Sets the XPath expression to evaluate. */
 92  
     public void setSelect(XPath select) {
 93  12
         this.select = select;
 94  12
     }
 95  
 
 96  
     // Implementation methods
 97  
     //-------------------------------------------------------------------------
 98  
 
 99  
     /** @return the source on which the stylesheet should run
 100  
      */
 101  
     protected Object getSource() throws JaxenException {
 102  18
         Object source = getXPathContext();
 103  18
         if ( select != null ) {
 104  12
             return select.evaluate(source);
 105  
         }
 106  6
         return source;
 107  
     }
 108  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.