+1 to the registering PostProcessor for specific resource types.
I'm less sure of registering by property name and modification type, mostly because you'll still need to iterate through the modification list. Also, it seems like there could be ambiguous cases, e.g. If I register a PostProcessor with modifiedPropertyNames = [ 'title', 'description' ], does the PostProcessor get called when only one of those properties is called?
Justin On Jan 14, 2010, at 7:30 AM, Vidar Ramdal <[email protected]> wrote:
I often write PostProcessors to catch a modification to a resource or property based on certain criteria. I usually know the name of the property I want to act on, and the resource type of the resource being posted to. For instance, I want to interfere with a user posting some HTML to a 'html' property on a resource with type "custom-html", to run the HTML through Tidy or something. I find myself writing code like this ever-so-often: public class MyPostProcessor implements SlingPostProcessor {public void process(SlingHttpServletRequest, List<Modification> changes) { // This PostProcessor should only act on resources with MY_RESOURCE_TYPEif (request.getResource().getResourceType() != MY_RESOURCE_TYPE) { return; } // This PostProcessor should only act on property modifications when the property name is MY_PROPERTY_NAME for (Modification change : changes) { // Only act on MODIFY if (change.getType().equals(ModificationType.MODIFY)) { Session session = request.getAttribute("javax.jcr.Session"); // Only at on Property modification, not Node if (session.getItem(change.getSource()).isNode()) { continue; } String propertyName = change.getSource(); if (propertyName.indexOf("/")>-1) propertyName = propertyName.substring(propertyName.lastIndexOf("/")+1); if (!propertyName.equals(MY_PROPERTY_NAME) { continue; } ... and so on. It appears to me that it would be useful to register a SlingPostProcesor for only some posts - e.g. when there's a match on resourceType, property name or other criteria. These criteria could be specified as scr.properties on the SlingPostProcessor implementation. SlingPostServlet would then only pass the matching SlingPostProcessors on to the SlingPostOperation - or maybe the filtering should be done by the SlingPostOperation. It strikes me that this would make registering a SlingPostProcessor somewhat similar to registering a Servlet. Maybe there are some synergies here. What do you think? Is this idea worth pursuing? -- Vidar S. Ramdal <[email protected]> - http://www.idium.no Sommerrogata 13-15, N-0255 Oslo, Norway + 47 22 00 84 00 / +47 21 531941, ext 2070
