Package org.apache.sis.internal.util
Class DefinitionURI
java.lang.Object
org.apache.sis.internal.util.DefinitionURI
Utility methods for parsing OGC's URI (URN or URL) in the
Some example of authorities are:
"urn:ogc:def" namespace.
For example, all the following URIs are for the same object:
"EPSG:4326"(older format)"EPSG::4326"(often seen for similarity with URN below)"urn:ogc:def:crs:EPSG::4326"(version number is omitted)"urn:ogc:def:crs:EPSG:8.2:4326"(explicit version number, here 8.2)"urn:x-ogc:def:crs:EPSG::4326"(prior registration of"ogc"to IANA)"http://www.opengis.net/def/crs/EPSG/0/4326""http://www.opengis.net/gml/srs/epsg.xml#4326"
code field will be "m%2Fs" instead of "m/s".
http://www.opengis.net/def/uom/SI/0/m%2Fs
Parts of URN
URN begins with"urn:ogc:def:" (formerly "urn:x-ogc:def:") followed by:
- an object type
- an authority
- an optional version number (often omitted)
- the code
- an arbitrary number of parameters
NameMeaning class.
| Object type | Meaning |
|---|---|
| axis | Coordinate system axe definition |
| axisDirection | Axis direction code definition |
| coordinateOperation | Coordinate operation definition |
| crs | Coordinate reference system definition |
| cs | Coordinate system definition |
| datum | Datum definition |
| dataType | Data type definition |
| derivedCRSType | Derived CRS type code definition |
| documentType | Document type definition |
| ellipsoid | Ellipsoid definition |
| featureType | Feature type definition |
| group | Operation parameter group definition |
| meaning | Parameter meaning definition |
| meridian | Prime meridian definition |
| method | Operation method definition |
| nil | Explanations for missing information |
| parameter | Operation parameter definition |
| phenomenon | Observable property definition |
| pixelInCell | Pixel in cell code definition |
| rangeMeaning | Range meaning code definition |
| referenceSystem | Value reference system definition |
| uom | Unit of measure definition |
| verticalDatumType | Vertical datum type code definition |
| Authority | Purpose |
|---|---|
"OGC" | Objects defined by the Open Geospatial Consortium. |
"EPSG" | Referencing objects defined in the EPSG database. |
"EDCS" | Environmental Data Coding Specification. |
"SI" | International System of Units. |
"UCUM" | Unified Code for Units of Measure. |
Combined URNs
This implementation does not handle combined URNs. An example of combined URN would be"urn:ogc:def:crs,crs:EPSG:6.3:27700,crs:EPSG:6.3:5701".- Since:
- 0.4
- Version:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe authority part of a URI, ornullif none (empty).The code part of a URI, ornullif none (empty).static final charThe separator between components in a URN.private static final charThe separator between a URL and its first components.private static final charThe separator between components in a URL after the first component.If the URI contains sub-components, those sub-components.static final StringThe domain of URLs in the OGC namespace.booleantrueif the URI is a"http://www.opengis.net/gml/…"URL.booleantrueif the URI is a"http://www.opengis.net/…"URL, orfalseif the URI is a"urn:ogc:def:…"URN.private static final charSeparator between keys and values in the query part of a URL.static final StringA version number to be considered as if no version were provided.String[]The parameters, ornullif none.Server and path portions of HTTP URL for various types (currently"crs").static final StringThe "urn:ogc:def" prefix used in all URN supported by this class.static final charThe path separator in URN.The type part of a URI, ornullif none (empty).The version part of a URI, ornullif none (empty). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidappendStringTo(StringBuilder buffer, char separator) Formats the string representation of this URI into the given buffer.private static StringcodeForGML(String type, String authority, String url, int lower, DefinitionURI result) Implementation of URI parser for the HTTP forms in GML namespace.static StringcodeOf(String type, String authority, CharSequence uri) Returns the code part of the given URI, provided that it matches the given object type and authority.static DefinitionURIAttempts to parse the given URI, which may either a URN or URL.private static DefinitionURIParses a sub-region of the given URI.static booleanregionMatches(String part, String urn, int lower, int upper) Returnstrueif a sub-region ofurnmatches the givenpart, ignoring case, leading and trailing whitespaces.private static intskipIdentifierPart(String text, int i) Returns the index after the last identifier character.private static intsplitKeyValue(String uri, int lower, int upper) Returns the index of the'='character in the given sub-string, provided that all characters before it are spaces or decimal digits.toString()Returns a string representation of this URI.
-
Field Details
-
PREFIX
The "urn:ogc:def" prefix used in all URN supported by this class.- See Also:
-
SEPARATOR
public static final char SEPARATORThe path separator in URN.- See Also:
-
COMPONENT_SEPARATOR
public static final char COMPONENT_SEPARATORThe separator between components in a URN.Example: in"urn:ogc:def:crs,crs:EPSG:9.1:27700,crs:EPSG:9.1:5701", the components are"crs:EPSG:9.1:27700"and"crs:EPSG:9.1:5701".- See Also:
-
COMPONENT_SEPARATOR_1
private static final char COMPONENT_SEPARATOR_1The separator between a URL and its first components. In URL syntax, this is the separator between URL path and the query.Example:http://www.opengis.net/def/crs-compound?1=…&2=…- See Also:
-
COMPONENT_SEPARATOR_2
private static final char COMPONENT_SEPARATOR_2The separator between components in a URL after the first component.Example:http://www.opengis.net/def/crs-compound?1=…&2=…- See Also:
-
KEY_VALUE_SEPARATOR
private static final char KEY_VALUE_SEPARATORSeparator between keys and values in the query part of a URL.Example:http://www.opengis.net/def/crs-compound?1=…&2=…- See Also:
-
DOMAIN
The domain of URLs in the OGC namespace.- See Also:
-
PATHS
Server and path portions of HTTP URL for various types (currently"crs"). For each URL, value starts after the protocol part and finishes before the authority filename.As of Apache SIS 0.4, this map has a single entry. However, more entries may be added in future SIS versions. If new entries are added, then see the TODO comment in the
codeForGML(String, String, String, int, DefinitionURI)method. -
NO_VERSION
A version number to be considered as if no version were provided. This value is part of OGC specification (not a SIS-specific hack).- See Also:
-
isHTTP
public boolean isHTTPtrueif the URI is a"http://www.opengis.net/…"URL, orfalseif the URI is a"urn:ogc:def:…"URN. -
isGML
public boolean isGMLtrueif the URI is a"http://www.opengis.net/gml/…"URL. A value oftrueshould imply thatisHTTPis alsotrue. -
type
The type part of a URI, ornullif none (empty). Note that the set of valid types in OGC namespace is restricted. See class javadoc for more information.Example: In the"urn:ogc:def:crs:EPSG:8.2:4326"URN, this is"crs".- See Also:
-
authority
The authority part of a URI, ornullif none (empty). Note that the set of valid authorities in OGC namespace is restricted. See class javadoc for more information.Example: In the"urn:ogc:def:crs:EPSG:8.2:4326"URN, this is"EPSG". -
version
The version part of a URI, ornullif none (empty). This field is null if the version in the parsed string was "0".Example: In the"urn:ogc:def:crs:EPSG:8.2:4326"URN, this is"8.2". -
code
The code part of a URI, ornullif none (empty).Example: In the"urn:ogc:def:crs:EPSG:8.2:4326"URN, this is"4326". -
parameters
The parameters, ornullif none.Example: In the"urn:ogc:def:crs:OGC:1.3:AUTO42003:1:-100:45"URN, this is{"1", "-100", "45"}}. -
components
If the URI contains sub-components, those sub-components. Otherwisenull.URN example: if the URI is"urn:ogc:def:crs,crs:EPSG:9.1:27700,crs:EPSG:9.1:5701", then thisDefinitionURIwill contain the"urn:ogc:def:crs"header with two components:"urn:ogc:def:crs:EPSG:9.1:27700""urn:ogc:def:crs:EPSG:9.1:5701"
HTTP example: if the URI isNote that this array may contain"http://www.opengis.net/def/crs-compound?1=(…)/crs/EPSG/9.1/27700&2=(…)/crs/EPSG/9.1/5701", then thisDefinitionURIwill contain the"http://www.opengis.net/def/crs-compound"header with two components:"http://http://www.opengis.net/def/crs/EPSG/9.1/27700""http://http://www.opengis.net/def/crs/EPSG/9.1/5701"
nullelements if we failed to parse the corresponding component.
-
-
Constructor Details
-
DefinitionURI
private DefinitionURI()Forparse(String)usage only.
-
-
Method Details
-
parse
Attempts to parse the given URI, which may either a URN or URL. If this method does not recognize the given URI, then it returnsnull. If the given URI is incomplete, then thecodevalue will benull.- Parameters:
uri- the URI to parse.- Returns:
- the parse result, or
nullif the given URI is not recognized.
-
parse
Parses a sub-region of the given URI. This method can start parsing for an arbitrary URI part, no necessarily the root. The first URI part is identified by an ordinal number: This method may invoke itself recursively if the URI contains sub-components.- Parameters:
uri- the URI to parse.prefixIsOptional-trueif "urn:ogc:def" may not be present.upper- upper index of the previous URI part, or -1 if none.stopAt- index (exclusive) where to stop parsing.- Returns:
- the parse result, or
nullif the URI is not recognized.
-
regionMatches
Returnstrueif a sub-region ofurnmatches the givenpart, ignoring case, leading and trailing whitespaces.- Parameters:
part- the expected part ("urn","ogc","def", etc.)urn- the URN for which to test a subregion.lower- index of the first character inurnto compare, after skipping whitespaces.upper- index after the last character inurnto compare, ignoring whitespaces.- Returns:
trueif the given sub-region ofurnmatch the given part.
-
splitKeyValue
Returns the index of the'='character in the given sub-string, provided that all characters before it are spaces or decimal digits. Returns -1 if the key-value separator character is not found. Note that a positive return value does not guarantee that the number is parsable. -
codeOf
Returns the code part of the given URI, provided that it matches the given object type and authority. This method is useful when:- the URI is expected to have a specific object type and authority;
- the version number is considered irrelevant;
- the code is expected to have no parameters.
- The given authority followed by the code (e.g.
"EPSG:4326"). - The URN form (e.g.
"urn:ogc:def:crs:EPSG::4326"), ignoring version number. This method accepts also the former"x-ogc"in place of"ogc". - The HTTP form (e.g.
"http://www.opengis.net/def/crs/EPSG/0/4326"). - The GML form (e.g.
"http://www.opengis.net/gml/srs/epsg.xml#4326").
- Parameters:
type- the expected object type (e.g."crs") in lower cases. See class javadoc for a list of types.authority- the expected authority, typically"EPSG". See class javadoc for a list of authorities.uri- the URI to parse.- Returns:
- the code part of the given URI, or
nullif the codespace does not match the given type and authority, the code is empty, or the code is followed by parameters.
-
codeForGML
private static String codeForGML(String type, String authority, String url, int lower, DefinitionURI result) Implementation of URI parser for the HTTP forms in GML namespace. The current implementation recognizes the following types:crsfor Coordinate Reference System objects (example:"http://www.opengis.net/gml/srs/epsg.xml#4326")
- Parameters:
type- the expected type in lower cases, ornullfor any.authority- the expected authority, ornullfor any.url- the URL to parse.result- if non-null, store the type, authority and code in that object.
-
skipIdentifierPart
Returns the index after the last identifier character. -
toString
Returns a string representation of this URI. If the URI were originally a GML's URL, then this method formats the URI in the"http://www.opengis.net/gml/srs/"namespace. Otherwise the URI were originally a URL, then this method formats the URI in the"http://www.opengis.net/"namespace. Otherwise this method formats the URI as a URN. -
appendStringTo
Formats the string representation of this URI into the given buffer. This method invoke itself recursively if this URI has components. The "urn:ogc:def" must be appended by the caller, if applicable.- Parameters:
buffer- where to format the string representation.separator- first separator to append. Ignored if the URI is actually a URL.
-