001
014
015 package com.liferay.portlet.journal.util;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import java.util.List;
021 import java.util.regex.Matcher;
022 import java.util.regex.Pattern;
023
024
027 public class RegexTransformerListener extends TransformerListener {
028
029 public String onXml(String s) {
030 if (_log.isDebugEnabled()) {
031 _log.debug("onXml");
032 }
033
034 return s;
035 }
036
037 public String onScript(String s) {
038 if (_log.isDebugEnabled()) {
039 _log.debug("onScript");
040 }
041
042 s = replace(s);
043
044 return s;
045 }
046
047 public String onOutput(String s) {
048 if (_log.isDebugEnabled()) {
049 _log.debug("onOutput");
050 }
051
052 s = replace(s);
053
054 return s;
055 }
056
057 protected String replace(String s) {
058 if (s == null) {
059 return s;
060 }
061
062 List<Pattern> patterns = RegexTransformerUtil.getPatterns();
063 List<String> replacements = RegexTransformerUtil.getReplacements();
064
065 for (int i = 0; i < patterns.size(); i++) {
066 Pattern pattern = patterns.get(i);
067 String replacement = replacements.get(i);
068
069 Matcher matcher = pattern.matcher(s);
070
071 s = matcher.replaceAll(replacement);
072 }
073
074 return s;
075 }
076
077 private static Log _log = LogFactoryUtil.getLog(
078 RegexTransformerListener.class);
079
080 }