1
22
23 package com.liferay.portal.events;
24
25 import com.liferay.portal.bean.BeanLocatorImpl;
26 import com.liferay.portal.jcr.jackrabbit.JCRFactoryImpl;
27 import com.liferay.portal.kernel.bean.BeanLocatorUtil;
28 import com.liferay.portal.kernel.events.ActionException;
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.ServerDetector;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.TimeZoneUtil;
38 import com.liferay.portal.log.CommonsLogFactoryImpl;
39 import com.liferay.portal.security.jaas.PortalConfiguration;
40 import com.liferay.portal.util.PropsUtil;
41 import com.liferay.portal.velocity.LiferayResourceLoader;
42 import com.liferay.util.FileUtil;
43 import com.liferay.util.SystemProperties;
44 import com.liferay.util.Time;
45 import com.liferay.util.log4j.Log4JUtil;
46
47 import java.io.File;
48
49 import javax.security.auth.login.Configuration;
50
51 import org.apache.commons.collections.ExtendedProperties;
52 import org.apache.commons.lang.time.StopWatch;
53 import org.apache.velocity.app.Velocity;
54 import org.apache.velocity.runtime.RuntimeConstants;
55
56
62 public class InitAction extends SimpleAction {
63
64 public void run(String[] ids) throws ActionException {
65 StopWatch stopWatch = null;
66
67 if (_PRINT_TIME) {
68 stopWatch = new StopWatch();
69
70 stopWatch.start();
71 }
72
73
76 String userLanguage = SystemProperties.get("user.language");
77 String userCountry = SystemProperties.get("user.country");
78 String userVariant = SystemProperties.get("user.variant");
79
80 LocaleUtil.setDefault(userLanguage, userCountry, userVariant);
81
82
85 String userTimeZone = SystemProperties.get("user.timezone");
86
87 TimeZoneUtil.setDefault(userTimeZone);
88
89
91 try {
92 PortalClassLoaderUtil.setClassLoader(
93 Thread.currentThread().getContextClassLoader());
94 }
95 catch (Exception e) {
96 e.printStackTrace();
97 }
98
99
101 if (GetterUtil.getBoolean(SystemProperties.get(
102 "log4j.configure.on.startup"), true)) {
103
104 ClassLoader classLoader = getClass().getClassLoader();
105
106 Log4JUtil.configureLog4J(
107 classLoader.getResource("META-INF/portal-log4j.xml"));
108 Log4JUtil.configureLog4J(
109 classLoader.getResource("META-INF/portal-log4j-ext.xml"));
110 }
111
112
114 try {
115 LogFactoryUtil.setLogFactory(new CommonsLogFactoryImpl());
116 }
117 catch (Exception e) {
118 e.printStackTrace();
119 }
120
121
124 SystemProperties.set(
125 PropsUtil.RESOURCE_REPOSITORIES_ROOT,
126 PropsUtil.get(PropsUtil.RESOURCE_REPOSITORIES_ROOT));
127
128
130 BeanLocatorUtil.setBeanLocator(new BeanLocatorImpl());
131
132
134 JavaProps.isJDK5();
135
136
138 if ((GetterUtil.getBoolean(PropsUtil.get(
139 PropsUtil.PORTAL_CONFIGURATION))) &&
140 (ServerDetector.isJBoss() || ServerDetector.isPramati() ||
141 ServerDetector.isWebLogic())) {
142
143 PortalConfiguration portalConfig = new PortalConfiguration(
144 Configuration.getConfiguration());
145
146 Configuration.setConfiguration(portalConfig);
147 }
148
149
151 try {
152 File repositoryRoot = new File(JCRFactoryImpl.REPOSITORY_ROOT);
153
154 if (!repositoryRoot.exists()) {
155 repositoryRoot.mkdirs();
156
157 File tempFile = new File(
158 SystemProperties.get(SystemProperties.TMP_DIR) +
159 File.separator + Time.getTimestamp());
160
161 String repositoryXmlPath =
162 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
163 "repository-ext.xml";
164
165 ClassLoader classLoader = getClass().getClassLoader();
166
167 if (classLoader.getResource(repositoryXmlPath) == null) {
168 repositoryXmlPath =
169 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
170 "repository.xml";
171 }
172
173 String content = StringUtil.read(
174 classLoader, repositoryXmlPath);
175
176 FileUtil.write(tempFile, content);
177
178 FileUtil.copyFile(
179 tempFile, new File(JCRFactoryImpl.CONFIG_FILE_PATH));
180
181 tempFile.delete();
182 }
183 }
184 catch (Exception e) {
185 e.printStackTrace();
186 }
187
188
190 LiferayResourceLoader.setListeners(PropsUtil.getArray(
191 PropsUtil.VELOCITY_ENGINE_RESOURCE_LISTENERS));
192
193 ExtendedProperties props = new ExtendedProperties();
194
195 props.setProperty(RuntimeConstants.RESOURCE_LOADER, "servlet");
196
197 props.setProperty(
198 "servlet." + RuntimeConstants.RESOURCE_LOADER + ".class",
199 LiferayResourceLoader.class.getName());
200
201 props.setProperty(
202 RuntimeConstants.RESOURCE_MANAGER_CLASS,
203 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER));
204
205 props.setProperty(
206 RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS,
207 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE));
208
209 props.setProperty(
210 "velocimacro.library",
211 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_VELOCIMACRO_LIBRARY));
212
213 props.setProperty(
214 RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
215 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER));
216
217 props.setProperty(
218 "runtime.log.logsystem.log4j.category",
219 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER_CATEGORY));
220
221 Velocity.setExtendedProperties(props);
222
223 try {
224 Velocity.init();
225 }
226 catch (Exception e) {
227 e.printStackTrace();
228 }
229
230 if (_PRINT_TIME) {
231 System.out.println(
232 "InitAction takes " + stopWatch.getTime() + " ms");
233 }
234 }
235
236 private static final boolean _PRINT_TIME = false;
237
238 }