Class Reader
java.lang.Object
org.apache.sis.internal.storage.xml.stream.StaxStreamIO
org.apache.sis.internal.storage.xml.stream.StaxStreamReader
org.apache.sis.internal.storage.gpx.Reader
- All Implemented Interfaces:
AutoCloseable,Runnable,Spliterator<AbstractFeature>,XMLStreamConstants
Reader for GPX 1.0 and 1.1 files.
This reader is itself a spliterator over all features found in the XML file.
Usage:
- Since:
- 0.8
- Version:
- 1.0
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.Spliterator
Spliterator.OfDouble, Spliterator.OfInt, Spliterator.OfLong, Spliterator.OfPrimitive<T extends Object,T_CONS extends Object, T_SPLITR extends Spliterator.OfPrimitive<T, T_CONS, T_SPLITR>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MetadataThe metadata (ISO 19115 compatible), ornullif none.private StringThe namespace, which should be eitherTags.NAMESPACE_V10orTags.NAMESPACE_V11.private intIdentifier of the last "route" feature instance created.private intIdentifier of the last "track" feature instance created.private intIdentifier of the last "way point" feature instance created.Fields inherited from class org.apache.sis.internal.storage.xml.stream.StaxStreamReader
readerFields inherited from class org.apache.sis.internal.storage.xml.stream.StaxStreamIO
ownerFields inherited from interface java.util.Spliterator
CONCURRENT, DISTINCT, IMMUTABLE, NONNULL, ORDERED, SIZED, SORTED, SUBSIZEDFields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Personauthor()Returns theMetadata.authorfield, creating all necessary objects if needed.voidforEachRemaining(Consumer<? super AbstractFeature> action) Performs the given action for each remaining element until all elements have been processed.Returns the metadata (ISO 19115 compatible), ornullif none.initialize(boolean readMetadata) Reads the metadata.private booleanisEndGPX()Returnstrueif the current position of the given reader is the closing</gpx>tag.private booleanisGPX()Returnstrueif the current element can be considered as in the GPX namespace.private static booleanReturnstrueif the given namespace is a GPX namespace or is null.private Linklink()Returns the first element of theMetadata.linksfield, creating all necessary objects if needed.private Metadatametadata()Returns themetadatafield, creating it if needed.private booleanparse(Consumer<? super AbstractFeature> action, boolean all) Implementation oftryAdvance(Consumer)andforEachRemaining(Consumer).private AbstractFeatureparseRoute(int index) Parses a<rte>element.private AbstractFeatureparseTrack(int index) Parses a<trk>element.private AbstractFeatureparseTrackSegment(int index) Parses a<trkseg>element.private AbstractFeatureparseWayPoint(int index) Parses a<wpt>,<rtept>or<trkpt>element.booleantryAdvance(Consumer<? super AbstractFeature> action) Performs the given action on the next feature instance, or returnsnullif there are no more features to parse.Methods inherited from class org.apache.sis.internal.storage.xml.stream.StaxStreamReader
canNotParseFile, characteristics, close, endOfFile, estimateSize, getElementAsDate, getElementAsDouble, getElementAsInteger, getElementAsList, getElementAsTemporal, getElementAsURI, getElementText, getSubReader, moveToRootElement, nestedElement, next, parseBoolean, parseDouble, run, skipUntilEnd, trySplit, unmarshalMethods inherited from class org.apache.sis.internal.storage.xml.stream.StaxStreamIO
errorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Spliterator
getComparator, getExactSizeIfKnown, hasCharacteristics
-
Field Details
-
namespace
The namespace, which should be eitherTags.NAMESPACE_V10orTags.NAMESPACE_V11. We store this information for identifying the closing<gpx>tag. -
metadata
The metadata (ISO 19115 compatible), ornullif none. -
wayPointId
private int wayPointIdIdentifier of the last "way point" feature instance created. We use sequential numbers starting from 1. -
routeId
private int routeIdIdentifier of the last "route" feature instance created. We use sequential numbers starting from 1. -
trackId
private int trackIdIdentifier of the last "track" feature instance created. We use sequential numbers starting from 1.
-
-
Constructor Details
-
Reader
Creates a new GPX reader for the given data store. Theinitialize(boolean)method must be invoked after this constructor.- Parameters:
owner- the data store for which this reader is created.- Throws:
DataStoreException- if the input type is not recognized.XMLStreamException- if an error occurred while opening the XML file.IOException- if an error occurred while preparing the input stream.Exception- if another kind of error occurred while closing a previous stream.
-
-
Method Details
-
isGPX
Returnstrueif the given namespace is a GPX namespace or is null. -
isGPX
private boolean isGPX()Returnstrueif the current element can be considered as in the GPX namespace. Strictly speaking we should require the namespace URI to be exactlynamespace, but this method is a little bit more lenient. -
isEndGPX
private boolean isEndGPX()Returnstrueif the current position of the given reader is the closing</gpx>tag. The reader event should beXMLStreamConstants.END_ELEMENTbefore to invoke this method. -
initialize
public Version initialize(boolean readMetadata) throws DataStoreException, XMLStreamException, JAXBException, URISyntaxException, EOFException Reads the metadata. This method should be invoked exactly once after construction. This work is performed outside the constructor for allowingStaxStreamReader.close()method invocation no matter if thisinitialize(boolean)method fails.- Parameters:
readMetadata- iffalse, skip the reading of metadata elements.- Returns:
- the GPX file version, or
nullif no version information was found. - Throws:
DataStoreException- if the root element is not the expected one.XMLStreamException- if an error occurred while reading the XML file.JAXBException- if an error occurred while parsing GPX 1.1 metadata.ClassCastException- if an object unmarshalled by JAXB was not of the expected type.URISyntaxException- if an error occurred while parsing URI in GPX 1.0 metadata.DateTimeParseException- if a text cannot be parsed as a date.EOFException- if the file seems to be truncated.
-
metadata
Returns themetadatafield, creating it if needed. This is a convenience method for GPX 1.0 metadata parsing. This is not for returning the metadata result after parsing.- See Also:
-
author
Returns theMetadata.authorfield, creating all necessary objects if needed. This is a convenience method for GPX 1.0 metadata parsing. -
link
Returns the first element of theMetadata.linksfield, creating all necessary objects if needed. This is a convenience method for GPX 1.0 metadata parsing. -
getMetadata
Returns the metadata (ISO 19115 compatible), ornullif none. This method can return a non-null value only ifinitialize(true)has been invoked before this method.- Returns:
- the metadata, or
nullif none. - See Also:
-
tryAdvance
Performs the given action on the next feature instance, or returnsnullif there are no more features to parse.- Specified by:
tryAdvancein interfaceSpliterator<AbstractFeature>- Specified by:
tryAdvancein classStaxStreamReader- Parameters:
action- the action to perform on the next feature instances.- Returns:
trueif a feature has been found, orfalseif we reached the end of GPX file.- Throws:
BackingStoreException- if an error occurred while parsing the next feature instance. The cause may beDataStoreException,IOException,URISyntaxExceptionor variousRuntimeException.
-
forEachRemaining
Performs the given action for each remaining element until all elements have been processed.- Parameters:
action- the action to perform on the remaining feature instances.- Throws:
BackingStoreException- if an error occurred while parsing the next feature instance. The cause may beDataStoreException,IOException,URISyntaxExceptionor variousRuntimeException.
-
parse
Implementation oftryAdvance(Consumer)andforEachRemaining(Consumer).- Parameters:
action- the action to perform on the remaining feature instances.all- whether to perform the action on all remaining instances or only the next one.- Returns:
falseif this method as detected the end of<gpx>element or the end of document.- Throws:
DataStoreException- if the file contains invalid elements.XMLStreamException- if an error occurred while reading the XML file.URISyntaxException- if an error occurred while parsing GPX 1.0 URI.JAXBException- if an error occurred while parsing GPX 1.1 link.ClassCastException- if an object unmarshalled by JAXB was not of the expected type.NumberFormatException- if a text cannot be parsed as an integer or a floating point number.DateTimeParseException- if a text cannot be parsed as a date.EOFException- if the file seems to be truncated.Exception
-
parseWayPoint
Parses a<wpt>,<rtept>or<trkpt>element. The STAX reader current event must be aXMLStreamConstants.START_ELEMENT. After this method invocation, the reader will be onXMLStreamConstants.END_ELEMENT.- Throws:
Exception- see the list of exceptions documented inparse(Consumer, boolean).
-
parseRoute
Parses a<rte>element. The STAX reader current event must be aXMLStreamConstants.START_ELEMENTand the name of that start element must beTags.ROUTES.- Throws:
Exception- see the list of exceptions documented inparse(Consumer, boolean).
-
parseTrackSegment
Parses a<trkseg>element. The STAX reader current event must be aXMLStreamConstants.START_ELEMENTand the name of that start element must beTags.TRACK_SEGMENTS.- Throws:
Exception- see the list of exceptions documented inparse(Consumer, boolean).
-
parseTrack
Parses a<trk>element. The STAX reader current event must be aXMLStreamConstants.START_ELEMENTand the name of that start element must beTags.TRACKS.- Throws:
Exception- see the list of exceptions documented inparse(Consumer, boolean).
-