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, the knowledge of Java and eXo Kernel (component model and its XML configuration) 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}

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

But you may want to support a special syntax, for example:
* #hashtags to feel like Twitter.
* smileys to look like Skype.
* [Markdown|http://en.wikipedia.org/wiki/Markdown] to experience 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 the full access to the Activity, you can very well process based on the owner, app, and media item.

h1. Write an ActivityProcessor {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering._write_ActivityProcessor}
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. Configure the processor {anchor:id=SOCref.DeveloperReferences.how_extend_the_activities_rendering.Configure_Processor}

Now, you have a nice procesor, so need to hook it to the system.
At runtime, the processors can be attached to _ActivityManager_ via the _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 do not 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 images on the server.

