Coverage report

  %line %branch
org.apache.commons.jelly.impl.StaticTag
45% 
82% 

 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.impl;
 17  
 
 18  
 import org.apache.commons.jelly.DynaTagSupport;
 19  
 import org.apache.commons.jelly.JellyTagException;
 20  
 import org.apache.commons.jelly.XMLOutput;
 21  
 
 22  
 import org.xml.sax.SAXException;
 23  
 import org.xml.sax.helpers.AttributesImpl;
 24  
 
 25  
 /**
 26  
  * <p><code>StaticTag</code> represents a static XML element
 27  
  * which echos itself to XMLOutput when it is invoked.</p>
 28  
  *
 29  
  * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 30  
  * @version $Revision: 155420 $
 31  
  */
 32  
 
 33  
 public class StaticTag extends DynaTagSupport {
 34  
 
 35  
     /** The namespace URI */
 36  
     private String uri;
 37  
 
 38  
     /** The qualified name */
 39  
     private String qname;
 40  
 
 41  
     /** The local name */
 42  
     private String localName;
 43  
 
 44  
     /** The XML Attributes */
 45  403
     private AttributesImpl attributes = new AttributesImpl();
 46  
 
 47  0
     public StaticTag() {
 48  0
     }
 49  
 
 50  403
     public StaticTag(String uri, String localName, String qname) {
 51  403
         this.uri = uri;
 52  403
         this.localName = localName;
 53  403
         this.qname = qname;
 54  403
     }
 55  
 
 56  
     public String toString() {
 57  0
         return super.toString() + "[qname=" + qname + ";attributes=" + attributes + "]";
 58  
     }
 59  
 
 60  
     // Tag interface
 61  
     //-------------------------------------------------------------------------
 62  
     public void doTag(XMLOutput output) throws JellyTagException {
 63  
         try {
 64  156
             output.startElement(uri, localName, qname, attributes);
 65  156
             invokeBody(output);
 66  156
             output.endElement(uri, localName, qname);
 67  0
         } catch (SAXException e) {
 68  0
             throw new JellyTagException(e);
 69  156
         }
 70  156
     }
 71  
 
 72  
     // DynaTag interface
 73  
     //-------------------------------------------------------------------------
 74  
     public void setAttribute(String name, Object value) throws JellyTagException {
 75  
         // ### we'll assume that all attributes are in no namespace!
 76  
         // ### this is severely limiting!
 77  
         // ### - Tag attributes should allow for namespace aware
 78  104
         int index = attributes.getIndex("", name);
 79  104
         if (index >= 0) {
 80  0
             attributes.removeAttribute(index);
 81  
         }
 82  
         // treat null values as no attribute
 83  104
         if (value != null) {
 84  104
             attributes.addAttribute("", name, name, "CDATA", value.toString());
 85  
         }
 86  104
     }
 87  
 
 88  
     // Properties
 89  
     //-------------------------------------------------------------------------
 90  
     public String getUri() {
 91  156
         return uri;
 92  
     }
 93  
 
 94  
     public void setUri(String uri) {
 95  0
         this.uri = uri;
 96  0
     }
 97  
 
 98  
     public String getQName() {
 99  0
         return qname;
 100  
     }
 101  
 
 102  
     public void setQName(String qname) {
 103  0
         this.qname = qname;
 104  0
         int idx = qname.indexOf(':');
 105  0
         if (idx >= 0) {
 106  0
             this.localName = qname.substring(idx + 1);
 107  0
         }
 108  
         else {
 109  0
             this.localName = qname;
 110  
         }
 111  0
     }
 112  
 
 113  
     public String getLocalName() {
 114  0
         return localName;
 115  
     }
 116  
 
 117  
     public void setLocalName(String localName) {
 118  0
         this.localName = localName;
 119  
         // FIXME This just doesn't seem right or work...
 120  0
         if (qname == null || !qname.endsWith(localName)) {
 121  0
             localName = qname;
 122  
         }
 123  0
     }
 124  
 }

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