PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/sitebricks/src/main/java/com/google/sitebricks/compiler/AnnotationNode.java

http://github.com/dhanji/sitebricks
Java | 58 lines | 32 code | 9 blank | 17 comment | 0 complexity | 4754b245ada999a4d8be9ac57b46d26a MD5 | raw file
 1package com.google.sitebricks.compiler;
 2
 3import org.jsoup.nodes.Node;
 4import org.jsoup.nodes.TextNode;
 5
 6/**
 7 Based on jsoup.nodes.TextNode by Jonathan Hedley, jonathan@hedley.net
 8 AnnotationNode is for Sitebricks text annotations such as
 9 @Repeat(...)  or @ShowIf(true)<div ... />
10 */
11public class AnnotationNode extends TextNode {
12    static final String ANNOTATION_KEY = "_annokey";
13    static final String ANNOTATION_CONTENT = "_annocontent";
14    static final String ANNOTATION = "_annotation";
15
16    /**
17     Create a new AnnotationNode representing the supplied (unencoded) text).
18
19     @param annotation raw text
20     @param baseUri base uri
21     @see #createFromEncoded(String, String)
22     */
23    public AnnotationNode(String annotation, String baseUri) {
24        super(annotation, baseUri);
25        this.annotation(annotation);
26    }
27
28    public AnnotationNode(String annotation) {
29        super(annotation, "");
30        this.annotation(annotation);
31    }
32  
33    public String nodeName() {
34        return "#annotation";
35    }
36
37    /**
38     * Set the annotation of this node.
39     * @param annotation raw annotation
40     * @return this, for chaining
41     */
42    public AnnotationNode annotation(String annotation) {
43        this.attr(ANNOTATION, annotation);
44        String[] kc = AnnotationParser.extractKeyAndContent(annotation);
45        this.attr(ANNOTATION_KEY, kc[0]);
46        this.attr(ANNOTATION_CONTENT, kc[1]);
47        return this;
48    }
49
50    public Node apply (Node annotate) {
51        annotate.attr(ANNOTATION, this.attr(ANNOTATION));
52        annotate.attr(ANNOTATION_KEY, this.attr(ANNOTATION_KEY));
53        annotate.attr(ANNOTATION_CONTENT, this.attr(ANNOTATION_CONTENT));
54
55        return annotate;
56    }
57
58}