Class URIPathDescriptor


  • public class URIPathDescriptor
    extends java.lang.Object
    Describes a link that may be absolute or relative, and that is anchored to an absolute URI.
    Since:
    1.2
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.net.URI baseURI  
      private java.net.URI link  
    • Constructor Summary

      Constructors 
      Constructor Description
      URIPathDescriptor​(java.lang.String baseURI, java.lang.String link)
      A URIPathDescriptor consists of a base URI and a link.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String correctRelativePath​(java.lang.String relativePath)  
      java.net.URI getBaseURI()
      Return the base of this URIPathDescriptor as a URI.
      java.net.URI getLink()
      Return the link of this URIPathDescriptor as a URI.
      java.net.URI rebaseLink​(java.lang.String newBase)
      Calculate the link as viewed from a different base.
      java.net.URI relativizeLink()
      Calculate the relative link with respect to the base.
      private static java.net.URI relativizeLink​(java.lang.String base, java.net.URI link)  
      java.net.URI resolveLink()
      Resolve the link to the base.
      boolean sameSite​(java.net.URI uri)
      Check if this URIPathDescriptor lives on the same site as the given URI.
      private static boolean sameSite​(java.net.URI baseURI, java.net.URI newBaseURI)  
      private static java.lang.String sanitizeBase​(java.lang.String base)  
      private static java.lang.String sanitizeLink​(java.lang.String link)  
      java.lang.String toString()
      Construct a string representation of this URIPathDescriptor.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • baseURI

        private final java.net.URI baseURI
      • link

        private final java.net.URI link
    • Constructor Detail

      • URIPathDescriptor

        public URIPathDescriptor​(java.lang.String baseURI,
                                 java.lang.String link)
        A URIPathDescriptor consists of a base URI and a link. Both arguments to this constructor have to be parsable to URIs. The baseURI parameter has to be absolute in the sense of URI.isAbsolute(). Before being parsed to URIs, the arguments are modified to catch some common bad practices: first all Windows-style backslashes '\' are replaced by forward slashes '/'. If the baseURI does not end with '/', a slash is appended. If the link starts with a '/', the first character is stripped.
        Parameters:
        baseURI - The base URI. Has to be a valid absolute URI. In addition, the path of the URI should not have any file part, ie http://maven.apache.org/ is valid, http://maven.apache.org/index.html is not. Even though the latter form is accepted without warning, the methods in this class will not return what is probably expected, because a slash is appended during construction, as noted above.
        link - the link. This may be a relative link or an absolute link. Note that URIs that start with a "/", ie don't specify a scheme, are considered relative.
        Throws:
        java.lang.IllegalArgumentException - if either argument is not parsable as a URI, or if baseURI is not absolute.
    • Method Detail

      • getBaseURI

        public java.net.URI getBaseURI()
        Return the base of this URIPathDescriptor as a URI. This is always normalized.
        Returns:
        the normalized base URI.
      • getLink

        public java.net.URI getLink()
        Return the link of this URIPathDescriptor as a URI. This is always normalized.
        Returns:
        the normalized link URI.
      • resolveLink

        public java.net.URI resolveLink()
        Resolve the link to the base. This always returns an absolute URI. If link is absolute, link is returned.
        Returns:
        the resolved link. This is equivalent to calling getBaseURI().resolve( getLink() ).
      • relativizeLink

        public java.net.URI relativizeLink()
        Calculate the relative link with respect to the base. The original link is returned if either link is relative; or link and base do not share the same site.
        Returns:
        the link as a relative URI.
      • relativizeLink

        private static java.net.URI relativizeLink​(java.lang.String base,
                                                   java.net.URI link)
      • rebaseLink

        public java.net.URI rebaseLink​(java.lang.String newBase)
        Calculate the link as viewed from a different base. This returns the original link if link is absolute. This returns resolveLink() if either newBase == null, or newBase is not parsable as a URI, or newBase and this getBaseURI() do not share the same site.
        Parameters:
        newBase - the new base URI. Has to be parsable as a URI. .
        Returns:
        a new relative link or the original link resolved, i.e. as an absolute link, if the link cannot be re-based.
      • correctRelativePath

        private static java.lang.String correctRelativePath​(java.lang.String relativePath)
      • sameSite

        public boolean sameSite​(java.net.URI uri)
        Check if this URIPathDescriptor lives on the same site as the given URI.
        Parameters:
        uri - a URI to compare with. May be null, in which case false is returned.
        Returns:
        true if getBaseURI() shares the same scheme, host and port with the given URI where null values are allowed.
      • sameSite

        private static boolean sameSite​(java.net.URI baseURI,
                                        java.net.URI newBaseURI)
      • toString

        public java.lang.String toString()
        Construct a string representation of this URIPathDescriptor. This is equivalent to calling resolveLink().toString().
        Overrides:
        toString in class java.lang.Object
        Returns:
        this URIPathDescriptor as a String.
      • sanitizeBase

        private static java.lang.String sanitizeBase​(java.lang.String base)
      • sanitizeLink

        private static java.lang.String sanitizeLink​(java.lang.String link)