Class URITool


  • @DefaultKey("uriTool")
    public class URITool
    extends Object
    An Apache Velocity tool that provides utility methods to work with URIs/URLs and links.
    Since:
    1.0
    Author:
    Andrius Velykis
    • Constructor Detail

      • URITool

        public URITool()
    • Method Detail

      • relativizeLink

        @Nonnull
        public static String relativizeLink​(@Nullable
                                            String baseDirUri,
                                            @Nonnull
                                            String link)
        Resolves the link as relative to the base dir URI.

        Relativizes only absolute links, if the link has the same scheme, host and port as the base, it is made into a relative link as viewed from the base.

        This is the same method that's used to relativize project links in Maven site.

        Parameters:
        baseDirUri - URI that will serve as the base to calculate the relative one
        link - The link to relativize (make it relative to the base URI if possible)
        Returns:
        the relative link, if calculated, or the original link if not.
        Since:
        1.0
      • toURI

        @Nonnull
        public static URI toURI​(@Nonnull
                                String uri)
        Creates a URI by parsing the given string.
        Parameters:
        uri - The string to be parsed into a URI
        Returns:
        Returns the new URI.
      • createURLRebaser

        @Nonnull
        public static URITool.URLRebaser createURLRebaser​(@Nullable
                                                          String parentBaseUrl,
                                                          @Nullable
                                                          String childBaseUrl)
        Parameters:
        parentBaseUrl - 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.
        childBaseUrl - the new base URI. Has to be parsable as a URI.
        Returns:
        Returns new instance of URITool.URLRebaser allowing to calculate/relative the link as viewed from a different base. This returns the parentBaseUrl link if link is absolute.
        See Also:
        URIPathDescriptor.rebaseLink(String), URITool.URLRebaser.rebaseLink(String)
      • normalisedBaseUrl

        @Nullable
        public static String normalisedBaseUrl​(@Nullable
                                               String baseUrl)
        remove url path separator ('/') to the end of path.
        Parameters:
        baseUrl - a base url
        Returns:
        Returns a String representing base path instance.