public Function < Collection < File > , Void > createExpanderHandler ( final Group group , final Resource resource , final String baseNameFolder ) { LOG . debug ( "createExpanderHandler using baseNameFolder: {}\n for resource {}" , baseNameFolder , resource ) ; return new Function < Collection < File > , Void > ( ) { public Void apply ( final Collection < File > files ) { if ( baseNameFolder == null ) { // replacing group with empty list since the original uri has no associated resources. // No BaseNameFolder found LOG . warn ( "The resource {} is probably invalid, removing it from the group." , resource ) ; group . replace ( resource , new ArrayList < Resource > ( ) ) ; } else { final List < Resource > expandedResources = new ArrayList < Resource > ( ) ; LOG . debug ( "baseNameFolder: {}" , baseNameFolder ) ; for ( final File file : files ) { final String resourcePath = getFullPathNoEndSeparator ( resource ) ; LOG . debug ( "\tresourcePath: {}" , resourcePath ) ; LOG . debug ( "\tfile path: {}" , file . getPath ( ) ) ; final String computedResourceUri = resourcePath + StringUtils . removeStart ( file . getPath ( ) , baseNameFolder ) . replace ( ' ' , ' ' ) ; final Resource expandedResource = Resource . create ( computedResourceUri , resource . getType ( ) ) ; LOG . debug ( "\texpanded resource: {}" , expandedResource ) ; expandedResources . add ( expandedResource ) ; } LOG . debug ( "\treplace resource {}" , resource ) ; group . replace ( resource , expandedResources ) ; } return null ; } /** * This method fixes the problem when a resource in a group uses deep wildcard and starts at the root. * <p/> * Find more details <a href="https://github.com/alexo/wro4j/pull/44">here</a>. */ private String getFullPathNoEndSeparator ( final Resource resource1 ) { final String result = FilenameUtils . getFullPathNoEndSeparator ( resource1 . getUri ( ) ) ; if ( result != null && 1 == result . length ( ) && 0 == FilenameUtils . indexOfLastSeparator ( result ) ) { return "" ; } return result ; } } ; }
create the handler which expand the resources containing wildcard .