Package org.xmlresolver.utils
Class URIUtils
java.lang.Object
org.xmlresolver.utils.URIUtils
URI utility methods.
- Author:
- ndw
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic URI
cwd()
Creates a URI for the users current working directory.static boolean
forbidAccess
(String allowed, String uri, boolean mergeHttps) static boolean
static URI
Create a new URI, attempting to deal with the vagaries of file: URIs.static String
normalizeURI
(String uriref) Perform character normalization on a URI reference.static URI
Resolve a URI against a base URI.
-
Constructor Details
-
URIUtils
public URIUtils()
-
-
Method Details
-
isWindows
public static boolean isWindows() -
cwd
Creates a URI for the users current working directory. In order that this method should neither raise an exception nor returnnull
, if theuser.dir
system property cannot be converted into a URI, the file URI "file:///
" is returned.- Returns:
- a file: URI for the current working directory
-
newURI
Create a new URI, attempting to deal with the vagaries of file: URIs. Given something that looks like a file: URI or a path, return a file: URI with a consistent number of leading "/". characters. Any number of leading slashes are interpreted the same way. (This is slightly at odds with specs, as file:///////path should probably be an error. But this method "fixes it" to file:///path.) Strings that don't begin file: or /, are constructed with new URI() without preprocessing. This will construct URIs for other schemes if the href parameter is valid. This method will encode query strings, but that's ok for this application.- Parameters:
href
- The string to be interpreted as a URI.- Returns:
- A URI constructed from the href parameter.
- Throws:
URISyntaxException
- if the string cannot be converted into a URI.
-
resolve
Resolve a URI against a base URI.What's special here is that we take special care to attempt to resolve
jar:
andclasspath:
URIs. TheURI
class doesn't handle those, but if we're going to support them in catalogs, we need to do better.- Parameters:
baseURI
- The base URI.uri
- The possibily relative URI to resolve against the base URI.- Returns:
- The resolved URI.
- Throws:
IllegalArgumentException
- if the uri cannot be converted to a URI.
-
normalizeURI
Perform character normalization on a URI reference.- Parameters:
uriref
- The URI reference.- Returns:
- The normalized URI reference.
-
forbidAccess
-