public LinkingTagRewriter(ILinkRewriter linkRewriter, Uri relativeBase) { this.linkRewriter = linkRewriter; this.relativeBase = relativeBase; this.tagAttributeTargets = getDefaultTargets(); builder = new StringBuilder(); }
public LinkingTagRewriter(ILinkRewriter linkRewriter, Uri relativeBase) { this.linkRewriter = linkRewriter; this.relativeBase = relativeBase; this.tagAttributeTargets = getDefaultTargets(); builder = new StringBuilder(); }
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 LinkingTagRewriter(Dictionary<String, HashSet<String>> tagAttributeTargets, ILinkRewriter linkRewriter, Uri relativeBase) { this.tagAttributeTargets = tagAttributeTargets; this.linkRewriter = linkRewriter; this.relativeBase = relativeBase; builder = new StringBuilder(); }
public LinkingTagRewriter(Dictionary <String, HashSet <String> > tagAttributeTargets, ILinkRewriter linkRewriter, Uri relativeBase) { this.tagAttributeTargets = tagAttributeTargets; this.linkRewriter = linkRewriter; this.relativeBase = relativeBase; builder = new StringBuilder(); }
private static String rewriteLink(Token token, Uri _base, ILinkRewriter rewriter) { Match matcher = urlMatcher.Match(token.toString()); if (!matcher.Success) { return(token.toString()); } return("url(\"" + rewriter.rewrite(matcher.Groups[2].Value.Trim(), _base) + "\")"); }
public StyleTagRewriter(Uri source, ILinkRewriter linkRewriter) { this.source = source; this.linkRewriter = linkRewriter; sb = new StringBuilder(500); }
public static List<String> rewrite(java.io.Reader content, Uri source, ILinkRewriter rewriter, java.io.Writer writer, bool extractImports) { List<String> imports = new List<string>(); CharProducer producer = CharProducer.Factory.create(content, new InputSource(new java.net.URI(source.ToString()))); CssLexer lexer = new CssLexer(producer); try { bool inImport = false; while (lexer.hasNext()) { Token token = lexer.next(); if (extractImports) { if (token.type == CssTokenType.SYMBOL && token.text.ToLower().Equals("@import")) { inImport = true; continue; } if (inImport) { if (token.type == CssTokenType.URI) { Match matcher = urlMatcher.Match(token.text); if (matcher.Success) { imports.Add(matcher.Groups[2].Value.Trim()); } } else if (token.type != CssTokenType.SPACE && token.type != CssTokenType.PUNCTUATION) { inImport = false; } } if (!inImport) { writer.write(token.text); } } else { if (token.type == CssTokenType.URI) { writer.write(rewriteLink(token, source, rewriter)); continue; } writer.write(token.text); } } writer.flush(); } catch (ParseException pe) { pe.printStackTrace(); } catch (Exception ioe) { throw ioe; } return imports; }
public static String rewrite(String content, Uri source, ILinkRewriter linkRewriter) { java.io.StringWriter sw = new java.io.StringWriter((content.Length * 110) / 100); rewrite(new java.io.StringReader(content), source, linkRewriter, sw, false); return sw.ToString(); }
private static String rewriteLink(Token token, Uri _base, ILinkRewriter rewriter) { Match matcher = urlMatcher.Match(token.toString()); if (!matcher.Success) return token.toString(); return "url(\"" + rewriter.rewrite(matcher.Groups[2].Value.Trim(), _base) + "\")"; }
public StyleTagRewriter(Uri source, ILinkRewriter linkRewriter) { this.source = source; this.linkRewriter = linkRewriter; sb = new StringBuilder(500); }
public static List <String> rewrite(java.io.Reader content, Uri source, ILinkRewriter rewriter, java.io.Writer writer, bool extractImports) { List <String> imports = new List <string>(); CharProducer producer = CharProducer.Factory.create(content, new InputSource(new java.net.URI(source.ToString()))); CssLexer lexer = new CssLexer(producer); try { bool inImport = false; while (lexer.hasNext()) { Token token = lexer.next(); if (extractImports) { if (token.type == CssTokenType.SYMBOL && token.text.ToLower().Equals("@import")) { inImport = true; continue; } if (inImport) { if (token.type == CssTokenType.URI) { Match matcher = urlMatcher.Match(token.text); if (matcher.Success) { imports.Add(matcher.Groups[2].Value.Trim()); } } else if (token.type != CssTokenType.SPACE && token.type != CssTokenType.PUNCTUATION) { inImport = false; } } if (!inImport) { writer.write(token.text); } } else { if (token.type == CssTokenType.URI) { writer.write(rewriteLink(token, source, rewriter)); continue; } writer.write(token.text); } } writer.flush(); } catch (ParseException pe) { pe.printStackTrace(); } catch (Exception ioe) { throw ioe; } return(imports); }
public static String rewrite(String content, Uri source, ILinkRewriter linkRewriter) { java.io.StringWriter sw = new java.io.StringWriter((content.Length * 110) / 100); rewrite(new java.io.StringReader(content), source, linkRewriter, sw, false); return(sw.ToString()); }