org.geotools.xml
Class AppSchemaResolver

java.lang.Object
  extended by org.geotools.xml.AppSchemaResolver

public class AppSchemaResolver
extends java.lang.Object

Application schema resolver that maps absolute URLs to local URL resources.

Resources are sought, in order:

  1. In an OASIS Catalog (with URI resolution semantics), which maps URLs to arbitrary filesystem locations.
  2. On the classpath, where resoruces are located by their Simple HTTP Resource Path (see getSimpleHttpResourcePath(URI)).
  3. In a cache, with optional downloading support.

Author:
Ben Caradoc-Davies, CSIRO Earth Science and Resource Engineering

Constructor Summary
AppSchemaResolver()
          Convenience constructor for a resolver with neither catalog nor cache (just classpath).
AppSchemaResolver(AppSchemaCache cache)
          Convenience constructor for a resolver with no catalog.
AppSchemaResolver(AppSchemaCatalog catalog)
          Convenience constructor for a resolver with no cache.
AppSchemaResolver(AppSchemaCatalog catalog, AppSchemaCache cache)
           
 
Method Summary
static java.net.URL getClasspathResourceUrl(java.lang.String location)
          Return the URL for a resource found on the classpath at the Simple HTTP Resource Path.
static java.lang.String getSimpleHttpResourcePath(java.lang.String location)
          Return the Simple HTTP Resource Path for an absolute http/https URL.
static java.lang.String getSimpleHttpResourcePath(java.net.URI location)
          Return the Simple HTTP Resource Path for an absolute http/https URL.
 java.lang.String resolve(java.lang.String location)
          Resolve an absolute URL to a local file or jar URL.
static java.lang.String resolveClasspathLocation(java.lang.String location)
          Return the string representation of URL for a resource found on the classpath at the Simple HTTP Resource Path.
 java.lang.String unresolve(java.lang.String resolvedLocation)
          Maps a resolved location (a URL used to obtain a schema from a file or the classpath) to the original HTTP URL used to obtain it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppSchemaResolver

public AppSchemaResolver(AppSchemaCatalog catalog,
                         AppSchemaCache cache)

AppSchemaResolver

public AppSchemaResolver()
Convenience constructor for a resolver with neither catalog nor cache (just classpath).


AppSchemaResolver

public AppSchemaResolver(AppSchemaCatalog catalog)
Convenience constructor for a resolver with no cache.

Parameters:
catalog -

AppSchemaResolver

public AppSchemaResolver(AppSchemaCache cache)
Convenience constructor for a resolver with no catalog.

Parameters:
cache -
Method Detail

resolve

public java.lang.String resolve(java.lang.String location)
Resolve an absolute URL to a local file or jar URL.

Parameters:
location - an absolute URL
Returns:
the string representation of a file or jar URL
Throws:
java.lang.RuntimeException - if a local resource could not be found

unresolve

public java.lang.String unresolve(java.lang.String resolvedLocation)
Maps a resolved location (a URL used to obtain a schema from a file or the classpath) to the original HTTP URL used to obtain it. This is required so that relative imports can be resolved if they cross resolution boundaries. For example, an import ../../../om/.. used to import om in a schema, where one is supplied locally and the other must be downloaded and cached. Yes, this does happen in real life.


getSimpleHttpResourcePath

public static java.lang.String getSimpleHttpResourcePath(java.lang.String location)
Return the Simple HTTP Resource Path for an absolute http/https URL.

Parameters:
location - not null
Returns:
the resource path with a leading slash
See Also:
getSimpleHttpResourcePath(URI)

getSimpleHttpResourcePath

public static java.lang.String getSimpleHttpResourcePath(java.net.URI location)
Return the Simple HTTP Resource Path for an absolute http/https URL.

The Simple HTTP Resource Path maps an HTTP or HTTPS URL to a path on the classpath or relative to some other root. To form the Simple HTTP Resource Path from an http/https URL:

  1. Protocol, port, fragment, and query are ignored.
  2. Take the host name, split it into its components, reverse their order, prepend a forward slash to each, and concatenate them.
  3. Append the path component of the URL.
For example http://schemas.example.org/exampleml/exml.xsd becomes /org/example/schemas/exampleml/exml.xsd .

The Simple HTTP Resource Path always starts with a forward slash (if not null).

Parameters:
location - not null
Returns:
the Simple HTTP Resource Path as a string, or null if the URI is not an absolute HTTP/HTTPS URL.

getClasspathResourceUrl

public static java.net.URL getClasspathResourceUrl(java.lang.String location)
Return the URL for a resource found on the classpath at the Simple HTTP Resource Path. This allows (for example) schema documents in jar files to be loaded from the classpath using their canonical HTTP URLs.

Parameters:
location -
Returns:
the URL or null if not found

resolveClasspathLocation

public static java.lang.String resolveClasspathLocation(java.lang.String location)
Return the string representation of URL for a resource found on the classpath at the Simple HTTP Resource Path. This allows (for example) schema documents in jar files to be loaded from the classpath using their canonical HTTP URLs.

Parameters:
location -
Returns:
the string representation of a classpath URL, or null if not found


Copyright © 1996-2010 Geotools. All Rights Reserved.