1
14
15 package com.liferay.portlet.journal.util;
16
17 import com.liferay.portal.kernel.log.Log;
18 import com.liferay.portal.kernel.log.LogFactoryUtil;
19
20 import java.util.List;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23
24
29 public class RegexTransformerListener extends TransformerListener {
30
31 public String onXml(String s) {
32 if (_log.isDebugEnabled()) {
33 _log.debug("onXml");
34 }
35
36 return s;
37 }
38
39 public String onScript(String s) {
40 if (_log.isDebugEnabled()) {
41 _log.debug("onScript");
42 }
43
44 s = replace(s);
45
46 return s;
47 }
48
49 public String onOutput(String s) {
50 if (_log.isDebugEnabled()) {
51 _log.debug("onOutput");
52 }
53
54 s = replace(s);
55
56 return s;
57 }
58
59 protected String replace(String s) {
60 if (s == null) {
61 return s;
62 }
63
64 List<Pattern> patterns = RegexTransformerUtil.getPatterns();
65 List<String> replacements = RegexTransformerUtil.getReplacements();
66
67 for (int i = 0; i < patterns.size(); i++) {
68 Pattern pattern = patterns.get(i);
69 String replacement = replacements.get(i);
70
71 Matcher matcher = pattern.matcher(s);
72
73 s = matcher.replaceAll(replacement);
74 }
75
76 return s;
77 }
78
79 private static Log _log = LogFactoryUtil.getLog(
80 RegexTransformerListener.class);
81
82 }