ThemeCssFilesProcessor extends ThemeFilesProcessor { protected String rewriteCssUrls(String css, File mergeFile, File mergedFile) throws IOException { String urlAdjustment = ThemeBuilderUtils.calculatePathToFile(mergedFile, mergeFile); if (StringUtils.isBlank(urlAdjustment)) { return css; } Pattern urlPattern = Pattern.compile(ThemeBuilderConstants.Patterns.CSS_URL_PATTERN); Matcher matcher = urlPattern.matcher(css); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String cssStatement = matcher.group(); String cssUrl = null; if (matcher.group(1) != null) { cssUrl = matcher.group(1); } else { cssUrl = matcher.group(2); } if (cssUrl != null) { String modifiedUrl = cssUrl; if (!cssUrl.startsWith("/")) { modifiedUrl = urlAdjustment + cssUrl; } String modifiedStatement = Matcher.quoteReplacement(cssStatement.replace(cssUrl, modifiedUrl)); matcher.appendReplacement(sb, modifiedStatement); } } matcher.appendTail(sb); return sb.toString(); } ThemeCssFilesProcessor(String themeName, File themeDirectory, Properties themeProperties,
            Map<String, File> themePluginDirsMap, File workingDir, String projectVersion);   }
@Test public void testRewriteCssUrls() throws Exception { String cssString = "#fancybox-loading, .fancybox-close, .fancybox-prev span, .fancybox-next span {\n" + "\tbackground-image: url('fancybox_sprite.png');\n" + "} " + ".infoGrowl{\n" + "\tbackground: url(\"images/information-frame.png\") no-repeat scroll 5px 5px transparent;\n" + "\tpadding-left: 25px;\n" + "}"; String expectedCssString = "#fancybox-loading, .fancybox-close, .fancybox-prev span, .fancybox-next span {\n" + "\tbackground-image: url('../subDir2/fancybox_sprite.png');\n" + "} " + ".infoGrowl{\n" + "\tbackground: url(\"../subDir2/images/information-frame.png\") no-repeat scroll 5px 5px transparent;\n" + "\tpadding-left: 25px;\n" + "}"; File mergedFile = new File("/basedir/subDir1/merge.css"); File mergeFile = new File("/basedir/subDir2/foo.css"); String rewriteCssString = cssFilesProcessor.rewriteCssUrls(cssString, mergeFile, mergedFile); Assert.assertEquals("Url not rewritten correctly in css string", expectedCssString, rewriteCssString); }