public class KMLRoot extends KMLAbstractObject implements KMLRenderable
gov.nasa.worldwind.ogc.kml
.Modifier and Type | Field and Description |
---|---|
protected AbsentResourceList |
absentResourceList |
protected double |
detailHint
Indicates this KML root's detail hint.
|
protected XMLEventReader |
eventReader
The event reader used to parse the document's XML.
|
protected InputStream |
eventStream
The input stream underlying the event reader.
|
protected KMLAbstractFeature |
feature |
protected boolean |
featureFetched
Flag to indicate that the feature has been fetched from the hash map.
|
protected KMLDoc |
kmlDoc
Reference to the KMLDoc representing the KML or KMZ file.
|
protected boolean |
linkControlFetched
Flag to indicate that the network link control element has been fetched from the hash map.
|
protected KMLNetworkLinkControl |
networkLinkControl |
protected KMLParserContext |
parserContext
The parser context for the document.
|
protected PropertyChangeSupport |
propertyChangeSupport
The
PropertyChangeSupport that receives property change events this KMLRoot listens for, and sends
property change events to this KMLRoot's listeners. |
MSG_BOX_CHANGED, MSG_GEOMETRY_CHANGED, MSG_LINK_CHANGED, MSG_STYLE_CHANGED, MSG_TIME_CHANGED, MSG_VIEW_CHANGED
CHARACTERS_CONTENT, fields, namespaceURI, parent
Constructor and Description |
---|
KMLRoot(File docSource)
Create a new
KMLRoot for a File . |
KMLRoot(File docSource,
boolean namespaceAware)
Create a new
KMLRoot for a File . |
KMLRoot(InputStream docSource,
String contentType)
Create a new
KMLRoot for an InputStream . |
KMLRoot(InputStream docSource,
String contentType,
boolean namespaceAware)
Create a new
KMLRoot for an InputStream . |
KMLRoot(KMLDoc docSource)
Create a new
KMLRoot for a KMLDoc instance. |
KMLRoot(KMLDoc docSource,
boolean namespaceAware)
Create a new
KMLRoot for a KMLDoc instance. |
KMLRoot(String namespaceURI,
KMLDoc docSource)
Create a new
KMLRoot with a specific namespace. |
KMLRoot(String namespaceURI,
KMLDoc docSource,
boolean namespaceAware)
Create a new
KMLRoot with a specific namespace. |
KMLRoot(URL docSource,
String contentType)
Create a
KMLRoot for a URL . |
KMLRoot(URL docSource,
String contentType,
boolean namespaceAware)
Create a
KMLRoot for a URL . |
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds the specified property change listener that will be called for all list changes.
|
protected boolean |
canParseContentType(String mimeType)
Determines if a MIME type can be parsed as KML or KMZ.
|
protected void |
closeEventStream()
Closes the event stream associated with this context's XML event reader.
|
static KMLRoot |
create(Object docSource)
Creates a KML root for an untyped source.
|
static KMLRoot |
create(Object docSource,
boolean namespaceAware)
Creates a KML root for an untyped source.
|
static KMLRoot |
createAndParse(Object docSource)
Creates a KML root for an untyped source and parses it.
|
protected KMLParserContext |
createParserContext(XMLEventReader reader)
Invoked during
initialize(boolean) to create the parser context. |
protected XMLEventReader |
createReader(Object docSource,
boolean namespaceAware)
Creates the event reader.
|
void |
evictIfExpired(String link,
long expirationTime)
Check a cached resource for expiration.
|
protected KMLAbstractFeature |
findFeature()
Searches this root's fields for the KML Feature element.
|
void |
firePropertyChange(PropertyChangeEvent propertyChangeEvent)
Fire a property change event.
|
void |
firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
Fire a property change event.
|
protected PropertyChangeSupport |
getChangeSupport()
Get the PropertyChangeSupport object for this KML object.
|
double |
getDetailHint()
Indicates this KML root's detail hint, which is described in
. |
long |
getExpiration(String link)
Returns the expiration time of a file retrieved by
resolveReference or resolveNetworkLink . |
KMLAbstractFeature |
getFeature()
Returns the KML
Feature element contained in the document root. |
String |
getHint()
Returns the
hint attribute of the KML element (the document root). |
Object |
getItemByID(String id)
Finds a named element in the document.
|
KMLDoc |
getKMLDoc()
Returns the KML document for this
KMLRoot . |
KMLNetworkLinkControl |
getNetworkLinkControl()
Returns the
KMLNetworkLinkControl element if the document root contains it. |
protected XMLEventParserContext |
getParserContext() |
String |
getSupportFilePath(String link) |
protected void |
initialize(boolean namespaceAware)
Called just before the constructor returns.
|
void |
onMessage(Message msg)
Invoked when a message is received.
|
KMLRoot |
parse(Object... args)
Starts document parsing.
|
protected KMLRoot |
parseCachedKMLFile(URL url,
String linkBase,
String contentType,
boolean namespaceAware)
Open and parse the specified file expressed as a file: URL..
|
void |
preRender(KMLTraversalContext tc,
DrawContext dc)
Pre-render this element.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Removes the specified property change listener.
|
void |
render(KMLTraversalContext tc,
DrawContext dc)
Render this element.
|
void |
requestRedraw()
Request any scene containing this KML document be repainted.
|
Object |
resolveLocalReference(String linkBase,
String linkRef)
Resolves a reference to a local element identified by address and identifier, where
linkBase identifies a
document, including the current document, and linkRef is the id of the desired element. |
Object |
resolveNetworkLink(String link,
boolean cacheRemoteFile,
long updateTime)
Resolves a NetworkLink to a local or remote KML document.
|
Object |
resolveReference(String link)
Resolves a reference to a remote or local element of the form address#identifier, where "address" identifies a
local or remote document, including the current document, and and "identifier" is the id of the desired element.
|
Object |
resolveReference(String link,
boolean cacheRemoteFile)
Resolves a reference to a remote or local element of the form address#identifier, where "address" identifies a
local or remote document, including the current document, and and "identifier" is the id of the desired element.
|
Object |
resolveRemoteReference(String linkBase,
String linkRef)
Resolves a reference to a remote element identified by address and identifier, where
linkBase identifies
a remote document, and linkRef is the id of the desired element. |
Object |
resolveRemoteReference(String linkBase,
String linkRef,
boolean cacheRemoteFile)
Resolves a reference to a remote element identified by address and identifier, where
linkBase identifies
a remote document, and linkRef is the id of the desired element. |
void |
setDetailHint(double detailHint)
Specifies this KML root's detail hint.
|
void |
setNotificationListener(XMLParserNotificationListener listener)
Specifies the object to receive notifications of important occurrences during parsing, such as exceptions and the
occurrence of unrecognized element types.
|
applyChange, getId, getRoot, getTargetId, onChange
allocate, doAddCharacters, doAddEventAttribute, doAddEventContent, doParseEventAttributes, doParseEventContent, freeResources, getAConstructor, getCharacters, getField, getField, getFields, getNamespaceURI, getParent, hasField, hasField, hasFields, mergeFields, newInstance, overrideFields, parse, parseCharacterContent, removeField, setField, setField, setFields, setNamespaceURI, setParent
protected AbsentResourceList absentResourceList
protected double detailHint
protected XMLEventReader eventReader
protected InputStream eventStream
protected KMLAbstractFeature feature
protected boolean featureFetched
protected KMLDoc kmlDoc
protected boolean linkControlFetched
protected KMLNetworkLinkControl networkLinkControl
protected KMLParserContext parserContext
protected PropertyChangeSupport propertyChangeSupport
PropertyChangeSupport
that receives property change events this KMLRoot listens for, and sends
property change events to this KMLRoot's listeners. Lazily initialized in getChangeSupport
.
Initially null
.public KMLRoot(File docSource) throws IOException
KMLRoot
for a File
.docSource
- the File containing the document.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(File docSource, boolean namespaceAware) throws IOException
KMLRoot
for a File
.docSource
- the File containing the document.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(InputStream docSource, String contentType) throws IOException
KMLRoot
for an InputStream
.docSource
- the input stream containing the document.contentType
- the content type of the stream data. Specify KMLConstants.KML_MIME_TYPE
for plain KML
and KMLConstants.KMZ_MIME_TYPE
for KMZ. The content is treated as KML for any other
value or a value of null.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(InputStream docSource, String contentType, boolean namespaceAware) throws IOException
KMLRoot
for an InputStream
.docSource
- the input stream containing the document.contentType
- the content type of the stream data. Specify KMLConstants.KML_MIME_TYPE
for plain
KML and KMLConstants.KMZ_MIME_TYPE
for KMZ. The content is treated as KML for any
other value or a value of null.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(KMLDoc docSource) throws IOException
KMLRoot
for a KMLDoc
instance. A KMLDoc represents KML and KMZ files from
either files or input streams.docSource
- the KMLDoc instance representing the KML document.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(KMLDoc docSource, boolean namespaceAware) throws IOException
KMLRoot
for a KMLDoc
instance. A KMLDoc represents KML and KMZ files from
either files or input streams.docSource
- the KMLDoc instance representing the KML document.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the KML document.public KMLRoot(String namespaceURI, KMLDoc docSource) throws IOException
KMLRoot
with a specific namespace. (The default namespace is defined by KMLConstants.KML_NAMESPACE
).namespaceURI
- the default namespace URI.docSource
- the KML source specified via a KMLDoc
instance. A KMLDoc represents KML and KMZ files
from either files or input streams.IllegalArgumentException
- if the document source is null.IOException
- if an I/O error occurs attempting to open the document source.public KMLRoot(String namespaceURI, KMLDoc docSource, boolean namespaceAware) throws IOException
KMLRoot
with a specific namespace. (The default namespace is defined by KMLConstants.KML_NAMESPACE
).namespaceURI
- the default namespace URI.docSource
- the KML source specified via a KMLDoc
instance. A KMLDoc represents KML and KMZ
files from either files or input streams.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IllegalArgumentException
- if the document source is null.IOException
- if an I/O error occurs attempting to open the document source.public KMLRoot(URL docSource, String contentType) throws IOException
KMLRoot
for a URL
.docSource
- the URL identifying the document.contentType
- the content type of the data. Specify KMLConstants.KML_MIME_TYPE
for plain KML and
KMLConstants.KMZ_MIME_TYPE
for KMZ. Any other non-null value causes the content to be
treated as plain KML. If null is specified the content type is read from the server or other
end point of the URL. When a content type is specified, the content type returned by the URL's
end point is ignored. You can therefore force the content to be treated as KML or KMZ
regardless of what a server declares it to be.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the document.public KMLRoot(URL docSource, String contentType, boolean namespaceAware) throws IOException
KMLRoot
for a URL
.docSource
- the URL identifying the document.contentType
- the content type of the data. Specify KMLConstants.KML_MIME_TYPE
for plain KML and
KMLConstants.KMZ_MIME_TYPE
for KMZ. Any other non-null value causes the content to
be treated as plain KML. If null is specified the content type is read from the server or
other end point of the URL. When a content type is specified, the content type returned by
the URL's end point is ignored. You can therefore force the content to be treated as KML or
KMZ regardless of what a server declares it to be.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IllegalArgumentException
- if the document source is null.IOException
- if an error occurs while reading the document.public void addPropertyChangeListener(PropertyChangeListener listener)
listener
- the listener to call.IllegalArgumentException
- if listener
is nullPropertyChangeSupport
protected boolean canParseContentType(String mimeType)
mimeType
- Type to test. May be null.true
if mimeType
can be parsed as KML.protected void closeEventStream()
public static KMLRoot create(Object docSource) throws IOException
File
, a URL
, a InputStream
, or a String
identifying either a file path or a URL. For all types other than
InputStream
an attempt is made to determine whether the source is KML or KMZ; KML is assumed if the
test is not definitive. Null is returned if the source type is not recognized.docSource
- either a File
, a URL
, or an InputStream
, or a String
identifying
a file path or URL.KMLRoot
for the specified source, or null if the source type is not supported.IllegalArgumentException
- if the source is null.IOException
- if an error occurs while reading the source.public static KMLRoot create(Object docSource, boolean namespaceAware) throws IOException
File
, a URL
, a InputStream
, or a String
identifying either a file path or a URL. For all types other than
InputStream
an attempt is made to determine whether the source is KML or KMZ; KML is assumed if the
test is not definitive. Null is returned if the source type is not recognized.docSource
- either a File
, a URL
, or an InputStream
, or a String
identifying a file path or URL.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.KMLRoot
for the specified source, or null if the source type is not supported.IllegalArgumentException
- if the source is null.IOException
- if an error occurs while reading the source.public static KMLRoot createAndParse(Object docSource) throws IOException, XMLStreamException
File
, a URL
,
a InputStream
, or a String
identifying either a file path or a URL. For all types other than
InputStream
an attempt is made to determine whether the source is KML or KMZ; KML is assumed if the
test is not definitive. Null is returned if the source type is not recognized.
Note: Because there are so many incorrectly formed KML files in distribution, it's often not possible to parse
with a namespace aware parser. This method first tries to use a namespace aware parser, but if a severe problem
occurs during parsing, it will try again using a namespace unaware parser. Namespace unaware parsing typically
bypasses many problems, but it also causes namespace qualified elements in the XML to be unrecognized.docSource
- either a File
, a URL
, or an InputStream
, or a String
identifying
a file path or URL.KMLRoot
for the specified source, or null if the source type is not supported.IllegalArgumentException
- if the source is null.IOException
- if an error occurs while reading the source.XMLStreamException
- if the KML file has severe errors.protected KMLParserContext createParserContext(XMLEventReader reader)
initialize(boolean)
to create the parser context. The parser context is created by the
global XMLEventParserContextFactory
.reader
- the reader to associate with the parser context.protected XMLEventReader createReader(Object docSource, boolean namespaceAware)
docSource
- the document source to create a reader for. The type can be any of those supported by
WWXML.openEventReader(Object)
.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.public void evictIfExpired(String link, long expirationTime)
link
- Link that identifies the resource to check for expiration. This is the same link that was
passed to resolveReference to retrieve the resource.expirationTime
- Time at which the resource expires, in milliseconds since the Epoch. If the current system
time is greater than the expiration time, then the resource will be evicted.protected KMLAbstractFeature findFeature()
public void firePropertyChange(PropertyChangeEvent propertyChangeEvent)
propertyChangeEvent
- Event to fire.public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
propertyName
- Name of the property change changed.oldValue
- The previous value of the property.newValue
- The new value of the property.protected PropertyChangeSupport getChangeSupport()
public double getDetailHint()
setDetailHint(double)
.setDetailHint(double)
public long getExpiration(String link)
resolveReference
or resolveNetworkLink
.link
- the address of the file (the same address as was previously passed to resolveReference). If null,
zero is returned.link
has
not been retrieved.public KMLAbstractFeature getFeature()
Feature
element contained in the document root.public String getHint()
hint
attribute of the KML
element (the document root).public Object getItemByID(String id)
id
- the element's identifier. If null, null is returned.public KMLDoc getKMLDoc()
KMLRoot
.public KMLNetworkLinkControl getNetworkLinkControl()
KMLNetworkLinkControl
element if the document root contains it.protected XMLEventParserContext getParserContext()
public String getSupportFilePath(String link) throws IOException
IOException
protected void initialize(boolean namespaceAware) throws IOException
super.initialize(boolean)
.namespaceAware
- specifies whether to use a namespace-aware XML parser. true
if so,
false
if not.IOException
- if an I/O error occurs attempting to open the document source.public void onMessage(Message msg)
onMessage
in interface MessageListener
onMessage
in class KMLAbstractObject
msg
- The message that was received.public KMLRoot parse(Object... args) throws XMLStreamException
args
- optional arguments to pass to parsers of sub-elements.this
if parsing is successful, otherwise null.XMLStreamException
- if an exception occurs while attempting to read the event stream.protected KMLRoot parseCachedKMLFile(URL url, String linkBase, String contentType, boolean namespaceAware) throws IOException, XMLStreamException
url
- the URL of the file to open, expressed as a URL with a scheme of "file".linkBase
- the original address of the document if the file is a retrieved and cached file.contentType
- the mime type of the file's content, either a KML or KMZ mime type.namespaceAware
- specifies whether to use a namespace aware event reader.KMLRoot
representing the file's KML contents.IOException
- if an I/O error occurs during opening and parsing.XMLStreamException
- if a server parsing error is encountered.public void preRender(KMLTraversalContext tc, DrawContext dc)
KMLRenderable
preRender
in interface KMLRenderable
tc
- the current KML traversal context.dc
- the current draw context.public void removePropertyChangeListener(PropertyChangeListener listener)
listener
- the listener to remove.IllegalArgumentException
- if listener
is null.PropertyChangeSupport
public void render(KMLTraversalContext tc, DrawContext dc)
KMLRenderable
render
in interface KMLRenderable
tc
- the current KML traversal context.dc
- the current draw context.public void requestRedraw()
public Object resolveLocalReference(String linkBase, String linkRef)
linkBase
identifies a
document, including the current document, and linkRef
is the id of the desired element.
If linkBase
refers to a local KML or KMZ file and linkRef
is non-null, the return value is the
element identified by linkRef
. If linkRef
is null, the return value is a parsed KMLRoot
for the KML file identified by linkBase
.
If linkBase
refers a local file that is not a KML or KMZ file then linkBase
is returned. If
linkBase
cannot be resolved to a local file then null is returned.linkBase
- the address of the document containing the requested element.linkRef
- the element's identifier.IllegalArgumentException
- if the address is null.public Object resolveNetworkLink(String link, boolean cacheRemoteFile, long updateTime)
FileStore
.
The return value is a parsed KMLRoot representing the linked document. The return value is null if the linked
file is not a KML file, or is not yet available in the FileStore.
The cacheRemoteFile
parameter specifies whether to store a retrieved remote file in the World Wind
cache or in a temporary location. This parameter has no effect if the file exists locally. The temporary location
for a retrieved file does not persist between runtime sessions, and subsequent invocations of this method may not
return the same temporary location.link
- the address to resolvecacheRemoteFile
- true
to store remote files in the World Wind cache, or false
to
store remote files in a temporary location. Has no effect if the address is a local file.updateTime
- the time at which the link was last updated. If a cached file exists for the specified
resource, the file must have been retrieved after the link update time. Otherwise, the
cache entry is considered invalid, and the file is deleted and retrieved again.IllegalArgumentException
- if the link
is null.public Object resolveReference(String link)
null
. Once the document is successfully retrieved, subsequent calls to this method
return the identified element, if it exists.
If the link does not contain an identifier part, this initiates a retrieval for document referenced by the
address part and returns null
. Once the document is retrieved this opens the the document as a
KMLRoot
. Subsequent calls to this method return the opened document, if it exists.link
- the document address in the form address#identifier.null
if the document
or the element are not found.IllegalArgumentException
- if the link
is null
.public Object resolveReference(String link, boolean cacheRemoteFile)
null
. Once the document is successfully retrieved, subsequent calls to this method
return the identified element, if it exists.
If the link does not contain an identifier part, this initiates a retrieval for document referenced by the
address part and returns null
. Once the document is retrieved this opens the the document as a
KMLRoot
. Subsequent calls to this method return the opened document, if it exists.
The cacheRemoteFile
parameter specifies whether to store a retrieved remote document in the World
Wind cache or in a temporary location. This parameter has no effect if the document exists locally. The temporary
location for a retrieved document does not persist between runtime sessions, and subsequent invocations of this
method may not return the same temporary location.link
- the document address in the form address#identifier.cacheRemoteFile
- true
to store remote documents in the World Wind cache, or false
to store remote documents in a temporary location. Has no effect if the address is a local
document.null
if the document
or the element are not found.IllegalArgumentException
- if the link
is null
.public Object resolveRemoteReference(String linkBase, String linkRef)
linkBase
identifies
a remote document, and linkRef
is the id of the desired element. This method retrieves resources
asynchronously using the FileStore
.
The return value is null if the file is not yet available in the FileStore. If linkBase
refers to a KML
or KMZ file and linkRef
is non-null, the return value is the element identified by linkRef
. If
linkBase
refers to a KML or KMZ and linkRef
is null, the return value is a parsed KMLRoot
for the KML file identified by linkBase
. Otherwise the return value is a URL
to the file in the
file cache.linkBase
- the address of the document containing the requested element.linkRef
- the element's identifier.IllegalArgumentException
- if the linkBase
is null.public Object resolveRemoteReference(String linkBase, String linkRef, boolean cacheRemoteFile)
linkBase
identifies
a remote document, and linkRef
is the id of the desired element. This method retrieves resources
asynchronously using the FileStore
.
The return value is null if the file is not yet available in the FileStore. If linkBase
refers to a KML
or KMZ file and linkRef
is non-null, the return value is the element identified by linkRef
. If
linkBase
refers to a KML or KMZ and linkRef
is null, the return value is a parsed KMLRoot
for the KML file identified by linkBase
. Otherwise the return value is a URL
to the file in the
file cache or a temporary location, depending on the value of cacheRemoteFile
.
The cacheRemoteFile
parameter specifies whether to store a retrieved remote file in the World Wind
cache or in a temporary location. This parameter has no effect if the file exists locally. The temporary location
for a retrieved file does not persist between runtime sessions, and subsequent invocations of this method may not
return the same temporary location.linkBase
- the address of the document containing the requested element.linkRef
- the element's identifier.cacheRemoteFile
- true
to store remote files in the World Wind cache, or false
to
store remote files in a temporary location. Has no effect if the address is a local file.IllegalArgumentException
- if the linkBase
is null.public void setDetailHint(double detailHint)
detailHint
- the degree to modify the default relationship of KML scene resolution to screen resolution as
viewing distance changes. Values greater than 0 increase the resolution. Values less than 0
decrease the resolution. The default value is 0.public void setNotificationListener(XMLParserNotificationListener listener)
listener
- the listener to receive notifications. Specify null to indicate no listener.XMLParserNotification