This article covers a Bloomreach Experience Manager version 12. There's an updated version available that covers our most recent release.

Custom Resource Containers

This page describes how you can inject custom resource containers into your HST2 website. We consider a resource container a node that can contain one or more binary blobs.

By default, the CMS ships with two resource containers, namely 'hippogallery:exampleImageSet' and 'hippogallery:exampleAssetSet'. In case of the container exampleImageSet, the node contains two binary blobs, 'hippogallery:thumbnail' and 'hippogallery:picture'. For example you have the node in jcr like:

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

Now, the default binary the HST2 shows should be 'hippogallery:picture' (the real picture). So, instead of having a undesirable ugly link like

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

the HST2 out-of-the-box shows the 'hippogallery:picture' when the link is:

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

This works with the help of default built in org.hippoecm.hst.core.linking.ResourceContainer's. The default available implementations are HippoGalleryImageSetContainer and HippoGalleryAssetSet. They both extend from the general AbstractResourceContainer, which you might reuse if you want to add your own custom resource container. The HippoGalleryImageSetContainer looks like:

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

Adding a custom Resource Container.

Now Assume, you have a custom image set, that looks like:

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

Now by default, if you do not add any custom resource container, then if myimageset.jpg is of type 'mygallery:imageset' the url

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

resolves to the mygallery:thumbnail. Also links /binaries/content/gallery/mysite/myimageset.jpg/myimageset.jpg/mygallery:original etcetera will work out-of-the-box, because the HST2 ships also with a fallback DefaultResourceContainer, which works on everything extending from 'hippo:document'.

But, what if you want to have the following links:

/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

This is possible by merely adding a very simple class extending AbstractResourceContainer, and add a piece of spring configuration. More advanced/exotic usecases can be easily achieved by overriding some AbstractResourceContainer methods. You can also take a look at the demosite at /src/main/java/META-INF/hst-assembly/overrides/customResourceContainers.xml and the DemositeResourceContainer.

Back to our example, we can achieve the links described above by adding the following spring config to your hst-assembly/overrides:

<?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

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

That's it.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?