Reputation: 135
I am trying to get the complete path of a page in order to convert it into a url.
What I have tried so far,
private static String PAGE = "/content/geometrixx/en/toolbar";
private static String URL_TO_OPEN;
public static String getUrl(Set<String> pages, ResourceResolver resolver){
Resource htmlPage = resolver.getResource(PAGE);
if(htmlPage != null){
URL_TO_OPEN = htmlPage.getPath().concat(StringConstraints.DOT).concat(StringConstraints.HTML);
return URL_TO_OPEN;
}
}
In this case, URL_TO_OPEN = "/content/geometrixx/en/toolbar.html"
But what I require is, e.g., "http://localhost:4502/content/geometrixx/en/toolbar.html"
Can someone please help me out with how I can get it to be in this format instead, that is get the [hostname]:[port] as well?
http://[hostname]:[port]/content/geometrixx/en/toolbar.html
Upvotes: 1
Views: 4597
Reputation: 41
This can be accomplished using the Externalizer OSGi Serive
Add the mappings in the externalizer service configuration
local http://localhost:4502
author http://localhost:4502
publish http://localhost:4503
To get the URL
String myURL = externalizer.externalLink(resolver, Externalizer.LOCAL, PAGE) + ".html";
This will create the URL
http://localhost:4502/content/geometrixx/en/toolbar.html
Please refer to documentation
Upvotes: 3