This section contains sample cartridge customizations that demonstrate how to use the various cartridge extension mechanisms to address different use cases.

The sample cartridges are intended to demonstrate the cartridge extension mechanisms and provide a model for your own cartridge customizations.

The sample code provided is written to be generic and easy to follow, rather than production-quality code. Oracle recommends that you follow a few best practices when working with the examples:

The steps described for creating and deploying the components of the sample cartridges correspond to the steps described in previous sections for the "Hello, World" cartridge. If you need additional information to complete a particular step in deploying one of the sample cartridges, refer to the more detailed procedures for the "Hello, World" example.

Oracle recommends that you use a test application to test the sample cartridges instead of deploying them in Discover Electronics or your own application.

Because a test application is for development use only, we do not need to deploy a live instance of the application.

To deploy a copy of Discover Electronics to use as a test for the sample cartridges:

  1. Deploy a new test application using the Deployment Template.

  2. Provision the test application.

  3. Deploy a copy of the authoring instance of the Discover Electronics application.

    1. Navigate to %ENDECA_TOOLS_ROOT%\reference (on Windows) or $ENDECA_TOOLS_ROOT/reference (on UNIX).

    2. Make a copy of the directory discover-electronics-authoring and save the copy with the name sandbox in the same parent directory.

    3. Navigate to the test directory and then to the WEB-INF subdirectory.

    4. Open assembler-context.xml in a text editor.

    5. Locate the CARTRIDGE SUPPORT section:

      <!--
          ########################################################################
          # CARTRIDGE SUPPORT
          #
          # The following section configures managers and other supporting objects.
          #
      -->
    6. In the mdexResource bean, update the Dgraph port:

      <bean id="mdexResource" scope="request"
      class="com.endeca.infront.navigation.model.MdexResource">
      				<property name="appName" value="${workbench.app.name}" />    
      				<property name="host" value="localhost" />
          <property name="port" value="15102" />
      				<property name="sslEnabled" value="${mdex.sslEnabled}" />
          <property name="recordSpecName" value="common.id" />
      </bean>
    7. Locate the Content Sources section:

      <!--
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ~ Content Sources
      -->
    8. In the ContentSource bean, update the application name:

      <bean id="ContentSource"" class="com.endeca.infront.content.source.WorkbenchContentSource"
      scope="singleton" init-method="init" destroy-method="destroy">
          <property name="storeFactory" ref="storeFactory"/>
          <property name="defaultSiteRootPath" ref="defaultSiteRootPath" />
          <property name="appName" value="${workbench.app.name}"/>
          <property name="siteManager" ref="siteManager"/>
      </bean>
    9. In the authoringMediaSources bean, update the application name:

      <bean id="authoringMediaSources" class="java.util.ArrayList" lazy-init="true">
          <constructor-arg>
              <list>
                  <bean class="com.endeca.infront.cartridge.model.MediaSourceConfig">
                      <property name="sourceName" value="IFCRSource" />
                      <property name="sourceValue" value="http://localhost:8006/ifcr/sites/Test/media/" />
                  </bean>
                  <bean class="com.endeca.infront.cartridge.model.MediaSourceConfig">
                      <property name="sourceName" value="default" />
                      <property name="sourceValue" value="http://localhost:8006/ifcr/sites/Test/media/" />
                  </bean>
              </list>
          </constructor-arg>
      </bean>
    10. Save and close the file.

    11. Navigate to %ENDECA_TOOLS_CONF%\conf\Standalone\localhost (on Windows) or $ENDECA_TOOLS_CONF/conf/Standalone/localhost (on UNIX).

    12. Make a copy of discover-authoring.xml and save the copy with the name test in the same directory.

    13. Open test.xml in a text editor.

    14. Change the value of docBase as follows:

      docBase="${catalina.base}/../../reference/test"
    15. Restart the Tools Service.

  4. Validate your new sandbox application:

  5. Optionally, update the Workbench configuration to use the test Web application for preview.

Oracle recommends that you specify the configuration for the sample cartridges in a separate Spring context file from the core cartridges.

To create a Spring context file for the sample cartridges:

  1. Navigate to %ENDECA_TOOLS_ROOT%\reference\sandbox\WEB-INF (on Windows) or $ENDECA_TOOLS_ROOT/reference/sandbox/WEB-INF (on UNIX).

  2. Open assembler-context.xml in a text editor.

  3. At the top of the file, add the following import:

    <beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    ">
        <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>WEB-INF/assembler.properties</value>
                </list>
            </property>
        </bean>
    
        <import resource="endeca-url-config.xml"/>
        <import resource="perf-logging-config.xml"/>
      <import resource="sample-cartridge-config.xml" />
                            
  4. Delete the configuration for the "Hello, World" sample cartridge that we added in an earlier example.

        <!--
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~ BEAN: CartridgeHandler_Hello
        -->
        <bean id="CartridgeHandler_Hello" 
        class="com.endeca.sample.cartridges.UppercaseCartridgeHandler"
        scope="prototype" />
  5. Save and close the file.

  6. Create a new file named sample-cartridge-config.xml in the same directory with the following contents:

    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
    
        <!--
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        ~ BEAN: CartridgeHandler_Hello
        -->
        <bean id="CartridgeHandler_Hello" 
        class="com.endeca.sample.cartridges.UppercaseCartridgeHandler"
        scope="prototype" />
    
    </beans>
  7. Save and close the file.

  8. Validate the new configuration by adding the "Hello, World" cartridge to your new sandbox application.

In this example, we build a cartridge that displays items from an RSS feed.

This cartridge enables a business user to specify some basic information about an existing RSS feed in Experience Manager. The cartridge handler fetches the RSS results and returns an output model to the client suitable for rendering.

It demonstrates the following use cases:

In this cartridge, we create the following components:

The business user needs to be able to configure the RSS Feed with a URL and the number of entries to display.

To create the RSS Feed template and add it to your application:

The cartridge instance configuration is saved as JSON. At this point, because there is no cartridge handler specified for this cartridge, the same configuration is passed to the client as the response from the Assembler.

The cartridge handler fetches the RSS results and returns an output model to the client suitable for rendering.

To create the RSS Feed cartridge handler and add it to the application:

The RSS feed does yet appear because we have not created the renderer. Nevertheless, you can validate that the response model has been populated with the information that we want to display in the JSON view:

{

    "@type": "RssFeed",
    "name": "RSS cartridge",
    "feedUrl": "http://www.wired.com/reviews/feed/",
    "numEntries": "5",
    "chanTitle": "Product Reviews",
    "chanUrl": "http://www.wired.com/reviews",
    "entries": [
        {
            "@type": "rssEntry",
            "itemDesc": "(description text omitted from this example)",
            "itemTitle": "(title text omitted from this example)",
            "itemUrl": "(url omitted from this example)"
        },
        {
            "@type": "rssEntry",
            "itemDesc": "(description text omitted from this example)",
            "itemTitle": "(title text omitted from this example)",
            "itemUrl": "(url omitted from this example)"
        },
        {
            "@type": "rssEntry",
            "itemDesc": "(description text omitted from this example)",
            "itemTitle": "(title text omitted from this example)",
            "itemUrl": "(url omitted from this example)"
        },
        {
            "@type": "rssEntry",
            "itemDesc": "(description text omitted from this example)",
            "itemTitle": "(title text omitted from this example)",
            "itemUrl": "(url omitted from this example)"
        },
        {
            "@type": "rssEntry",
            "itemDesc": "(description text omitted from this example)",
            "itemTitle": "(title text omitted from this example)",
            "itemUrl": "(url omitted from this example)"
        }
    ]

}

The following shows the code for the sample RSS Feed cartridge handler:

package com.endeca.sample.cartridges;

import com.endeca.infront.assembler.AbstractCartridgeHandler;
import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.assembler.ContentItem;
import com.endeca.infront.assembler.BasicContentItem;
import java.net.URL;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;

public class RssFeedHandler extends AbstractCartridgeHandler {

	public ContentItem process(ContentItem pContentItem)
			throws CartridgeHandlerException {
		
		final String urlString = (String) pContentItem.get("feedUrl");
		final int numEntries = 
    Integer.parseInt((String)pContentItem.get("numEntries"));
		
		try {
			URL url = new URL(urlString);
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			DocumentBuilder docBuilder = factory.newDocumentBuilder();
			Document RssContents = docBuilder.parse(url.openStream());
			
			// get the channel info
			Element channel = 
    (Element)RssContents.getElementsByTagName("channel").item(0);
			pContentItem.put("chanTitle", getElementValue(channel, "title"));
			pContentItem.put("chanUrl", getElementValue(channel, "link"));
			
			// get the entries and add them to a list
			ArrayList<ContentItem> entries = new ArrayList<ContentItem>(numEntries);
			NodeList nodes = RssContents.getElementsByTagName("item");
			for(int i=0; i<numEntries; i++) {
				Element element = (Element)nodes.item(i);
				if (element!=null) {
					ContentItem entry = new BasicContentItem("rssEntry");
					entry.put("itemTitle", getElementValue(element, "title"));
					entry.put("itemUrl", getElementValue(element, "link"));
					entry.put("itemDesc", getElementValue(element, "description"));
					entries.add(entry);
				}
			}
			pContentItem.put("entries", entries);
		}
		catch (Exception e) {
			throw new CartridgeHandlerException(e);
		}
		
		return pContentItem;
	}
	
	private static String getCharacterDataFromElement(Element e) {
		try {
			Node child = e.getFirstChild();
			if(child instanceof CharacterData) {
				CharacterData cd = (CharacterData) child;
				return cd.getData();
			}
		}
		catch(Exception ex) {
		}
		return "";
	}
	
	private static String getElementValue(Element parent, String label) {
		return getCharacterDataFromElement(
    (Element)parent.getElementsByTagName(label).item(0));
	}

}

In this example, we extend the Record Details cartridge to display information about the availability of a product.

It demonstrates the following use cases:

In this cartridge, we create the following components:

Because this cartridge does not introduce any change in the configuration options for the business user, there are no template changes for this cartridge. To enable the full functionality of this cartridge, the renderer should be updated to display the availability information, however that is not demonstrated in this guide.

The AvailabilityRecordDetailsHandler extends the core RecordDetailsHandler to call a simple mock availability service to retrieve availability information about a particular record.

To create a cartridge handler that calls an availability service:

  1. Create the following classes: Availability, AvailabilityService, and FixedAvailabilityService based on the examples below.

    The AvailabilityService defines an interface that returns availability information based on a record identifier, and FixedAvailabilityService provides a basic implementation of the interface.

  2. Create a new Java class in the package com.endeca.sample.cartridges based on the example below, which extends RecordDetailsHandler.

    The handler takes the results of the MDEX Engine query and adds an additional property that represents the product availability.

  3. Compile the classes and add them to your application.

  4. Configure the Assembler to use the AvailabilityRecordDetailsHandler for the Record Details cartridge by editing the Spring context file as in the following example.

    <bean id="CartridgeHandler_RecordDetails"
      class="com.endeca.sample.cartridges.AvailabilityRecordDetailsHandler"
      parent="NavigationCartridgeHandler" scope="prototype" >
        <property name="recordState" ref="recordState" />
        <property name="availabilityService" ref="availabilityService" />
        <property name="recordSpec" value="common.id" /> 
        <property name="availabilityPropertyName" 
          value="product.availability" />
    </bean>
    
    <bean id="availabilityService"
      class="com.endeca.sample.cartridges.FixedAvailabilityService"
      scope="singleton" >
      <!-- Implementation-specific configuration for the service
           could be specified here -->
    </bean>
  5. Restart the Tools Service.

  6. Refresh the application and then click on any record to view its details page.

The availability property is now returned as part of the record details information:

{
    "@type": "RecordDetailsPageSlot",
    "name": "Record Details Page",
    "contentCollection": "Record Details Pages",
    "ruleLimit": "1",
    "contents": [
        {
            …
            },
            "recordDetails": {
                "@type": "RecordDetails",
                "record": {
                   "@class": "com.endeca.infront.cartridge.model.Record",
                   "numRecords": 1,
                   "attributes": {
                        …
                        "product.availability": [
                            "BACKORDER"
                        ],
                        …
                   },
                   "records": [ … ]
                },
                "name": "Record Details"
            }
        }
    ],
    …
}

The renderer can now be updated to display availability information based on the value of this property.

The following shows the code for the availability service and its supporting classes:

package com.endeca.sample.cartridges;

public enum Availability {
    IMMEDIATE,
    WEEK,
    DROP_SHIP,
    BACKORDER;

}
package com.endeca.sample.cartridges;

public interface AvailabilityService {

    Availability getAvailabilityFor(String identifier);
}
package com.endeca.sample.cartridges;

public class FixedAvailabilityService implements AvailabilityService {

    public Availability getAvailabilityFor(String identifier) {
        try {
            return Availability.valueOf(identifier);
        } catch (IllegalArgumentException e) {
            return Availability.BACKORDER;
        }
    }
}

The following shows the code for the custom cartridge handler:

package com.endeca.sample.cartridges;

import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.cartridge.RecordDetails;
import com.endeca.infront.cartridge.RecordDetailsConfig;
import com.endeca.infront.cartridge.RecordDetailsHandler;
import com.endeca.infront.cartridge.model.Attribute;
import org.springframework.beans.factory.annotation.Required;

public class AvailabilityRecordDetailsHandler extends RecordDetailsHandler {

    private AvailabilityService availabilityService;
    private String recordSpec;
    private String availabilityPropertyName;

    @Required
    public void setAvailabilityService(
      AvailabilityService availabilityService_) {
        availabilityService = availabilityService_;
    }

    @Required
    public void setRecordSpec(String recordSpec_) {
        recordSpec = recordSpec_;
    }

    @Required
    public void setAvailabilityPropertyName(
      String availabilityPropertyName_) {
        availabilityPropertyName = availabilityPropertyName_;
    }

    @Override
    public RecordDetails process(RecordDetailsConfig detailsConfig) 
      throws CartridgeHandlerException {
        RecordDetails details = super.process(detailsConfig);
        if (null == details) return null;
        Attribute attr = 
          details.getRecord().getAttributes().get(recordSpec);
        if (null == attr || 1 != attr.size()) {
            throw new CartridgeHandlerException("No record spec 
              available on record, or spec is multiassign");
        }
        Attribute<Availability> availability = 
          new Attribute<Availability>();
        availability.add(
          availabilityService.getAvailabilityFor(attr.toString()));
        details.getRecord().getAttributes().put(availabilityPropertyName,
          availability);
        return details;
    }

}

In this example, we extend the Results List cartridge to boost certain products based on information from a recommendation engine.

It demonstrates the following use cases:

In this cartridge, we create the following components:

Because this cartridge does not introduce any change in the configuration options for the business user, there are no template changes for this cartridge. Additionally, the response model for the customized cartridge is the same as the default Results List (only with the records in a different order), so there is no need for changes to the default renderer.

The RecommendationsResultsListHandler extends the core ResultsListHandler to call a simple mock recommendations service and boosts the recommended products.

To create a cartridge handler that boosts recommended records:

  1. Create the interface RecommendationService and the concrete implementation TestRecommendationService based on the examples below.

    As a proof of concept, the recommendations service always returns the same recommendations from the Discover Electronics data set.

  2. Create a new Java class in the package com.endeca.sample.cartridges based on the example below, which extends ResultsListHandler.

    The handler retrieves a list of recommended records from the service and adds them to a boost stratum for the MDEX Engine query. If the records are present in the results set, they are boosted to the top of the results list.

  3. Compile the classes and add them to your application.

  4. Configure the Assembler to use the RecommendationsResultsListHandler for the Results List cartridge by editing the Spring context file as follows:

    <bean id="CartridgeHandler_ResultsList"
      class="com.endeca.sample.cartridges.RecommendationsResultsListHandler"
      parent="NavigationCartridgeHandler" scope="prototype">
        <property name="contentItemInitializer">
          <!-- additional elements omitted from this example -->
        </property>
        <property name="sortOptions">
          <!-- additional elements omitted from this example -->
        </property>
        <property name="recommendationService" ref="recommendationService" />
        <property name="recordSpec" value="common.id"/>
    </bean>
    
    <bean id="recommendationService"
      class="com.endeca.sample.cartridges.TestRecommendationService"
      scope="singleton" >
      <!-- Implementation-specific configuration for the service
           could be specified here -->
    </bean>
  5. Restart the Tools Service.

  6. Refresh the application.

The recommended records are boosted to the top of the results.

The following shows the code for the recommendations service interface and concrete implementation:

package com.endeca.sample.cartridges;

import java.util.List;

public interface RecommendationService {
    public List<String> getRecommendedProductIds();
}
package com.endeca.sample.cartridges;

import java.util.Arrays;
import java.util.List;

public class TestRecommendationService 
  implements RecommendationService {
    public static final List<String> IDS = 
      Arrays.asList("5891932", "6001963", "1438066", "1581692", 
        "2708142", "1235424", "3422480");

    public List<String> getRecommendedProductIds() {
        return IDS;
    }

}

The following shows the code for the custom cartridge handler:

package com.endeca.sample.cartridges;

import java.util.ArrayList;
import java.util.List;

import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.cartridge.ResultsListConfig;
import com.endeca.infront.cartridge.ResultsListHandler;
import com.endeca.infront.navigation.model.CollectionFilter;
import com.endeca.infront.navigation.model.PropertyFilter;

public class RecommendationsResultsListHandler extends ResultsListHandler {
    private RecommendationService recommendationService;
    private String recordSpec;
    
    public String getRecordSpec() {
        return recordSpec;
    }

    public void setRecordSpec(String recordSpec_) {
        this.recordSpec = recordSpec_;
    }

    public void setRecommendationService(
      RecommendationService recommendationService_) {
        recommendationService = recommendationService_;
    }

    /**
     * This cartridge will get the list of recommended products
     * (by record spec) and explicitly boost each one of them using 
     * a PropertyFilter.
     */
    @Override
    public void preprocess(ResultsListConfig pContentItem)
      throws CartridgeHandlerException {
        List<String> ids =
          recommendationService.getRecommendedProductIds();
        List<CollectionFilter> boostFilters =
          new ArrayList<CollectionFilter>(
                ids.size());
        for (String s : ids) {
            boostFilters.add(new CollectionFilter(new PropertyFilter(
                    recordSpec, s)));
        }

        pContentItem.setBoostStrata(boostFilters);
        super.preprocess(pContentItem);
    }

}

In this example, we extend the "Hello, World" example cartridge to demonstrate the layering of configuration from several sources.

In this scenario, we can define a default color for the message in our "Hello, World" cartridge, which the business user can override on a per-instance basis in Experience Manager. The site visitor can also select a preferred color from the client application.

It demonstrates the following use cases:

In this cartridge, we create the following components:

Because this cartridge does not introduce any change in the configuration options for the business user, there are no template changes for this cartridge.

The cartridge handler combines the various sources of configuration for message color using the ConfigInitializer and RequestParamMarshaller helper classes.

To create the "Hello, World" cartridge handler with color configuration and add it to the application:

  1. Create a new Java class in the package com.endeca.sample.cartridges based on the example below, which extends AbstractCartridgeHandler.

  2. Create a configuration bean for this cartridge based on the example below. This enables us to define default values for the cartridge properties in the Spring context file.

  3. Compile the cartridge handler and configuration bean and add them to your application.

  4. Configure the Assembler to use the ColorConfigHandler for the "Hello, World" cartridge by editing the Spring context file as follows:

    <bean id="CartridgeHandler_Hello" 
      class="com.endeca.sample.cartridges.ColorConfigHandler"
      scope="prototype">
      <property name="contentItemInitializer">
        <bean class="com.endeca.infront.cartridge.ConfigInitializer" 
          scope="singleton">
          <property name="defaults">
            <bean class="com.endeca.sample.cartridges.ColorConfig" 
              scope="singleton">
              <property name="messageColor" value="#FF6600"/>
            </bean>
          </property>
          <property name="requestParamMarshaller">
            <bean 
              class="com.endeca.infront.cartridge.RequestParamMarshaller" 
              scope="singleton">
              <property name="httpServletRequest" ref="httpServletRequest"/>
              <property name="requestMap">
                <map>
                  <entry key="color" value="messageColor"/>
                </map>
              </property>
            </bean>
          </property>
        </bean>
      </property>
      <property name="colorOptions">
        <map>
          <entry key="Red" value="#FF0000"/>
          <entry key="Green" value="#00FF00"/>
          <entry key="Blue" value="#0000FF"/>
          <entry key="Black" value="#000000"/>
        </map>            
      </property>
    </bean>
  5. Restart the Tools Service.

  6. Refresh the application.

The color options do not display yet because we have not updated the renderer, but you can validate that the response model has been populated with the information that we want the renderer to use in the JSON view:

{

    "@type": "Hello",
    "name": "Hello cartridge",
    "message": "Hello, color world!",
    "messageColor": "#0000FF",
    "colorOptions": [
        {
            "@type": "colorOption",
            "hexCode": "#FF0000",
            "label": "Red"
        },
        {
            "@type": "colorOption",
            "hexCode": "#00FF00",
            "label": "Green"
        },
        {
            "@type": "colorOption",
            "hexCode": "#0000FF",
            "label": "Blue"
        },
        {
            "@type": "colorOption",
            "hexCode": "#000000",
            "label": "Black"
        }
    ]

}

The following shows the code for the sample "Hello, World" cartridge handler with color configuration:

package com.endeca.sample.cartridges;

import com.endeca.infront.assembler.AbstractCartridgeHandler;
import com.endeca.infront.assembler.CartridgeHandlerException;
import com.endeca.infront.assembler.ContentItem;
import com.endeca.infront.assembler.BasicContentItem;
import com.endeca.infront.assembler.ContentItemInitializer;
import com.endeca.sample.cartridges.ColorConfig;
import java.util.ArrayList;
import java.util.Map;

public class ColorConfigHandler extends AbstractCartridgeHandler {
    
	private ContentItemInitializer mInitializer;
	private Map<String, String> mColorOptions;

  public void setContentItemInitializer(ContentItemInitializer initializer) {
    mInitializer = initializer;
  }
  
  public void setColorOptions(Map<String, String> colorOptions) {
  	 mColorOptions = colorOptions;
  }

  /**
   * Returns the merged configuration based on Spring defaults,
   * Experience Manager configuration, and request parameters
   */
  @Override 
  public ContentItem initialize(ContentItem pContentItem) {
    // If any configuration from Experience Manager is empty, remove 
    // that property so we can use the default value
    for (String key: pContentItem.keySet()) {
      if (((String)pContentItem.get(key)).isEmpty())
        pContentItem.remove(key);
    }
      return mInitializer == null ? new ColorConfig(pContentItem) :
        mInitializer.initialize(pContentItem);
    }

  /**
   * Returns the merged configuration and information about the color options
   * available to the site visitor.
   */
  @Override
  public ContentItem process(ContentItem pContentItem)
    throws CartridgeHandlerException {
    int numColors = mColorOptions.size();
    ArrayList<ContentItem> colors = 
      new ArrayList<ContentItem>(numColors);		
    if (mColorOptions != null && !mColorOptions.isEmpty()) {
      for (String key: mColorOptions.keySet()) {
        ContentItem color = new BasicContentItem("colorOption");
        color.put("label", key);
        color.put("hexCode", mColorOptions.get(key));
        colors.add(color);
      }
      pContentItem.put("colorOptions", colors);
    }
    return pContentItem;
  }
}

The following code implements a basic bean that enables us to specify a default value for the message color in the Spring configuration:

package com.endeca.sample.cartridges;

import com.endeca.infront.assembler.BasicContentItem;
import com.endeca.infront.assembler.ContentItem;

public class ColorConfig extends BasicContentItem {
    
	 public ColorConfig() {
		  super();
	 }
	
	 public ColorConfig(final String pType) {
		  super(pType);
	 }
	
 	public ColorConfig(ContentItem pContentItem) {
    super(pContentItem);
  }
    
  public String getMessageColor() {
    return getTypedProperty("messageColor");
  }
  
  public void setMessageColor(String color) {
    this.put("messageColor", color);
  }
}

Copyright © Legal Notices