NASA World Wind

gov.nasa.worldwind.ogc.kml.impl
Class KMLBalloonTextDecoder

java.lang.Object
  extended by gov.nasa.worldwind.util.BasicTextDecoder
      extended by gov.nasa.worldwind.ogc.kml.impl.KMLBalloonTextDecoder
All Implemented Interfaces:
TextDecoder

public class KMLBalloonTextDecoder
extends BasicTextDecoder

Text decoder that performs entity substitution for KML description balloons. This class is thread safe.


Field Summary
protected  Map<String,String> entityCache
          Keep a cache of entities that have been resolved so that we don't have to re-resolve them every time the decoded text is requested.
protected  KMLAbstractFeature feature
          Feature to use as context for entity replacements.
protected  boolean isUnresolved
          True if there are entities in the balloon text which may refer to unresolved schema.
 
Fields inherited from class gov.nasa.worldwind.util.BasicTextDecoder
decodedText, lastUpdateTime, text
 
Constructor Summary
KMLBalloonTextDecoder(KMLAbstractFeature feature)
          Create a decoder to generate balloon text for a feature.
 
Method Summary
protected  String decode(String textToDecode)
          Perform entity substitution.
 String getDecodedText()
          Get the balloon text after entity substitutions (for example, $[name], $[description], etc) have been made.
 KMLAbstractFeature getFeature()
          Get the feature used as context for resolving entity references.
protected  String getGeDirectionsText()
          Get the text used to replace the $[geDirections] entity.
protected  String resolveEntityReference(String pattern)
          Resolve an entity reference.
 void setText(String input)
          Set the input text which the decoder will process.
 
Methods inherited from class gov.nasa.worldwind.util.BasicTextDecoder
getLastUpdateTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityCache

protected Map<String,String> entityCache
Keep a cache of entities that have been resolved so that we don't have to re-resolve them every time the decoded text is requested.


feature

protected KMLAbstractFeature feature
Feature to use as context for entity replacements.


isUnresolved

protected boolean isUnresolved
True if there are entities in the balloon text which may refer to unresolved schema. False if all entities have been resolved, or are known to be unresolvable (because the data they refer to does not exist).

Constructor Detail

KMLBalloonTextDecoder

public KMLBalloonTextDecoder(KMLAbstractFeature feature)
Create a decoder to generate balloon text for a feature. The feature becomes the context of the entity replacements (for example "$[name]" will be replaced with the feature's name.

Parameters:
feature - Feature that is the context of entity replacements.
Method Detail

decode

protected String decode(String textToDecode)
Perform entity substitution.

Overrides:
decode in class BasicTextDecoder
Parameters:
textToDecode - The text to decode.
Returns:
Decoded text.

getDecodedText

public String getDecodedText()
Get the balloon text after entity substitutions (for example, $[name], $[description], etc) have been made. See the KML specification for details on entity replacement. If some entities could not be resolved because they refer to unresolved schema, the decoder will try to decode the string again the next time this method is called.

Specified by:
getDecodedText in interface TextDecoder
Overrides:
getDecodedText in class BasicTextDecoder
Returns:
String after replacements have been made. Returns null if the input text is null.

getFeature

public KMLAbstractFeature getFeature()
Get the feature used as context for resolving entity references.

Returns:
The context feature.

getGeDirectionsText

protected String getGeDirectionsText()
Get the text used to replace the $[geDirections] entity. This implementation returns an empty string. Subclasses can override this method to provide directions text.

Returns:
Text to replace the $[geDirections] entity.

resolveEntityReference

protected String resolveEntityReference(String pattern)
Resolve an entity reference. The pattern can be in one of these forms:
  FeatureField
  DataField
  DataField/displayName
  SchemaName/SchemaField
  SchemaName/SchemaField/displayName
  
See the KML spec for details.

Parameters:
pattern - Pattern of entity to resolve.
Returns:
Return the replacement string for the entity, or null if no replacement can be found.

setText

public void setText(String input)
Set the input text which the decoder will process.

Specified by:
setText in interface TextDecoder
Overrides:
setText in class BasicTextDecoder
Parameters:
input - Text to decode.

NASA World Wind