NASA World Wind

gov.nasa.worldwind.util
Class WWXML

java.lang.Object
  extended by gov.nasa.worldwind.util.WWXML

public class WWXML
extends Object

A collection of static methods use for opening, reading and otherwise working with XML files.


Constructor Summary
WWXML()
           
 
Method Summary
static void checkAndSetBooleanParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetDoubleParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetIntegerParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetLatLonParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetLongParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetSectorParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetSectorResolutionParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static void checkAndSetStringParam(Element context, AVList params, String paramKey, String paramName, XPath xpath)
          Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression.
static String checkOGCException(Document doc)
           
static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware)
          Create a DOM builder.
static String extractOGCServiceException(ByteBuffer buffer)
           
static String fixGetMapString(String gms)
           
static Boolean getBoolean(Element context, String path, XPath xpath)
          Returns the Boolean value of an element identified by an XPath expression.
static Double getDouble(Element context, String path, XPath xpath)
          Returns the Double value of an element identified by an XPath expression.
static Element getElement(Element context, String path, XPath xpath)
          Returns the element identified by an XPath expression.
static Element[] getElements(Element context, String path, XPath xpath)
          Returns all elements identified by an XPath expression.
static Integer getInteger(Element context, String path, XPath xpath)
          Returns the Integer value of an element identified by an XPath expression.
static LatLon getLatLon(Element context, String path, XPath xpath)
          Returns the LatLon value of an element identified by an XPath expression.
static Long getLong(Element context, String path, XPath xpath)
          Returns the Long value of an element identified by an XPath expression.
static Sector getSector(Element context, String path, XPath xpath)
          Returns the Sector value of an element identified by an XPath expression.
static LevelSet.SectorResolution getSectorResolutionLimit(Element context, String path, XPath xpath)
          Returns the LevelSet.SectorResolution value of an element identified by an XPath expression.
static String getText(Element context, String path)
          Returns the text of the element identified by an XPath expression.
static String getText(Element context, String path, XPath xpath)
          Returns the text of the element identified by an XPath expression.
static String[] getTextArray(Element context, String path, XPath xpath)
          Returns the text of all elements identified by an XPath expression.
static Element[] getUniqueElements(Element context, String path, String uniqueTag, XPath xpath)
          Returns the unique elements identified by an XPath expression and a sub-expression.
static String[] getUniqueText(Element context, String path, XPath xpath)
          Returns the text of all unique elements identified by an XPath expression.
static XPath makeXPath()
          Shortcut method to create an XPath.
static Document openDocumentFile(String filePath, Class c)
          Opens an XML file given the file's location in the file system or on the classpath.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WWXML

public WWXML()
Method Detail

checkAndSetBooleanParam

public static void checkAndSetBooleanParam(Element context,
                                           AVList params,
                                           String paramKey,
                                           String paramName,
                                           XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetDoubleParam

public static void checkAndSetDoubleParam(Element context,
                                          AVList params,
                                          String paramKey,
                                          String paramName,
                                          XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetIntegerParam

public static void checkAndSetIntegerParam(Element context,
                                           AVList params,
                                           String paramKey,
                                           String paramName,
                                           XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetLatLonParam

public static void checkAndSetLatLonParam(Element context,
                                          AVList params,
                                          String paramKey,
                                          String paramName,
                                          XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetLongParam

public static void checkAndSetLongParam(Element context,
                                        AVList params,
                                        String paramKey,
                                        String paramName,
                                        XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetSectorParam

public static void checkAndSetSectorParam(Element context,
                                          AVList params,
                                          String paramKey,
                                          String paramName,
                                          XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetSectorResolutionParam

public static void checkAndSetSectorResolutionParam(Element context,
                                                    AVList params,
                                                    String paramKey,
                                                    String paramName,
                                                    XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkAndSetStringParam

public static void checkAndSetStringParam(Element context,
                                          AVList params,
                                          String paramKey,
                                          String paramName,
                                          XPath xpath)
Checks a parameter list for a specified key and if not present attempts to find a value for the key from an element matched by an XPath expression. If found, the key and value are added to the parameter list.

Parameters:
context - the context from which to start the XPath search.
params - the parameter list.
paramKey - the key used to identify the paramater in the parameter list.
paramName - the Xpath expression identifying the parameter value within the specified context.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Throws:
IllegalArgumentException - if either the context, parameter list, parameter key or parameter name are null.

checkOGCException

public static String checkOGCException(Document doc)

createDocumentBuilder

public static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware)
Create a DOM builder.

Parameters:
isNamespaceAware - true if the builder is to be namespace aware, otherwise false.
Returns:
a DocumentBuilder.
Throws:
WWRuntimeException - if an error occurs.

extractOGCServiceException

public static String extractOGCServiceException(ByteBuffer buffer)

fixGetMapString

public static String fixGetMapString(String gms)

getBoolean

public static Boolean getBoolean(Element context,
                                 String path,
                                 XPath xpath)
Returns the Boolean value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a Boolean.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getDouble

public static Double getDouble(Element context,
                               String path,
                               XPath xpath)
Returns the Double value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a Double.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getElement

public static Element getElement(Element context,
                                 String path,
                                 XPath xpath)
Returns the element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the element matching the XPath expression, or null if no element matches.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getElements

public static Element[] getElements(Element context,
                                    String path,
                                    XPath xpath)
Returns all elements identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
an array containing the elements matching the XPath expression.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getInteger

public static Integer getInteger(Element context,
                                 String path,
                                 XPath xpath)
Returns the Integer value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a Integer.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getLatLon

public static LatLon getLatLon(Element context,
                               String path,
                               XPath xpath)
Returns the LatLon value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression. If null, indicates that the context is the LatLon element itself. If non-null, the context is searched for a LatLon element using the expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a LatLon.
Throws:
IllegalArgumentException - if the context is null.

getLong

public static Long getLong(Element context,
                           String path,
                           XPath xpath)
Returns the Long value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a Integer.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getSector

public static Sector getSector(Element context,
                               String path,
                               XPath xpath)
Returns the Sector value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression. If null, indicates that the context is the Sector element itself. If non-null, the context is searched for a Sector element using the expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a Sector.
Throws:
IllegalArgumentException - if the context is null.

getSectorResolutionLimit

public static LevelSet.SectorResolution getSectorResolutionLimit(Element context,
                                                                 String path,
                                                                 XPath xpath)
Returns the LevelSet.SectorResolution value of an element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression. If null, indicates that the context is the SectorResolution element itself. If non-null, the context is searched for a SectorResolution element using the expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the value of an element matching the XPath expression, or null if no match is found or the match does not contain a LevelSet.SectorResolution.
Throws:
IllegalArgumentException - if the context is null.

getText

public static String getText(Element context,
                             String path)
Returns the text of the element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
Returns:
the text of an element matching the XPath expression, or null if no match is found.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getText

public static String getText(Element context,
                             String path,
                             XPath xpath)
Returns the text of the element identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
the text of an element matching the XPath expression, or null if no match is found.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getTextArray

public static String[] getTextArray(Element context,
                                    String path,
                                    XPath xpath)
Returns the text of all elements identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
an array containing the text of each element matching the XPath expression.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

getUniqueElements

public static Element[] getUniqueElements(Element context,
                                          String path,
                                          String uniqueTag,
                                          XPath xpath)
Returns the unique elements identified by an XPath expression and a sub-expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
uniqueTag - an XPath expression to match with the elements matched with the above expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
an array containing the unique elements matching the XPath expression and subexpression. If multiple elements have the same content only the first one found is returned. Returns null if no matching element is found.
Throws:
IllegalArgumentException - if either the context, XPath expression or XPath sub-expression are null.

getUniqueText

public static String[] getUniqueText(Element context,
                                     String path,
                                     XPath xpath)
Returns the text of all unique elements identified by an XPath expression.

Parameters:
context - the context from which to start the XPath search.
path - the XPath expression.
xpath - an XPath object to use for the search. This allows the caller to re-use XPath objects when performing multiple searches. May be null.
Returns:
an array containing the text of each element matching the XPath expression and containing unique text. If multiple elements contain the same text only the first one found is returned. Returns null if no matching element is found.
Throws:
IllegalArgumentException - if the context or XPath expression are null.

makeXPath

public static XPath makeXPath()
Shortcut method to create an XPath.

Returns:
a new XPath.

openDocumentFile

public static Document openDocumentFile(String filePath,
                                        Class c)
Opens an XML file given the file's location in the file system or on the classpath.

Parameters:
filePath - the path to the file. Must be an absolute path or a path relative to a location in the classpath.
c - the class that will be used to find a path relative to the classpath.
Returns:
a DOM for the file.
Throws:
IllegalArgumentException - if the file path is null.
WWRuntimeException - if an exception or error occurs while opening and parsing the file. The causing exception is included in this exception's Throwable.initCause(Throwable) .

NASA World Wind