I have used the following code for it. When I create a space, a rule (Transform n copy content to PDF) is automatically applied to it and its sub-spaces.
private void setupSpaceRuleConvToPDF(NodeRef nodeRef1){
Rule rule=new Rule();
rule.setRuleType("inbound");
rule.setTitle("Transform to PDF n copy to Data-PDF");
rule.setDescription("Transform to PDF n copy to Data-PDF");
rule.applyToChildren(true);
// rule.setExecuteAsynchronously(true);
System.out.println("Rule creation started…Part-II");
CompositeAction compositeAction = getActionService().createCompositeAction();
rule.setAction(compositeAction);
ActionCondition actionCondition = getActionService().createActionCondition("no-condition");
actionCondition.setParameterValues(new HashMap());
compositeAction.addActionCondition(actionCondition);
IHandler handler=null;
Map repoActionParams = new HashMap();
Map actionParams=new HashMap();
actionParams.put("actionName", "transform");
actionParams.put("transformer", "application/pdf");
actionParams.put("destinationLocation",nodeRef1 ); // prntDestinationNodeRef
actionParams.put("actionSummary", "Transform and copy content to a specific space");
try {
handler=(IHandler)Class.forName("org.alfresco.web.bean.actions.handlers.TransformHandler").newInstance();
} catch (Exception e) {
System.out.println("Class Generation Exception:"+e);
}
if(handler != null){
handler.prepareForSave(actionParams, repoActionParams);
}
//System.out.println("B4 saving action");
Action action = getActionService().createAction("transform");
action.setParameterValues(repoActionParams);
compositeAction.addAction(action);
getRuleService().saveRule(nodeRef1, rule);
}
Hope, it helps you. U'll need to import d necessary classes.
Thanks.