Get content URL of document


#1

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


#2

Hi kiki,

You can use the HstLinkCreator following this instruction


#3

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


#4

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


#5

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


#6

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


#7

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.


#8

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


#9

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


#10

Great, @jeroen.hoffman! :+1: