Search code examples
hippocms

Load content from external source


What would be the best approach to load content from external source? Only approach what I could come up with is to load this data in component and then update hippo bean (see example code bellow). But is there a better way? Is there some "hippo bean post processor" or "external source provider"?



    public class MyComponent extends BaseHstComponent {
        @Overrideenter code here
        public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
            SalesDocument doc = (SalesDocument)request.getRequestContext().getContentBean();

            ExternalData externalData = externalDataSource.getExternalData(doc.getId());
            doc.setValue(externalData.getValue());

            if (doc == null) {
                response.setStatus(404);
                return;
            }

            request.setAttribute("document",doc);
        }

    }



Solution

  • There is no HippoBean post processor or external source provider at the moment. I guess in your case you want to fetch a piece of data from a remote system and you want to merge these two types of data so you can use them as one single unit in your template.

    I think the above solution probably the easiest way to go. Or you can pass along both objects to the JSP / Freemarker template and render them if needed separately.

    I do think that providing such a postprocessor might be a usefull addition especially in these kind of use cases.