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.log.LogFactoryUtil;
29 import com.liferay.portal.kernel.util.GetterUtil;
30 import com.liferay.portal.kernel.util.JavaProps;
31 import com.liferay.portal.kernel.util.LocaleUtil;
32 import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
33 import com.liferay.portal.kernel.util.ServerDetector;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.kernel.util.TimeZoneUtil;
36 import com.liferay.portal.log.CommonsLogFactoryImpl;
37 import com.liferay.portal.security.jaas.PortalConfiguration;
38 import com.liferay.portal.struts.ActionException;
39 import com.liferay.portal.struts.SimpleAction;
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
116 BeanLocatorUtil.setBeanLocator(new BeanLocatorImpl());
117
118
120 JavaProps.isJDK5();
121
122
124 if ((GetterUtil.getBoolean(PropsUtil.get(
125 PropsUtil.PORTAL_CONFIGURATION))) &&
126 (ServerDetector.isJBoss() || ServerDetector.isPramati() ||
127 ServerDetector.isSun() || ServerDetector.isWebLogic())) {
128
129 PortalConfiguration portalConfig = new PortalConfiguration(
130 Configuration.getConfiguration());
131
132 Configuration.setConfiguration(portalConfig);
133 }
134
135
137 try {
138 File repositoryRoot = new File(JCRFactoryImpl.REPOSITORY_ROOT);
139
140 if (!repositoryRoot.exists()) {
141 repositoryRoot.mkdirs();
142
143 File tempFile = new File(
144 SystemProperties.get(SystemProperties.TMP_DIR) +
145 File.separator + Time.getTimestamp());
146
147 String repositoryXmlPath =
148 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
149 "repository-ext.xml";
150
151 ClassLoader classLoader = getClass().getClassLoader();
152
153 if (classLoader.getResource(repositoryXmlPath) == null) {
154 repositoryXmlPath =
155 "com/liferay/portal/jcr/jackrabbit/dependencies/" +
156 "repository.xml";
157 }
158
159 String content = StringUtil.read(
160 classLoader, repositoryXmlPath);
161
162 FileUtil.write(tempFile, content);
163
164 FileUtil.copyFile(
165 tempFile, new File(JCRFactoryImpl.CONFIG_FILE_PATH));
166
167 tempFile.delete();
168 }
169 }
170 catch (Exception e) {
171 e.printStackTrace();
172 }
173
174
176 LiferayResourceLoader.setListeners(PropsUtil.getArray(
177 PropsUtil.VELOCITY_ENGINE_RESOURCE_LISTENERS));
178
179 ExtendedProperties props = new ExtendedProperties();
180
181 props.setProperty(RuntimeConstants.RESOURCE_LOADER, "servlet");
182
183 props.setProperty(
184 "servlet." + RuntimeConstants.RESOURCE_LOADER + ".class",
185 LiferayResourceLoader.class.getName());
186
187 props.setProperty(
188 RuntimeConstants.RESOURCE_MANAGER_CLASS,
189 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER));
190
191 props.setProperty(
192 RuntimeConstants.RESOURCE_MANAGER_CACHE_CLASS,
193 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_RESOURCE_MANAGER_CACHE));
194
195 props.setProperty(
196 "velocimacro.library",
197 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_VELOCIMACRO_LIBRARY));
198
199 props.setProperty(
200 RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
201 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER));
202
203 props.setProperty(
204 "runtime.log.logsystem.log4j.category",
205 PropsUtil.get(PropsUtil.VELOCITY_ENGINE_LOGGER_CATEGORY));
206
207 Velocity.setExtendedProperties(props);
208
209 try {
210 Velocity.init();
211 }
212 catch (Exception e) {
213 e.printStackTrace();
214 }
215 }
216
217 }