Package org.openstreetmap.josm.io
Class GpxParser
- java.lang.Object
-
- org.xml.sax.helpers.DefaultHandler
-
- org.openstreetmap.josm.io.GpxParser
-
- All Implemented Interfaces:
org.xml.sax.ContentHandler,org.xml.sax.DTDHandler,org.xml.sax.EntityResolver,org.xml.sax.ErrorHandler
class GpxParser extends org.xml.sax.helpers.DefaultHandler
A parser for gpx files
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classGpxParser.State
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilderaccumulatorprivate GpxExtensionCollectioncurrentExtensionCollectionprivate GpxLinkcurrentLinkprivate GpxRoutecurrentRouteprivate GpxParser.StatecurrentStateprivate java.util.Collection<IGpxTrackSegment>currentTrackprivate java.util.Map<java.lang.String,java.lang.Object>currentTrackAttrprivate GpxExtensionCollectioncurrentTrackExtensionCollectionprivate java.util.Collection<WayPoint>currentTrackSegprivate WayPointcurrentWayPointprivate GpxDatadataprivate java.util.Stack<java.lang.String[]>elementsprivate booleannokiaSportsTrackerBugprivate java.util.Stack<GpxParser.State>statesprivate java.lang.Stringversion
-
Constructor Summary
Constructors Constructor Description GpxParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcharacters(char[] ch, int start, int length)private static voidconvertUrlToLink(java.util.Map<java.lang.String,java.lang.Object> attr)convert url/urlname to link element (GPX 1.0 → GPX 1.1).voidendDocument()voidendElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)private voidendElementAuthor(java.lang.String localName)End the author elementprivate voidendElementCopyright(java.lang.String localName)End the copyright elementprivate voidendElementDefault(java.lang.String localName)End the default elementprivate voidendElementExt(java.lang.String localName, java.lang.String qName)End an ext elementprivate voidendElementLink(java.lang.String localName)End a link elementprivate voidendElementMetadata(java.lang.String localName)End the metadata elementprivate voidendElementTrk(java.lang.String localName)End a trk elementprivate voidendElementTrkseg(java.lang.String localName)End a trkseg elementprivate voidendElementWpt(java.lang.String localName)End a wpt elementprivate java.util.Optional<java.util.Map<java.lang.String,java.lang.Object>>getAttr()Get the current attributes(package private) GpxDatagetData()Get the parsedGpxDataprivate static doubleparseCoordinates(java.lang.String s)Convert a string coordinate to a doubleprivate static doubleparseCoordinates(org.xml.sax.Attributes attributes, java.lang.String key)Convert the specified key's value to a numberprivate static LatLonparseLatLon(org.xml.sax.Attributes attributes)Convert coordinates in attributes to aLatLonobjectvoidstartDocument()voidstartElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)private voidstartElementAuthor(java.lang.String localName, org.xml.sax.Attributes attributes)Start an author elementprivate voidstartElementExt(java.lang.String namespaceURI, java.lang.String qName, org.xml.sax.Attributes attributes)Start an ext elementprivate voidstartElementGpx(java.lang.String localName, org.xml.sax.Attributes attributes)Start the root gpx elementprivate voidstartElementInit(org.xml.sax.Attributes attributes)Start the root elementprivate voidstartElementMetadata(java.lang.String localName, org.xml.sax.Attributes attributes)Start a metadata elementprivate voidstartElementRte(java.lang.String localName, org.xml.sax.Attributes attributes)Start the rte elementprivate voidstartElementTrk(java.lang.String localName, org.xml.sax.Attributes attributes)Start a trk elementprivate voidstartElementTrkSeg(java.lang.String localName, org.xml.sax.Attributes attributes)Start a trkseg elementprivate voidstartElementWpt(java.lang.String localName, org.xml.sax.Attributes attributes)Start the wpt elementvoidstartPrefixMapping(java.lang.String prefix, java.lang.String uri)(package private) voidtryToFinish()Attempt to finish parsing
-
-
-
Field Detail
-
version
private java.lang.String version
-
currentTrack
private java.util.Collection<IGpxTrackSegment> currentTrack
-
currentTrackAttr
private java.util.Map<java.lang.String,java.lang.Object> currentTrackAttr
-
currentTrackSeg
private java.util.Collection<WayPoint> currentTrackSeg
-
currentRoute
private GpxRoute currentRoute
-
currentWayPoint
private WayPoint currentWayPoint
-
currentState
private GpxParser.State currentState
-
currentLink
private GpxLink currentLink
-
currentExtensionCollection
private GpxExtensionCollection currentExtensionCollection
-
currentTrackExtensionCollection
private GpxExtensionCollection currentTrackExtensionCollection
-
states
private final java.util.Stack<GpxParser.State> states
-
elements
private final java.util.Stack<java.lang.String[]> elements
-
accumulator
private java.lang.StringBuilder accumulator
-
nokiaSportsTrackerBug
private boolean nokiaSportsTrackerBug
-
-
Constructor Detail
-
GpxParser
GpxParser()
-
-
Method Detail
-
startDocument
public void startDocument()
- Specified by:
startDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
startDocumentin classorg.xml.sax.helpers.DefaultHandler
-
startPrefixMapping
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
- Specified by:
startPrefixMappingin interfaceorg.xml.sax.ContentHandler- Overrides:
startPrefixMappingin classorg.xml.sax.helpers.DefaultHandler
-
parseCoordinates
private static double parseCoordinates(org.xml.sax.Attributes attributes, java.lang.String key)
Convert the specified key's value to a number- Parameters:
attributes- The attributes to get the value fromkey- The key to use- Returns:
- A valid double, or
Double.NaN
-
parseCoordinates
private static double parseCoordinates(java.lang.String s)
Convert a string coordinate to a double- Parameters:
s- The string to convert to double- Returns:
- A valid double, or
Double.NaN
-
parseLatLon
private static LatLon parseLatLon(org.xml.sax.Attributes attributes)
Convert coordinates in attributes to aLatLonobject- Parameters:
attributes- The attributes to parse- Returns:
- The
LatLon, warning: it may be invalid, useLatLon.isValid()
-
startElement
public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
startElementin interfaceorg.xml.sax.ContentHandler- Overrides:
startElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
startElementInit
private void startElementInit(org.xml.sax.Attributes attributes)
Start the root element- Parameters:
attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
-
startElementGpx
private void startElementGpx(java.lang.String localName, org.xml.sax.Attributes attributes)
Start the root gpx element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
-
startElementMetadata
private void startElementMetadata(java.lang.String localName, org.xml.sax.Attributes attributes)
Start a metadata element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- See Also:
endElementMetadata(String)
-
startElementAuthor
private void startElementAuthor(java.lang.String localName, org.xml.sax.Attributes attributes)
Start an author element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- See Also:
endElementAuthor(String)
-
startElementTrk
private void startElementTrk(java.lang.String localName, org.xml.sax.Attributes attributes)
Start a trk element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- See Also:
endElementTrk(String)
-
startElementTrkSeg
private void startElementTrkSeg(java.lang.String localName, org.xml.sax.Attributes attributes)
Start a trkseg element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- See Also:
endElementTrkseg(String)
-
startElementWpt
private void startElementWpt(java.lang.String localName, org.xml.sax.Attributes attributes)
Start the wpt element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.- See Also:
endElementWpt(String)
-
startElementRte
private void startElementRte(java.lang.String localName, org.xml.sax.Attributes attributes)
Start the rte element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
-
startElementExt
private void startElementExt(java.lang.String namespaceURI, java.lang.String qName, org.xml.sax.Attributes attributes)
Start an ext element- Parameters:
namespaceURI- The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.qName- The qualified name (with prefix), or the empty string if qualified names are not available.attributes- The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
-
characters
public void characters(char[] ch, int start, int length)
- Specified by:
charactersin interfaceorg.xml.sax.ContentHandler- Overrides:
charactersin classorg.xml.sax.helpers.DefaultHandler
-
getAttr
private java.util.Optional<java.util.Map<java.lang.String,java.lang.Object>> getAttr()
Get the current attributes- Returns:
- The current attributes, if available
-
endElement
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName) throws org.xml.sax.SAXException
- Specified by:
endElementin interfaceorg.xml.sax.ContentHandler- Overrides:
endElementin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
endElementMetadata
private void endElementMetadata(java.lang.String localName)
End the metadata element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
startElementMetadata(String, Attributes)
-
endElementAuthor
private void endElementAuthor(java.lang.String localName)
End the author element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
startElementAuthor(String, Attributes)
-
endElementCopyright
private void endElementCopyright(java.lang.String localName)
End the copyright element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endElementLink
private void endElementLink(java.lang.String localName)
End a link element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endElementWpt
private void endElementWpt(java.lang.String localName) throws org.xml.sax.SAXException
End a wpt element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- Throws:
org.xml.sax.SAXException- If a waypoint does not have valid coordinates- See Also:
startElementWpt(String, Attributes)
-
endElementTrkseg
private void endElementTrkseg(java.lang.String localName)
End a trkseg element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
startElementTrkSeg(String, Attributes)
-
endElementTrk
private void endElementTrk(java.lang.String localName)
End a trk element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
startElementTrk(String, Attributes)
-
endElementExt
private void endElementExt(java.lang.String localName, java.lang.String qName)
End an ext element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.qName- The qualified name (with prefix), or the empty string if qualified names are not available.- See Also:
startElementExt(String, String, Attributes)
-
endElementDefault
private void endElementDefault(java.lang.String localName)
End the default element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endDocument
public void endDocument() throws org.xml.sax.SAXException
- Specified by:
endDocumentin interfaceorg.xml.sax.ContentHandler- Overrides:
endDocumentin classorg.xml.sax.helpers.DefaultHandler- Throws:
org.xml.sax.SAXException
-
convertUrlToLink
private static void convertUrlToLink(java.util.Map<java.lang.String,java.lang.Object> attr)
convert url/urlname to link element (GPX 1.0 → GPX 1.1).- Parameters:
attr- attributes
-
tryToFinish
void tryToFinish() throws org.xml.sax.SAXException
Attempt to finish parsing- Throws:
org.xml.sax.SAXException- If there are additional parsing errors
-
-