Coverage report

  %line %branch
org.apache.commons.jelly.tags.xml.CopyTag
0% 
0% 

 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.xml;
 17  
 
 18  
 import org.apache.commons.jelly.JellyTagException;
 19  
 import org.apache.commons.jelly.XMLOutput;
 20  
 import org.apache.commons.jelly.xpath.XPathTagSupport;
 21  
 import org.dom4j.Element;
 22  
 import org.dom4j.io.SAXWriter;
 23  
 import org.jaxen.JaxenException;
 24  
 import org.jaxen.XPath;
 25  
 import org.xml.sax.SAXException;
 26  
 
 27  
 /**
 28  
  * A tag which performs a copy operation like the XSLT tag,
 29  
  * performing a shallow copy of the element and its attributes but no content.
 30  
  *
 31  
  * @author James Strachan
 32  
  */
 33  
 public class CopyTag extends XPathTagSupport {
 34  
 
 35  
     /** The XPath expression to evaluate. */
 36  
     private XPath select;
 37  
 
 38  
     /** Should we output lexical XML data like entity names?
 39  
      */
 40  
     private boolean lexical;
 41  
 
 42  0
     public CopyTag() {
 43  0
     }
 44  
 
 45  
     // Tag interface
 46  
     //-------------------------------------------------------------------------
 47  
     public void doTag(XMLOutput output) throws JellyTagException {
 48  0
         Object xpathContext = getXPathContext();
 49  
 
 50  0
         Object node = xpathContext;
 51  
 
 52  
         try {
 53  0
             if (select != null) {
 54  0
                 node = select.selectSingleNode(xpathContext);
 55  
             }
 56  
 
 57  0
             if ( node instanceof Element ) {
 58  0
                 Element element = (Element) node;
 59  
 
 60  
                 SAXWriter saxWriter;
 61  
 
 62  0
                 if (lexical) {
 63  0
                     saxWriter = new SAXWriter(output, output);
 64  
                 } else {
 65  0
                     saxWriter = new SAXWriter(output);
 66  
                 }
 67  
 
 68  0
                 saxWriter.writeOpen(element);
 69  0
                 invokeBody(output);
 70  0
                 saxWriter.writeClose(element);
 71  
             }
 72  
             else {
 73  0
                 invokeBody(output);
 74  
             }
 75  0
         }
 76  
         catch (SAXException e) {
 77  0
             throw new JellyTagException(e);
 78  
         }
 79  
         catch (JaxenException e) {
 80  0
             throw new JellyTagException(e);
 81  
         }
 82  0
     }
 83  
 
 84  
     // Properties
 85  
     //-------------------------------------------------------------------------
 86  
     /** Sets the XPath expression to evaluate. */
 87  
     public void setSelect(XPath select) {
 88  0
         this.select = select;
 89  0
     }
 90  
     public void setLexical(boolean lexical) {
 91  0
         this.lexical = lexical;
 92  0
     }
 93  
 }

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