Is there a way to associate custom processors with a specific group?

15 views
Skip to first unread message

Ryan Lubke

unread,
Dec 16, 2014, 2:57:18 PM12/16/14
to wr...@googlegroups.com
Hey folks,

I've come across a use case where it would be advantageous to associate custom processors with a specific group.  

I didn't see anything that stood out in the documentation, so I thought I'd check in with the experts.  Is this possible?
If it's a case of RTFM, please point me in the right direction.

Thanks!

Alex Objelean

unread,
Dec 17, 2014, 10:50:07 AM12/17/14
to wr...@googlegroups.com
Hi Ryan,

though it is not available by default, it doesn't mean it is not possible to implement.

First of all, you'll have to create a custom processor for that (you'll be able to reuse existing processor or implement the new one as a decorator of any other processor).
The custom processor will have to implement ResourcePreProcessor interface, because it will be provided with the information about the resource being processed (which will be used to identify it if belongs to a certain group, though there will be a problem when the same resource belongs to different groups). 
When your custom processor will be used as preProcessor - the provided resource should be used to identify the group it belongs to, while when used as a postProcessor - the provided resource is the groupName suffixed with extension of the resourceType being processed (example: if the group is called "myGroup" and the type of the resource processed is "js", then the resourceName will be "myGroup.js").
To identify if a resource belong to a group, you can inject the WroModel to your custom processor and use the WroModelInspector to perform the quesry as in example below:
public class MyCustomProcessor implements ResourcePreProcessor {

  @Inject
  private final WroModelFactory modelFactory;

public void process(Resource resource, Reader reader, Writer writer) throws IOException {
   // custom implementation
      WroModel model = modelFactory.create();

      Collection<String> groupNames = new WroModelInspector(model).getGroupNamesContainingResource(resource.getUri());
      //check if the groupNames contains the group you want to include/exclude....
     
      //Since this processor can be used as postProcessor as well, check if there is a groupName equals to resource.getUri()...
}

I agree that this approach requires some coding and is not very straightforward. But this use case was never required before. You could open an issue (feature request) and it would be implemented at some point in the future (at least it won't be lost).

Thanks,
Alex

Ryan Lubke

unread,
Dec 18, 2014, 12:42:59 PM12/18/14
to wr...@googlegroups.com
Hi Alex, 

Thanks for the timely response.  I've logged an enhancement request for this.  Thanks for offering up a workaround. 

Ryan Lubke

unread,
Dec 18, 2014, 2:36:53 PM12/18/14
to wr...@googlegroups.com
It occurred to me that another possible solution would be configuration at the Servlet Filter level vs wro.properties.

The documentation showed that this was supported at one point, but it looks like backwards compatibility may have been broken here as the code that configures the runtime based on the FilterConfig doesn't look at the factory or processor options as it once did.

Maybe it's worth adding this functionality back?  

sapi...@gmail.com

unread,
Jan 30, 2015, 4:55:51 PM1/30/15
to wr...@googlegroups.com
Please someone help to know exactly the way to do that.

Alex Objelean

unread,
Feb 2, 2015, 5:55:57 AM2/2/15
to wr...@googlegroups.com
Hi,

it is not yet possible out of the box. If you need this feature, please open an issue and it will be implemented in one of the future releases.

Thanks,
Alex

On 30 January 2015 at 23:55, <sapi...@gmail.com> wrote:
Please someone help to know exactly the way to do that.

--
You received this message because you are subscribed to the Google Groups "wro4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wro4j+un...@googlegroups.com.
To post to this group, send email to wr...@googlegroups.com.
Visit this group at http://groups.google.com/group/wro4j.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages