summaryrefslogtreecommitdiffstats
blob: abe86925657885f01541568f8a9545b574dc4895 (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
/*
* Copyright (c) 2010-2015, Isode Limited, London, England.
* All rights reserved.
*/

package com.isode.stroke.parser.payloadparsers;

import com.isode.stroke.elements.StatusShow;
import com.isode.stroke.parser.AttributeMap;
import com.isode.stroke.parser.GenericPayloadParser;

public class StatusShowParser extends GenericPayloadParser<StatusShow> {
    
    public StatusShowParser() {
        super(new StatusShow());
    }

    public void handleStartElement(String element, String ns, AttributeMap attributes) {
        ++level_;
    }
    
    public void handleEndElement(String element, String ns) {
        --level_;
        if (level_ == 0) {
            if ("away".equals(text_)) {
                getPayloadInternal().setType(StatusShow.Type.Away);
            }
            else if ("chat".equals(text_)) {
                getPayloadInternal().setType(StatusShow.Type.FFC);
            }
            else if ("xa".equals(text_)) {
                getPayloadInternal().setType(StatusShow.Type.XA);
            }
            else if ("dnd".equals(text_)) {
                getPayloadInternal().setType(StatusShow.Type.DND);
            }
            else {
                getPayloadInternal().setType(StatusShow.Type.Online);
            }
        }
    }
    
    public void handleCharacterData(String data) {
        text_ = text_ == null ? data : text_ + data;
    }

    private int level_;
    private String text_;
}