com.endeca.infront.assembler
Class BasicContentItem

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<String,Object>
          extended by com.endeca.infront.assembler.BasicContentItem
All Implemented Interfaces:
ContentItem, Serializable, Cloneable, Map<String,Object>
Direct Known Subclasses:
Breadcrumbs, BreadcrumbsConfig, ContentInclude, ContentSlotConfig, ContentSlotListConfig, DimensionSearchResults, DimensionSearchResultsConfig, MediaBanner, MediaBannerConfig, NavigationContainer, NavigationContainerConfig, RecordDetails, RecordDetailsConfig, RecordSpotlight, RecordSpotlightConfig, RefinementMenu, RefinementMenuConfig, RequestEvent, ResultsList, ResultsListConfig, SearchAdjustments, SearchAdjustmentsConfig

public class BasicContentItem
extends HashMap<String,Object>
implements ContentItem

Convenience class to extend when implementing ContentItem

This class implements a copy constructor and a constructor that requires only the content item type. In addition, it implements all of the typed getters from ContentItem

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
BasicContentItem()
          Creates a new BasicContentItem without a type.
BasicContentItem(ContentItem pContentItem)
          Copy constructor.
BasicContentItem(String pType)
          Creates a new BasicContentItem without the specified type.
 
Method Summary
 boolean getBooleanProperty(String key, boolean defaultValue)
          Convenience method for getting a boolean property value.
 int getIntProperty(String key, int defaultValue)
          Convenience method for getting an int property value.
 long getLongProperty(String key, long defaultValue)
          Convenience method for getting a long property value.
 String getType()
          Returns the type of this content item.
<T> T
getTypedProperty(String key)
          Convenience method for returning a property value without having to cast the return value to the desired type.
protected  void setType(String type)
          Sets the type for this content item.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

BasicContentItem

public BasicContentItem()
Creates a new BasicContentItem without a type.


BasicContentItem

public BasicContentItem(String pType)
Creates a new BasicContentItem without the specified type.

Parameters:
pType - the content item type
See Also:
getType()

BasicContentItem

public BasicContentItem(ContentItem pContentItem)
Copy constructor. Populates the new BasicContentItem with the contents of the supplied content item.

Parameters:
pContentItem - the contents for this instance
Method Detail

getType

public String getType()
Returns the type of this content item.

Specified by:
getType in interface ContentItem
Returns:
the Experience Manager cartridge type (same as the 'template ID').

setType

protected void setType(String type)
Sets the type for this content item.


getTypedProperty

public <T> T getTypedProperty(String key)
Convenience method for returning a property value without having to cast the return value to the desired type.

e.g. instead of

      Object value = contentItem.get("record");
      Record record = (Record)value;
 
use
      Record record = contentItem.getTypedProperty("record");
 

Parameters:
key - key whose associated value is to be returned.
Returns:
the typed value to which this ContentItem maps the specified key, or null if the ContentItem contains no mapping for this key.
Throws:
ClassCastException - if the property value could not be coerced to the required type
See Also:
HashMap.put(K, V)

getIntProperty

public int getIntProperty(String key,
                          int defaultValue)
Convenience method for getting an int property value.

Parameters:
key - key whose associated int value is to be returned. The value may be of type Integer or a String that parses to an int.
defaultValue - the value to return if the ContentItem does not contain the given key.
Returns:
the int value to which this ContentItem maps the specified key, or defaultValue if the ContentItem contains no mapping for the key.
Throws:
RuntimeException - if the value associated with the key cannot be parsed into an int

getLongProperty

public long getLongProperty(String key,
                            long defaultValue)
Convenience method for getting a long property value.

Parameters:
key - key whose associated long value is to be returned. The value may be of type Long or a String that parses to a long.
defaultValue - the value to return if the ContentItem does not contain the given key.
Returns:
the long value to which this ContentItem maps the specified key, or defaultValue if the ContentItem contains no mapping for the key.
Throws:
RuntimeException - if the value associated with the key cannot be parsed into a long

getBooleanProperty

public boolean getBooleanProperty(String key,
                                  boolean defaultValue)
Convenience method for getting a boolean property value.

Parameters:
key - key whose associated boolean value is to be returned. The value may be of type Boolean or a String that parses to a boolean.
defaultValue - the value to return if the ContentItem does not contain the specified key.
Returns:
the boolean value to which this ContentItem maps the specified key, or defaultValue if the ContentItem contains no mapping for this key.
Throws:
RuntimeException - if the value associated with the key cannot be parsed into a boolean


Copyright © 2012, Oracle and/or its affiliates. All rights reserved.