// Dont rewrite content if the spec is unavailable
if (spec == null) {
return false;
}
ContentRewriterFeature rewriterFeature
= new ContentRewriterFeature(spec, includeUrls, excludeUrls, expires, includeTags);
if (!rewriterFeature.isRewriteEnabled()) {
return false;
}
if (isHTML(mimeType)) {
Map<String, HtmlTagTransformer> transformerMap = Maps.newHashMap();
if (getProxyUrl() != null) {
LinkRewriter linkRewriter = createLinkRewriter(spec, rewriterFeature);
LinkingTagRewriter rewriter = new LinkingTagRewriter(
linkRewriter,
source);
Set<String> toProcess = Sets.newHashSet(rewriter.getSupportedTags());
toProcess.retainAll(rewriterFeature.getIncludedTags());
for (String tag : toProcess) {
transformerMap.put(tag, rewriter);
}
if (rewriterFeature.getIncludedTags().contains("style")) {
transformerMap.put("style", new StyleTagRewriter(source, linkRewriter));
}
}
if (getConcatUrl() != null && rewriterFeature.getIncludedTags().contains("script")) {
transformerMap
.put("script", new JavascriptTagMerger(spec, rewriterFeature, getConcatUrl(), source));
}
HtmlRewriter.rewrite(new StringReader(mc.getContent()), source, transformerMap, w);
return true;