use of org.openstreetmap.osmosis.tagtransform.Output 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.Output in project osmosis by openstreetmap.
the class TransformHelper method processEntityContainer.
/**
* Transforms entity container according to configFile.
*
* @param entityContainer
* The entity to be processed.
* @return transformed (if needed) entityContainer
*/
protected EntityContainer processEntityContainer(EntityContainer entityContainer) {
// Entities may have been made read-only at some point in the pipeline.
// We want a writeable instance so that we can update the tags.
EntityContainer writeableEntityContainer = entityContainer.getWriteableInstance();
Entity entity = entityContainer.getEntity();
Collection<Tag> entityTags = entity.getTags();
EntityType entityType = entity.getType();
// Store the tags in a map keyed by tag key.
Map<String, String> tagMap = new HashMap<String, String>();
for (Tag tag : entity.getTags()) {
tagMap.put(tag.getKey(), tag.getValue());
}
// Apply tag transformations.
for (Translation translation : translations) {
Collection<Match> matches = translation.match(tagMap, TTEntityType.fromEntityType06(entityType), entity.getUser().getName(), entity.getUser().getId());
if (matches == null || matches.isEmpty()) {
continue;
}
if (translation.isDropOnMatch()) {
return null;
}
Map<String, String> newTags = new HashMap<String, String>();
for (Output output : translation.getOutputs()) {
output.apply(tagMap, newTags, matches, translation.getDataSources());
}
tagMap = newTags;
}
// Replace the entity tags with the transformed values.
entityTags.clear();
for (Entry<String, String> tag : tagMap.entrySet()) {
entityTags.add(new Tag(tag.getKey(), tag.getValue()));
}
return writeableEntityContainer;
}
Aggregations