Package org.openstreetmap.josm.io
Class GpxParser
java.lang.Object
org.xml.sax.helpers.DefaultHandler
org.openstreetmap.josm.io.GpxParser
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
A parser for gpx files
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringBuilderprivate GpxExtensionCollectionprivate GpxLinkprivate GpxRouteprivate GpxParser.Stateprivate Collection<IGpxTrackSegment>private GpxExtensionCollectionprivate Collection<WayPoint>private WayPointprivate GpxDataprivate booleanprivate final Stack<GpxParser.State>private String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcharacters(char[] ch, int start, int length) private static voidconvertUrlToLink(Map<String, Object> attr) convert url/urlname to link element (GPX 1.0 → GPX 1.1).voidvoidendElement(String namespaceURI, String localName, String qName) private voidendElementAuthor(String localName) End the author elementprivate voidendElementCopyright(String localName) End the copyright elementprivate voidendElementDefault(String localName) End the default elementprivate voidendElementExt(String localName, String qName) End an ext elementprivate voidendElementLink(String localName) End a link elementprivate voidendElementMetadata(String localName) End the metadata elementprivate voidendElementTrk(String localName) End a trk elementprivate voidendElementTrkseg(String localName) End a trkseg elementprivate voidendElementWpt(String localName) End a wpt elementgetAttr()Get the current attributes(package private) GpxDatagetData()Get the parsedGpxDataprivate static doubleConvert a string coordinate to a doubleprivate static doubleparseCoordinates(Attributes attributes, String key) Convert the specified key's value to a numberprivate static LatLonparseLatLon(Attributes attributes) Convert coordinates in attributes to aLatLonobjectvoidvoidstartElement(String namespaceURI, String localName, String qName, Attributes attributes) private voidstartElementAuthor(String localName, Attributes attributes) Start an author elementprivate voidstartElementExt(String namespaceURI, String qName, Attributes attributes) Start an ext elementprivate voidstartElementGpx(String localName, Attributes attributes) Start the root gpx elementprivate voidstartElementInit(Attributes attributes) Start the root elementprivate voidstartElementMetadata(String localName, Attributes attributes) Start a metadata elementprivate voidstartElementRte(String localName, Attributes attributes) Start the rte elementprivate voidstartElementTrk(String localName, Attributes attributes) Start a trk elementprivate voidstartElementTrkSeg(String localName, Attributes attributes) Start a trkseg elementprivate voidstartElementWpt(String localName, Attributes attributes) Start the wpt elementvoidstartPrefixMapping(String prefix, String uri) (package private) voidAttempt to finish parsingMethods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
version
-
data
-
currentTrack
-
currentTrackAttr
-
currentTrackSeg
-
currentRoute
-
currentWayPoint
-
currentState
-
currentLink
-
currentExtensionCollection
-
currentTrackExtensionCollection
-
states
-
elements
-
accumulator
-
nokiaSportsTrackerBug
-
-
Constructor Details
-
GpxParser
-
-
Method Details
-
startDocument
- Specified by:
startDocumentin interfaceContentHandler- Overrides:
startDocumentin classDefaultHandler
-
startPrefixMapping
- Specified by:
startPrefixMappingin interfaceContentHandler- Overrides:
startPrefixMappingin classDefaultHandler
-
parseCoordinates
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
Convert a string coordinate to a double- Parameters:
s- The string to convert to double- Returns:
- A valid double, or
Double.NaN
-
parseLatLon
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(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXException
-
startElementInit
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
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
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:
-
startElementAuthor
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:
-
startElementTrk
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:
-
startElementTrkSeg
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:
-
startElementWpt
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:
-
startElementRte
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
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
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler
-
getAttr
Get the current attributes- Returns:
- The current attributes, if available
-
endElement
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXException
-
endElementMetadata
End the metadata element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
-
endElementAuthor
End the author element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
-
endElementCopyright
End the copyright element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endElementLink
End a link element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endElementWpt
End a wpt element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- Throws:
SAXException- If a waypoint does not have valid coordinates- See Also:
-
endElementTrkseg
End a trkseg element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
-
endElementTrk
End a trk element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.- See Also:
-
endElementExt
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:
-
endElementDefault
End the default element- Parameters:
localName- The local name (without prefix), or the empty string if Namespace processing is not being performed.
-
endDocument
- Specified by:
endDocumentin interfaceContentHandler- Overrides:
endDocumentin classDefaultHandler- Throws:
SAXException
-
getData
Get the parsedGpxData- Returns:
- The data
-
convertUrlToLink
convert url/urlname to link element (GPX 1.0 → GPX 1.1).- Parameters:
attr- attributes
-
tryToFinish
Attempt to finish parsing- Throws:
SAXException- If there are additional parsing errors
-