2 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
\r
4 * This library is free software; you can redistribute it and/or modify it under
\r
5 * the terms of the GNU Lesser General Public License as published by the Free
\r
6 * Software Foundation; either version 2.1 of the License, or (at your option)
\r
9 * This library is distributed in the hope that it will be useful, but WITHOUT
\r
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
\r
15 package com.liferay.portlet.admin.action;
\r
17 import java.io.File;
\r
18 import java.util.Enumeration;
\r
19 import java.util.HashSet;
\r
20 import java.util.List;
\r
21 import java.util.Map;
\r
22 import java.util.Set;
\r
23 import java.util.concurrent.CountDownLatch;
\r
24 import java.util.concurrent.TimeUnit;
\r
26 import javax.portlet.ActionRequest;
\r
27 import javax.portlet.ActionResponse;
\r
28 import javax.portlet.PortletConfig;
\r
29 import javax.portlet.PortletContext;
\r
30 import javax.portlet.PortletPreferences;
\r
31 import javax.portlet.PortletSession;
\r
32 import javax.portlet.PortletURL;
\r
33 import javax.portlet.WindowState;
\r
34 import javax.servlet.http.HttpServletRequest;
\r
35 import javax.servlet.http.HttpSession;
\r
37 import org.apache.log4j.Level;
\r
38 import org.apache.struts.action.ActionForm;
\r
39 import org.apache.struts.action.ActionMapping;
\r
41 import com.liferay.mail.service.MailServiceUtil;
\r
42 import com.liferay.portal.captcha.CaptchaImpl;
\r
43 import com.liferay.portal.captcha.recaptcha.ReCaptchaImpl;
\r
44 import com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl;
\r
45 import com.liferay.portal.convert.ConvertProcess;
\r
46 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
\r
47 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
\r
48 import com.liferay.portal.kernel.captcha.Captcha;
\r
49 import com.liferay.portal.kernel.captcha.CaptchaUtil;
\r
50 import com.liferay.portal.kernel.cluster.Address;
\r
51 import com.liferay.portal.kernel.cluster.ClusterExecutorUtil;
\r
52 import com.liferay.portal.kernel.cluster.ClusterLinkUtil;
\r
53 import com.liferay.portal.kernel.cluster.ClusterRequest;
\r
54 import com.liferay.portal.kernel.concurrent.ThreadPoolExecutor;
\r
55 import com.liferay.portal.kernel.dao.shard.ShardUtil;
\r
56 import com.liferay.portal.kernel.exception.SystemException;
\r
57 import com.liferay.portal.kernel.executor.PortalExecutorManagerUtil;
\r
58 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
\r
59 import com.liferay.portal.kernel.io.unsync.UnsyncPrintWriter;
\r
60 import com.liferay.portal.kernel.json.JSONFactoryUtil;
\r
61 import com.liferay.portal.kernel.json.JSONObject;
\r
62 import com.liferay.portal.kernel.log.Log;
\r
63 import com.liferay.portal.kernel.log.LogFactoryUtil;
\r
64 import com.liferay.portal.kernel.mail.Account;
\r
65 import com.liferay.portal.kernel.messaging.BaseAsyncDestination;
\r
66 import com.liferay.portal.kernel.messaging.Destination;
\r
67 import com.liferay.portal.kernel.messaging.DestinationNames;
\r
68 import com.liferay.portal.kernel.messaging.MessageBus;
\r
69 import com.liferay.portal.kernel.messaging.MessageBusUtil;
\r
70 import com.liferay.portal.kernel.messaging.proxy.MessageValuesThreadLocal;
\r
71 import com.liferay.portal.kernel.scripting.ScriptingException;
\r
72 import com.liferay.portal.kernel.scripting.ScriptingUtil;
\r
73 import com.liferay.portal.kernel.search.Indexer;
\r
74 import com.liferay.portal.kernel.search.SearchEngineUtil;
\r
75 import com.liferay.portal.kernel.servlet.SessionErrors;
\r
76 import com.liferay.portal.kernel.servlet.SessionMessages;
\r
77 import com.liferay.portal.kernel.util.CharPool;
\r
78 import com.liferay.portal.kernel.util.Constants;
\r
79 import com.liferay.portal.kernel.util.InstancePool;
\r
80 import com.liferay.portal.kernel.util.MethodHandler;
\r
81 import com.liferay.portal.kernel.util.MethodKey;
\r
82 import com.liferay.portal.kernel.util.ParamUtil;
\r
83 import com.liferay.portal.kernel.util.PropsKeys;
\r
84 import com.liferay.portal.kernel.util.StringBundler;
\r
85 import com.liferay.portal.kernel.util.StringPool;
\r
86 import com.liferay.portal.kernel.util.StringUtil;
\r
87 import com.liferay.portal.kernel.util.ThreadUtil;
\r
88 import com.liferay.portal.kernel.util.Time;
\r
89 import com.liferay.portal.kernel.util.UnsyncPrintWriterPool;
\r
90 import com.liferay.portal.kernel.util.Validator;
\r
91 import com.liferay.portal.kernel.webcache.WebCachePoolUtil;
\r
92 import com.liferay.portal.kernel.xuggler.XugglerInstallStatus;
\r
93 import com.liferay.portal.kernel.xuggler.XugglerUtil;
\r
94 import com.liferay.portal.model.Portlet;
\r
95 import com.liferay.portal.search.lucene.LuceneHelperUtil;
\r
96 import com.liferay.portal.search.lucene.cluster.LuceneClusterUtil;
\r
97 import com.liferay.portal.security.auth.PrincipalException;
\r
98 import com.liferay.portal.security.permission.PermissionChecker;
\r
99 import com.liferay.portal.service.PortletLocalServiceUtil;
\r
100 import com.liferay.portal.service.ServiceComponentLocalServiceUtil;
\r
101 import com.liferay.portal.struts.ActionConstants;
\r
102 import com.liferay.portal.struts.PortletAction;
\r
103 import com.liferay.portal.theme.ThemeDisplay;
\r
104 import com.liferay.portal.upload.UploadServletRequestImpl;
\r
105 import com.liferay.portal.util.MaintenanceUtil;
\r
106 import com.liferay.portal.util.PortalInstances;
\r
107 import com.liferay.portal.util.PortalUtil;
\r
108 import com.liferay.portal.util.PrefsPropsUtil;
\r
109 import com.liferay.portal.util.PropsValues;
\r
110 import com.liferay.portal.util.ShutdownUtil;
\r
111 import com.liferay.portal.util.WebKeys;
\r
112 import com.liferay.portlet.ActionResponseImpl;
\r
113 import com.liferay.portlet.admin.util.CleanUpPermissionsUtil;
\r
114 import com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor;
\r
115 import com.liferay.portlet.documentlibrary.util.PDFProcessorUtil;
\r
116 import com.liferay.util.log4j.Log4JUtil;
\r
119 * @author Brian Wing Shun Chan
\r
120 * @author Shuyang Zhou
\r
122 public class EditServerAction extends PortletAction {
\r
125 public void processAction(
\r
126 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
\r
127 ActionRequest actionRequest, ActionResponse actionResponse)
\r
130 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
\r
131 WebKeys.THEME_DISPLAY);
\r
133 PermissionChecker permissionChecker =
\r
134 themeDisplay.getPermissionChecker();
\r
136 if (!permissionChecker.isOmniadmin()) {
\r
138 actionRequest, PrincipalException.class.getName());
\r
140 setForward(actionRequest, "portlet.admin.error");
\r
145 PortletPreferences preferences = PrefsPropsUtil.getPreferences();
\r
147 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
\r
149 String redirect = null;
\r
151 if (cmd.equals("addLogLevel")) {
\r
152 addLogLevel(actionRequest);
\r
154 else if (cmd.equals("cacheDb")) {
\r
157 else if (cmd.equals("cacheMulti")) {
\r
160 else if (cmd.equals("cacheSingle")) {
\r
163 else if (cmd.equals("cleanUpPermissions")) {
\r
164 CleanUpPermissionsUtil.cleanUpAddToPagePermissions(actionRequest);
\r
166 else if (cmd.startsWith("convertProcess.")) {
\r
167 redirect = convertProcess(actionRequest, actionResponse, cmd);
\r
169 else if (cmd.equals("dlPreviews")) {
\r
170 DLPreviewableProcessor.deleteFiles();
\r
172 else if (cmd.equals("gc")) {
\r
175 else if (cmd.equals("installXuggler")) {
\r
176 installXuggler(actionRequest, actionResponse);
\r
178 setForward(actionRequest, ActionConstants.COMMON_NULL);
\r
182 else if (cmd.equals("reindex")) {
\r
183 reindex(actionRequest);
\r
185 else if (cmd.equals("runScript")) {
\r
186 runScript(portletConfig, actionRequest, actionResponse);
\r
188 else if (cmd.equals("shutdown")) {
\r
189 shutdown(actionRequest);
\r
191 else if (cmd.equals("threadDump")) {
\r
194 else if (cmd.equals("updateCaptcha")) {
\r
195 updateCaptcha(actionRequest, preferences);
\r
197 else if (cmd.equals("updateExternalServices")) {
\r
198 updateExternalServices(actionRequest, preferences);
\r
200 else if (cmd.equals("updateFileUploads")) {
\r
201 updateFileUploads(actionRequest, preferences);
\r
203 else if (cmd.equals("updateLogLevels")) {
\r
204 updateLogLevels(actionRequest);
\r
206 else if (cmd.equals("updateMail")) {
\r
207 updateMail(actionRequest, preferences);
\r
209 else if (cmd.equals("verifyPluginTables")) {
\r
210 verifyPluginTables();
\r
213 sendRedirect(actionRequest, actionResponse, redirect);
\r
216 protected void addLogLevel(ActionRequest actionRequest) throws Exception {
\r
217 String loggerName = ParamUtil.getString(actionRequest, "loggerName");
\r
218 String priority = ParamUtil.getString(actionRequest, "priority");
\r
220 Log4JUtil.setLevel(loggerName, priority, true);
\r
223 protected void cacheDb() throws Exception {
\r
224 CacheRegistryUtil.clear();
\r
227 protected void cacheMulti() throws Exception {
\r
228 MultiVMPoolUtil.clear();
\r
231 protected void cacheSingle() throws Exception {
\r
232 WebCachePoolUtil.clear();
\r
235 protected String convertProcess(
\r
236 ActionRequest actionRequest, ActionResponse actionResponse,
\r
240 ActionResponseImpl actionResponseImpl =
\r
241 (ActionResponseImpl)actionResponse;
\r
243 PortletSession portletSession = actionRequest.getPortletSession();
\r
245 String className = StringUtil.replaceFirst(
\r
246 cmd, "convertProcess.", StringPool.BLANK);
\r
248 ConvertProcess convertProcess = (ConvertProcess)InstancePool.get(
\r
251 String[] parameters = convertProcess.getParameterNames();
\r
253 if (parameters != null) {
\r
254 String[] values = new String[parameters.length];
\r
256 for (int i = 0; i < parameters.length; i++) {
\r
258 className + StringPool.PERIOD + parameters[i];
\r
260 if (parameters[i].contains(StringPool.EQUAL)) {
\r
261 String[] parameterPair = StringUtil.split(
\r
262 parameters[i], CharPool.EQUAL);
\r
265 className + StringPool.PERIOD + parameterPair[0];
\r
268 values[i] = ParamUtil.getString(actionRequest, parameter);
\r
271 convertProcess.setParameterValues(values);
\r
274 String path = convertProcess.getPath();
\r
276 if (path != null) {
\r
277 PortletURL portletURL = actionResponseImpl.createRenderURL();
\r
279 portletURL.setWindowState(WindowState.MAXIMIZED);
\r
281 portletURL.setParameter("struts_action", path);
\r
283 return portletURL.toString();
\r
286 MaintenanceUtil.maintain(portletSession.getId(), className);
\r
288 MessageBusUtil.sendMessage(
\r
289 DestinationNames.CONVERT_PROCESS, className);
\r
295 protected void gc() throws Exception {
\r
296 Runtime.getRuntime().gc();
\r
299 protected String getFileExtensions(
\r
300 ActionRequest actionRequest, String name) {
\r
302 String value = ParamUtil.getString(actionRequest, name);
\r
304 return value.replace(", .", ",.");
\r
307 protected void installXuggler(
\r
308 ActionRequest actionRequest, ActionResponse actionResponse)
\r
311 HttpServletRequest request = PortalUtil.getHttpServletRequest(
\r
314 HttpSession session = request.getSession();
\r
316 XugglerInstallStatus xugglerInstallStatus = new XugglerInstallStatus();
\r
318 session.setAttribute(
\r
319 WebKeys.XUGGLER_INSTALL_STATUS, xugglerInstallStatus);
\r
321 String jarName = ParamUtil.getString(actionRequest, "jarName");
\r
324 XugglerUtil.installNativeLibraries(jarName, xugglerInstallStatus);
\r
326 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
\r
328 jsonObject.put("success", Boolean.TRUE);
\r
330 writeJSON(actionRequest, actionResponse, jsonObject);
\r
332 catch (Exception e) {
\r
333 JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
\r
335 jsonObject.put("exception", e.getMessage());
\r
336 jsonObject.put("success", Boolean.FALSE);
\r
338 writeJSON(actionRequest, actionResponse, jsonObject);
\r
341 session.removeAttribute(WebKeys.XUGGLER_INSTALL_STATUS);
\r
345 protected void reindex(ActionRequest actionRequest) throws Exception {
\r
346 String portletId = ParamUtil.getString(actionRequest, "portletId");
\r
348 long[] companyIds = PortalInstances.getCompanyIds();
\r
350 if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
\r
351 MessageValuesThreadLocal.setValue(
\r
352 ClusterLinkUtil.CLUSTER_FORWARD_MESSAGE, true);
\r
355 Set<String> usedSearchEngineIds = new HashSet<String>();
\r
357 if (Validator.isNull(portletId)) {
\r
358 List<Portlet> portlets = PortletLocalServiceUtil.getPortlets(companyIds[0], false, false);
\r
360 String[] companyId = {String.valueOf(companyIds[0])};
\r
362 for (Portlet portlet : portlets) {
\r
366 if (!portlet.isActive()) {
\r
370 List<Indexer> indexers = portlet.getIndexerInstances();
\r
372 if (indexers == null || indexers.isEmpty()) {
\r
376 for(Indexer indexer: indexers){
\r
377 indexer.reindex(companyId);
\r
380 } catch (Exception e){
\r
384 // for (long companyId : companyIds) {
\r
386 // LuceneIndexer luceneIndexer = new LuceneIndexer(companyId);
\r
388 // luceneIndexer.reindex();
\r
390 // usedSearchEngineIds.addAll(
\r
391 // luceneIndexer.getUsedSearchEngineIds());
\r
393 // catch (Exception e) {
\r
394 // _log.error(e, e);
\r
399 Portlet portlet = PortletLocalServiceUtil.getPortletById(
\r
400 companyIds[0], portletId);
\r
402 if (portlet == null) {
\r
406 List<Indexer> indexers = portlet.getIndexerInstances();
\r
408 if (indexers == null) {
\r
412 for (Indexer indexer : indexers) {
\r
413 for (long companyId : companyIds) {
\r
414 ShardUtil.pushCompanyService(companyId);
\r
417 SearchEngineUtil.deletePortletDocuments(
\r
418 indexer.getSearchEngineId(), companyId, portletId);
\r
421 new String[] {String.valueOf(companyId)});
\r
423 usedSearchEngineIds.add(indexer.getSearchEngineId());
\r
425 catch (Exception e) {
\r
429 ShardUtil.popCompanyService();
\r
434 if (LuceneHelperUtil.isLoadIndexFromClusterEnabled()) {
\r
435 Set<BaseAsyncDestination> searchWriterDestinations =
\r
436 new HashSet<BaseAsyncDestination>();
\r
438 MessageBus messageBus = MessageBusUtil.getMessageBus();
\r
440 for (String usedSearchEngineId : usedSearchEngineIds) {
\r
441 String searchWriterDestinationName =
\r
442 SearchEngineUtil.getSearchWriterDestinationName(
\r
443 usedSearchEngineId);
\r
445 Destination destination = messageBus.getDestination(
\r
446 searchWriterDestinationName);
\r
448 if (destination instanceof BaseAsyncDestination) {
\r
449 BaseAsyncDestination baseAsyncDestination =
\r
450 (BaseAsyncDestination)destination;
\r
452 searchWriterDestinations.add(baseAsyncDestination);
\r
456 submitClusterIndexLoadingSyncJob(
\r
457 searchWriterDestinations, companyIds);
\r
461 protected void runScript(
\r
462 PortletConfig portletConfig, ActionRequest actionRequest,
\r
463 ActionResponse actionResponse)
\r
466 String language = ParamUtil.getString(actionRequest, "language");
\r
467 String script = ParamUtil.getString(actionRequest, "script");
\r
469 PortletContext portletContext = portletConfig.getPortletContext();
\r
471 Map<String, Object> portletObjects = ScriptingUtil.getPortletObjects(
\r
472 portletConfig, portletContext, actionRequest, actionResponse);
\r
474 UnsyncByteArrayOutputStream unsyncByteArrayOutputStream =
\r
475 new UnsyncByteArrayOutputStream();
\r
477 UnsyncPrintWriter unsyncPrintWriter = UnsyncPrintWriterPool.borrow(
\r
478 unsyncByteArrayOutputStream);
\r
480 portletObjects.put("out", unsyncPrintWriter);
\r
483 SessionMessages.add(actionRequest, "language", language);
\r
484 SessionMessages.add(actionRequest, "script", script);
\r
486 ScriptingUtil.exec(null, portletObjects, language, script);
\r
488 unsyncPrintWriter.flush();
\r
490 SessionMessages.add(
\r
491 actionRequest, "script_output",
\r
492 unsyncByteArrayOutputStream.toString());
\r
494 catch (ScriptingException se) {
\r
496 actionRequest, ScriptingException.class.getName(), se);
\r
498 _log.error(se.getMessage());
\r
502 protected void shutdown(ActionRequest actionRequest) throws Exception {
\r
504 ParamUtil.getInteger(actionRequest, "minutes") * Time.MINUTE;
\r
505 String message = ParamUtil.getString(actionRequest, "message");
\r
507 if (minutes <= 0) {
\r
508 ShutdownUtil.cancel();
\r
511 ShutdownUtil.shutdown(minutes, message);
\r
515 protected void submitClusterIndexLoadingSyncJob(
\r
516 Set<BaseAsyncDestination> baseAsyncDestinations, long[] companyIds)
\r
519 if (_log.isInfoEnabled()) {
\r
520 StringBundler sb = new StringBundler(
\r
521 baseAsyncDestinations.size() + 1);
\r
525 for (BaseAsyncDestination baseAsyncDestination :
\r
526 baseAsyncDestinations) {
\r
528 sb.append(baseAsyncDestination.getName());
\r
532 sb.setStringAt("]", sb.index() - 1);
\r
535 "Synchronizecluster index loading for destinations " +
\r
539 int totalWorkersMaxSize = 0;
\r
541 for (BaseAsyncDestination baseAsyncDestination :
\r
542 baseAsyncDestinations) {
\r
544 totalWorkersMaxSize += baseAsyncDestination.getWorkersMaxSize();
\r
547 if (_log.isInfoEnabled()) {
\r
549 "There are " + totalWorkersMaxSize +
\r
550 " synchronization threads");
\r
553 CountDownLatch countDownLatch = new CountDownLatch(
\r
554 totalWorkersMaxSize + 1);
\r
556 ClusterLoadingSyncJob slaveClusterLoadingSyncJob =
\r
557 new ClusterLoadingSyncJob(companyIds, countDownLatch, false);
\r
559 for (BaseAsyncDestination baseAsyncDestination :
\r
560 baseAsyncDestinations) {
\r
562 ThreadPoolExecutor threadPoolExecutor =
\r
563 PortalExecutorManagerUtil.getPortalExecutor(
\r
564 baseAsyncDestination.getName());
\r
566 for (int i = 0; i < baseAsyncDestination.getWorkersMaxSize(); i++) {
\r
567 threadPoolExecutor.execute(slaveClusterLoadingSyncJob);
\r
571 ClusterLoadingSyncJob masterClusterLoadingSyncJob =
\r
572 new ClusterLoadingSyncJob(companyIds, countDownLatch, true);
\r
574 ThreadPoolExecutor threadPoolExecutor =
\r
575 PortalExecutorManagerUtil.getPortalExecutor(
\r
576 EditServerAction.class.getName());
\r
578 threadPoolExecutor.execute(masterClusterLoadingSyncJob);
\r
581 protected void threadDump() throws Exception {
\r
582 if (_log.isInfoEnabled()) {
\r
583 _log.info(ThreadUtil.threadDump());
\r
587 "Thread dumps require the log level to be at least INFO for " +
\r
588 getClass().getName());
\r
592 protected void updateCaptcha(
\r
593 ActionRequest actionRequest, PortletPreferences preferences)
\r
596 boolean reCaptchaEnabled = ParamUtil.getBoolean(
\r
597 actionRequest, "reCaptchaEnabled");
\r
598 String reCaptchaPrivateKey = ParamUtil.getString(
\r
599 actionRequest, "reCaptchaPrivateKey");
\r
600 String reCaptchaPublicKey = ParamUtil.getString(
\r
601 actionRequest, "reCaptchaPublicKey");
\r
603 Captcha captcha = null;
\r
605 if (reCaptchaEnabled) {
\r
606 captcha = new ReCaptchaImpl();
\r
609 captcha = new SimpleCaptchaImpl();
\r
612 validateCaptcha(actionRequest);
\r
614 if (SessionErrors.isEmpty(actionRequest)) {
\r
615 preferences.setValue(
\r
616 PropsKeys.CAPTCHA_ENGINE_IMPL, captcha.getClass().getName());
\r
617 preferences.setValue(
\r
618 PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE,
\r
619 reCaptchaPrivateKey);
\r
620 preferences.setValue(
\r
621 PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PUBLIC,
\r
622 reCaptchaPublicKey);
\r
624 preferences.store();
\r
626 CaptchaImpl captchaImpl = (CaptchaImpl)CaptchaUtil.getCaptcha();
\r
628 captchaImpl.setCaptcha(captcha);
\r
632 protected void updateExternalServices(
\r
633 ActionRequest actionRequest, PortletPreferences preferences)
\r
636 boolean imageMagickEnabled = ParamUtil.getBoolean(
\r
637 actionRequest, "imageMagickEnabled");
\r
638 String imageMagickPath = ParamUtil.getString(
\r
639 actionRequest, "imageMagickPath");
\r
640 boolean openOfficeEnabled = ParamUtil.getBoolean(
\r
641 actionRequest, "openOfficeEnabled");
\r
642 int openOfficePort = ParamUtil.getInteger(
\r
643 actionRequest, "openOfficePort");
\r
644 boolean xugglerEnabled = ParamUtil.getBoolean(
\r
645 actionRequest, "xugglerEnabled");
\r
647 preferences.setValue(
\r
648 PropsKeys.IMAGEMAGICK_ENABLED, String.valueOf(imageMagickEnabled));
\r
649 preferences.setValue(
\r
650 PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, imageMagickPath);
\r
651 preferences.setValue(
\r
652 PropsKeys.OPENOFFICE_SERVER_ENABLED,
\r
653 String.valueOf(openOfficeEnabled));
\r
654 preferences.setValue(
\r
655 PropsKeys.OPENOFFICE_SERVER_PORT, String.valueOf(openOfficePort));
\r
656 preferences.setValue(
\r
657 PropsKeys.XUGGLER_ENABLED, String.valueOf(xugglerEnabled));
\r
659 Enumeration<String> enu = actionRequest.getParameterNames();
\r
661 while (enu.hasMoreElements()) {
\r
662 String name = enu.nextElement();
\r
664 if (name.startsWith("imageMagickLimit")) {
\r
665 String key = name.substring(16, name.length()).toLowerCase();
\r
666 String value = ParamUtil.getString(actionRequest, name);
\r
668 preferences.setValue(
\r
669 PropsKeys.IMAGEMAGICK_RESOURCE_LIMIT + key, value);
\r
673 preferences.store();
\r
675 PDFProcessorUtil.reset();
\r
678 protected void updateFileUploads(
\r
679 ActionRequest actionRequest, PortletPreferences preferences)
\r
682 long dlFileEntryThumbnailMaxHeight = ParamUtil.getLong(
\r
683 actionRequest, "dlFileEntryThumbnailMaxHeight");
\r
684 long dlFileEntryThumbnailMaxWidth = ParamUtil.getLong(
\r
685 actionRequest, "dlFileEntryThumbnailMaxWidth");
\r
686 String dlFileExtensions = getFileExtensions(
\r
687 actionRequest, "dlFileExtensions");
\r
688 long dlFileMaxSize = ParamUtil.getLong(actionRequest, "dlFileMaxSize");
\r
689 String journalImageExtensions = getFileExtensions(
\r
690 actionRequest, "journalImageExtensions");
\r
691 long journalImageSmallMaxSize = ParamUtil.getLong(
\r
692 actionRequest, "journalImageSmallMaxSize");
\r
693 String shoppingImageExtensions = getFileExtensions(
\r
694 actionRequest, "shoppingImageExtensions");
\r
695 long scImageMaxSize = ParamUtil.getLong(
\r
696 actionRequest, "scImageMaxSize");
\r
697 long scImageThumbnailMaxHeight = ParamUtil.getLong(
\r
698 actionRequest, "scImageThumbnailMaxHeight");
\r
699 long scImageThumbnailMaxWidth = ParamUtil.getLong(
\r
700 actionRequest, "scImageThumbnailMaxWidth");
\r
701 long shoppingImageLargeMaxSize = ParamUtil.getLong(
\r
702 actionRequest, "shoppingImageLargeMaxSize");
\r
703 long shoppingImageMediumMaxSize = ParamUtil.getLong(
\r
704 actionRequest, "shoppingImageMediumMaxSize");
\r
705 long shoppingImageSmallMaxSize = ParamUtil.getLong(
\r
706 actionRequest, "shoppingImageSmallMaxSize");
\r
707 long uploadServletRequestImplMaxSize = ParamUtil.getLong(
\r
708 actionRequest, "uploadServletRequestImplMaxSize");
\r
709 String uploadServletRequestImplTempDir = ParamUtil.getString(
\r
710 actionRequest, "uploadServletRequestImplTempDir");
\r
711 long usersImageMaxSize = ParamUtil.getLong(
\r
712 actionRequest, "usersImageMaxSize");
\r
714 preferences.setValue(
\r
715 PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_HEIGHT,
\r
716 String.valueOf(dlFileEntryThumbnailMaxHeight));
\r
717 preferences.setValue(
\r
718 PropsKeys.DL_FILE_ENTRY_THUMBNAIL_MAX_WIDTH,
\r
719 String.valueOf(dlFileEntryThumbnailMaxWidth));
\r
720 preferences.setValue(PropsKeys.DL_FILE_EXTENSIONS, dlFileExtensions);
\r
721 preferences.setValue(
\r
722 PropsKeys.DL_FILE_MAX_SIZE, String.valueOf(dlFileMaxSize));
\r
723 preferences.setValue(
\r
724 PropsKeys.JOURNAL_IMAGE_EXTENSIONS, journalImageExtensions);
\r
725 preferences.setValue(
\r
726 PropsKeys.JOURNAL_IMAGE_SMALL_MAX_SIZE,
\r
727 String.valueOf(journalImageSmallMaxSize));
\r
728 preferences.setValue(
\r
729 PropsKeys.SHOPPING_IMAGE_EXTENSIONS, shoppingImageExtensions);
\r
730 preferences.setValue(
\r
731 PropsKeys.SHOPPING_IMAGE_LARGE_MAX_SIZE,
\r
732 String.valueOf(shoppingImageLargeMaxSize));
\r
733 preferences.setValue(
\r
734 PropsKeys.SHOPPING_IMAGE_MEDIUM_MAX_SIZE,
\r
735 String.valueOf(shoppingImageMediumMaxSize));
\r
736 preferences.setValue(
\r
737 PropsKeys.SHOPPING_IMAGE_SMALL_MAX_SIZE,
\r
738 String.valueOf(shoppingImageSmallMaxSize));
\r
739 preferences.setValue(
\r
740 PropsKeys.SC_IMAGE_MAX_SIZE, String.valueOf(scImageMaxSize));
\r
741 preferences.setValue(
\r
742 PropsKeys.SC_IMAGE_THUMBNAIL_MAX_HEIGHT,
\r
743 String.valueOf(scImageThumbnailMaxHeight));
\r
744 preferences.setValue(
\r
745 PropsKeys.SC_IMAGE_THUMBNAIL_MAX_WIDTH,
\r
746 String.valueOf(scImageThumbnailMaxWidth));
\r
747 preferences.setValue(
\r
748 PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE,
\r
749 String.valueOf(uploadServletRequestImplMaxSize));
\r
751 if (Validator.isNotNull(uploadServletRequestImplTempDir)) {
\r
752 preferences.setValue(
\r
753 PropsKeys.UPLOAD_SERVLET_REQUEST_IMPL_TEMP_DIR,
\r
754 uploadServletRequestImplTempDir);
\r
756 UploadServletRequestImpl.setTempDir(
\r
757 new File(uploadServletRequestImplTempDir));
\r
760 preferences.setValue(
\r
761 PropsKeys.USERS_IMAGE_MAX_SIZE, String.valueOf(usersImageMaxSize));
\r
763 preferences.store();
\r
766 protected void updateLogLevels(ActionRequest actionRequest)
\r
769 Enumeration<String> enu = actionRequest.getParameterNames();
\r
771 while (enu.hasMoreElements()) {
\r
772 String name = enu.nextElement();
\r
774 if (name.startsWith("logLevel")) {
\r
775 String loggerName = name.substring(8);
\r
777 String priority = ParamUtil.getString(
\r
778 actionRequest, name, Level.INFO.toString());
\r
780 Log4JUtil.setLevel(loggerName, priority, true);
\r
785 protected void updateMail(
\r
786 ActionRequest actionRequest, PortletPreferences preferences)
\r
789 String advancedProperties = ParamUtil.getString(
\r
790 actionRequest, "advancedProperties");
\r
791 String pop3Host = ParamUtil.getString(actionRequest, "pop3Host");
\r
792 String pop3Password = ParamUtil.getString(
\r
793 actionRequest, "pop3Password");
\r
794 int pop3Port = ParamUtil.getInteger(actionRequest, "pop3Port");
\r
795 boolean pop3Secure = ParamUtil.getBoolean(actionRequest, "pop3Secure");
\r
796 String pop3User = ParamUtil.getString(actionRequest, "pop3User");
\r
797 String smtpHost = ParamUtil.getString(actionRequest, "smtpHost");
\r
798 String smtpPassword = ParamUtil.getString(
\r
799 actionRequest, "smtpPassword");
\r
800 int smtpPort = ParamUtil.getInteger(actionRequest, "smtpPort");
\r
801 boolean smtpSecure = ParamUtil.getBoolean(actionRequest, "smtpSecure");
\r
802 String smtpUser = ParamUtil.getString(actionRequest, "smtpUser");
\r
804 String storeProtocol = Account.PROTOCOL_POP;
\r
807 storeProtocol = Account.PROTOCOL_POPS;
\r
810 String transportProtocol = Account.PROTOCOL_SMTP;
\r
813 transportProtocol = Account.PROTOCOL_SMTPS;
\r
816 preferences.setValue(PropsKeys.MAIL_SESSION_MAIL, "true");
\r
817 preferences.setValue(
\r
818 PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES,
\r
819 advancedProperties);
\r
820 preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, pop3Host);
\r
821 preferences.setValue(
\r
822 PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, pop3Password);
\r
823 preferences.setValue(
\r
824 PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, String.valueOf(pop3Port));
\r
825 preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_USER, pop3User);
\r
826 preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, smtpHost);
\r
827 preferences.setValue(
\r
828 PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, smtpPassword);
\r
829 preferences.setValue(
\r
830 PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, String.valueOf(smtpPort));
\r
831 preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, smtpUser);
\r
832 preferences.setValue(
\r
833 PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, storeProtocol);
\r
834 preferences.setValue(
\r
835 PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, transportProtocol);
\r
837 preferences.store();
\r
839 MailServiceUtil.clearSession();
\r
842 protected void validateCaptcha(ActionRequest actionRequest)
\r
845 boolean reCaptchaEnabled = ParamUtil.getBoolean(
\r
846 actionRequest, "reCaptchaEnabled");
\r
848 if (!reCaptchaEnabled) {
\r
852 String reCaptchaPrivateKey = ParamUtil.getString(
\r
853 actionRequest, "reCaptchaPrivateKey");
\r
854 String reCaptchaPublicKey = ParamUtil.getString(
\r
855 actionRequest, "reCaptchaPublicKey");
\r
857 if (Validator.isNull(reCaptchaPublicKey)) {
\r
858 SessionErrors.add(actionRequest, "reCaptchaPublicKey");
\r
860 else if (Validator.isNull(reCaptchaPrivateKey)) {
\r
861 SessionErrors.add(actionRequest, "reCaptchaPrivateKey");
\r
865 protected void verifyPluginTables() throws Exception {
\r
866 ServiceComponentLocalServiceUtil.verifyDB();
\r
869 private static Log _log = LogFactoryUtil.getLog(EditServerAction.class);
\r
871 private static MethodKey _loadIndexesFromClusterMethodKey = new MethodKey(
\r
872 LuceneClusterUtil.class.getName(), "loadIndexesFromCluster",
\r
873 long[].class, Address.class);
\r
875 private static class ClusterLoadingSyncJob implements Runnable {
\r
877 public ClusterLoadingSyncJob(
\r
878 long[] companyIds, CountDownLatch countDownLatch, boolean master) {
\r
880 _companyIds = companyIds;
\r
881 _countDownLatch = countDownLatch;
\r
885 public void run() {
\r
886 _countDownLatch.countDown();
\r
888 String logPrefix = StringPool.BLANK;
\r
890 if (_log.isInfoEnabled()) {
\r
891 Thread currentThread = Thread.currentThread();
\r
895 "Monitor thread name " + currentThread.getName() +
\r
896 " with thread ID " + currentThread.getId();
\r
900 "Thread name " + currentThread.getName() +
\r
901 " with thread ID " + currentThread.getId();
\r
905 if (!_master && _log.isInfoEnabled()) {
\r
907 logPrefix + " synchronized on latch. Waiting for others.");
\r
912 _countDownLatch.await();
\r
915 boolean result = _countDownLatch.await(
\r
916 PropsValues.LUCENE_CLUSTER_INDEX_LOADING_SYNC_TIMEOUT,
\r
917 TimeUnit.MILLISECONDS);
\r
921 logPrefix + " timed out. You may need to " +
\r
922 "re-trigger a reindex process.");
\r
926 catch (InterruptedException ie) {
\r
929 logPrefix + " was interrupted. Skip cluster index " +
\r
930 "loading notification.",
\r
937 logPrefix + " was interrupted. You may need to " +
\r
938 "re-trigger a reindex process.",
\r
944 Address localClusterNodeAddress =
\r
945 ClusterExecutorUtil.getLocalClusterNodeAddress();
\r
947 ClusterRequest clusterRequest =
\r
948 ClusterRequest.createMulticastRequest(
\r
950 _loadIndexesFromClusterMethodKey, _companyIds,
\r
951 localClusterNodeAddress),
\r
955 ClusterExecutorUtil.execute(clusterRequest);
\r
957 catch (SystemException se) {
\r
959 "Unable to notify peers to start index loading", se);
\r
962 if (_log.isInfoEnabled()) {
\r
964 logPrefix + " unlocked latch. Notified peers to " +
\r
965 "start index loading.");
\r
970 private long[] _companyIds;
\r
971 private CountDownLatch _countDownLatch;
\r
972 private boolean _master;
\r