Class KmlFormat

All Implemented Interfaces:
MultipleRoutesFormat<KmlRoute>, NavigationFormat<KmlRoute>
Direct Known Subclasses:
Kml20Format, Kml21Format, Kml22BetaFormat, Kml22Format

public abstract class KmlFormat extends BaseKmlFormat
The base of all Google Earth formats.
Author:
Christian Pesch
  • Constructor Details

    • KmlFormat

      public KmlFormat()
  • Method Details

    • getExtension

      public String getExtension()
    • isSupportsMultipleRoutes

      public boolean isSupportsMultipleRoutes()
    • isWritingRouteCharacteristics

      public boolean isWritingRouteCharacteristics()
    • createRoute

      public <P extends NavigationPosition> KmlRoute createRoute(RouteCharacteristics characteristics, String name, List<P> positions)
    • asKmlPosition

      protected KmlPosition asKmlPosition(NavigationPosition position)
    • asKmlPositions

      protected List<KmlPosition> asKmlPositions(List<String> strings)
    • createDocumentName

      protected String createDocumentName(KmlRoute route)
    • parseFolderName

      protected String parseFolderName(String folderName)
    • createFolderName

      protected String createFolderName(String prefix, KmlRoute route)
    • createCoordinates

      protected String createCoordinates(KmlPosition position, boolean separateWithSpace)
    • parseCharacteristics

      protected RouteCharacteristics parseCharacteristics(String nameToParse, String styleUrl, RouteCharacteristics fallback)
    • parseTime

      protected CompactCalendar parseTime(String time)
    • enrichPosition

      protected void enrichPosition(KmlPosition position, CompactCalendar time, String name, String description, CompactCalendar startDate)
    • appendPlacemarkAsWaypointOrTrack

      protected void appendPlacemarkAsWaypointOrTrack(String name, String description, String placemarkName, boolean characteristicsFromRouteName, String placemarkDescription, String styleUrl, CompactCalendar time, List<KmlPosition> positions, List<KmlPosition> waypoints, ParserContext<KmlRoute> context)
      Appends a placemark's positions as a single waypoint (one position) or a track (more). Shared across all KML versions. The only behavioural divergence is which name feeds parseCharacteristics: KML 2.0/2.1/2.2-beta use the path-prefixed route name, KML 2.2 uses the bare placemark name; characteristicsFromRouteName preserves that exactly.
    • prependWaypointsRoute

      protected void prependWaypointsRoute(String name, String description, List<KmlPosition> waypoints, ParserContext<KmlRoute> context)
      Prepends the accumulated single-position placemarks as one combined waypoint route. Identical across all KML versions.
    • find

      protected <T> List<jakarta.xml.bind.JAXBElement<T>> find(List<? extends jakarta.xml.bind.JAXBElement<?>> elements, String name, Class<T> resultClass)
      Filters a list of feature elements down to those whose element local name matches, regardless of the JAXB-bound feature supertype (KML 2.1 binds against FeatureType, KML 2.2-beta/2.2 against AbstractFeatureType) -- the lookup only needs the element's QName, which JAXBElement exposes independent of its type parameter. Identical across all three modern KML versions; previously duplicated verbatim in each.
    • extractTracksFromContainers

      protected <T> void extractTracksFromContainers(List<jakarta.xml.bind.JAXBElement<T>> containers, Function<T,String> nameOf, KmlFormat.FeatureRecursor<T> recurseInto) throws IOException
      Recurses into each child container (KML Folder or Document), invoking recurseInto with the container's resolved name and its raw (version-specific) value. nameOf may return null to skip a container without recursing into it -- KML 2.2 uses this to ignore its internal "speed" and "marks" folders, a behaviour the other versions don't have and don't trigger (their nameOf never returns null). Loop shape identical across KML 2.1/2.2-beta/2.2; the per-version divergence lives entirely in the nameOf/recurseInto lambdas the caller supplies.
      Throws:
      IOException
    • extractPositionsByElementName

      protected List<KmlPosition> extractPositionsByElementName(jakarta.xml.bind.JAXBElement<?> geometryElement, Function<Object,List<? extends jakarta.xml.bind.JAXBElement<?>>> multiGeometryChildrenOf, Function<jakarta.xml.bind.JAXBElement<?>,List<KmlPosition>> recurse)
      Extracts positions from a Point/LineString/MultiGeometry element by dispatching on the element's local name rather than its JAXB-bound Java type. KML 2.1/2.2-beta/2.2 each generate separate, unrelated PointType/LineStringType/MultiGeometryType classes with no shared supertype, but all three expose an identical getCoordinates() shape on Point/ LineString -- read here via reflection so one method serves all three instead of each duplicating the same instanceof chain. Geometry kinds other than Point/LineString/ MultiGeometry (e.g. KML 2.2's gx:Track) are left to the caller, matching the original per-version code, which also silently ignored anything it didn't explicitly check for. multiGeometryChildrenOf supplies the version-specific MultiGeometry child accessor (getGeometry() in KML 2.1, getAbstractGeometryGroup() in 2.2-beta/2.2); recurse must be the caller's own full extraction method (not this one), so that version-specific geometry kinds nested inside a MultiGeometry are still recognised by the caller on the way back in. Operates on raw JAXBElementinvalid input: '<'?>/Object rather than a shared bound type -- the per-version binding classes don't have one -- so each caller's lambdas carry a single unchecked cast at the type-erasure boundary; that cast is always safe since the value really is whatever binding type the caller's own JAXB unmarshalling produced.
    • createLineStringCoordinates

      protected List<String> createLineStringCoordinates(KmlRoute route, int startIndex, int endIndex)
      Renders route.getPositions()[startIndex, endIndex) as KML coordinate strings for a LineString. Identical across all KML versions; previously duplicated in each createTrack().
    • concatPath

      protected String concatPath(String path, String fragment)
    • getLineWidth

      protected float getLineWidth()
    • getRouteLineColor

      protected byte[] getRouteLineColor()
    • getTrackLineColor

      protected byte[] getTrackLineColor()
    • isWriteName

      protected boolean isWriteName()
    • isWriteDesc

      protected boolean isWriteDesc()