Search in sources :

Example 16 with XMLStartElement

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);
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement) LinkedHashMap(java.util.LinkedHashMap) Pair(org.apache.commons.lang3.tuple.Pair)

Example 17 with XMLStartElement

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);
}
Also used : XMLStartElement(io.georocket.util.XMLStartElement) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

XMLStartElement (io.georocket.util.XMLStartElement)17 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)14 Test (org.junit.Test)13 Buffer (io.vertx.core.buffer.Buffer)7 Result (io.georocket.input.Splitter.Result)6 BufferWriteStream (io.georocket.util.io.BufferWriteStream)4 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)4 Async (io.vertx.ext.unit.Async)4 TestContext (io.vertx.ext.unit.TestContext)4 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)4 Arrays (java.util.Arrays)4 Pair (org.apache.commons.lang3.tuple.Pair)4 RunWith (org.junit.runner.RunWith)4 ChunkMeta (io.georocket.storage.ChunkMeta)2 ChunkReadStream (io.georocket.storage.ChunkReadStream)2 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)2 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)2 ArrayList (java.util.ArrayList)2 Rule (org.junit.Rule)2 Observable (rx.Observable)2