aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs/response.js
blob: 9a92c66f8707d41f520521a79819189aa403a3d8 (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
68
69
70
var xmlGen = require('./xmlGenerator');
// FIXME: this is a total mess
exports.mkJsonRes = function mkJsonRes(res){
    res.started = false;
    res.atStart = function (){ 
        if(!this.started){
            this.writeHead(200);
            this.write('json start start');
            this.started = true;
        }   
    }   
    res.atEnd = function(){
        if(!this.started){
            this.atStart(pojo);
        }   
        this.write('json enden');
        this.end();
    }   
    res.putNode = function (pojo){
        if(!this.started){
            this.atStart(pojo);
        }   
        this.write(JSON.stringify(pojo));
    }   

    res.endWith500 = function(){
        this.writeHead(500);
        this.end();
    }   
    return res;
}

exports.mkXmlRes = function (res){
    res.started = false;
    res.atStart = function (){ 
        if(!this.started){
            this.writeHead(200);
            this.write('<xml>');
            this.started = true;
        }   
    }   
    res.atEnd = function(){
        if(!this.started){
            this.atStart();
        }   
        this.write('</xml>');
        this.end();
    }   
    res.putWay = function (pojo){
        if(!this.started){
            this.atStart(pojo);
        }   
        this.write(xmlGen.createWay(pojo));
    }   

    res.putNode = function (pojo){
        if(!this.started){
            this.atStart(pojo);
        }   
        this.write(xmlGen.createNode(pojo));
    }   

    res.endWith500 = function(){
        this.writeHead(500);
        this.end();
    }   
    return res;
}