summaryrefslogtreecommitdiffstats
path: root/server/src/org/jsoup/nodes/Comment.java
blob: 6abe0e3066fe29fdae8431e24541524a098f74d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.jsoup.nodes;

/**
 * A comment node.
 * 
 * @author Jonathan Hedley, jonathan@hedley.net
 */
public class Comment extends Node {
    private static final String COMMENT_KEY = "comment";

    /**
     * Create a new comment node.
     * 
     * @param data
     *            The contents of the comment
     * @param baseUri
     *            base URI
     */
    public Comment(String data, String baseUri) {
        super(baseUri);
        attributes.put(COMMENT_KEY, data);
    }

    @Override
    public String nodeName() {
        return "#comment";
    }

    /**
     * Get the contents of the comment.
     * 
     * @return comment content
     */
    public String getData() {
        return attributes.get(COMMENT_KEY);
    }

    @Override
    void outerHtmlHead(StringBuilder accum, int depth,
            Document.OutputSettings out) {
        if (out.prettyPrint()) {
            indent(accum, depth, out);
        }
        accum.append("<!--").append(getData()).append("-->");
    }

    @Override
    void outerHtmlTail(StringBuilder accum, int depth,
            Document.OutputSettings out) {
    }

    @Override
    public String toString() {
        return outerHtml();
    }
}