JBoss.orgCommunity Documentation

Interceptors

By placing interceptors in your template, you will be able to execute a Groovy script just before and just after saving the node. Pre-save interceptors are mostly used to validate input values and their overall meaning while the post-save interceptor can be used to do some manipulations or references for the newly created node, such as binding it with a forum discussion or wiki space.

To place interceptors, use the following fragment:



<% uicomponent.addInterceptor("ecm-explorer/interceptor/PreNodeSaveInterceptor.groovy", "prev");%>

Interceptor Groovy scripts are managed in the 'Manage Script' section in the ECM admin portlet. They must implement the CmsScript interface. Pre-save interceptors obtain input values within the context:



public class PreNodeSaveInterceptor implements CmsScript {
  public PreNodeSaveInterceptor() {
  }
  public void execute(Object context) {
    Map inputValues = (Map) context;
    Set keys = inputValues.keySet();
    for(String key : keys) {
      JcrInputProperty prop = (JcrInputProperty) inputValues.get(key);
      println("   --> "+prop.getJcrPath());
    }
  }
  public void setParams(String[] params) {
  }
}

Whereas the post-save interceptor is passed the path of the saved node in the context:



<% uicomponent.addInterceptor("ecm-explorer/interceptor/PostNodeSaveInterceptor.groovy", "post");%>
public class PostNodeSaveInterceptor implements CmsScript {
  public PostNodeSaveInterceptor() {
  }
  public void execute(Object context) {
    String path = (String) context;
    println("Post node save interceptor, created node: "+path);
  }
  public void setParams(String[] params) {
  }
}