1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.verify;
24  
25  import com.liferay.portal.util.PropsUtil;
26  import com.liferay.util.SystemProperties;
27  
28  import org.apache.commons.logging.Log;
29  import org.apache.commons.logging.LogFactory;
30  
31  /**
32   * <a href="VerifyProperties.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class VerifyProperties extends VerifyProcess {
38  
39      public void verify() throws VerifyException {
40          _log.info("Verifying");
41  
42          try {
43              verifyProperties();
44          }
45          catch (Exception e) {
46              throw new VerifyException(e);
47          }
48      }
49  
50      protected void verifyProperties() throws Exception {
51  
52          // system.properties
53  
54          for (String[] keys : _MIGRATED_SYSTEM_KEYS) {
55              String oldKey = keys[0];
56              String newKey = keys[1];
57  
58              verifyMigratedSystemProperty(oldKey, newKey);
59          }
60  
61          for (String[] keys : _RENAMED_SYSTEM_KEYS) {
62              String oldKey = keys[0];
63              String newKey = keys[1];
64  
65              verifyRenamedSystemProperty(oldKey, newKey);
66          }
67  
68          for (String key : _OBSOLETE_SYSTEM_KEYS) {
69              verifyObsoleteSystemProperty(key);
70          }
71  
72          // portal.properties
73  
74          for (String[] keys : _RENAMED_PORTAL_KEYS) {
75              String oldKey = keys[0];
76              String newKey = keys[1];
77  
78              verifyRenamedPortalProperty(oldKey, newKey);
79          }
80  
81          for (String key : _OBSOLETE_PORTAL_KEYS) {
82              verifyObsoletePortalProperty(key);
83          }
84      }
85  
86      protected void verifyMigratedSystemProperty(String oldKey, String newKey)
87          throws Exception {
88  
89          String value = SystemProperties.get(oldKey);
90  
91          if (value != null) {
92              _log.error(
93                  "System property \"" + oldKey +
94                      "\" was migrated to the portal property \"" + newKey +
95                          "\"");
96          }
97      }
98  
99      protected void verifyRenamedPortalProperty(String oldKey, String newKey)
100         throws Exception {
101 
102         String value = PropsUtil.get(oldKey);
103 
104         if (value != null) {
105             _log.error(
106                 "Portal property \"" + oldKey + "\" was renamed to \"" +
107                     newKey + "\"");
108         }
109     }
110 
111     protected void verifyRenamedSystemProperty(String oldKey, String newKey)
112         throws Exception {
113 
114         String value = SystemProperties.get(oldKey);
115 
116         if (value != null) {
117             _log.error(
118                 "System property \"" + oldKey + "\" was renamed to \"" +
119                     newKey + "\"");
120         }
121     }
122 
123     protected void verifyObsoletePortalProperty(String key) throws Exception {
124         String value = PropsUtil.get(key);
125 
126         if (value != null) {
127             _log.error("Portal property \"" + key + "\" is obsolete");
128         }
129     }
130 
131     protected void verifyObsoleteSystemProperty(String key) throws Exception {
132         String value = SystemProperties.get(key);
133 
134         if (value != null) {
135             _log.error("System property \"" + key + "\" is obsolete");
136         }
137     }
138 
139     private static final String[][] _MIGRATED_SYSTEM_KEYS = new String[][] {
140         new String[] {
141             "com.liferay.filters.compression.CompressionFilter",
142             "com.liferay.portal.servlet.filters.compression.CompressionFilter"
143         },
144         new String[] {
145             "com.liferay.filters.doubleclick.DoubleClickFilter",
146             "com.liferay.portal.servlet.filters.doubleclick.DoubleClickFilter"
147         },
148         new String[] {
149             "com.liferay.filters.strip.StripFilter",
150             "com.liferay.portal.servlet.filters.strip.StripFilter"
151         },
152         new String[] {
153             "com.liferay.util.Http.max.connections.per.host",
154             "com.liferay.portal.util.HttpImpl.max.connections.per.host"
155         },
156         new String[] {
157             "com.liferay.util.Http.max.total.connections",
158             "com.liferay.portal.util.HttpImpl.max.total.connections"
159         },
160         new String[] {
161             "com.liferay.util.Http.proxy.auth.type",
162             "com.liferay.portal.util.HttpImpl.proxy.auth.type"
163         },
164         new String[] {
165             "com.liferay.util.Http.proxy.ntlm.domain",
166             "com.liferay.portal.util.HttpImpl.proxy.ntlm.domain"
167         },
168         new String[] {
169             "com.liferay.util.Http.proxy.ntlm.host",
170             "com.liferay.portal.util.HttpImpl.proxy.ntlm.host"
171         },
172         new String[] {
173             "com.liferay.util.Http.proxy.password",
174             "com.liferay.portal.util.HttpImpl.proxy.password"
175         },
176         new String[] {
177             "com.liferay.util.Http.proxy.username",
178             "com.liferay.portal.util.HttpImpl.proxy.username"
179         },
180         new String[] {
181             "com.liferay.util.Http.timeout",
182             "com.liferay.portal.util.HttpImpl.timeout"
183         }
184     };
185 
186     private static final String[] _OBSOLETE_PORTAL_KEYS = new String[] {
187     };
188 
189     private static final String[] _OBSOLETE_SYSTEM_KEYS = new String[] {
190         "com.liferay.util.Http.proxy.host",
191         "com.liferay.util.Http.proxy.port",
192         "com.liferay.util.XSSUtil.regexp.pattern"
193     };
194 
195     private static final String[][] _RENAMED_PORTAL_KEYS = new String[][] {
196     };
197 
198     private static final String[][] _RENAMED_SYSTEM_KEYS = new String[][] {
199     };
200 
201     private static Log _log = LogFactory.getLog(VerifyProperties.class);
202 
203 }