Get content URL of document

Hello,

Greetings !
Please could someone tell me how do i get the full URL of the content via Java code ? I only am able to get the path /content/documents and not the hostname. I do not want to hardcode it because I could have multiple deployments.

Thanks

Hi kiki,

You can use the HstLinkCreator following this instruction

Thank you for the response. But ., I do not want to create a URL. I just need it to return http://localhost:8080/cms/?1&path=/content/documents/… . I was wondering if there is a API call to return the same. There is API that gets the PATH (getPath and getCanonicalPath) but not the URL itself

Hello Kiki,

Basically what you are trying to achieve is what the HST tag manageContent [1] [2] does for generating the content edit buttons when in preview mode. So you can look into the implementation of it. Not sure if there is a service you could use.

[1] https://javadoc.onehippo.org/13.0/tlddocs/
[2] org.hippoecm.hst.tag.HstManageContentTag

Kind regards,
Lef

Thanks. Sadly, looks there like there is no direct way to get the CMS hostname via code. I have to hardcode my deployments , i suppose

A possible workaround is to use org.hippoecm.hst.configuration.hosting.Mount#getMountProperties() after setting a mount property on each hst:root mount.

For example,

  • Set @hst:mountcmsbaseurl = "http://cms.example.com/ on an hst:root mount under a vhost.
  • From HstRequestContext#getResolvedMount().getMount(), find the root mount upward.
  • Invoke Mount#getMountProperties().get("cmsbaseurl"), which will return your configuration.

So, your code may depend on hst host / mount configurations. Even if you should set the properties on each hst:root mount in every vhost, but that should be doable.

Regards,

Woonsan

For Bloomreach Experience 12 and earlier you have this property available already. Your virtual host group has a property hst:cmslocation. From 13 you will need Woonsan’s workaround.

How about Mount#getCmsLocations() in CMS 12?
How about HstRequestUtils.getCmsBaseURL() in CMS 13?

For 12 it’s based on the ‘hst:cmslocation’ property on your host group.

Jeroen

I am using Hippo 12, so ^ helped. Thanks a lot everybody !! :smiley:

Great, @jeroen.hoffman! :+1: