summaryrefslogtreecommitdiffstats
blob: fa1881e20dd4ba0d310aa14f44fd1c5c49a4a0c6 (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
/*
 * Copyright (c) 2010-2012, Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2010, Remko Tronçon.
 * All rights reserved.
 */
package com.isode.stroke.serializer.xml;

public class XMLTextNode implements XMLNode {

    private String text_;

    public XMLTextNode(String text) {
        text_ = text;
        text_ = text_.replaceAll("&", "&"); // Should come first
        text_ = text_.replaceAll("<", "&lt;");
        text_ = text_.replaceAll(">", "&gt;");
    }

    public String serialize() {
        return text_;
    }

    /**
     * Create new object.
     * 
     * @param text Text to create object with, must not be null
     * 
     * @return new object, will never be null
     */
    public static XMLTextNode create(String text) {
        if (text == null) {
            throw new NullPointerException("'text' must not be null");
        }

        return new XMLTextNode(text);
    }
}