01: package org.enhydra.xml;
02:
03: import org.w3c.dom.Comment;
04: import org.w3c.dom.Node;
05:
06: /**
07: * @author Tweety
08: *
09: * A class representing a node in a meta-data tree, which implements
10: * the <a href="../../../../api/org/w3c/dom/Comment.html">
11: *
12: * <p> Namespaces are ignored in this implementation. The terms "tag
13: * name" and "node name" are always considered to be synonymous.
14: *
15: * @version 1.0
16: */
17: public class CommentImpl extends CharacterDataImpl implements Comment {
18:
19: /**
20: * Constructs a <code>CommentImpl</code> from the given node.
21: *
22: * @param node, as a <code>CommentImpl</code>.
23: */
24: public CommentImpl(CommentImpl node) {
25: super ((NodeImpl) node);
26: }
27:
28: /**
29: * Constructs a <code>CommentImpl</code> from the given node value.
30: *
31: * @param value, as a <code>String</code>.
32: */
33: public CommentImpl(String value) {
34: nodeValue = value;
35: type = Node.COMMENT_NODE;
36: }
37:
38: /**
39: * Constructs a <code>CommentImpl</code> from a given node,
40: * as a <code>Node</code>
41: *
42: * @param node, as <code>Node</code>.
43: */
44: public CommentImpl(Node node) {
45: super (node);
46: }
47:
48: /**
49: * Returns the node type.
50: *
51: * @return the <code>COMMENT_NODE</code> node type.
52: */
53: public short getNodeType() {
54: return Node.COMMENT_NODE;
55: }
56:
57: /**
58: * Returns the name ("#comment") associated with this node.
59: *
60: * @return the name, as a <code>String</code>.
61: */
62: public String getNodeName() {
63: return "#comment";
64: }
65:
66: /**
67: * Method beginToString for this class writes the xml
68: * comment prefix string and the comment string.
69: *
70: * @param sb string buffer to add resulting string.
71: * @param indent used in formating the output.
72: */
73: protected void beginToString(StringBuffer sb, Indent indent) {
74: sb.append("\n" + indent + "<!-- " + this .nodeValue.trim());
75: }
76:
77: /**
78: * Method endToString writes the xml comment postfix string.
79: */
80: protected void endToString(StringBuffer sb, Indent indent) {
81: sb.append(" -->");
82: }
83:
84: }
|