List of usage examples for com.liferay.portal.kernel.util ServerDetector getServerId
public static String getServerId()
From source file:com.liferay.petra.log4j.Log4JUtil.java
License:Open Source License
private static String _getURLContent(URL url) { Map<String, String> variables = new HashMap<>(); variables.put("@liferay.home@", _getLiferayHome()); String spiId = System.getProperty("spi.id"); if (spiId == null) { spiId = StringPool.BLANK;/*from www . j av a2 s .c o m*/ } variables.put("@spi.id@", spiId); String urlContent = null; try (InputStream inputStream = url.openStream()) { byte[] bytes = _getBytes(inputStream); urlContent = new String(bytes, StringPool.UTF8); } catch (Exception e) { _logger.error(e, e); return null; } for (Map.Entry<String, String> variable : variables.entrySet()) { urlContent = StringUtil.replace(urlContent, variable.getKey(), variable.getValue()); } if (ServerDetector.getServerId() != null) { return urlContent; } urlContent = _removeAppender(urlContent, "TEXT_FILE"); return _removeAppender(urlContent, "XML_FILE"); }
From source file:com.liferay.portlet.documentlibrary.util.AudioProcessorImpl.java
License:Open Source License
private void _generateAudioXuggler(FileVersion fileVersion, File srcFile, File destFile) throws Exception { StopWatch stopWatch = null;//from w w w.ja v a 2 s.c o m if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } try { if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) { ProcessCallable<String> processCallable = new LiferayAudioProcessCallable( ServerDetector.getServerId(), PropsUtil.get(PropsKeys.LIFERAY_HOME), Log4JUtil.getCustomLogSettings(), srcFile.getCanonicalPath(), destFile.getCanonicalPath()); ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath()); } else { LiferayConverter liferayConverter = new LiferayAudioConverter(srcFile.getCanonicalPath(), destFile.getCanonicalPath()); liferayConverter.convert(); } } catch (Exception e) { _log.error(e, e); } addFileToStore(fileVersion.getCompanyId(), PREVIEW_PATH, getPreviewFilePath(fileVersion), destFile); if (_log.isInfoEnabled()) { _log.info("Xuggler generated a preview audio for " + fileVersion.getTitle() + " in " + stopWatch); } }
From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java
License:Open Source License
private void _generateThumbnailXuggler(FileVersion fileVersion, File file, int height, int width) throws Exception { StopWatch stopWatch = null;//from w w w. ja va2 s. c om if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } String tempFileId = DLUtil.getTempFileId(fileVersion.getFileEntryId(), fileVersion.getVersion()); File thumbnailTempFile = getThumbnailTempFile(tempFileId); try { try { if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) { ProcessCallable<String> processCallable = new LiferayVideoThumbnailProcessCallable( ServerDetector.getServerId(), PropsUtil.get(PropsKeys.LIFERAY_HOME), Log4JUtil.getCustomLogSettings(), file.getCanonicalPath(), thumbnailTempFile, THUMBNAIL_TYPE, height, width, PropsValues.DL_FILE_ENTRY_THUMBNAIL_VIDEO_FRAME_PERCENTAGE); ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath()); } else { LiferayConverter liferayConverter = new LiferayVideoThumbnailConverter(file.getCanonicalPath(), thumbnailTempFile, THUMBNAIL_TYPE, height, width, PropsValues.DL_FILE_ENTRY_THUMBNAIL_VIDEO_FRAME_PERCENTAGE); liferayConverter.convert(); } } catch (Exception e) { _log.error(e, e); } storeThumbnailImages(fileVersion, thumbnailTempFile); if (_log.isInfoEnabled()) { _log.info("Xuggler generated a thumbnail for " + fileVersion.getTitle() + " in " + stopWatch); } } catch (Exception e) { throw new SystemException(e); } finally { FileUtil.delete(thumbnailTempFile); } }
From source file:com.liferay.portlet.documentlibrary.util.VideoProcessorImpl.java
License:Open Source License
private void _generateVideoXuggler(FileVersion fileVersion, File srcFile, File destFile, String containerType) throws Exception { if (!_isGeneratePreview(fileVersion, containerType)) { return;/* w w w . j av a 2 s. c o m*/ } StopWatch stopWatch = null; if (_log.isInfoEnabled()) { stopWatch = new StopWatch(); stopWatch.start(); } if (PropsValues.DL_FILE_ENTRY_PREVIEW_FORK_PROCESS_ENABLED) { ProcessCallable<String> processCallable = new LiferayVideoProcessCallable(ServerDetector.getServerId(), PropsUtil.get(PropsKeys.LIFERAY_HOME), Log4JUtil.getCustomLogSettings(), srcFile.getCanonicalPath(), destFile.getCanonicalPath(), FileUtil.createTempFileName(), PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false), PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true)); ProcessExecutor.execute(processCallable, ClassPathUtil.getPortalClassPath()); } else { LiferayConverter liferayConverter = new LiferayVideoConverter(srcFile.getCanonicalPath(), destFile.getCanonicalPath(), FileUtil.createTempFileName(), PropsUtil.getProperties(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO, false), PropsUtil.getProperties(PropsKeys.XUGGLER_FFPRESET, true)); liferayConverter.convert(); } addFileToStore(fileVersion.getCompanyId(), PREVIEW_PATH, getPreviewFilePath(fileVersion, containerType), destFile); if (_log.isInfoEnabled()) { _log.info("Xuggler generated a " + containerType + " preview video for " + fileVersion.getTitle() + " in " + stopWatch); } }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected void uninstall(ActionRequest actionRequest) throws Exception { String appServerType = ServerDetector.getServerId(); String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); if (appServerType.startsWith(ServerDetector.JBOSS_ID)) { deploymentContext += ".war"; }//from www .j av a 2s . c om File deployDir = new File(DeployUtil.getAutoDeployDestDir() + "/" + deploymentContext); DeployUtil.undeploy(appServerType, deployDir); SessionMessages.add(actionRequest, "triggeredPortletUndeploy"); }
From source file:com.liferay.util.log4j.Log4JUtil.java
License:Open Source License
private static String _getURLContent(URL url) { Map<String, String> variables = new HashMap<String, String>(); variables.put("liferay.home", _getLiferayHome()); String urlContent = null;// www .j a v a 2 s .c o m InputStream inputStream = null; try { inputStream = url.openStream(); byte[] bytes = _getBytes(inputStream); urlContent = new String(bytes, StringPool.UTF8); } catch (Exception e) { e.printStackTrace(); return null; } finally { StreamUtil.cleanUp(inputStream); } for (Map.Entry<String, String> variable : variables.entrySet()) { urlContent = urlContent.replaceAll("@" + variable.getKey() + "@", variable.getValue()); } if (ServerDetector.getServerId() != null) { return urlContent; } int x = urlContent.indexOf("<appender name=\"FILE\""); int y = urlContent.indexOf("</appender>", x); if (y != -1) { y = urlContent.indexOf("<", y + 1); } if ((x != -1) && (y != -1)) { urlContent = urlContent.substring(0, x) + urlContent.substring(y); } urlContent = StringUtil.replace(urlContent, "<appender-ref ref=\"FILE\" />", StringPool.BLANK); return urlContent; }
From source file:eu.ibacz.extlet.restart.ServletContainerUtil.java
License:Open Source License
/** * Returns true only if current servlet container is supported by this implementation *///from ww w .j a va2 s .c om public static boolean isContainerSupported() { return SUPPORTED_CONTROLLERS.containsKey(ServerDetector.getServerId()); }
From source file:eu.ibacz.extlet.restart.ServletContainerUtil.java
License:Open Source License
/** * Returns current ServletContainerController implementation * @throws RuntimeException When there is not support for this servlet container */// w w w . j a v a 2 s .c o m public static ServletContainerController getController() throws RuntimeException { if (!ServletContainerUtil.isContainerSupported()) { throw new RuntimeException("This container is unsupported by Extlet!"); } return (ServletContainerController) SUPPORTED_CONTROLLERS.get(ServerDetector.getServerId()); }
From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java
License:Open Source License
public String runCommand(long userId, long companyId, String mode, String command) { String response = ""; Date startDate = new Date(); if ("server".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the Liferay Portal\n" + "date\t\t\tDisplay the date and time of the database server\n" + "uptime\t\t Display the uptime of the portal\n" + "adduser\t\t Add a new user"; } else if ("version".equalsIgnoreCase(command)) { response = ReleaseInfo.getReleaseInfo() + " running on " + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId()); } else if ("date".equalsIgnoreCase(command)) { response = new Date().toString(); } else if ("uptime".equalsIgnoreCase(command)) { response = getUptime(PortalUtil.getUptime().getTime()); } else if (command.toLowerCase().startsWith("adduser")) { response = handleAddUser(userId, companyId, command); }//w ww.j a va2 s . c o m } else if ("db".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\t\tShow this help message\n" + "version\t\t Display the version of the database\n" + "date\t\t\tDisplay the date and time of the database server\n" + "<sql query>\t Display result of any SQL query"; } else if ("date".equalsIgnoreCase(command)) { response = runSQLQuery("select now() \"\""); } else if ("version".equalsIgnoreCase(command)) { response = runSQLQuery( "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''"); } else response = runSQLQuery(command); } else if ("jvm".equalsIgnoreCase(mode)) { if ("help".equalsIgnoreCase(command)) { response = "Commands:\n" + "help\t\tShow this help message\n" + "mem\t\t Display memory usage of the JVM\n" + "osinfo\t Display operating system info of the running JVM\n" + "vminfo\t Display VM info"; } else if ("mem".equalsIgnoreCase(command)) { MemoryMXBean mem = ManagementFactory.getMemoryMXBean(); response = "Heap : " + mem.getHeapMemoryUsage().toString(); response += "\nNon Heap : " + mem.getNonHeapMemoryUsage().toString(); response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending"; } else if ("osinfo".equalsIgnoreCase(command)) { OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " (" + os.getAvailableProcessors() + " processors)"; response += "\nLoad Average: " + os.getSystemLoadAverage(); } else if ("vminfo".equalsIgnoreCase(command)) { RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean(); response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor(); response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor(); response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime())); response += "\nUptime : " + getUptime(vm.getStartTime()); } else { response = UNRECOGNIZED_COMMAND; } } // save command to database if it is not 'help' if (!command.startsWith("help")) { try { // add to history Date endDate = new Date(); long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName()); CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id); history.setCommand(command); history.setExecutionDate(startDate); history.setExecutionTime(endDate.getTime() - startDate.getTime()); history.setMode(mode); history.setUserId(userId); CommandHistoryLocalServiceUtil.updateCommandHistory(history); // TODO: delete the oldest entry > MAX_HISTORY_SIZE // get the history size long historySize = 100; List<CommandHistory> historyList = CommandHistoryLocalServiceUtil .findCommandHistoryByUserId(userId); if (historyList.size() >= historySize) { CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0)); } } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } return response; }