aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs/xmlGenerator.js
blob: 6ba01914171a983f8335bb3ca2f146e6cfbf11dc (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var config;

var builder = require('xmlbuilder');
//set up logger
var log4js = require('log4js')(); //note the need to call the function
//log4js.addAppender(log4js.fileAppender('osm-xapi.log'), 'cheese');

var log = log4js.getLogger('xmlGenerator');
// TODO how to get log level from main's config?

exports.createNode = function (node) {
    log.debug(node);
    var xmlNode = builder.begin('node')
    .att('id', node.id)
    .att('timestamp', node.timestamp)
    .att('version', node.version)
    .att('changeset', node.changeset)
    .att('lat', node.lat)
    .att('lon', node.lon);

    if(node.tags) {
        node.tags.forEach(function(tuple){
            xmlNode.ele('tag')
            .att('k',escape(tuple.key))
            .att('v',escape(tuple.value));
        });
    }
    return builder.toString({ pretty: true });
};

// FIXME: make this shit working
exports.createWay = function (row) {
    var xmlWay = builder.begin('way')
        .att('id', row.id)
        .att('timestamp', row.timestamp)
        .att('version', row.version)
        .att('changeset', row.changeset);
        
    if(row.tags) {
        row.tags.forEach(function(tuple){
            xmlWay.ele('tag')
            .att('k',escape(tuple.key))
            .att('v',escape(tuple.value));
        });
    }
        
    //temp = row.nodes.replace("{","").replace("}","").split(",");
    //for(var i=0;i<temp.length;i++) {
    //    way.ele('nd').att('ref',temp[i]);
    //}
    return builder.toString({pretty:'true'});
};

//header for xml response with information about xapi instance...
exports.createHeader = function createHeader() {
    var header = "<?xml version='1.0' standalone='no'?>";
    var tmp = builder.begin('osm')
        .att('version',this.config.version)
        .att('generator',this.config.generator)
        .att('xmlns:xapi',this.config.namespace)
        .att('xapi:uri','')
        .att('xapi:planetDate','')
        .att('xapi:copyright',this.config.copyright)
        .att('xapi:instance',this.config.instance);
    header = header + tmp.toString();
    return header.substr(0,header.length-2) + " >";
}