Patrick Kwinten
Patrick Kwinten

Reputation: 2048

Get the base url of application in Java

Is there a nicer way to get the base URL of ref to the current application in XPages/Java?

FacesContext facesContext = FacesContext.getCurrentInstance();
XSPContext context = XSPContext.getXSPContext(facesContext);
XSPUrl url = context.getUrl();
String host = url.getScheme() + "://" + url.getHost() + "/" + url.getPath();

Upvotes: 1

Views: 1879

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30960

Maybe just a little bit nicer:

String serverPathNsf = url.getAddress().replace(url.getSiteRelativeAddress(context), "")

url.getAddress() gives you server + path to nsf + xsp

    http://yourServer/pathTo.nsf/your.xsp

url.getSiteRelativeAddress(context) gives you the xsp

    /your.xsp

and url.getAddress().replace(url.getSiteRelativeAddress(context), "") returns server + path to nsf

    http://yourServer/pathTo.nsf

Upvotes: 3

Related Questions