%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.xml.CommentTag |
|
|
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 | ||
22 | import org.xml.sax.SAXException; |
|
23 | ||
24 | /** |
|
25 | * A tag which outputs a comment to the underlying XMLOutput based on the |
|
26 | * contents of its body. |
|
27 | * |
|
28 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
29 | * @version $Revision: 1.5 $ |
|
30 | */ |
|
31 | public class CommentTag extends XPathTagSupport { |
|
32 | ||
33 | private String text; |
|
34 | ||
35 | 3 | public CommentTag() { |
36 | 3 | } |
37 | ||
38 | // Tag interface |
|
39 | //------------------------------------------------------------------------- |
|
40 | public void doTag(XMLOutput output) throws JellyTagException { |
|
41 | 3 | String text = getText(); |
42 | 3 | if (text == null) { |
43 | 0 | text = getBodyText(false); |
44 | } |
|
45 | 3 | char[] ch = text.toCharArray(); |
46 | try { |
|
47 | 3 | output.comment(ch, 0, ch.length); |
48 | 3 | } catch (SAXException e) { |
49 | 0 | throw new JellyTagException(e); |
50 | } |
|
51 | 3 | } |
52 | ||
53 | // Properties |
|
54 | //------------------------------------------------------------------------- |
|
55 | /** |
|
56 | * Returns the text. |
|
57 | * @return String |
|
58 | */ |
|
59 | public String getText() { |
|
60 | 3 | return text; |
61 | } |
|
62 | ||
63 | /** |
|
64 | * Sets the comment text. If no text is specified then the body of the tag |
|
65 | * is used instead. |
|
66 | * |
|
67 | * @param text The comment text to use |
|
68 | */ |
|
69 | public void setText(String text) { |
|
70 | 3 | this.text = text; |
71 | 3 | } |
72 | ||
73 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |