Coverage report

  %line %branch
org.apache.commons.jelly.tags.jsl.ApplyTemplatesTag
73% 
100% 

 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.TagSupport;
 20  
 import org.apache.commons.jelly.XMLOutput;
 21  
 import org.apache.commons.logging.Log;
 22  
 import org.apache.commons.logging.LogFactory;
 23  
 import org.dom4j.rule.Stylesheet;
 24  
 import org.jaxen.XPath;
 25  
 
 26  
 /**
 27  
  * Implements the apply templates function in the stylesheet, similar to the XSLT equivalent.
 28  
  * a JSP include.
 29  
  *
 30  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 31  
  * @version $Revision: 155420 $
 32  
  */
 33  
 public class ApplyTemplatesTag extends TagSupport {
 34  
 
 35  
     /** The Log to which logging calls will be made. */
 36  39
     private Log log = LogFactory.getLog(ApplyTemplatesTag.class);
 37  
 
 38  
     /** Holds value of property mode. */
 39  
     private String mode;
 40  
 
 41  
     /** Holds the XPath object */
 42  
     private XPath select;
 43  
 
 44  
 
 45  27
     public ApplyTemplatesTag() {
 46  27
     }
 47  
 
 48  
     // Tag interface
 49  
     //-------------------------------------------------------------------------
 50  
     /** By default just evaluate the body */
 51  
     public void doTag(XMLOutput output) throws JellyTagException {
 52  33
         StylesheetTag tag = (StylesheetTag) findAncestorWithClass( StylesheetTag.class );
 53  33
         if (tag == null) {
 54  0
             throw new JellyTagException(
 55  
                 "<applyTemplates> tag must be inside a <stylesheet> tag"
 56  
             );
 57  
         }
 58  33
         Stylesheet stylesheet = tag.getStylesheet();
 59  
 
 60  33
         XMLOutput oldOutput = tag.getStylesheetOutput();
 61  33
         tag.setStylesheetOutput(output);
 62  
 
 63  33
         Object source = tag.getXPathSource();
 64  
         // for some reason, these DOM4J methods only throw Exception
 65  
         try {
 66  33
             if ( select != null ) {
 67  0
                 stylesheet.applyTemplates( source, select, mode );
 68  
             }
 69  
             else {
 70  33
                 stylesheet.applyTemplates( source, mode );
 71  
             }
 72  
         }
 73  0
         catch (Exception e) {
 74  0
             throw new JellyTagException(e);
 75  33
         }
 76  
 
 77  33
         tag.setStylesheetOutput(oldOutput);
 78  
 
 79  
         // #### should support MODE!!!
 80  
 
 81  33
     }
 82  
 
 83  
     // Properties
 84  
     //-------------------------------------------------------------------------
 85  
 
 86  
     public void setSelect( XPath select ) {
 87  0
         this.select = select;
 88  0
     }
 89  
 
 90  
     /** Sets the mode.
 91  
      * @param mode New value of property mode.
 92  
      */
 93  
     public void setMode(String mode) {
 94  3
         this.mode = mode;
 95  3
     }
 96  
 }

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