Class URIUtils

java.lang.Object
org.xmlresolver.utils.URIUtils

public abstract class URIUtils extends Object
URI utility methods.
Author:
ndw
  • Constructor Details

    • URIUtils

      public URIUtils()
  • Method Details

    • isWindows

      public static boolean isWindows()
    • cwd

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

      public static URI resolve(URI baseURI, 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:
      IllegalArgumentException - if the uri cannot be converted to a URI.
    • normalizeURI

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

      public static boolean forbidAccess(String allowed, String uri, boolean mergeHttps)