
h1. Objective {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering.Objective}
In this section, you will learn how to implement a preprocessor for activities rendering.

h1. Requirements {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering.Requirements}
To understand this section, java and eXo Kernel (component model and its XML configuration) knowledge is prerequisite.

h1. Why would you need to do this? {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering.what_you_need_to_do_this}

An simple activity is made of simple text. We have created an extension point at the level of activities rendering for two cases:
* support more HTML tags.
* support @mentions.

But you may want to support a special syntax like:
* #hashtags to feel like Twitter.
* smileys to look like Skype.
* [Markdown|http://en.wikipedia.org/wiki/Markdown] to feel like Buzz.

You can have more sophisticated cases to process, such as parsing the link that include in the activity's content. Because a process actually has full the access to the Activity, so you can very well process based on the owner, the app, media item.

h1. Writing an ActivityProcessor {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering._writing_ActivityProcessor}
eXo Social lets you pre-process an activity before it is returned by the ActivityManager. To do this, you simply need to implement the interface ActivityProcessor:

{code:java}
/**
 * An activity processor is responsible to pre-process an activity before it is returned by the {@link ActivityManager}
 */
public interface ActivityProcessor {

  /**
   * Process an activity
   * @param activity the activity. It can be modified
   */
  void processActivity(Activity activity);

  /**
   * Priority of this processor.
   * All activity processors will be executed in ascending priority order
   * @return
   */
  int getPriority();

}
{code}


For example, the following shows you how to implement a SmileyProcessor that will replace text smileys by icons:

{code:java}
public class SmileyProcessor implements ActivityProcessor {

  String smiley =  "<img src='/images/smiley.gif'/>";

  public void processActivity(Activity activity) {
    String title = activity.getTitle();
     activity.setTitle(title.replaceAll(":-\\)", smiley));
  }

  public int getPriority() {
    return 100;
  }

}
{code}

h1. Configuring the processor {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering.Configuring_the_Processor}

Now that you have a nice procesor you need to hook it to the system.
At runtime, the processors can be attached to ActivityManager via addProcessor(ActivityProcessor) method..

But there is also a component plugin hooked for it: public void addProcessorPlugin(BaseActivityProcessorPlugin plugin)

So, to make your processor easy to hook, you simply need to let him extend the BaseActivityProcessorPlugin.

{code:java}
public class SmileyProcessor extends BaseActivityProcessorPlugin {

  String smiley =  "<img src='/images/smiley.gif'/>";

  public SmileyProcessor(InitParams params) {
    super(params);
  }

  public void processActivity(Activity activity) {
    String title = activity.getTitle();
      activity.setTitle(title.replaceAll(":-\\)", smiley));
  }
}
{code}

It will have the additional benefit to make the priority field configurable, so you don't need to implement getPriorty().

Then your processor can be configured as a component plugin like this:

{code:xml}
  <external-component-plugins>
    <target-component>org.exoplatform.social.core.activitystream.ActivityManager</target-component>
    <component-plugin>
      <name>SmileyProcessor</name>
      <set-method>addProcessorPlugin</set-method>
      <type>org.example.SmileyProcessor</type>
      <init-params>
        <value-param>
          <name>priority</name>
          <description>priority of this processor (lower are executed first)</description>
          <value>2</value>
        </value-param>
      </init-params>
    </component-plugin>
  </external-component-plugins>
{code}

Restart then place the smiley imagesu on the server and you should see something like that:

!activity-smiley.png!
