use of org.javarosa.core.model.osm.OSMTag 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.OSMTag 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);
}
use of org.javarosa.core.model.osm.OSMTag in project javarosa by opendatakit.
the class QuestionDef method readExternal.
@Override
public void readExternal(DataInputStream dis, PrototypeFactory pf) throws IOException, DeserializationException {
try {
setID(ExtUtil.readInt(dis));
binding = (IDataReference) ExtUtil.read(dis, new ExtWrapNullable(new ExtWrapTagged()), pf);
setAppearanceAttr((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setTextID((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setLabelInnerText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setHelpText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setHelpTextID((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setHelpInnerText((String) ExtUtil.read(dis, new ExtWrapNullable(String.class), pf));
setControlType(ExtUtil.readInt(dis));
additionalAttributes = ExtUtil.readAttributes(dis, null);
choices = (List<SelectChoice>) ExtUtil.nullIfEmpty((List<SelectChoice>) ExtUtil.read(dis, new ExtWrapList(SelectChoice.class), pf));
for (int i = 0; i < getNumChoices(); i++) {
choices.get(i).setIndex(i);
}
setDynamicChoices((ItemsetBinding) ExtUtil.read(dis, new ExtWrapNullable(ItemsetBinding.class)));
osmTags = (List<OSMTag>) ExtUtil.nullIfEmpty((List<OSMTag>) ExtUtil.read(dis, new ExtWrapList(OSMTag.class), pf));
} catch (OutOfMemoryError e) {
throw new DeserializationException("serialization format change caused misalignment and out-of-memory error");
}
}
Aggregations