InjectorBuilder.create(getManagerFactory()).build().inject(processor);
processor.process(resource, reader, new StringWriter());
}
private ResourcePreProcessor createCssImportProcessor(final Function<String, ChangeStatus> func) {
final ResourcePreProcessor cssImportProcessor = new AbstractCssImportPreProcessor() {
@Override
protected void onImportDetected(final String importedUri) {
getLog().debug("Found @import " + importedUri);
try {
final ChangeStatus status = func.apply(importedUri);
getLog().debug("ChangeStatus for " + importedUri + ": " + status);
if (ChangeStatus.NOT_CHANGED.equals(status)) {
remember(Resource.create(importedUri, ResourceType.CSS));
}
} catch (final Exception e) {
getLog().error("Cannot apply a function on @import resource: " + importedUri + ". Ignoring it.", e);
}
remember(Resource.create(importedUri, ResourceType.CSS));
}
@Override
protected String doTransform(final String cssContent, final List<Resource> foundImports)
throws IOException {
// no need to build the content, since we are interested in finding imported resources only
return "";
}
@Override
public String toString() {
return CssImportPreProcessor.class.getSimpleName();
}
};
final ResourcePreProcessor processor = new ExceptionHandlingProcessorDecorator(cssImportProcessor) {
@Override
protected boolean isIgnoreFailingProcessor() {
return true;
}
};