use of org.javarosa.core.model.osm.OSMTagItem in project javarosa by opendatakit.
the class XFormParser method parseOsmTags.
/**
* Parses the OSM Tag Elements when we are parsing
* an OSM Upload element.
*/
private List<OSMTag> parseOsmTags(Element e) {
List<OSMTag> tags = new ArrayList<>();
int childCount = e.getChildCount();
for (int i = 0; i < childCount; ++i) {
Object child = e.getChild(i);
if (child instanceof Element) {
Element childEl = (Element) child;
String name = childEl.getName();
// the child elements we are interested in are tags
if (name.equals("tag")) {
OSMTag tag = new OSMTag();
tags.add(tag);
// parse tag key
int attrCount = childEl.getAttributeCount();
for (int j = 0; j < attrCount; ++j) {
String attrName = childEl.getAttributeName(j);
if (attrName.equals("key")) {
tag.key = childEl.getAttributeValue(j);
// parse tag children
int tagChildCount = childEl.getChildCount();
for (int k = 0; k < tagChildCount; ++k) {
Object child2 = childEl.getChild(k);
if (child2 instanceof Element) {
Element tagChildEl = (Element) child2;
String tagChildName = tagChildEl.getName();
// a tag child might be a label
if (tagChildName.equals("label")) {
tag.label = tagChildEl.getText(0);
} else // a tag child might be an item
if (tagChildName.equals("item")) {
OSMTagItem item = new OSMTagItem();
tag.items.add(item);
// parse item children
int itemChildCount = tagChildEl.getChildCount();
for (int l = 0; l < itemChildCount; ++l) {
Object child3 = tagChildEl.getChild(l);
if (child3 instanceof Element) {
Element itemChildEl = (Element) child3;
String itemChildName = itemChildEl.getName();
// an item child might be a label
if (itemChildName.equals("label")) {
item.label = itemChildEl.getText(0);
} else // an item child might be a value
if (itemChildName.equals("value")) {
item.value = itemChildEl.getText(0);
}
}
}
}
}
}
}
}
}
}
}
return tags;
}
use of org.javarosa.core.model.osm.OSMTagItem in project collect by opendatakit.
the class OSMWidget method writeOsmRequiredTagsToExtras.
/**
* See: https://github.com/AmericanRedCross/openmapkit/wiki/ODK-Collect-Tag-Intent-Extras
*/
private void writeOsmRequiredTagsToExtras(Intent intent) {
ArrayList<String> tagKeys = new ArrayList<>();
for (OSMTag tag : osmRequiredTags) {
tagKeys.add(tag.key);
if (tag.label != null) {
intent.putExtra("TAG_LABEL." + tag.key, tag.label);
}
ArrayList<String> tagValues = new ArrayList<>();
if (tag.items != null) {
for (OSMTagItem item : tag.items) {
tagValues.add(item.value);
if (item.label != null) {
intent.putExtra("TAG_VALUE_LABEL." + tag.key + "." + item.value, item.label);
}
}
}
intent.putStringArrayListExtra("TAG_VALUES." + tag.key, tagValues);
}
intent.putStringArrayListExtra("TAG_KEYS", tagKeys);
}
Aggregations