close

Filter

loading table of contents...

Content Application Developer Manual / Version 2110

Table Of Contents

4.3.3.3 Using Multiple View Repositories

In a smaller project it might be sufficient to use a single view repository only.

When hosting several sites with different template sets in a single CAE, multiple view repositories may be used. The CAE provides a mechanism for choosing a set of view repositories dynamically per request.

This mechanism is separated into two services that are implementations of ViewRepositoryNameProvider and ViewRepositoryProvider respectively.

ViewRepositoryNameProvider

The ViewRepositoryNameProvider is responsible for providing the names of the view repositories to be used for resolving templates for the current request. For instance, if a page is requested that is located in a "sports" subsite within a larger site, a list [sports,site] might be returned where "site" refers to a common template sets that is used when the more special set "sports" does not provide a matching template. If another request is sent for a "politics" page, then a list [politics,site] might be returned so that the output is rendered differently due to the use of different templates.

A default implementation StaticViewRepositoryNameProvider returns a list of predefined view repository names. Another default implementation CompoundViewRepositoryNameProvider returns the view repository names from several view repository name providers. Applications that require more flexibility must implement the interface ViewRepositoryNameProvider to return a project specific list of view repository names.

ViewRepositoryProvider

The ViewRepositoryProvider is responsible for providing a ViewRepository instance for a given name. A default implementation TemplateViewRepositoryProvider is included. It inserts the repository name into a configured base path format pattern, for example, a name "sports" with a format /WEB-INF/templates/%s provides a ViewRepository instance with a base path /WEB-INF/templates/sports.

The following example configuration registers a custom ViewRepositoryNameProvider and a TemplateViewRepositoryProvider to locate view repositories using the pattern /WEB-INF/templates/sites/<viewRepositoryName>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:customize="...">

  <!--
    Instance of the project specific viewRepositoryNameProvider
  -->
  <bean id="customViewRepositoryNameProvider"
        class="com.company.CustomViewRepositoryNameProvider">
    ...
  </bean>

  <!--
   Register the view repository name provider
  -->
  <customize:append id="addCustomViewRepositoryNameProvider"
                    bean="viewRepositoryNameProviders">
    <list>
      <ref bean="customViewRepositoryNameProvider"/>
    </list>
  </customize:append>

  <!--
   Create an instance of TemplateViewRepositoryProvider
  -->
  <bean id="customViewRepositoryProvider"
        class="com.coremedia.objectserver.view.resolver.TemplateViewRepositoryProvider">
    <property name="templatesLocationFormat"
              value="/WEB-INF/templates/sites/%s"/>
    <!-- configure predefined beans -->
    <property name="viewDecorators" ref="viewDecorators"/>
    <property name="viewEngines" ref="viewEngines"/>
    <property name="loader" ref="templatesResourceLoader"/>
    <property name="programmedViews" ref="programmedViews"/>
  </bean>

  <!--
   Register the view repository provider
  -->
  <customize:append id="addCustomViewRepositoryProvider"
                    bean="viewRepositoryProviders">
    <list>
      <ref bean="customViewRepositoryProvider"/>
    </list>
  </customize:append>
</beans>

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.