Closed GoogleCodeExporter closed 9 years ago
Original comment by alex.obj...@gmail.com
on 3 Sep 2014 at 5:21
This processor is used currently for tests only. Do you have any use-case for
this processor?
Original comment by alex.obj...@gmail.com
on 3 Sep 2014 at 2:47
I was using to make one processor that I could use to minify anything:
ResourcePreProcessor chainedProcessor;
protected ResourcePreProcessor getChainedProcessor(){
ServletContextAttributeHelper servletContextAttributeHelper = new ServletContextAttributeHelper(ServletContextHolder.getServletContext());
boolean minimize = servletContextAttributeHelper.getWroConfiguration().isMinimizeEnabled();
WroManager wroManager =
servletContextAttributeHelper.getManagerFactory().create();
ProcessorsFactory processorsFactory = wroManager.getProcessorsFactory();
List<ResourcePreProcessor> processors = new ArrayList<ResourcePreProcessor>();
for(ResourcePreProcessor processor : processorsFactory.getPreProcessors()){
processors.add(new DefaultProcessorDecorator(processor, minimize));
}
for(ResourcePostProcessor processor : processorsFactory.getPostProcessors()){
processors.add(new DefaultProcessorDecorator(processor, minimize));
}
return chainedProcessor = ChainedProcessor.create(processors.toArray(new ResourcePreProcessor[processors.size()]));
}
public String compress(String source) {
if(chainedProcessor==null){
synchronized(this){
if(chainedProcessor==null){
chainedProcessor = getChainedProcessor();
}
}
}
final StringWriter stringWriter = new StringWriter();
try {
chainedProcessor.process(Resource.create("", resourceType), new StringReader(source), stringWriter);
} catch (Exception e) {
throw new RuntimeException("Exception occurred while using wro4j to process inline " + resourceType.getContentType(),e);
}
return stringWriter.toString();
}
So I could just call compress("whatever") and it will returned the processed
output.
If there's a better way to do that, please do let me know - but either way, it
would be nice if ChainedProcessor lost that junit dependency. :)
Original comment by candrews...@gmail.com
on 3 Sep 2014 at 3:14
You cannot just minimize anything, simply because each type of resource require
a certain processor (ex: googleClosure for js, cssMin for css). But I agree
that since the ChainedProcessor is part of non test code base, it should not
depend on TestUtils.
Original comment by alex.obj...@gmail.com
on 3 Sep 2014 at 3:24
In the constructor of this class, a ResourceType is specified. That's how wro4j
can know which processors to apply.
My motivation for this adapter is to work with
https://code.google.com/p/htmlcompressor/ btw.
Attached is the class.
Original comment by candrews...@gmail.com
on 3 Sep 2014 at 3:32
Attachments:
Fixed in branch 1.7.x
Original comment by alex.obj...@gmail.com
on 4 Sep 2014 at 8:26
Original comment by alex.obj...@gmail.com
on 10 Sep 2014 at 9:06
Original issue reported on code.google.com by
candrews...@gmail.com
on 2 Sep 2014 at 5:18