use of org.openstreetmap.osmosis.tagtransform.DataSource in project osmosis by openstreetmap.
the class TransformLoader method parseTranslation.
private Translation parseTranslation(File parentDir, Element element) {
String name = "";
String description = "";
Matcher matcher = null;
Matcher finder = null;
List<Output> output = new ArrayList<>();
Map<String, DataSource> dataSources = Collections.emptyMap();
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element)) {
continue;
}
Element child = (Element) children.item(i);
String nodeName = child.getNodeName();
if (nodeName.equals("name")) {
name = child.getTextContent();
} else if (nodeName.equals("description")) {
description = child.getTextContent();
} else if (nodeName.equals("match")) {
matcher = parseMatcher(child);
} else if (nodeName.equals("find")) {
finder = parseMatcher(child);
} else if (nodeName.equals("data")) {
dataSources = parseDataSources(parentDir, child);
} else if (nodeName.equals("output")) {
NodeList outputs = child.getChildNodes();
for (int j = 0; j < outputs.getLength(); j++) {
if (!(outputs.item(j) instanceof Element)) {
continue;
}
Output o = parseOutput((Element) outputs.item(j));
if (o != null) {
output.add(o);
}
}
}
}
if (matcher != null) {
LOG.info("New translation: " + name);
return new TranslationImpl(name, description, matcher, finder, dataSources, output);
} else {
return null;
}
}
use of org.openstreetmap.osmosis.tagtransform.DataSource in project osmosis by openstreetmap.
the class TagOutput method apply.
@Override
public void apply(Map<String, String> originalTags, Map<String, String> tags, Collection<Match> matches, Map<String, DataSource> dataSources) {
// each and every matching match
if (fromMatch != null) {
DataSource keyDataSourceImpl = this.keyDataSource != null && dataSources.containsKey(this.keyDataSource) ? dataSources.get(this.keyDataSource) : dummyDataSource;
DataSource valueDataSourceImpl = this.valueDataSource != null && dataSources.containsKey(this.valueDataSource) ? dataSources.get(this.valueDataSource) : dummyDataSource;
for (Match match : matches) {
String matchID = match.getMatchID();
if (matchID != null && matchID.equals(fromMatch)) {
// process key args
String[] args = new String[match.getKeyGroupCount()];
for (int i = 0; i < args.length; i++) {
args[i] = match.getKey(i);
}
String key = keyFormat.format(keyDataSourceImpl.transform(args));
// process value args
args = new String[match.getValueGroupCount()];
for (int i = 0; i < args.length; i++) {
args[i] = match.getValue(i);
}
String value = valueFormat.format(valueDataSourceImpl.transform(args));
// put the tag
tags.put(key, value);
}
}
} else {
// simple case
tags.put(keyFormat.format(null), valueFormat.format(null));
}
}
use of org.openstreetmap.osmosis.tagtransform.DataSource in project osmosis by openstreetmap.
the class TransformLoader method parseDataSources.
private Map<String, DataSource> parseDataSources(File parentDir, Element parent) {
NodeList children = parent.getChildNodes();
Map<String, DataSource> dataSources = new HashMap<>();
for (int i = 0; i < children.getLength(); i++) {
if (!(children.item(i) instanceof Element)) {
continue;
}
Element child = (Element) children.item(i);
String name = child.getNodeName();
if (name.equals("source")) {
DataSource ds;
String id = child.getAttribute("source_id");
try {
ds = DataSources.valueOf(child.getAttribute("type")).create(parentDir, child.getAttributes());
dataSources.put(id, ds);
} catch (IllegalArgumentException ex) {
Logger.getLogger(DataSourceCSV.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return dataSources;
}
Aggregations