Skip to content

Commit 43f595a

Browse files
authored
Translation server now offer JOSM preset xml (#5560)
* publish JOSM preset xml from translation server * support other translation-* dir paths * make schema2json runnable from translations-local dir
1 parent b993d03 commit 43f595a

9 files changed

+171055
-36
lines changed

translations/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
script/
22
node_modules/
33
validation_mappings.json
4-
*_preset.xml
54
.nyc_output/

translations/GGDMv30_preset.xml

+42,929
Large diffs are not rendered by default.

translations/MGCP_preset.xml

+5,730
Large diffs are not rendered by default.

translations/TDSv40_preset.xml

+22,701
Large diffs are not rendered by default.

translations/TDSv61_preset.xml

+40,388
Large diffs are not rendered by default.

translations/TDSv70_preset.xml

+25,064
Large diffs are not rendered by default.

translations/TDSv71_preset.xml

+34,175
Large diffs are not rendered by default.

translations/TranslationServer.js

+28-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ if (typeof hoot === 'undefined') {
3838
// Setup the lists of schema
3939
var availableTrans = {};
4040
var availableTranslations = [];
41+
var availablePresets = {};
4142
var schemaMap = {};
4243
var fcodeLookup = {};
4344

@@ -84,6 +85,8 @@ fs.readdirSync(HOOT_HOME,{withFileTypes:true}).filter(file => file.isDirectory()
8485
{
8586
availableTrans[fmt.name] = {"isavailable":true};
8687
availableTranslations.push(fmt.name);
88+
availablePresets[fmt.name] = ((dirName !== 'translations') ? dirName : '')
89+
+ fmt.name + '_preset.xml';
8790
schemaMap[fmt.name] = require(dirName + fmt.schema);
8891

8992
// Either a "path" or "importPath" and "exportPath"
@@ -197,9 +200,15 @@ function TranslationServer(request, response) {
197200
params.method = request.method;
198201
params.path = request.path || urlbits.pathname;
199202
var result = handleInputs(params);
200-
header['Content-Type'] = 'application/json';
203+
204+
if (params.path === '/presets') {
205+
header['Content-Type'] = 'application/xml';
206+
} else {
207+
header['Content-Type'] = 'application/json';
208+
result = JSON.stringify(result);
209+
}
201210
response.writeHead(200, header);
202-
response.end(JSON.stringify(result));
211+
response.end(result);
203212
} else if (request.method === 'OPTIONS') {
204213
header["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS";
205214
header["Access-Control-Allow-Credentials"] = false;
@@ -250,8 +259,11 @@ function handleInputs(params) {
250259
case '/translations':
251260
result = getTranslations(params);
252261
break;
262+
case '/presets':
263+
result = getPresets(params);
264+
break;
253265
case '/version':
254-
result = {version: '0.0.4'};
266+
result = {version: '0.0.5'};
255267
break;
256268
default:
257269
throw new Error('Not found');
@@ -289,6 +301,19 @@ var getTranslations = function(params) {
289301
}
290302
};
291303

304+
var getPresets = function(params) {
305+
if (params.method === 'GET') {
306+
var presetFile = availablePresets[params.translation];
307+
if (fs.existsSync(presetFile)) {
308+
return fs.readFileSync(presetFile);
309+
} else {
310+
throw new Error('Not found');
311+
}
312+
} else {
313+
throw new Error('Unsupported method');
314+
}
315+
};
316+
292317
// This is where all interesting things happen interfacing with hoot core lib directly
293318
var postHandler = function(data) {
294319
if (availableTranslations.indexOf(data.translation) === -1) {

translations/schema2josmpreset.js

+40-32
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,47 @@ var crypto = require('crypto');
1313
// <?xml version="1.0" encoding="UTF-8"?>
1414
// <presets xmlns="http://josm.openstreetmap.de/tagging-preset-1.0">
1515

16+
var objs;
1617

17-
const objs = {
18-
TDSv40: {
19-
schema: tds40_schema,
20-
name: 'TDSv40',
21-
icon: 'presets/misc/nga_logo.png'
22-
},
23-
TDSv61: {
24-
schema: tds61_schema,
25-
name: 'TDSv61',
26-
icon: 'presets/misc/nga_logo.png'
27-
},
28-
TDSv70: {
29-
schema: tds70_schema,
30-
name: 'TDSv70',
31-
icon: 'presets/misc/nga_logo.png'
32-
},
33-
TDSv71: {
34-
schema: tds71_schema,
35-
name: 'TDSv71',
36-
icon: 'presets/misc/nga_logo.png'
37-
},
38-
MGCP: {
39-
schema: mgcp_schema,
40-
name: 'MGCP',
41-
icon: 'presets/misc/MGCP_logo.png'
42-
},
43-
GGDMv30: {
44-
schema: ggdm30_schema,
45-
name: 'GGDMv30',
46-
icon: 'presets/misc/usace_logo.png'
47-
}
48-
};
18+
if (process.argv.length === 3) {
19+
objs = require(process.cwd() + '/' + process.argv[2]);
20+
Object.keys(objs).forEach(s => {
21+
objs[s].schema = require(process.cwd() + '/' + objs[s].schema).getDbSchema();
22+
});
23+
} else {
24+
objs = {
25+
TDSv40: {
26+
schema: tds40_schema,
27+
name: 'TDSv40',
28+
icon: 'presets/misc/nga_logo.png'
29+
},
30+
TDSv61: {
31+
schema: tds61_schema,
32+
name: 'TDSv61',
33+
icon: 'presets/misc/nga_logo.png'
34+
},
35+
TDSv70: {
36+
schema: tds70_schema,
37+
name: 'TDSv70',
38+
icon: 'presets/misc/nga_logo.png'
39+
},
40+
TDSv71: {
41+
schema: tds71_schema,
42+
name: 'TDSv71',
43+
icon: 'presets/misc/nga_logo.png'
44+
},
45+
MGCP: {
46+
schema: mgcp_schema,
47+
name: 'MGCP',
48+
icon: 'presets/misc/MGCP_logo.png'
49+
},
50+
GGDMv30: {
51+
schema: ggdm30_schema,
52+
name: 'GGDMv30',
53+
icon: 'presets/misc/usace_logo.png'
54+
}
55+
};
56+
}
4957

5058
function lookupType(geom) {
5159
let set = new Set();

0 commit comments

Comments
 (0)