com.ibm.websphere.personalization
Class ContentSpot

java.lang.Object
  extended by com.ibm.websphere.personalization.RuleTrigger
      extended by com.ibm.websphere.personalization.ContentSpot
All Implemented Interfaces:
java.io.Serializable

public class ContentSpot
extends RuleTrigger

Overview

The ContentSpot is the main access point to the Personalization runtime. ContentSpots are instantiated to represent a place where a rule is executed. Invoking a ContentSpot will execute rule(s) mapped to that ContentSpot. You may also execute a rule by its name directly.

Multiple calls to the same instance of this class will return the same results.

Setting the request into the Content Spot

Callers to this class should first set the request into the ContentSpot. Setting the request through one of the setRequest(...) methods is the way in which Personalization receives the input to the rule.

The request object passed to this class may be an instance of

When executing rules in a JSP or JSP tag inside a Portlet container, callers should pass the portletRequest variable from the JSP rather than passing the request variable whenever possible.

With rare exception upon which callers should not depend, the request must be set into the ContentSpot (either through a constructor or by explicitly calling setRequest) prior to any other methods being called on this class.

Specifying what rule or content spot to execute

The contentSpotName, contentSpotUuid, ruleName, and ruleUuid for which there exist setter methods are used to identify what rule or content spot should be executed when this Content Spot object is triggered. These names and uuids correspond to the paths and unique identifers of items created in the Personalization Navigator portlet.

Executing generated content spots

Content Spots classes may also be generated using wizards in Rational tooling. Generated Content Spots extend RuleTrigger directly, and do not make use of this class. The generated classes have the advantage that they have strongly types methods for returning content, and you do not have to set an identifier for the content spot or rule to be executed.

Using this class has the advantage that your code can be more agile, taking a content spot or rule path as a parameter to some mehod you create. Using this class also allows you to define new Content Spots without generating a single class for each Content Spot.

When executing a generated Content Spot, the Content Spot object should still exist in the Personalization Navigator. In the case of generated spots, the value of contentSpotName is simply implied by the display name given to the Conent Spot in the Rational wizard. If the display name is "/PznDemo/GeneralNewsSpot", then the Content Spot will execute as if you had called setContentSpotName("/PznDemo/GeneralNewsSpt") on this object. If the display name is simply "GeneralNewsSpot", then the Content Spot will execute as if you had called setContentSpotName("GeneralNewsSpot") on this class. In this case, the Content Spot object in the Personalization Navigator to be executed will be one located directly in the root.

Examples

To execute a Content Spot called "GeneralNewsSpot" in a folder called "PznDemo" in a JSP in Portal, the following series of calls would be issued.

 
                ContentSpot contentSpot = new ContentSpot();
                contentSpot.setRequest(portletRequest);
                contentSpot.setContentSpotName("/PznDemo/GeneralNewsSpot");
                Object[] content = contentSpot.getRuleContent();
 
 

If this was done outside of Portal, portletRequest would instead be simply request or some object implementing PznRequestObjectInterface.

To execute a Rule called "Get General News About Sports" in a folder called "FrontPage" which is in a folder called "Pzndemo", the following series of calls would be issued.

 
                ContentSpot contentSpot = new ContentSpot();
                contentSpot.setRequest(portletRequest);
                contentSpot.setRuleName("/PznDemo/FrontPage/Get General News About Sports");
                Object[] content = contentSpot.getRuleContent();
 
 

After either of these series of invocations, you may need to iterate over the results and cast to your own resource class.

 
                for (int i=0; i<content.length; i++) {
                        GeneralNews nextContent = (GeneralNews) content[i];
                        /// do something with the nextContent object
                        ...
                }
 
 

See Also:
PznRequestObjectInterface, Serialized Form

Field Summary
 
Fields inherited from class com.ibm.websphere.personalization.RuleTrigger
additionalQuery, asOfDate, audit, campaignName, CAMPAIGNS_FINDER, categorizationOrder, content, contentSpotUuid, defaultRuleExit, displayName, includeRuntimeResultsInPreview, limit, name, req, requestContext, resourceCollectionName, ruleExit, ruleJSON, ruleMapping, ruleMappingsList, ruleName, ruleUuid, scopeId, showErrors, startIndex, useCascadingCampaigns
 
Constructor Summary
ContentSpot()
          Constructs an object to execute a rule.
ContentSpot(java.lang.String contentSpotName)
          Constructs an object to execute a rule.
ContentSpot(java.lang.String contentSpotName, java.lang.Object request)
          Contructs an object to execute a rule.
 
Method Summary
 Query getAdditionalQueryParameters()
          Returns the query to be joined with the query of the rule run by this content spot.
 java.lang.String getContentSpotName()
          Returns the path to the Content Spot.
 java.lang.Object[] getRuleContent()
          Executes the rule and returns the results.
 java.lang.Object getRuleContent(int i)
          Executes the rule and returns the ith result
 void setAdditionalQueryParameters(Query query)
          Joins an additional query with the query of the rule run by this content spot.
 void setContentSpotName(java.lang.String contentSpotName)
          Sets which Content Spot to execute.
 
Methods inherited from class com.ibm.websphere.personalization.RuleTrigger
addContentResourceCollectionName, dateUsed, findRule, getAllItemsCached, getAudit, getCachedItems, getCampaign, getCampaignIndex, getCampaignName, getCampaigns, getClassification, getClassifications, getContent, getContent, getContentResourceCollectionName, getContentResourceCollectionName, getContentSpotId, getContext, getDisplayName, getFirstPageRetrieved, getIds, getMaxAvailableItems, getPreviewAnchorTag, getPreviewAnchorTag, getProfile, getProfiles, getResource, getRuleId, getRuleJSON, getRuleMapping, getRuleName, getRuleResults, getRuleResults, getScopeId, getShowError, idOfUser, isClassifiedAs, isProfiledAs, isProfiledAsAll, isProfiledAsAny, isUsingCascadingCampaigns, resetContext, selectRule, setAsOfDate, setAudit, setCampaignName, setCategorization, setContentResourceCollectionName, setContentSpotId, setContext, setDisplayName, setLimit, setName, setRequest, setRequest, setRequest, setRequest, setRuleExit, setRuleId, setRuleJSON, setRuleMapping, setRuleName, setShowError, setStartIndex, setUseCascadingCampaigns, trigger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContentSpot

public ContentSpot()
Constructs an object to execute a rule. Callers must subsequently call a method to set the rule name or uuid or content spot name or uuid onto this ContentSpot. setRequest and one of the methods to set the Content Spot name or uuid or rule name or uuid before triggering or trying to get results.


ContentSpot

public ContentSpot(java.lang.String contentSpotName)
Constructs an object to execute a rule. Callers must subsequently call setRequest before triggering or trying to get results.

Parameters:
contentSpotName - The name of the content spot to be executed. The contentSpotName is the path to the Content Spot in the Personalization Navigator
request - The input to the rules. This object must be an HttpServletRequest, PortletRequest, or implementation of com.ibm.websphere.personalization.PznRequestObjectInterface

ContentSpot

public ContentSpot(java.lang.String contentSpotName,
                   java.lang.Object request)
Contructs an object to execute a rule.

Parameters:
contentSpotName - The name of the Content Spot to be executed. The contentSpotName is the path to the Content Spot in the Personalization Navigator
request - The input to the rules. This object must be an HttpServletRequest, PortletRequest, or implementation of com.ibm.websphere.personalization.PznRequestObjectInterface
Method Detail

getContentSpotName

public java.lang.String getContentSpotName()
Returns the path to the Content Spot.

Overrides:
getContentSpotName in class RuleTrigger
Returns:
The name of the content spot executed or to be executed. This is the path to the Content Spot in the Personalization Navigator

setContentSpotName

public void setContentSpotName(java.lang.String contentSpotName)
Sets which Content Spot to execute.

Overrides:
setContentSpotName in class RuleTrigger
Parameters:
contentSpotName - The name of the Content spot executed or to be executed. The contentSpotName is the path to the Content Spot in the Personalization Navigator

getAdditionalQueryParameters

public Query getAdditionalQueryParameters()
Returns the query to be joined with the query of the rule run by this content spot.


setAdditionalQueryParameters

public void setAdditionalQueryParameters(Query query)
Joins an additional query with the query of the rule run by this content spot. Predicates are anded with the query of the rule. Categorization order is first, then orders in this query, order set in the rule. If a limit is present in the query and the rule, the smaller limit is observed.

Parameters:
query - The query to be joined with the query of the rule run by this content spot

getRuleContent

public java.lang.Object[] getRuleContent()
                                  throws java.lang.Throwable
Executes the rule and returns the results.

Returns:
The results of the rule.
Throws:
java.lang.Throwable

getRuleContent

public java.lang.Object getRuleContent(int i)
                                throws java.lang.ArrayIndexOutOfBoundsException,
                                       java.lang.Throwable
Executes the rule and returns the ith result

Parameters:
i - The index (index 0 based) of the result to return
Returns:
The results of the rule.
Throws:
java.lang.ArrayIndexOutOfBoundsException - Throws an exception if there are no results or less than i results.
java.lang.Throwable