ucar.unidata.util
Class CatalogUtil

java.lang.Object
  extended by ucar.unidata.util.CatalogUtil

public class CatalogUtil
extends Object

A set of utilities for dealing with Thredds catalogs

Version:
$Revision: 1.68 $Date: 2007/07/09 22:59:58 $
Author:
IDV development team

Field Summary
static String ATTR_ACTION
          Attribute name for the xml attribute "action "
static String ATTR_BASE
          Attribute name for the xml attribute "base "
static String ATTR_CATALOGURL
          Xml attribute name for the url where the doc came from
static String ATTR_DATASETGROUP
          Xml attribute name for the data set group
static String ATTR_DATASETID
          Xml attribute name for the data set id
static String ATTR_DATATYPE
          Attribute name for the xml attribute "dataType "
static String ATTR_ID
          Attribute name for the xml attribute "ID "
static String ATTR_INHERITED
          Attribute name for the xml attribute "inherited "
static String ATTR_METADATATYPE
           
static String ATTR_NAME
          Attribute name for the xml attribute "name "
static String ATTR_SERVERID
          Attribute name for the xml attribute "serverID "
static String ATTR_SERVICENAME
          Attribute name for the xml attribute "serviceName "
static String ATTR_SERVICETYPE
          Attribute name for the xml attribute "serviceType "
static String ATTR_SUFFIX
          Attribute name for the xml attribute "suffix "
static String ATTR_TYPE
          Attribute name for the xml attribute "type "
static String ATTR_UNITS
          Attribute name for the xml node "units"
static String ATTR_URL
          Attribute name for the xml attribute "url "
static String ATTR_URLPATH
          Attribute name for the xml attribute "urlPath "
static String ATTR_VALUE
          Attribute name for the xml attribute "value "
static String ATTR_VERSION
          Attribute name for the xml attribute "version "
static String ATTR_XLINK_HREF
          Attribute name for the xml attribute "xlink:href "
static String ATTR_XLINK_TITLE
          Attribute name for the xml attribute "xlink:title "
static String NULL_STRING
          More clear than then doing (String)null
static String PROP_ANNOTATIONSERVER
          Property name for the annotations server url
static String PROP_CATALOGURL
          Property name for the url of the catalog
static String PROP_DATASETGROUP
          Property name for the data set group
static String PROP_DATASETID
          Property name for the data set id
static String PROP_SERVICE_HTTP
          This needs to be the same as unidata.data.DataSource
static String PROP_TITLE
          This needs to be the same as unidata.data.DataSource.PROP_TITLE
static String SERVICE_ADDE
          Service type value for the adde service
static String SERVICE_COMPOUND
          Service type value for the compound service
static String SERVICE_DODS
          Service type value for the dods service
static String SERVICE_FILE
          Service type value for the compound service
static String SERVICE_HTTP
          Service type value for the wcs service
static String SERVICE_OPENDAP
          Service type value for the OPeNDAP service
static String SERVICE_RESOLVER
          Service name of the special resolver service.
static String TAG_ACCESS
          Tag name for the xml node "access"
static String TAG_CATALOG
          Tag name for the xml node "catalog"
static String TAG_CATALOGREF
          Tag name for the xml node "catalogRef"
static String TAG_COLLECTION
          Tag name for the xml node "collection"
static String TAG_CONTACT
          contact
static String TAG_DATASET
          Tag name for the xml node "dataset"
static String TAG_DATASIZE
          _more_
static String TAG_DATATYPE
          Tag name for the xml node "dataType"
static String TAG_DATE
          _more_
static String TAG_DOCPARENT
          Tag name for the xml node "docparent"
static String TAG_DOCUMENTATION
          Tag name for the xml node "documentation"
static String TAG_EAST
          xml tag name
static String TAG_END
          _more_
static String TAG_GEOSPATIALCOVERAGE
          _more_
static String TAG_LATLONBOX
          xml tag name
static String TAG_METADATA
          Tag name for the xml node "metadata"
static String TAG_NAME
          name
static String TAG_NORTH
          xml tag name
static String TAG_PROPERTY
          Tag name for the xml node "property"
static String TAG_QUERYCAPABILITY
          Tag name for the xml node "queryCapability"
static String TAG_SERVER
          Tag name for the xml node "server "
static String TAG_SERVICE
          Tag name for the xml node "service "
static String TAG_SERVICENAME
          Tag name for the xml node "serviceName"
static String TAG_SOUTH
          xml tag name
static String TAG_START
          _more_
static String TAG_TIMECOVERAGE
          _more_
static String TAG_WEST
          xml tag name
static double THREDDS_VERSION_0_4
          Value for the thredds catalog v0.4
static double THREDDS_VERSION_0_5
          Value for the thredds catalog v0.5
static double THREDDS_VERSION_0_6
          Value for the thredds catalog v0.6
static double THREDDS_VERSION_1_0
          Value for the thredds catalog v1.0
static String VALUE_ANNOTATIONSERVER
          Xml attribute name for the data set id
static String VALUE_RIGHTS
          Xml attribute value for the rights documentation
static String VALUE_SUMMARY
          Xml attribute value for the summary documentation
 
Constructor Summary
CatalogUtil()
           
 
Method Summary
static void addServiceProperties(Element datasetNode, Hashtable properties, String urlPath)
          Add any service urls to the properties
static void errorMessage(String msg)
          Log the error
static String findBaseForDataset(Element datasetNode, Element root)
          Find the base url attribute from the service that the given datasetNode is associated with.
static String findDataTypeForDataset(Element datasetNode, Element root, double version, boolean firstCall)
          Recurse up the DOM tree, looking for a dataset that contains a dataType attribute.
static Element findServiceNodeForDataset(Element datasetNode, boolean showErrors, String type)
          Find the service xml element for the given dataset node.
static int generateHtml(Element root, Element datasetNode, int cnt, String bundleTemplate, String jnlpTemplate)
          Generate an html representation of the catalog
static String getAbsoluteUrl(Element serviceNode, String urlPath)
          Find the base url for the given service node.
static Object[] getResolverData(String resolverUrl, Hashtable properties)
          This reads the xml pointed to by the given resolverUrl.
static String getServiceType(Element serviceNode)
          Find the service type attribute for the given service node.
static String getTitleFromDataset(Element datasetNode)
          Assemble the String title for the given dataset.
static String getUrlPath(Element datasetNode)
          Lookup and return the urlPath defined for the given datasetNode.
static double getVersion(Element node)
          A utiliry to get the version from the catalog root.
static boolean haveChildCatalogs(Element node)
           
static boolean haveChildDatasets(Element node)
           
static String resolveUrl(String resolverUrl, Hashtable properties)
          The given resolverUrl should return a catalog that holds one dataset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_TITLE

public static final String PROP_TITLE
This needs to be the same as unidata.data.DataSource.PROP_TITLE

See Also:
Constant Field Values

PROP_SERVICE_HTTP

public static final String PROP_SERVICE_HTTP
This needs to be the same as unidata.data.DataSource

See Also:
Constant Field Values

PROP_CATALOGURL

public static final String PROP_CATALOGURL
Property name for the url of the catalog

See Also:
Constant Field Values

PROP_DATASETID

public static final String PROP_DATASETID
Property name for the data set id

See Also:
Constant Field Values

PROP_DATASETGROUP

public static final String PROP_DATASETGROUP
Property name for the data set group

See Also:
Constant Field Values

PROP_ANNOTATIONSERVER

public static final String PROP_ANNOTATIONSERVER
Property name for the annotations server url

See Also:
Constant Field Values

ATTR_CATALOGURL

public static final String ATTR_CATALOGURL
Xml attribute name for the url where the doc came from

See Also:
Constant Field Values

ATTR_DATASETGROUP

public static final String ATTR_DATASETGROUP
Xml attribute name for the data set group

See Also:
Constant Field Values

ATTR_DATASETID

public static final String ATTR_DATASETID
Xml attribute name for the data set id

See Also:
Constant Field Values

ATTR_METADATATYPE

public static final String ATTR_METADATATYPE
See Also:
Constant Field Values

VALUE_ANNOTATIONSERVER

public static final String VALUE_ANNOTATIONSERVER
Xml attribute name for the data set id

See Also:
Constant Field Values

VALUE_SUMMARY

public static final String VALUE_SUMMARY
Xml attribute value for the summary documentation

See Also:
Constant Field Values

VALUE_RIGHTS

public static final String VALUE_RIGHTS
Xml attribute value for the rights documentation

See Also:
Constant Field Values

NULL_STRING

public static final String NULL_STRING
More clear than then doing (String)null


SERVICE_RESOLVER

public static final String SERVICE_RESOLVER
Service name of the special resolver service. If a data set has a resolver service then the url of the data set actually points to a resolver service which will give back a catalog that contains the actual data set

See Also:
Constant Field Values

SERVICE_COMPOUND

public static final String SERVICE_COMPOUND
Service type value for the compound service

See Also:
Constant Field Values

SERVICE_FILE

public static final String SERVICE_FILE
Service type value for the compound service

See Also:
Constant Field Values

SERVICE_HTTP

public static final String SERVICE_HTTP
Service type value for the wcs service

See Also:
Constant Field Values

SERVICE_DODS

public static final String SERVICE_DODS
Service type value for the dods service

See Also:
Constant Field Values

SERVICE_ADDE

public static final String SERVICE_ADDE
Service type value for the adde service

See Also:
Constant Field Values

SERVICE_OPENDAP

public static final String SERVICE_OPENDAP
Service type value for the OPeNDAP service

See Also:
Constant Field Values

THREDDS_VERSION_0_4

public static final double THREDDS_VERSION_0_4
Value for the thredds catalog v0.4

See Also:
Constant Field Values

THREDDS_VERSION_0_5

public static final double THREDDS_VERSION_0_5
Value for the thredds catalog v0.5

See Also:
Constant Field Values

THREDDS_VERSION_0_6

public static final double THREDDS_VERSION_0_6
Value for the thredds catalog v0.6

See Also:
Constant Field Values

THREDDS_VERSION_1_0

public static final double THREDDS_VERSION_1_0
Value for the thredds catalog v1.0

See Also:
Constant Field Values

TAG_LATLONBOX

public static final String TAG_LATLONBOX
xml tag name

See Also:
Constant Field Values

TAG_NORTH

public static final String TAG_NORTH
xml tag name

See Also:
Constant Field Values

TAG_SOUTH

public static final String TAG_SOUTH
xml tag name

See Also:
Constant Field Values

TAG_EAST

public static final String TAG_EAST
xml tag name

See Also:
Constant Field Values

TAG_WEST

public static final String TAG_WEST
xml tag name

See Also:
Constant Field Values

TAG_NAME

public static final String TAG_NAME
name

See Also:
Constant Field Values

TAG_CONTACT

public static final String TAG_CONTACT
contact

See Also:
Constant Field Values

TAG_GEOSPATIALCOVERAGE

public static final String TAG_GEOSPATIALCOVERAGE
_more_

See Also:
Constant Field Values

TAG_TIMECOVERAGE

public static final String TAG_TIMECOVERAGE
_more_

See Also:
Constant Field Values

TAG_START

public static final String TAG_START
_more_

See Also:
Constant Field Values

TAG_END

public static final String TAG_END
_more_

See Also:
Constant Field Values

TAG_DATASIZE

public static final String TAG_DATASIZE
_more_

See Also:
Constant Field Values

TAG_DATE

public static final String TAG_DATE
_more_

See Also:
Constant Field Values

TAG_ACCESS

public static final String TAG_ACCESS
Tag name for the xml node "access"

See Also:
Constant Field Values

TAG_DOCUMENTATION

public static final String TAG_DOCUMENTATION
Tag name for the xml node "documentation"

See Also:
Constant Field Values

TAG_DOCPARENT

public static final String TAG_DOCPARENT
Tag name for the xml node "docparent"

See Also:
Constant Field Values

TAG_CATALOG

public static final String TAG_CATALOG
Tag name for the xml node "catalog"

See Also:
Constant Field Values

TAG_CATALOGREF

public static final String TAG_CATALOGREF
Tag name for the xml node "catalogRef"

See Also:
Constant Field Values

TAG_COLLECTION

public static final String TAG_COLLECTION
Tag name for the xml node "collection"

See Also:
Constant Field Values

TAG_DATASET

public static final String TAG_DATASET
Tag name for the xml node "dataset"

See Also:
Constant Field Values

TAG_DATATYPE

public static final String TAG_DATATYPE
Tag name for the xml node "dataType"

See Also:
Constant Field Values

TAG_METADATA

public static final String TAG_METADATA
Tag name for the xml node "metadata"

See Also:
Constant Field Values

TAG_QUERYCAPABILITY

public static final String TAG_QUERYCAPABILITY
Tag name for the xml node "queryCapability"

See Also:
Constant Field Values

TAG_SERVER

public static final String TAG_SERVER
Tag name for the xml node "server "

See Also:
Constant Field Values

TAG_SERVICE

public static final String TAG_SERVICE
Tag name for the xml node "service "

See Also:
Constant Field Values

TAG_SERVICENAME

public static final String TAG_SERVICENAME
Tag name for the xml node "serviceName"

See Also:
Constant Field Values

ATTR_UNITS

public static final String ATTR_UNITS
Attribute name for the xml node "units"

See Also:
Constant Field Values

TAG_PROPERTY

public static final String TAG_PROPERTY
Tag name for the xml node "property"

See Also:
Constant Field Values

ATTR_ACTION

public static final String ATTR_ACTION
Attribute name for the xml attribute "action "

See Also:
Constant Field Values

ATTR_DATATYPE

public static final String ATTR_DATATYPE
Attribute name for the xml attribute "dataType "

See Also:
Constant Field Values

ATTR_BASE

public static final String ATTR_BASE
Attribute name for the xml attribute "base "

See Also:
Constant Field Values

ATTR_ID

public static final String ATTR_ID
Attribute name for the xml attribute "ID "

See Also:
Constant Field Values

ATTR_INHERITED

public static final String ATTR_INHERITED
Attribute name for the xml attribute "inherited "

See Also:
Constant Field Values

ATTR_NAME

public static final String ATTR_NAME
Attribute name for the xml attribute "name "

See Also:
Constant Field Values

ATTR_VALUE

public static final String ATTR_VALUE
Attribute name for the xml attribute "value "

See Also:
Constant Field Values

ATTR_SERVERID

public static final String ATTR_SERVERID
Attribute name for the xml attribute "serverID "

See Also:
Constant Field Values

ATTR_SERVICENAME

public static final String ATTR_SERVICENAME
Attribute name for the xml attribute "serviceName "

See Also:
Constant Field Values

ATTR_SERVICETYPE

public static final String ATTR_SERVICETYPE
Attribute name for the xml attribute "serviceType "

See Also:
Constant Field Values

ATTR_SUFFIX

public static final String ATTR_SUFFIX
Attribute name for the xml attribute "suffix "

See Also:
Constant Field Values

ATTR_TYPE

public static final String ATTR_TYPE
Attribute name for the xml attribute "type "

See Also:
Constant Field Values

ATTR_URL

public static final String ATTR_URL
Attribute name for the xml attribute "url "

See Also:
Constant Field Values

ATTR_URLPATH

public static final String ATTR_URLPATH
Attribute name for the xml attribute "urlPath "

See Also:
Constant Field Values

ATTR_VERSION

public static final String ATTR_VERSION
Attribute name for the xml attribute "version "

See Also:
Constant Field Values

ATTR_XLINK_HREF

public static final String ATTR_XLINK_HREF
Attribute name for the xml attribute "xlink:href "

See Also:
Constant Field Values

ATTR_XLINK_TITLE

public static final String ATTR_XLINK_TITLE
Attribute name for the xml attribute "xlink:title "

See Also:
Constant Field Values
Constructor Detail

CatalogUtil

public CatalogUtil()
Method Detail

getVersion

public static double getVersion(Element node)
A utiliry to get the version from the catalog root.

Parameters:
node - The xml node
Returns:
The version

haveChildDatasets

public static boolean haveChildDatasets(Element node)

haveChildCatalogs

public static boolean haveChildCatalogs(Element node)

getServiceType

public static String getServiceType(Element serviceNode)
Find the service type attribute for the given service node. This is thredds version specific - looking for either "servicetype" attribute or "type" attr.

Parameters:
serviceNode - The service node to look for the service type.
Returns:
The service type attribute or null if not found.

getTitleFromDataset

public static String getTitleFromDataset(Element datasetNode)
Assemble the String title for the given dataset. We look for the first two "name" attributes in the xml tree and concatenate them (If found).

Parameters:
datasetNode - The dataset node we are looking at.
Returns:
The title for this dataset node. (may be null).

errorMessage

public static void errorMessage(String msg)
Log the error

Parameters:
msg - the error message

findServiceNodeForDataset

public static Element findServiceNodeForDataset(Element datasetNode,
                                                boolean showErrors,
                                                String type)
Find the service xml element for the given dataset node. First, we look for any service nodes contained by the dataset node. If not found then we find the service name from the dataset node. If no service name attrbiute is found then print an error and return null. Now, we search the xml tree under the root node to find a service node with the given name. If not found then print an error and return null.

Parameters:
datasetNode - The dataset node to look for a service node for.
showErrors - Do we tell the user if there was an error
type - service type
Returns:
Return the service node or null if not found.

findBaseForDataset

public static String findBaseForDataset(Element datasetNode,
                                        Element root)
Find the base url attribute from the service that the given datasetNode is associated with.

Parameters:
datasetNode - The dataset node we are looking for a base url for.
root -
Returns:
The base url for the given dataset node.

findDataTypeForDataset

public static String findDataTypeForDataset(Element datasetNode,
                                            Element root,
                                            double version,
                                            boolean firstCall)
Recurse up the DOM tree, looking for a dataset that contains a dataType attribute. We also look at "access" nodes contained by the dataset node.

Parameters:
datasetNode - The dataset node we are looking at.
root - The root of the xml tree
version - The catalog version<
firstCall - Is this the leaf node
Returns:
The name of the service that provides this dataset.

getAbsoluteUrl

public static String getAbsoluteUrl(Element serviceNode,
                                    String urlPath)
Find the base url for the given service node. If not found print an error and return null. If found then look for the "suffix" attribute of the service node. If found append it to the urlPath. Return the base concatenated with the urlPath.

Parameters:
serviceNode - The service node for the given urlPath.
urlPath - The tail end of the absolute url.
Returns:
The full url path.

getUrlPath

public static String getUrlPath(Element datasetNode)
Lookup and return the urlPath defined for the given datasetNode.

Parameters:
datasetNode - The dataset node we are looking at.
Returns:
The url path for the dataset node.

getResolverData

public static Object[] getResolverData(String resolverUrl,
                                       Hashtable properties)
This reads the xml pointed to by the given resolverUrl. It flags an error if the url is bad, the xml is bad, the xml contains 0 dataset nodes, the xml contains more than one dataset node. It returns an array of object which contain:
        Object[] {newXmlRoot, datasetNode, serviceNode, url}
  

Parameters:
resolverUrl - The url pointing to the resolver catalog.
properties - The properties
Returns:
Array of root element, dataset node, service node and the absolute url of the data.

resolveUrl

public static String resolveUrl(String resolverUrl,
                                Hashtable properties)
The given resolverUrl should return a catalog that holds one dataset. This method returns the absolute url that that catalog holds. If the given properties is no null then this will also try to extract the title from the xml and will put the PROP_TITLE into the properties.

Parameters:
resolverUrl - The url pointing to the resolved catalog.
properties - To put the title into.
Returns:
The absolute url that the resolverUrl resolves to (may be null).

addServiceProperties

public static void addServiceProperties(Element datasetNode,
                                        Hashtable properties,
                                        String urlPath)
Add any service urls to the properties

Parameters:
datasetNode - data set node
properties - properties
urlPath - base url

generateHtml

public static int generateHtml(Element root,
                               Element datasetNode,
                               int cnt,
                               String bundleTemplate,
                               String jnlpTemplate)
Generate an html representation of the catalog

Parameters:
root - Root of the catalog
datasetNode - The data set node we are looking at
cnt - The current count of the data set nodes we have processed
bundleTemplate - The bundle template we generate the bundle from
jnlpTemplate - The jnlp template
Returns:
The current count