com.google.code.facebookapi
Class TemplatizedAction

java.lang.Object
  extended by com.google.code.facebookapi.TemplatizedAction

public class TemplatizedAction
extends java.lang.Object

Utility class to assist in creating a templatized action for publishing to the minifeed/newsfeed, because the API call Facebook decided to add in order to do it is ridiculously complex.


Field Summary
protected static org.apache.commons.logging.Log log
           
static java.lang.String UID_TOKEN
           
 
Constructor Summary
TemplatizedAction(java.lang.String titleTemplate)
          Constructor
TemplatizedAction(java.lang.String titleTemplate, java.lang.String bodyTemplate)
          Constructor
TemplatizedAction(java.lang.String titleTemplate, java.lang.String bodyTemplate, java.lang.String bodyGeneral)
          Constructor
 
Method Summary
 void addBodyParam(java.lang.String key, java.lang.String value)
          Add a parameter value for the body template.
 void addPicture(java.lang.Long imageUid, java.lang.String linkHref)
          Add a picture to be associated with this feed entry, along with a link to be associated with the picture (clicking on the picture in the feed will go to the specified link).

Note that only 4 pictures may be present at any given time.
 void addPicture(java.lang.String imageHref)
          Add a picture to be associated with this feed entry, the picture will not have an associated link.
 void addPicture(java.lang.String imageHref, java.lang.String linkHref)
          Add a picture to be associated with this feed entry, along with a link to be associated with the picture (clicking on the picture in the feed will go to the specified link).

Note that only 4 pictures may be present at any given time.
 void addTargetIds(java.util.Collection<java.lang.Object> facebookIds)
          Append to the set of friends who are associated with this action.
 void addTargetIds(java.lang.String newIds)
          Append to the list of friends who are associated with this action.

This method *will not* clear out any previously added target ids.
 void addTitleParam(java.lang.String key, java.lang.String value)
          Add a parameter value for the title template.
 java.lang.String getBodyGeneral()
           
 java.lang.String getBodyParams()
          Get the body params as a JSON-formatted string.
 java.lang.String getBodyTemplate()
           
 java.lang.Long getPageActorId()
           
 java.util.Collection<IPair<java.lang.Object,java.net.URL>> getPictures()
          Get the list of pictures.
 java.lang.String getTargetIds()
           
 java.lang.String getTitleParams()
          Get the title params as a JSON-formatted string.
 java.lang.String getTitleTemplate()
           
 void removePicture(int index)
          Remove a picture from the list, this can be used to revise the list/free up space for alternate pictures.
 void setBodyGeneral(java.lang.String bodyGeneral)
          Set the general body content for this feed entry.
 void setBodyTemplate(java.lang.String bodyTemplate)
          Set the body template for this feed entry.
 void setPageActorId(java.lang.Long pageActorId)
           
 void setPictures(java.util.List<IPair<java.lang.Object,java.net.URL>> pics)
          Set the pictures to display all at once, if you feel like building the Collection> on your own.
 void setTargetIds(java.util.Collection<java.lang.Object> facebookIds)
          Set the target ids of friends who are associated with this action.
 void setTargetIds(java.lang.String targetIds)
          Set the target ids of friends who are associated with this action.
 void setTitleTemplate(java.lang.String titleTemplate)
          Set the title template for this feed entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static org.apache.commons.logging.Log log

UID_TOKEN

public static final java.lang.String UID_TOKEN
See Also:
Constant Field Values
Constructor Detail

TemplatizedAction

public TemplatizedAction(java.lang.String titleTemplate)
Constructor

Parameters:
titleTemplate - the title-template to set.

TemplatizedAction

public TemplatizedAction(java.lang.String titleTemplate,
                         java.lang.String bodyTemplate)
Constructor

Parameters:
titleTemplate - the title template to use
bodyTemplate - the body template to use

TemplatizedAction

public TemplatizedAction(java.lang.String titleTemplate,
                         java.lang.String bodyTemplate,
                         java.lang.String bodyGeneral)
Constructor

Parameters:
titleTemplate - the title template to use
bodyTemplate - the body template to use
bodyGeneral - the non-templatized body content to use
Method Detail

removePicture

public void removePicture(int index)
Remove a picture from the list, this can be used to revise the list/free up space for alternate pictures.

Parameters:
index - the index to remove from.

addPicture

public void addPicture(java.lang.Long imageUid,
                       java.lang.String linkHref)
Add a picture to be associated with this feed entry, along with a link to be associated with the picture (clicking on the picture in the feed will go to the specified link).

Note that only 4 pictures may be present at any given time. Any pictures beyond this are ignored. Use removePicture if you need to change something after 4 pictures have been added.

Parameters:
imageUid - the id of the image to display. This can be a picture id or a Facebook user-id.
linkHref - the URL of the link to go to when the image is clicked.

addPicture

public void addPicture(java.lang.String imageHref,
                       java.lang.String linkHref)
Add a picture to be associated with this feed entry, along with a link to be associated with the picture (clicking on the picture in the feed will go to the specified link).

Note that only 4 pictures may be present at any given time. Any pictures beyond this are ignored. Use removePicture if you need to change something after 4 pictures have been added.

Parameters:
imageHref - the URL of the image to display in the feed.
linkHref - the URL of the link to go to when the image is clicked.

addPicture

public void addPicture(java.lang.String imageHref)
Add a picture to be associated with this feed entry, the picture will not have an associated link. Note that only 4 pictures may be present at any given time. Any pictures beyond this are ignored. Use removePicture if you need to change something after 4 pictures have been added.

Parameters:
imageHref - the URL of the image to display in the feed.

setPictures

public void setPictures(java.util.List<IPair<java.lang.Object,java.net.URL>> pics)
Set the pictures to display all at once, if you feel like building the Collection> on your own. Otherwise use the more convenient addPic() method instead.

Parameters:
pics - the pictures to set.

getPictures

public java.util.Collection<IPair<java.lang.Object,java.net.URL>> getPictures()
Get the list of pictures.

Returns:
the list of pictures.

addTitleParam

public void addTitleParam(java.lang.String key,
                          java.lang.String value)
Add a parameter value for the title template. It will be used to replace the corresponding token when the feed entry is rendered.

Parameters:
key - the name of the parameter/token.
value - the value to set it to.

addBodyParam

public void addBodyParam(java.lang.String key,
                         java.lang.String value)
Add a parameter value for the body template. It will be used to replace the corresponding token when the feed entry is rendered.

Parameters:
key - the name of the parameter/token.
value - the value to set it to.

getTitleParams

public java.lang.String getTitleParams()
Get the title params as a JSON-formatted string.

Returns:
the parameters for the templatized title tokens.

getBodyParams

public java.lang.String getBodyParams()
Get the body params as a JSON-formatted string.

Returns:
the parameters for the templatized body tokens.

getBodyGeneral

public java.lang.String getBodyGeneral()
Returns:
the bodyGeneral

setBodyGeneral

public void setBodyGeneral(java.lang.String bodyGeneral)
Set the general body content for this feed entry. This is optional, non-templatized markup, and is distinct from and unrelated to bodyTemplate. A feed entry can have both at once, either or, or neither.

Parameters:
bodyGeneral - non-templatized markup that will be displayed in this feed entry. When multiple entries are aggregated, only the bodyGeneral from (an arbitrarily chosen) one of them will appear in the aggregate entry, meaning that any markup specified here must be generic enough that it can make sense in any context.

getBodyTemplate

public java.lang.String getBodyTemplate()
Returns:
the bodyTemplate

setBodyTemplate

public void setBodyTemplate(java.lang.String bodyTemplate)
Set the body template for this feed entry. The body template is optinal.

Parameters:
bodyTemplate - templatized markup that will be used to compute the body section of this feed entry. Unlike titleTemplate, this markup *is not* required to utilize the "{actor}" token, although you may choose to use any desired tokens in this section if you wish.

getTargetIds

public java.lang.String getTargetIds()
Returns:
the targetIds

setTargetIds

public void setTargetIds(java.lang.String targetIds)
Set the target ids of friends who are associated with this action. This must be specified if you have used the "{target}" token in any of your markup.

This method will clear out any previously added target ids. To append additional target ids to a previous list, use addTargetIds instead.

Parameters:
targetIds - a comma-seperated list of Facebook UID's representing any friends of the current user who are associated with the action being published (so if the action is "Bob waves to Sally and Susie", Sally and Susie are the targets).

addTargetIds

public void addTargetIds(java.lang.String newIds)
Append to the list of friends who are associated with this action.

This method *will not* clear out any previously added target ids.

Parameters:
newIds - a comma-seperated list of Facebook UID's representing any friends of the current user who are associated with the action being published (so if the action is "Bob waves to Sally and Susie", Sally and Susie are the targets).

setTargetIds

public void setTargetIds(java.util.Collection<java.lang.Object> facebookIds)
Set the target ids of friends who are associated with this action. This must be specified if you have used the "{target}" token in any of your markup.

This method will clear out any previously added target ids. To append additional target ids to a previous list, use addTargetIds instead.

Parameters:
facebookIds - a list of all the Facebook UID to specify as targets. The elements in the collection may only be of type Integer or type String.

addTargetIds

public void addTargetIds(java.util.Collection<java.lang.Object> facebookIds)
Append to the set of friends who are associated with this action. This must be specified if you have used the "{target}" token in any of your markup.

This method *will not* clear out any previously added target ids.

Parameters:
facebookIds - a list of all the Facebook UID to specify as targets. The elements in the collection may only be of type Long or type String.

getTitleTemplate

public java.lang.String getTitleTemplate()
Returns:
the titleTemplate

setTitleTemplate

public void setTitleTemplate(java.lang.String titleTemplate)
Set the title template for this feed entry. This is a required field, and the template must always contain the "{actor}" token.

Parameters:
titleTemplate - templatized markup to use as the title of this feed entry. It must contain the "{actor}" token.

getPageActorId

public java.lang.Long getPageActorId()
Returns:
the page actor-id

setPageActorId

public void setPageActorId(java.lang.Long pageActorId)
Parameters:
pageActorId - the page actor-id to set


Copyright © 2010. All Rights Reserved.