Custom Resource Containers

This page explains how to register custom resource containers in your HST2 website. A resource container is a node that holds one or more binary blobs.

By default, Bloomreach Content provides two resource containers: hippogallery:exampleImageSet and hippogallery:exampleAssetSet. For example, the exampleImageSet node contains two binaries: hippogallery:thumbnail and hippogallery:picture. The JCR structure looks like this:

/content:
  /gallery:
    /mysite:
      /myimageset.jpg:
        /myimageset.jpg:
          /hippogallery:thumbnail:
          /hippogallery:picture:

By default, HST2 serves the hippogallery:picture binary (the main image) when you request the following URL:

/binaries/content/gallery/mysite/myimageset.jpg

Without custom configuration, you might see a less user-friendly link such as:

/binaries/content/gallery/mysite/myimageset.jpg/imageset.jpg/hippogallery:picture

However, HST2 is configured to resolve /binaries/content/gallery/mysite/myimageset.jpg directly to the main picture. This behavior is managed by the built-in org.hippoecm.hst.core.linking.ResourceContainer implementations. The default implementations are HippoGalleryImageSetContainer and HippoGalleryAssetSet, both of which extend AbstractResourceContainer. You can extend AbstractResourceContainer to create your own custom resource container. The following example shows the HippoGalleryImageSetContainer:

public class HippoGalleryImageSetContainer extends AbstractResourceContainer { public String getNodeType() { return "hippogallery:imageset"; } }

Adding a Custom Resource Container

Suppose you have a custom image set with the following structure:

/mygallery:imageset:
  /mygallery:thumbnail:
  /mygallery:original:
  /mygallery:medium:
  /mygallery:small:

If you do not register a custom resource container, and myimageset.jpg is of type mygallery:imageset, then the URL

/binaries/content/gallery/mysite/myimageset.jpg

will resolve to mygallery:thumbnail by default. URLs such as /binaries/content/gallery/mysite/myimageset.jpg/myimageset.jpg/mygallery:original will also work, because HST2 includes a fallback DefaultResourceContainer that handles all types extending from hippo:document.

To map specific URLs to specific binaries, such as:

/binaries/content/gallery/mysite/myimageset.jpg
      --> mygallery:original

/binaries/medium/content/gallery/mysite/myimageset.jpg
      --> mygallery:medium

/binaries/small/content/gallery/mysite/myimageset.jpg
      --> mygallery:small

/binaries/thumbnail/content/gallery/mysite/myimageset.jpg
      --> mygallery:thumbnail

you need to implement a custom resource container by extending AbstractResourceContainer and registering it in your Spring configuration. For advanced use cases, you can override additional methods in AbstractResourceContainer. For reference, see the demo site configuration at /src/main/java/META-INF/hst-assembly/overrides/customResourceContainers.xml and the DemositeResourceContainer class.

To implement the mapping shown above, add the following Spring configuration to your hst-assembly/overrides directory:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/beans/spring-lang-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" > <bean id="customResourceContainers" class="org.springframework.beans.factory.config.ListFactoryBean"> <property name="sourceList"> <list> <bean class= "org.hippoecm.hst.demo.linking.MyGalleryResoureContainer"> <property name="primaryItem" value="mygallery:original"/> <property name="mappings"> <bean class= "org.springframework.beans.factory.config.MapFactoryBean"> <property name="sourceMap"> <map key-type= "java.lang.String" value-type="java.lang.String"> <entry key="mygallery:thumbnail" value="thumbnail"/> <entry key="mygallery:medium" value="medium"/> <entry key="mygallery:small" value="small"/> </map> </property> </bean> </property> </bean> </list> </property> </bean> </beans>

And implement the following Java class:

public class MyGalleryResourceContainer extends AbstractResourceContainer { public String getNodeType() { return "mygallery:imageset"; } }

This configuration enables the URL mappings described above for your custom image set.

Share Feedback
Page: /build/images-assets/custom-resource-containers
Section: Build
Category *