1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
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  import com.liferay.portal.kernel.util.Validator;
20  import com.liferay.portal.util.PropsUtil;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  import java.util.regex.Pattern;
25  
26  /**
27   * <a href="RegexTransformerUtil.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class RegexTransformerUtil {
32  
33      public static List<Pattern> getPatterns() {
34          return _instance._patterns;
35      }
36  
37      public static List<String> getReplacements() {
38          return _instance._replacements;
39      }
40  
41      private RegexTransformerUtil() {
42          _patterns = new ArrayList<Pattern>();
43          _replacements = new ArrayList<String>();
44  
45          for (int i = 0; i < 100; i++) {
46              String regex = PropsUtil.get(
47                  "journal.transformer.regex.pattern." + i);
48              String replacement = PropsUtil.get(
49                  "journal.transformer.regex.replacement." + i);
50  
51              if (Validator.isNull(regex) || Validator.isNull(replacement)) {
52                  break;
53              }
54  
55              if (_log.isInfoEnabled()) {
56                  _log.info(
57                      "Pattern " + regex + " will be replaced with " +
58                          replacement);
59              }
60  
61              _patterns.add(Pattern.compile(regex));
62              _replacements.add(replacement);
63          }
64      }
65  
66      private static Log _log = LogFactoryUtil.getLog(RegexTransformerUtil.class);
67  
68      private static RegexTransformerUtil _instance = new RegexTransformerUtil();
69  
70      private List<Pattern> _patterns;
71      private List<String> _replacements;
72  
73  }