private String applyPreProcessors ( final Resource resource , final ProcessingCriteria criteria ) throws IOException { final Collection < ResourcePreProcessor > processors = processorsFactory . getPreProcessors ( ) ; LOG . debug ( "applying preProcessors: {}" , processors ) ; String resourceContent = null ; try { resourceContent = getResourceContent ( resource ) ; } catch ( final IOException e ) { LOG . debug ( "Invalid resource found: {}" , resource ) ; if ( Context . get ( ) . getConfig ( ) . isIgnoreMissingResources ( ) ) { return StringUtils . EMPTY ; } else { LOG . error ( "Cannot ignore missing resource: {}" , resource ) ; throw e ; } } if ( ! processors . isEmpty ( ) ) { Writer writer = null ; for ( final ResourcePreProcessor processor : processors ) { final ResourcePreProcessor decoratedProcessor = decoratePreProcessor ( processor , criteria ) ; writer = new StringWriter ( ) ; final Reader reader = new StringReader ( resourceContent ) ; // decorate and process decoratedProcessor . process ( resource , reader , writer ) ; // use the outcome for next input resourceContent = writer . toString ( ) ; } } // add explicitly new line at the end to avoid unexpected comment issue return String . format ( "%s%n" , resourceContent ) ; }
Apply a list of preprocessors on a resource .