org.nlab.xml.stream.context.StreamContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xml-stream-css Show documentation
Show all versions of xml-stream-css Show documentation
Stream Xml using StAX and Css matcher
The newest version!
package org.nlab.xml.stream.context;
import java.util.stream.Stream;
import org.nlab.util.Tries;
import org.nlab.xml.stream.XmlStream;
import org.nlab.xml.stream.XmlStreamSpec;
import org.nlab.xml.stream.consumer.XmlConsumer;
import org.nlab.xml.stream.reader.XmlMatcherStreamReader;
import jodd.lagarto.dom.Document;
import jodd.lagarto.dom.Node;
/**
* Created by nlabrot on 14/12/15.
*/
public class StreamContext {
private final XmlMatcherStreamReader streamReader;
private final UserContext userContext;
private final PathContext pathContext;
private int event;
public StreamContext(XmlMatcherStreamReader streamReader, UserContext userContext, PathContext pathContext) {
this.streamReader = streamReader;
this.userContext = userContext;
this.pathContext = pathContext;
}
public int getEvent() {
return event;
}
public void setEvent(int event) {
this.event = event;
}
public XmlMatcherStreamReader getStreamReader() {
return streamReader;
}
public UserContext getUserContext() {
return userContext;
}
public PathContext getPathContext() {
return pathContext;
}
public Node getNode() {
return pathContext.getCurrentNode();
}
public String getElementText() {
return Tries.tryWithResult(() -> streamReader.getElementText());
}
public Document getDocument() {
return pathContext.getDocument();
}
public XmlStream partialStream() {
return new XmlStreamSpec(streamReader).partial().uncheckedStream();
}
public XmlConsumer partialConsumer() {
return new XmlStreamSpec(streamReader).partial().uncheckedConsumer();
}
}