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.events;
24  
25  import com.liferay.portal.bean.BeanLocatorImpl;
26  import com.liferay.portal.configuration.ConfigurationFactoryImpl;
27  import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
28  import com.liferay.portal.kernel.configuration.ConfigurationFactoryUtil;
29  import com.liferay.portal.kernel.events.SimpleAction;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.JavaProps;
33  import com.liferay.portal.kernel.util.LocaleUtil;
34  import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
35  import com.liferay.portal.kernel.util.TimeZoneUtil;
36  import com.liferay.portal.log.CommonsLogFactoryImpl;
37  import com.liferay.util.SystemProperties;
38  import com.liferay.util.log4j.Log4JUtil;
39  
40  import org.apache.commons.lang.time.StopWatch;
41  
42  /**
43   * <a href="InitAction.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   */
48  public class InitAction extends SimpleAction {
49  
50      public void run(String[] ids) {
51          StopWatch stopWatch = null;
52  
53          if (_PRINT_TIME) {
54              stopWatch = new StopWatch();
55  
56              stopWatch.start();
57          }
58  
59          // Set the default locale used by Liferay. This locale is no longer set
60          // at the VM level. See LEP-2584.
61  
62          String userLanguage = SystemProperties.get("user.language");
63          String userCountry = SystemProperties.get("user.country");
64          String userVariant = SystemProperties.get("user.variant");
65  
66          LocaleUtil.setDefault(userLanguage, userCountry, userVariant);
67  
68          // Set the default time zone used by Liferay. This time zone is no
69          // longer set at the VM level. See LEP-2584.
70  
71          String userTimeZone = SystemProperties.get("user.timezone");
72  
73          TimeZoneUtil.setDefault(userTimeZone);
74  
75          // Shared class loader
76  
77          try {
78              PortalClassLoaderUtil.setClassLoader(
79                  Thread.currentThread().getContextClassLoader());
80          }
81          catch (Exception e) {
82              e.printStackTrace();
83          }
84  
85          // Log4J
86  
87          if (GetterUtil.getBoolean(SystemProperties.get(
88                  "log4j.configure.on.startup"), true)) {
89  
90              ClassLoader classLoader = getClass().getClassLoader();
91  
92              Log4JUtil.configureLog4J(
93                  classLoader.getResource("META-INF/portal-log4j.xml"));
94              Log4JUtil.configureLog4J(
95                  classLoader.getResource("META-INF/portal-log4j-ext.xml"));
96          }
97  
98          // Shared log
99  
100         try {
101             LogFactoryUtil.setLogFactory(new CommonsLogFactoryImpl());
102         }
103         catch (Exception e) {
104             e.printStackTrace();
105         }
106 
107         // Configuration factory
108 
109         ConfigurationFactoryUtil.setConfigurationFactory(
110             new ConfigurationFactoryImpl());
111 
112         // Bean locator
113 
114         PortalBeanLocatorUtil.setBeanLocator(new BeanLocatorImpl());
115 
116         // Java properties
117 
118         JavaProps.isJDK5();
119 
120         if (_PRINT_TIME) {
121             System.out.println(
122                 "InitAction takes " + stopWatch.getTime() + " ms");
123         }
124     }
125 
126     private static final boolean _PRINT_TIME = false;
127 
128 }