001: /*
002: Copyright (C) 2003 Together
003:
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008:
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013:
014: You should have received a copy of the GNU Lesser General Public
015: License along with this library; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.enhydra.xml;
020:
021: import org.w3c.dom.Comment;
022: import org.w3c.dom.DOMException;
023: import org.w3c.dom.Node;
024:
025: /**
026: * @author Tweety
027: *
028: * A class representing a node in a meta-data tree, which implements
029: * the <a href="../../../../api/org/w3c/dom/Comment.html">
030: *
031: * <p> Namespaces are ignored in this implementation. The terms "tag
032: * name" and "node name" are always considered to be synonymous.
033: *
034: * @version 1.0
035: */
036: public class CommentImpl extends CharacterDataImpl implements Comment {
037:
038: /**
039: * Constructs a <code>CommentImpl</code> from the given node.
040: *
041: * @param node , as a <code>CommentImpl</code>.
042: */
043: public CommentImpl(CommentImpl node) {
044: super ((NodeImpl) node);
045: }
046:
047: /**
048: * Constructs a <code>CommentImpl</code> from the given node value.
049: *
050: * @param value , as a <code>String</code>.
051: */
052: public CommentImpl(String value) {
053: nodeValue = value;
054: type = Node.COMMENT_NODE;
055: }
056:
057: /**
058: * Constructs a <code>CommentImpl</code> from a given node,
059: * as a <code>Node</code>
060: *
061: * @param node , as <code>Node</code>.
062: */
063: public CommentImpl(Node node) {
064: super (node);
065: }
066:
067: /**
068: * Returns the node type.
069: *
070: * @return the <code>COMMENT_NODE</code> node type.
071: */
072: public short getNodeType() {
073: return Node.COMMENT_NODE;
074: }
075:
076: /**
077: * Returns the name ("#comment") associated with this node.
078: *
079: * @return the name, as a <code>String</code>.
080: */
081: public String getNodeName() {
082: return "#comment";
083: }
084:
085: /**
086: * Method beginToString for this class writes the xml
087: * comment prefix string and the comment string.
088: *
089: * @param sb string buffer to add resulting string.
090: * @param indent used in formating the output.
091: */
092: protected void beginToString(StringBuffer sb, Indent indent) {
093: sb.append("\n" + indent + "<!-- " + this .nodeValue.trim());
094: }
095:
096: /**
097: * Method endToString writes the xml comment postfix string.
098: * @param sb represents StringBuffer
099: * @param indent is indent
100: */
101: protected void endToString(StringBuffer sb, Indent indent) {
102: sb.append(" -->");
103: }
104:
105: }
|