Class URIUtils


  • public abstract class URIUtils
    extends java.lang.Object
    URI utility methods.
    Author:
    ndw
    • Constructor Summary

      Constructors 
      Constructor Description
      URIUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.net.URI cwd()
      Creates a URI for the users current working directory.
      static boolean forbidAccess​(java.lang.String allowed, java.lang.String uri, boolean mergeHttps)  
      static boolean isWindows()  
      static java.net.URI newURI​(java.lang.String href)
      Create a new URI, attempting to deal with the vagaries of file: URIs.
      static java.lang.String normalizeURI​(java.lang.String uriref)
      Perform character normalization on a URI reference.
      static java.net.URI resolve​(java.net.URI baseURI, java.lang.String uri)
      Resolve a URI against a base URI.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • URIUtils

        public URIUtils()
    • Method Detail

      • isWindows

        public static boolean isWindows()
      • cwd

        public static java.net.URI cwd()
        Creates a URI for the users current working directory. In order that this method should neither raise an exception nor return null, if the user.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

        public static java.net.URI newURI​(java.lang.String href)
                                   throws java.net.URISyntaxException
        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:
        java.net.URISyntaxException - if the string cannot be converted into a URI.
      • resolve

        public static java.net.URI resolve​(java.net.URI baseURI,
                                           java.lang.String uri)
        Resolve a URI against a base URI.

        What's special here is that we take special care to attempt to resolve jar: and classpath: URIs. The URI 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:
        java.lang.IllegalArgumentException - if the uri cannot be converted to a URI.
      • normalizeURI

        public static java.lang.String normalizeURI​(java.lang.String uriref)
        Perform character normalization on a URI reference.
        Parameters:
        uriref - The URI reference.
        Returns:
        The normalized URI reference.
      • forbidAccess

        public static boolean forbidAccess​(java.lang.String allowed,
                                           java.lang.String uri,
                                           boolean mergeHttps)