diff options
author | slomo <steve.harrison@gmx.net> | 2011-01-22 13:31:32 +0100 |
---|---|---|
committer | slomo <steve.harrison@gmx.net> | 2011-01-22 13:31:32 +0100 |
commit | 1a37a20fd94a60ce686a6f1e11534b504b2e2308 (patch) | |
tree | ee9d83cbcccab110a981615a3e6ac3cba83caaae /src/nodejs | |
parent | 35778e6742567d38d349ca358cc5068cc0db1232 (diff) | |
download | osm-xapi-1a37a20fd94a60ce686a6f1e11534b504b2e2308.tar.gz osm-xapi-1a37a20fd94a60ce686a6f1e11534b504b2e2308.tar.xz osm-xapi-1a37a20fd94a60ce686a6f1e11534b504b2e2308.zip |
the xml output works now
Diffstat (limited to '')
-rw-r--r-- | src/nodejs/main.js | 28 | ||||
-rw-r--r-- | src/nodejs/response.js | 37 | ||||
-rw-r--r-- | src/nodejs/xmlGenerator.js | 53 |
3 files changed, 78 insertions, 40 deletions
diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 1928f28..2c4cb26 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -43,11 +43,24 @@ function rowToNode(row){ 'version': row.version, 'changeset': row.changeset_id, 'lat' : row.lat, - 'lon' : row.lon - } + 'lon' : row.lon, + }; + + if(row.tags != '{}') { + node.tags = []; + // FIXME: something doesnt work at all + temp = row.tags.replace("{","").replace("}","").split(","); + for(var x=0;x<temp.length;x=x+2){ + node.tags.push({ + 'k' : temp[x], + 'v' : temp[x+1] + }); + } + } return node; } +//FIXME: parsing of ways is meesed up function rowToWay(row){ var way = { 'id' : row.id, @@ -55,6 +68,17 @@ function rowToWay(row){ 'version' : row.version, 'changeset' : row.changeset_id }; + if(row.tags != '{}') { + node.tags = []; + // FIXME: something doesnt work at all + temp = row.tags.replace("{","").replace("}","").split(","); + for(var x=0;x<temp.length;x=x+2){ + node.tags.push({ + 'k' : temp[x], + 'v' : temp[x+1] + }); + } + } return way; } diff --git a/src/nodejs/response.js b/src/nodejs/response.js index 47fb170..45dcc89 100644 --- a/src/nodejs/response.js +++ b/src/nodejs/response.js @@ -1,3 +1,5 @@ +var xmlGen = require('./xmlGenerator'); +// FIXME: this is a total mess exports.mkJsonRes = function mkJsonRes(res){ res.started = false; res.atStart = function (){ @@ -29,7 +31,40 @@ exports.mkJsonRes = function mkJsonRes(res){ } exports.mkXmlRes = function (res){ - return exports.mkJsonRes(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(pojo); + } + 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; } diff --git a/src/nodejs/xmlGenerator.js b/src/nodejs/xmlGenerator.js index 08ea833..921056d 100644 --- a/src/nodejs/xmlGenerator.js +++ b/src/nodejs/xmlGenerator.js @@ -8,50 +8,29 @@ var log4js = require('log4js')(); //note the need to call the function var log = log4js.getLogger('xmlGenerator'); log.setLevel(config.logLevel); -function toISO8601(date) { - //2007-03-31T00:09:22+01:00 - var pad_two = function(n) { - return (n < 10 ? '0' : '') + n; - }; +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); - return [ - date.getUTCFullYear(), - '-', - pad_two(date.getUTCMonth() + 1), - '-', - pad_two(date.getUTCDate()), - 'T', - pad_two(date.getUTCHours()), - ':', - pad_two(date.getUTCMinutes()), - ':', - pad_two(date.getUTCSeconds()), - '+01:00' //FIX ME - ].join(''); -} - -exports.createNode = function (row) { - log.debug(row); - var node = builder.begin('node') - .att('id', row.id) - .att('timestamp', toISO8601(row.tstamp)) - .att('version', row.version) - .att('changeset', row.changeset_id) - .att('lat', row.lat) - .att('lon', row.lon); - if(row.tags != '{}') { - var temp = row.tags.replace("{","").replace("}","").split(","); - for(var x=0;x<temp.length;x=x+2){ - node.ele('tag') - .att('k',escape(temp[x])) - .att('v',escape(temp[x+1])); + if(node.tags) { + var tags = node.tags; + for(var x=0;x<tags.length;x=x+2){ + xmlNode.ele('tag') + .att('k',escape(tags[x])) + .att('v',escape(tags[x+1])); } } return builder.toString({ pretty: true }); }; +// FIXME: make this shit working exports.createWay = function (row) { - var temp; var way = builder.begin('way') .att('id', row.id) .att('timestamp', toISO8601(row.tstamp)) |