public class JSStringTransformer extends Object implements StringTransformer
Looks for http/https absolute URLs in JavaScript code and translates
them with ReplayParseContext.contextualizeUrl(String).
You can customize the pattern for finding URLs with regex property.
Regular expression must have at least one capturing group, and the first
capturing group is assumed to enclose URL to be rewritten.
(new feature 2014-04-22) Any matching text preceding and
following the first group will be preserved in the output.
For example: if you want to replace protocol-relative URL in addition to regular full URL in JavaScript, you could use conservative regex like:
"[\"']((?:https?:)?//(?:[^/]+@)?[^@:/]+(?:\\.[^@:/]+)+(?:[0-9]+)?)"Note single/double quote preceding URL is preserved in 2014-04-22 version and on.
TODO: org.archive.wayback.archivalurl.ArchivalUrlJSReplayRenderer has similar code. can be consolidated, like ArchivalURLJSStringTransformerReplayRenderer?
May 1, 2014: slight design change:
Now JSStringTransformer does not run it's own should-rewrite check and sends all matching
text to ReplayParseContext.contextualizeUrl(String). More specifically it no longer
be affected by rewriteHttpsOnly flag. This is a design choice to keep
StringTransformer detached from replay mode knowledge and focus on find-and-replace URLs
| Constructor and Description |
|---|
JSStringTransformer() |
public void setRegex(String regex)
regex - public String getRegex()
public String transform(ReplayParseContext context, String input)
StringTransformerRefactoring: change input type to CharSequence.
transform in interface StringTransformercontext - ReplayParseContextinput - text data to be transformedCopyright © 2005–2015 IIPC. All rights reserved.