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 import com.liferay.portal.kernel.util.Validator;
020 import com.liferay.portal.util.PropsUtil;
021
022 import java.util.ArrayList;
023 import java.util.List;
024 import java.util.regex.Pattern;
025
026
029 public class RegexTransformerUtil {
030
031 public static List<Pattern> getPatterns() {
032 return _instance._patterns;
033 }
034
035 public static List<String> getReplacements() {
036 return _instance._replacements;
037 }
038
039 private RegexTransformerUtil() {
040 _patterns = new ArrayList<Pattern>();
041 _replacements = new ArrayList<String>();
042
043 for (int i = 0; i < 100; i++) {
044 String regex = PropsUtil.get(
045 "journal.transformer.regex.pattern." + i);
046 String replacement = PropsUtil.get(
047 "journal.transformer.regex.replacement." + i);
048
049 if (Validator.isNull(regex) || Validator.isNull(replacement)) {
050 break;
051 }
052
053 if (_log.isInfoEnabled()) {
054 _log.info(
055 "Pattern " + regex + " will be replaced with " +
056 replacement);
057 }
058
059 _patterns.add(Pattern.compile(regex));
060 _replacements.add(replacement);
061 }
062 }
063
064 private static Log _log = LogFactoryUtil.getLog(RegexTransformerUtil.class);
065
066 private static RegexTransformerUtil _instance = new RegexTransformerUtil();
067
068 private List<Pattern> _patterns;
069 private List<String> _replacements;
070
071 }