Package org.devacfr.maven.skins.reflow
Class URITool
- java.lang.Object
-
- org.devacfr.maven.skins.reflow.URITool
-
@DefaultKey("uriTool") public class URITool extends ObjectAn Apache Velocity tool that provides utility methods to work with URIs/URLs and links.- Since:
- 1.0
- Author:
- Andrius Velykis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classURITool.URLRebaserURL rebaser: based on an old and a new path, can rebase a link based on old path to a value based on the new path.
-
Constructor Summary
Constructors Constructor Description URITool()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URITool.URLRebasercreateURLRebaser(String parentBaseUrl, String childBaseUrl)static StringnormalisedBaseUrl(String baseUrl)remove url path separator ('/') to the end of path.static StringrelativizeLink(String baseDirUri, String link)Resolves the link as relative to the base dir URI.static URItoURI(String uri)Creates a URI by parsing the given string.
-
-
-
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 onelink- 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, iehttp://maven.apache.org/is valid,http://maven.apache.org/index.htmlis not.childBaseUrl- the new base URI. Has to be parsable as a URI.- Returns:
- Returns new instance of
URITool.URLRebaserallowing to calculate/relative the link as viewed from a different base. This returns theparentBaseUrllink if link is absolute. - See Also:
URIPathDescriptor.rebaseLink(String),URITool.URLRebaser.rebaseLink(String)
-
-