aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/core/stanza_attribute.vala
blob: 3169e90e8e4543b05176f3abcfc7d5e550312216 (plain) (blame)
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
namespace Xmpp.Core {
public class StanzaAttribute : StanzaEntry {

    public StanzaAttribute() {}

    public StanzaAttribute.build(string ns_uri, string name, string val) {
        this.ns_uri = ns_uri;
        this.name = name;
        this.val = val;
    }

    public string to_string() {
        if (ns_uri == null) {
            return @"$name='$val'";
        } else {
            return @"{$ns_uri}:$name='$val'";
        }
    }

    public string to_xml(NamespaceState? state_) throws XmlError {
        NamespaceState state = state_ ?? new NamespaceState();
        if (ns_uri == state.current_ns_uri || (ns_uri == XMLNS_URI && name == "xmlns")) {
            return @"$name='$val'";
        } else {
            return "%s:%s='%s'".printf (state.find_name (ns_uri), name, val);
        }
    }
}
}