Package org.geotools.xml.resolver
Class SchemaResolver
Object
SchemaResolver
XML Schema resolver that maps absolute URLs to local URL resources.
Resources are sought, in order:
- In an OASIS Catalog (with URI resolution semantics), which maps URLs to arbitrary filesystem locations.
- On the classpath, where resources are located by their Simple HTTP Resource Path (see
getSimpleHttpResourcePath(URI)
). - In a cache, with optional downloading support.
- Author:
- Ben Caradoc-Davies (CSIRO Earth Science and Resource Engineering)
-
Constructor Summary
ConstructorsConstructorDescriptionConvenience constructor for a resolver with neither catalog nor cache (just classpath).SchemaResolver
(SchemaCache cache) Convenience constructor for a resolver with no catalog.SchemaResolver
(SchemaCatalog catalog) Convenience constructor for a resolver with no cache.SchemaResolver
(SchemaCatalog catalog, boolean classpath, SchemaCache cache) Constructor.SchemaResolver
(SchemaCatalog catalog, SchemaCache cache) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiongetCache()
Cache used by this Schema Resolver.static URL
getClasspathResourceUrl
(String location) Return the URL for a resource found on the classpath at the Simple HTTP Resource Path.static String
getSimpleHttpResourcePath
(String location) Return the Simple HTTP Resource Path for an absolute http/https URL.static String
getSimpleHttpResourcePath
(String location, boolean keepQuery) Return the Simple HTTP Resource Path for an absolute http/https URL.static String
getSimpleHttpResourcePath
(URI location) Return the Simple HTTP Resource Path for an absolute http/https URL.static String
getSimpleHttpResourcePath
(URI location, boolean keepQuery) Return the Simple HTTP Resource Path for an absolute http/https URL.Resolve an absolute URL to a local file or jar URL.Resolve an absolute or relative URL to a local file or jar URL.static String
resolveClasspathLocation
(String location) Return the string representation of URL for a resource found on the classpath at the Simple HTTP Resource Path.
-
Constructor Details
-
SchemaResolver
Constructor.- Parameters:
classpath
- whether schemas can be located on the classpath
-
SchemaResolver
Constructor. -
SchemaResolver
public SchemaResolver()Convenience constructor for a resolver with neither catalog nor cache (just classpath). -
SchemaResolver
Convenience constructor for a resolver with no cache. -
SchemaResolver
Convenience constructor for a resolver with no catalog.
-
-
Method Details
-
resolve
Resolve an absolute or relative URL to a local file or jar URL. Relative URLs are resolved against a context schema URL if provided.- Parameters:
location
- an absolute or relative URL for a schemacontext
- an absolute URL specifying the context schema of a relative location, or null if none- Returns:
- the string representation of a file or jar URL
- Throws:
RuntimeException
- if a local resource could not be found
-
getCache
Cache used by this Schema Resolver. Could be null if not set. -
resolve
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:
RuntimeException
- if a local resource could not be found
-
getSimpleHttpResourcePath
Return the Simple HTTP Resource Path for an absolute http/https URL. Does not include query components in the path.- Parameters:
location
- not null- Returns:
- the resource path with a leading slash
- See Also:
-
getSimpleHttpResourcePath
Return the Simple HTTP Resource Path for an absolute http/https URL.- Parameters:
location
- not nullkeepQuery
- indicates whether or not the query components should be included in the path. If this is set to true then the query portion is converted to an MD5 message digest and that string is used to identify the file in the cache.- Returns:
- the resource path with a leading slash
- See Also:
-
getSimpleHttpResourcePath
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:
- Protocol, port, fragment, and query are ignored.
- Take the host name, split it into its components, reverse their order, prepend a forward slash to each, and concatenate them.
- Append the path component of the URL.
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). Does not include query components in the path.
- 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.
-
getSimpleHttpResourcePath
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:
- Protocol, port, fragment, and query are ignored.
- Take the host name, split it into its components, reverse their order, prepend a forward slash to each, and concatenate them.
- Append the path component of the URL.
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). Does not include query components in the path.
- Parameters:
location
- not nullkeepQuery
- indicates whether or not the query components should be included in the path. If this is set to true then the query portion is converted to an MD5 message digest and that string is used to identify the file in the cache.- Returns:
- the Simple HTTP Resource Path as a string, or null if the URI is not an absolute HTTP/HTTPS URL.
-
getClasspathResourceUrl
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.- Returns:
- the URL or null if not found
-
resolveClasspathLocation
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.- Returns:
- the string representation of a classpath URL, or null if not found
-