1
2
3
4
5
6
7
8
9
10
11
12
13
14
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: 155420 $
30 */
31 public class CommentTag extends XPathTagSupport {
32
33 private String text;
34
35 public CommentTag() {
36 }
37
38
39
40 public void doTag(XMLOutput output) throws JellyTagException {
41 String text = getText();
42 if (text == null) {
43 text = getBodyText(false);
44 }
45 char[] ch = text.toCharArray();
46 try {
47 output.comment(ch, 0, ch.length);
48 } catch (SAXException e) {
49 throw new JellyTagException(e);
50 }
51 }
52
53
54
55 /***
56 * Returns the text.
57 * @return String
58 */
59 public String getText() {
60 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 this.text = text;
71 }
72
73 }