aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/client/model/StateReader.java
blob: a3549179df0f7cf1bf72cb486986554703c0aefc (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
package org.traccar.web.client.model;

import java.util.LinkedList;
import java.util.List;

import org.traccar.web.shared.model.Position;
import org.traccar.web.shared.model.XmlParser;

import com.google.gwt.i18n.client.DateTimeFormat;

public class StateReader {

    private static String toString(Object object) {
        if (object != null) {
            return object.toString();
        }
        return null;
    }

    public static List<StateItem> getState(Position position) {
        List<StateItem> state = new LinkedList<StateItem>();

        state.add(new StateItem("valid", toString(position.getValid())));
        state.add(new StateItem("time", DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss").format(position.getTime())));
        state.add(new StateItem("latitude", toString(position.getLatitude())));
        state.add(new StateItem("longitude", toString(position.getLongitude())));
        state.add(new StateItem("altitude", toString(position.getAltitude())));
        state.add(new StateItem("speed", toString(position.getSpeed())));
        state.add(new StateItem("course", toString(position.getCourse())));
        state.add(new StateItem("power", toString(position.getPower())));
        state.add(new StateItem("address", position.getAddress()));

        String other = position.getOther();
        if (other != null) {
            for (String key : XmlParser.enumerateElements(other)) {
                state.add(new StateItem(key, XmlParser.getElement(other, key)));
            }
        }

        return state;
    }

}