use of io.georocket.util.XMLStartElement in project georocket by georocket.
the class MergeNamespacesStrategy method setParents.
@Override
public void setParents(List<XMLStartElement> parents) {
currentNamespaces = new ArrayList<>();
currentAttributes = new ArrayList<>();
for (XMLStartElement e : parents) {
// collect namespaces from parents
Map<String, String> nss = new LinkedHashMap<>();
currentNamespaces.add(nss);
for (int i = 0; i < e.getNamespaceCount(); ++i) {
String nsp1 = e.getNamespacePrefix(i);
String nsu1 = e.getNamespaceUri(i);
if (nsp1 == null) {
nsp1 = "";
}
nss.put(nsp1, nsu1);
}
// collect attributes from parents
Map<Pair<String, String>, String> as = new LinkedHashMap<>();
currentAttributes.add(as);
for (int i = 0; i < e.getAttributeCount(); ++i) {
String ap = e.getAttributePrefix(i);
String aln = e.getAttributeLocalName(i);
String av = e.getAttributeValue(i);
if (ap == null) {
ap = "";
}
as.put(Pair.of(ap, aln), av);
}
}
super.setParents(parents);
}
use of io.georocket.util.XMLStartElement in project georocket by georocket.
the class MergeNamespacesStrategy method mergeParents.
@Override
protected Observable<Void> mergeParents(XMLChunkMeta meta) {
if (getParents() == null) {
// no merge necessary yet, just save the chunk's parents
setParents(meta.getParents());
return Observable.just(null);
}
// merge current parents and chunk parents
List<XMLStartElement> newParents = new ArrayList<>();
boolean changed = false;
for (int i = 0; i < meta.getParents().size(); ++i) {
XMLStartElement p = meta.getParents().get(i);
Map<String, String> currentNamespaces = this.currentNamespaces.get(i);
Map<Pair<String, String>, String> currentAttributes = this.currentAttributes.get(i);
XMLStartElement newParent = mergeParent(p, currentNamespaces, currentAttributes);
if (newParent == null) {
newParent = this.getParents().get(i);
} else {
changed = true;
}
newParents.add(newParent);
}
if (changed) {
super.setParents(newParents);
}
return Observable.just(null);
}
Aggregations