0

I'm a new bee to Hippo CMS. I'm working on version 10 and I'm using angularJS service to consume the rest url for "banners" I created through HippoCms.

This is my Rest URL for Banners created via Hippo's Rest Api Manager:

http://localhost:8080/site/stbetrest/Banner?_type=json

and the reponse I'm getting when consumed the link is:

    {
        "pageSize": 10,
        "total": 3,
        "items": [
            {
                "content": "<![CDATA[\r\n\r\n          <p>Banner description</p>\r\n\r\n          \r\n]]>",
                "title": "Sample banner"
            },
            {
                "content": "<![CDATA[<p>10 Simple Steps to Green Your Office:</p>\n\n<p>&nbsp;</p>\n\n<p>
<img src=\"/site/pagenotfound\" /></p>]]>",
                "title": "10 Simple Steps to Green Your Office"
            },
            {
                "content": "<![CDATA[<p>How to Green Your Dorm Room</p>]]>",
                "title": "How to Green Your Dorm Room"
            }
        ],
        "currentPage": 1,
        "totalPages": 1
    }

The Problem here is I can't see the Images I used inside the banner documents in Hippo. I want to get those Images/links to load them into a carousel created in AngularJs. Please guide me how to generate the images also into the above banner response.

UPDATE:

All though via the 'localhost:8080/cms' it shows uploaded images, but can not access the image via response:

@XmlRootElement(name = "banner")
@XmlAccessorType(XmlAccessType.NONE)
@HippoEssentialsGenerated(internalName = "gogreen:bannerdocument")
@Node(jcrType = "gogreen:bannerdocument")
public class Banner extends BaseDocument {
    @XmlElement
    @HippoEssentialsGenerated(internalName = "gogreen:title")
    public String getTitle() {
        return getProperty("gogreen:title");
    }

    @XmlJavaTypeAdapter(HippoHtmlAdapter.class)
    @XmlElement
    @HippoEssentialsGenerated(internalName = "gogreen:content")
    public HippoHtml getContent() {
        return getHippoHtml("gogreen:content");
    }

    @HippoEssentialsGenerated(internalName = "gogreen:link")
    public HippoBean getLink() {
        return getLinkedBean("gogreen:link", HippoBean.class);
    }

    @XmlJavaTypeAdapter(KerkRestAdapter.class)
    @XmlElement
    @HippoEssentialsGenerated(internalName = "gogreen:image")
    public Kerk getImage() {
        return getLinkedBean("gogreen:image", Kerk.class);
    }
}

and my Content rewriter is :

    public class RestContentRewriter extends SimpleContentRewriter {
   @Override
    protected String rewriteBinaryLink(String binaryLinkSrc, Node node, HstRequestContext requestContext, Mount targetMount) {
        return super.rewriteBinaryLink(binaryLinkSrc, node, requestContext, requestContext.getMount("site"));

    }

And My Adapter is:

public class KerkRestAdapter extends XmlAdapter<String, HippoHtml> {

@Override
public HippoHtml unmarshal(String representation) throws Exception {
    throw new UnsupportedOperationException("Unmarshalling not implemented.");
}


@Override
public String marshal(HippoHtml html) throws Exception {
    if (html == null) {
        return null;
    }

    final HstRequestContext context = RequestContextProvider.get();
    //final RestContentRewriter contentRewriter = new RestContentRewriter();
    final ContentReWriter<String> contentRewriter = new RestContentRewriter();

    final String rewrite = contentRewriter.rewrite(html.getContent(), html.getNode(), context, context.getMount("api")); 
    return "<![CDATA[" + rewrite + "]]>";
}

}

additional Question: what is the mount point to be used in rewriter? ( Rest mount name or gogreen??)

Please help !

Nomesh DeSilva
  • 1,649
  • 4
  • 25
  • 43

1 Answers1

1

You have used the Essentials Rest setup tool. That generates a example or demo Rest implementation. After generating the setup a developer shall always want to extend and refine the result.

The links inside rich text in this setup are by default generated for the current mount, which is the rest mount. Since the images are not available through the rest mount, HST generated the /pagenotfound URL.

If you inspect the bean for the Banner you see that for the HippoHtml field an HippoHtmlAdapter is used. Check the code of it: it uses the SimpleContentRewriter. Create your own version of the Adapter and use an extended version of the ContentRewriter. Override the #rewriteBinaryLink method. In it call the super method, but specify the site mount as the target mount.

I think adding an hst:alias to the site mount is a good idea so you can reference the site with the alias.

b.leunis
  • 43
  • 3