summaryrefslogtreecommitdiffstats
path: root/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java
diff options
context:
space:
mode:
Diffstat (limited to 'gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java')
-rw-r--r--gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java35
1 files changed, 19 insertions, 16 deletions
diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java
index a3c7a3c6fd..10cd1f0fa5 100644
--- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java
+++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/ui/CommentLinkProcessor.java
@@ -15,9 +15,9 @@
package com.google.gerrit.client.ui;
import com.google.gerrit.client.Gerrit;
-import com.google.gwtjsonrpc.common.AsyncCallback;
-import com.google.gwtexpui.safehtml.client.RegexFindReplace;
+import com.google.gwtexpui.safehtml.client.FindReplace;
import com.google.gwtexpui.safehtml.client.SafeHtml;
+import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.VoidResult;
import java.util.ArrayList;
@@ -25,17 +25,23 @@ import java.util.Collections;
import java.util.List;
public class CommentLinkProcessor {
- public static SafeHtml apply(SafeHtml buf) {
- try {
- return buf.replaceAll(Gerrit.getConfig().getCommentLinks());
+ private List<FindReplace> commentLinks;
+
+ public CommentLinkProcessor(List<FindReplace> commentLinks) {
+ this.commentLinks = commentLinks;
+ }
+ public SafeHtml apply(SafeHtml buf) {
+ try {
+ return buf.replaceAll(commentLinks);
} catch (RuntimeException err) {
// One or more of the patterns isn't valid on this browser.
// Try to filter the list down and remove the invalid ones.
- List<RegexFindReplace> safe = new ArrayList<RegexFindReplace>();
+ List<FindReplace> safe = new ArrayList<FindReplace>(commentLinks.size());
+
List<PatternError> bad = new ArrayList<PatternError>();
- for (RegexFindReplace r : Gerrit.getConfig().getCommentLinks()) {
+ for (FindReplace r : commentLinks) {
try {
buf.replaceAll(Collections.singletonList(r));
safe.add(r);
@@ -50,7 +56,7 @@ public class CommentLinkProcessor {
for (PatternError e : bad) {
msg.append("\n");
msg.append("\"");
- msg.append(e.pattern.find());
+ msg.append(e.pattern.pattern().getSource());
msg.append("\": ");
msg.append(e.errorMessage);
}
@@ -67,28 +73,25 @@ public class CommentLinkProcessor {
}
try {
- Gerrit.getConfig().setCommentLinks(safe);
+ commentLinks = safe;
return buf.replaceAll(safe);
} catch (RuntimeException err2) {
// To heck with it. The patterns passed individually above but
- // failed as a group? Just drop them all and render without.
+ // failed as a group? Just render without.
//
- Gerrit.getConfig().setCommentLinks(null);
+ commentLinks = null;
return buf;
}
}
}
private static class PatternError {
- RegexFindReplace pattern;
+ FindReplace pattern;
String errorMessage;
- PatternError(RegexFindReplace r, String w) {
+ PatternError(FindReplace r, String w) {
pattern = r;
errorMessage = w;
}
}
-
- private CommentLinkProcessor() {
- }
}