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.velocity.app.Velocity;
53 import org.apache.velocity.runtime.RuntimeConstants;
54
55
61 public class InitAction extends SimpleAction {
62
63 public void run(String[] ids) throws ActionException {
64
65
68 String userLanguage = SystemProperties.get("user.language");
69 String userCountry = SystemProperties.get("user.country");
70 String userVariant = SystemProperties.get("user.variant");
71
72 LocaleUtil.setDefault(userLanguage, userCountry, userVariant);
73
74
77 String userTimeZone = SystemProperties.get("user.timezone");
78
79 TimeZoneUtil.setDefault(userTimeZone);
80
81
83 try {
84 PortalClassLoaderUtil.setClassLoader(
85 Thread.currentThread().getContextClassLoader());
86 }
87 catch (Exception e) {
88 e.printStackTrace();
89 }
90
91
93 if (GetterUtil.getBoolean(SystemProperties.get(
94 "log4j.configure.on.startup"), true) &&
95 !ServerDetector.isSun()) {
96
97 ClassLoader classLoader = getClass().getClassLoader();
98
99 Log4JUtil.configureLog4J(
100 classLoader.getResource("META-INF/portal-log4j.xml"));
101 Log4JUtil.configureLog4J(
102 classLoader.getResource("META-INF/portal-log4j-ext.xml"));
103 }
104
105
107 try {
108 LogFactoryUtil.setLogFactory(new CommonsLogFactoryImpl());
109 }
110 catch (Exception e) {
111 e.printStackTrace();
112 }
113
114
117 SystemProperties.set(
118 PropsUtil.RESOURCE_REPOSITORIES_ROOT,
119 PropsUtil.get(PropsUtil.RESOURCE_REPOSITORIES_ROOT));
120
121
123 BeanLocatorUtil.setBeanLocator(new BeanLocatorImpl());
124
125
127 JavaProps.isJDK5();
128
129
131 if ((GetterUtil.getBoolean(PropsUtil.get(
132 PropsUtil.PORTAL_CONFIGURATION))) &&
133 (ServerDetector.isJBoss() || ServerDetector.isPramati() ||
134 ServerDetector.isSun() || ServerDetector.isWebLogic())) {
135
136 PortalConfiguration portalConfig = new PortalConfiguration(
137 Configuration.getConfiguration());
138
139 Configuration.setConfiguration(portalConfig);
140 }
141
142
144 try {
145 File repositoryRoot = new File(JCRFactoryImpl.REPOSITORY_ROOT);
146
147 if (!repositoryRoot.exists()) {
148 repositoryRoot.mkdirs();
149
150 File tempFile = new File(
151 SystemProperties.get(SystemProperties.TMP_DIR) +
152 File.separator + Time.getTimestamp());
153
154 String repositoryXmlPath =
155 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
156 "repository-ext.xml";
157
158 ClassLoader classLoader = getClass().getClassLoader();
159
160 if (classLoader.getResource(repositoryXmlPath) == null) {
161 repositoryXmlPath =
162 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
163 "repository.xml";
164 }
165
166 String content = StringUtil.read(
167 classLoader, repositoryXmlPath);
168
169 FileUtil.write(tempFile, content);
170
171 FileUtil.copyFile(
172 tempFile, new File(JCRFactoryImpl.CONFIG_FILE_PATH));
173
174 tempFile.delete();
175 }
176 }
177 catch (Exception e) {
178 e.printStackTrace();
179 }
180
181
183 LiferayResourceLoader.setListeners(PropsUtil.getArray(
184 PropsUtil.VELOCITY_ENGINE_RESOURCE_LISTENERS));
185
186 ExtendedProperties props = new ExtendedProperties();
187
188 props.setProperty(RuntimeConstants.RESOURCE_LOADER, "servlet");
189
190 props.setProperty(
191 "servlet." + RuntimeConstants.RESOURCE_LOADER + ".class",
192 LiferayResourceLoader.class.getName());
193
194 props.setProperty(
195 RuntimeConstants.RESOURCE_MANAGER_CLASS,
196 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER));
197
198 props.setProperty(
199 RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS,
200 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE));
201
202 props.setProperty(
203 "velocimacro.library",
204 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_VELOCIMACRO_LIBRARY));
205
206 props.setProperty(
207 RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
208 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER));
209
210 props.setProperty(
211 "runtime.log.logsystem.log4j.category",
212 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER_CATEGORY));
213
214 Velocity.setExtendedProperties(props);
215
216 try {
217 Velocity.init();
218 }
219 catch (Exception e) {
220 e.printStackTrace();
221 }
222 }
223
224 }