All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marklogic.spark.reader.file.xml.UriElementExtractingVisitor Maven / Gradle / Ivy

There is a newer version: 2.4.2
Show newest version
/*
 * Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
 */
package com.marklogic.spark.reader.file.xml;

import com.marklogic.client.datamovement.XMLSplitter;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.StringHandle;

import javax.xml.stream.XMLStreamReader;

/**
 * Supports extracting a URI element value for each aggregate element.
 */
class UriElementExtractingVisitor extends XMLSplitter.BasicElementVisitor {

    private final String uriNamespace;
    private final String uriElement;

    UriElementExtractingVisitor(String nsUri, String localName, String uriNamespace, String uriElement) {
        super(nsUri, localName);
        this.uriNamespace = uriNamespace;
        this.uriElement = uriElement;
    }

    @Override
    public StringHandle makeBufferedHandle(XMLStreamReader xmlStreamReader) {
        UriElementExtractingReader reader = new UriElementExtractingReader(xmlStreamReader, uriNamespace, uriElement);
        String content = serialize(reader);
        String uriValue = reader.getUriValue();
        return new StringHandleWithUriValue(content, uriValue).withFormat(Format.XML);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy