private bool rewrite(GadgetSpec spec, Uri source, MutableContent mc, String mimeType, java.io.Writer writer) { // Dont rewrite content if the spec is unavailable if (spec == null) { return(false); } // Store the feature in the spec so we dont keep parsing it ContentRewriterFeature rewriterFeature = new ContentRewriterFeature(spec, includeUrls, excludeUrls, expires, includeTags); if (!rewriterFeature.isRewriteEnabled()) { return(false); } if (isHTML(mimeType)) { Dictionary <String, IHtmlTagTransformer> transformerMap = new Dictionary <string, IHtmlTagTransformer>(); if (ProxyUrl != null) { ILinkRewriter linkRewriter = CreateLinkRewriter(spec, rewriterFeature); LinkingTagRewriter rewriter = new LinkingTagRewriter(linkRewriter, source); HashSet <String> toProcess = new HashSet <string>(); foreach (var item in rewriter.getSupportedTags()) { toProcess.Add(item); } toProcess.IntersectWith(rewriterFeature.getIncludedTags()); foreach (string tag in toProcess) { transformerMap[tag] = rewriter; } if (rewriterFeature.getIncludedTags().Contains("style")) { transformerMap["style"] = new StyleTagRewriter(source, linkRewriter); } } if (ConcatUrl != null && rewriterFeature.getIncludedTags().Contains("script")) { transformerMap["script"] = new JavascriptTagMerger(spec, rewriterFeature, ConcatUrl, source); } HtmlRewriter.rewrite(new StringReader(mc.getContent()), source, transformerMap, writer); return(true); } if (isCSS(mimeType)) { if (ProxyUrl != null) { CssRewriter.rewrite(new StringReader(mc.getContent()), source, CreateLinkRewriter(spec, rewriterFeature), writer, false); return(true); } return(false); } return(false); }
public void accept(Token token, Token lastToken) { if (token.type == HtmlTokenType.UNESCAPED) { sb.Append(CssRewriter.rewrite(token.toString(), source, linkRewriter)); } else { sb.Append(HtmlRewriter.producePreTokenSeparator(token, lastToken)); sb.Append(token.toString()); sb.Append(HtmlRewriter.producePostTokenSeparator(token, lastToken)); } }
public void accept(Token token, Token lastToken) { if (token.type == HtmlTokenType.TAGBEGIN) { tagAttributeTargets.TryGetValue(token.toString().Substring(1).ToLower(), out currentTagAttrs); } if (currentTagAttrs != null && lastToken != null && lastToken.type == HtmlTokenType.ATTRNAME && currentTagAttrs.Contains(lastToken.toString().ToLower())) { String link = stripQuotes(token.toString()); builder.Append("=\""); builder.Append(linkRewriter.rewrite(link, relativeBase)); builder.Append('\"'); return; } builder.Append(HtmlRewriter.producePreTokenSeparator(token, lastToken)); builder.Append(token.toString()); builder.Append(HtmlRewriter.producePostTokenSeparator(token, lastToken)); }