List of usage examples for com.liferay.portal.kernel.util StringPool SLASH
String SLASH
To view the source code for com.liferay.portal.kernel.util StringPool SLASH.
Click Source Link
From source file:com.liferay.portlet.messageboards.service.impl.MBThreadLocalServiceImpl.java
License:Open Source License
protected void moveAttachmentFromOldThread(long companyId, String fileName, String newAttachmentsDir) throws PortalException, SystemException { long repositoryId = CompanyConstants.SYSTEM; StringBundler sb = new StringBundler(4); sb.append(newAttachmentsDir);/* www . ja va2 s . co m*/ sb.append(StringPool.SLASH); sb.append(StringUtil.extractLast(fileName, CharPool.SLASH)); String newFileName = sb.toString(); try { File file = DLStoreUtil.getFile(companyId, repositoryId, fileName); DLStoreUtil.addFile(companyId, repositoryId, newFileName, false, file); } catch (UnsupportedOperationException uoe) { InputStream is = DLStoreUtil.getFileAsStream(companyId, repositoryId, fileName); try { DLStoreUtil.addFile(companyId, repositoryId, newFileName, false, is); } finally { try { is.close(); } catch (IOException ioe) { _log.error(ioe); } } } DLStoreUtil.deleteFile(companyId, repositoryId, fileName); }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected void localDeploy(ActionRequest actionRequest) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String fileName = null;//from w ww .ja va 2s . c o m String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); if (Validator.isNotNull(deploymentContext)) { fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if ((bytes == null) || (bytes.length == 0)) { SessionErrors.add(actionRequest, UploadException.class.getName()); return; } try { PluginPackageUtil.registerPluginPackageInstallation(deploymentContext); String source = file.toString(); String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, PropsValues.AUTO_DEPLOY_DEPLOY_DIR); String destination = deployDir + StringPool.SLASH + fileName; FileUtil.copyFile(source, destination); SessionMessages.add(actionRequest, "pluginUploaded"); } finally { PluginPackageUtil.endPluginPackageInstallation(deploymentContext); } }
From source file:com.liferay.portlet.plugininstaller.action.InstallPluginAction.java
License:Open Source License
protected int remoteDeploy(String url, URL urlObj, ActionRequest actionRequest, boolean failOnError) throws Exception { int responseCode = HttpServletResponse.SC_OK; GetMethod getMethod = null;/* w w w .ja v a 2 s . co m*/ String deploymentContext = ParamUtil.getString(actionRequest, "deploymentContext"); try { HttpImpl httpImpl = (HttpImpl) HttpUtil.getHttp(); HostConfiguration hostConfiguration = httpImpl.getHostConfiguration(url); HttpClient httpClient = httpImpl.getClient(hostConfiguration); getMethod = new GetMethod(url); String fileName = null; if (Validator.isNotNull(deploymentContext)) { fileName = BaseDeployer.DEPLOY_TO_PREFIX + deploymentContext + ".war"; } else { fileName = url.substring(url.lastIndexOf(CharPool.SLASH) + 1); int pos = fileName.lastIndexOf(CharPool.PERIOD); if (pos != -1) { deploymentContext = fileName.substring(0, pos); } } PluginPackageUtil.registerPluginPackageInstallation(deploymentContext); responseCode = httpClient.executeMethod(hostConfiguration, getMethod); if (responseCode != HttpServletResponse.SC_OK) { if (failOnError) { SessionErrors.add(actionRequest, "errorConnectingToUrl", new Object[] { String.valueOf(responseCode) }); } return responseCode; } long contentLength = getMethod.getResponseContentLength(); String progressId = ParamUtil.getString(actionRequest, Constants.PROGRESS_ID); ProgressInputStream pis = new ProgressInputStream(actionRequest, getMethod.getResponseBodyAsStream(), contentLength, progressId); String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR, PropsValues.AUTO_DEPLOY_DEPLOY_DIR); String tmpFilePath = deployDir + StringPool.SLASH + _DOWNLOAD_DIR + StringPool.SLASH + fileName; File tmpFile = new File(tmpFilePath); if (!tmpFile.getParentFile().exists()) { tmpFile.getParentFile().mkdirs(); } FileOutputStream fos = new FileOutputStream(tmpFile); try { pis.readAll(fos); if (_log.isInfoEnabled()) { _log.info("Downloaded plugin from " + urlObj + " has " + pis.getTotalRead() + " bytes"); } } finally { pis.clearProgress(); } getMethod.releaseConnection(); if (pis.getTotalRead() > 0) { String destination = deployDir + StringPool.SLASH + fileName; File destinationFile = new File(destination); boolean moved = FileUtil.move(tmpFile, destinationFile); if (!moved) { FileUtil.copyFile(tmpFile, destinationFile); FileUtil.delete(tmpFile); } SessionMessages.add(actionRequest, "pluginDownloaded"); } else { if (failOnError) { SessionErrors.add(actionRequest, UploadException.class.getName()); } responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } catch (IOException ioe) { SessionErrors.add(actionRequest, "errorConnectingToUrl", ioe); } finally { if (getMethod != null) { getMethod.releaseConnection(); } PluginPackageUtil.endPluginPackageInstallation(deploymentContext); } return responseCode; }
From source file:com.liferay.portlet.PortletBagFactory.java
License:Open Source License
protected InputStream getResourceBundleInputStream(String resourceBundleName, Locale locale) { resourceBundleName = resourceBundleName.replace(StringPool.PERIOD, StringPool.SLASH); Locale newLocale = locale;/* ww w.j ava 2 s. c o m*/ InputStream inputStream = null; while (inputStream == null) { locale = newLocale; StringBundler sb = new StringBundler(4); sb.append(resourceBundleName); if (locale != null) { String localeName = locale.toString(); if (localeName.length() > 0) { sb.append(StringPool.UNDERLINE); sb.append(localeName); } } if (!resourceBundleName.endsWith(".properties")) { sb.append(".properties"); } String localizedResourceBundleName = sb.toString(); if (_log.isInfoEnabled()) { _log.info("Attempting to load " + localizedResourceBundleName); } inputStream = _classLoader.getResourceAsStream(localizedResourceBundleName); if (locale == null) { break; } newLocale = LanguageResources.getSuperLocale(locale); if (newLocale == null) { break; } if (newLocale.equals(locale)) { break; } } return inputStream; }
From source file:com.liferay.portlet.PortletRequestImpl.java
License:Open Source License
public String getContextPath() { PortletContextImpl portletContextImpl = (PortletContextImpl) _portletContext; ServletContext servletContext = portletContextImpl.getServletContext(); String servletContextName = servletContext.getServletContextName(); if (ServletContextPool.containsKey(servletContextName)) { servletContext = ServletContextPool.get(servletContextName); return ContextPathUtil.getContextPath(servletContext); }/* w w w. j a v a 2 s. c o m*/ return StringPool.SLASH.concat(_portletContext.getPortletContextName()); }
From source file:com.liferay.portlet.social.model.impl.SocialActivityLimitImpl.java
License:Open Source License
public int getCount(int limitPeriod) { String[] valueParts = StringUtil.split(getValue(), StringPool.SLASH); if ((limitPeriod != SocialActivityCounterDefinition.LIMIT_PERIOD_LIFETIME) && (valueParts.length < 2)) { return 0; }//from ww w .ja v a 2 s . c om int count = GetterUtil.getInteger(valueParts[valueParts.length - 1], 0); if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_DAY) { int activityDay = SocialCounterPeriodUtil.getActivityDay(); if (activityDay == GetterUtil.getInteger(valueParts[0], 0)) { return count; } } else if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_LIFETIME) { return count; } else if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_PERIOD) { int activityDay = SocialCounterPeriodUtil.getActivityDay(); String[] periodParts = StringUtil.split(valueParts[0], StringPool.DASH); int startPeriod = GetterUtil.getInteger(periodParts[0]); int endPeriod = GetterUtil.getInteger(periodParts[1]); if ((activityDay >= startPeriod) && (activityDay <= endPeriod)) { return count; } } return 0; }
From source file:com.liferay.portlet.social.model.impl.SocialActivityLimitImpl.java
License:Open Source License
public void setCount(int limitPeriod, int count) { if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_DAY) { setValue(String.valueOf(SocialCounterPeriodUtil.getActivityDay()) + StringPool.SLASH + String.valueOf(count)); } else if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_LIFETIME) { setValue(String.valueOf(count)); } else if (limitPeriod == SocialActivityCounterDefinition.LIMIT_PERIOD_PERIOD) { StringBundler sb = new StringBundler(5); sb.append(SocialCounterPeriodUtil.getStartPeriod()); sb.append(StringPool.DASH);/*w ww. j a v a 2s . c o m*/ sb.append(SocialCounterPeriodUtil.getEndPeriod()); sb.append(StringPool.SLASH); sb.append(count); setValue(sb.toString()); } }
From source file:com.liferay.portlet.social.model.SocialActivityCounterDefinition.java
License:Open Source License
public String getKey() { return _name.concat(StringPool.SLASH).concat(String.valueOf(_ownerType)); }
From source file:com.liferay.portlet.social.util.FacebookUtil.java
License:Open Source License
public static String[] getFacebookData(HttpServletRequest request) { String path = GetterUtil.getString(request.getPathInfo()); if (Validator.isNull(path)) { return null; }/* ww w . j a v a2 s . c o m*/ int pos = path.indexOf(StringPool.SLASH, 1); if (pos == -1) { return null; } String facebookCanvasPageURL = path.substring(1, pos); if (_log.isDebugEnabled()) { _log.debug("Facebook canvas page URL " + facebookCanvasPageURL); } if (Validator.isNull(facebookCanvasPageURL)) { return null; } String redirect = path.substring(pos); if (_log.isDebugEnabled()) { _log.debug("Redirect " + redirect); } if (Validator.isNull(redirect)) { return null; } pos = path.indexOf(Portal.FRIENDLY_URL_SEPARATOR); String appPath = StringPool.BLANK; if (pos != -1) { pos = path.indexOf(CharPool.SLASH, pos + 3); if (pos != -1) { appPath = path.substring(pos); } } return new String[] { facebookCanvasPageURL, redirect, appPath }; }
From source file:com.liferay.portlet.usersadmin.action.EditUserAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {//from w w w. jav a2 s. c o m User user = null; String oldScreenName = StringPool.BLANK; String oldLanguageId = StringPool.BLANK; if (cmd.equals(Constants.ADD)) { user = addUser(actionRequest); } else if (cmd.equals(Constants.DEACTIVATE) || cmd.equals(Constants.DELETE) || cmd.equals(Constants.RESTORE)) { deleteUsers(actionRequest); } else if (cmd.equals("deleteRole")) { deleteRole(actionRequest); } else if (cmd.equals(Constants.UPDATE)) { Object[] returnValue = updateUser(actionRequest, actionResponse); user = (User) returnValue[0]; oldScreenName = ((String) returnValue[1]); oldLanguageId = ((String) returnValue[2]); } else if (cmd.equals("unlock")) { user = updateLockout(actionRequest); } ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); String redirect = ParamUtil.getString(actionRequest, "redirect"); if (user != null) { if (Validator.isNotNull(oldScreenName)) { // This will fix the redirect if the user is on his personal // my account page and changes his screen name. A redirect // that references the old screen name no longer points to a // valid screen name and therefore needs to be updated. Group group = user.getGroup(); if (group.getGroupId() == themeDisplay.getScopeGroupId()) { Layout layout = themeDisplay.getLayout(); String friendlyURLPath = group.getPathFriendlyURL(layout.isPrivateLayout(), themeDisplay); String oldPath = friendlyURLPath + StringPool.SLASH + oldScreenName; String newPath = friendlyURLPath + StringPool.SLASH + user.getScreenName(); redirect = StringUtil.replace(redirect, oldPath, newPath); redirect = StringUtil.replace(redirect, HttpUtil.encodeURL(oldPath), HttpUtil.encodeURL(newPath)); } } if (Validator.isNotNull(oldLanguageId) && themeDisplay.isI18n()) { String i18nLanguageId = user.getLanguageId(); int pos = i18nLanguageId.indexOf(CharPool.UNDERLINE); if (pos != -1) { i18nLanguageId = i18nLanguageId.substring(0, pos); } String i18nPath = StringPool.SLASH + i18nLanguageId; redirect = StringUtil.replace(redirect, themeDisplay.getI18nPath(), i18nPath); } redirect = HttpUtil.setParameter(redirect, actionResponse.getNamespace() + "p_u_i_d", user.getUserId()); } Group scopeGroup = themeDisplay.getScopeGroup(); if (scopeGroup.isUser()) { try { UserLocalServiceUtil.getUserById(scopeGroup.getClassPK()); } catch (NoSuchUserException nsue) { redirect = HttpUtil.setParameter(redirect, "doAsGroupId", 0); redirect = HttpUtil.setParameter(redirect, "refererPlid", 0); } } sendRedirect(actionRequest, actionResponse, redirect); } catch (Exception e) { if (e instanceof NoSuchUserException || e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, "portlet.users_admin.error"); } else if (e instanceof AddressCityException || e instanceof AddressStreetException || e instanceof AddressZipException || e instanceof CompanyMaxUsersException || e instanceof ContactBirthdayException || e instanceof ContactFirstNameException || e instanceof ContactFullNameException || e instanceof ContactLastNameException || e instanceof DuplicateUserEmailAddressException || e instanceof DuplicateUserScreenNameException || e instanceof EmailAddressException || e instanceof GroupFriendlyURLException || e instanceof NoSuchCountryException || e instanceof NoSuchListTypeException || e instanceof NoSuchRegionException || e instanceof PhoneNumberException || e instanceof RequiredUserException || e instanceof ReservedUserEmailAddressException || e instanceof ReservedUserScreenNameException || e instanceof UserEmailAddressException || e instanceof UserIdException || e instanceof UserPasswordException || e instanceof UserReminderQueryException || e instanceof UserScreenNameException || e instanceof UserSmsException || e instanceof WebsiteURLException) { if (e instanceof NoSuchListTypeException) { NoSuchListTypeException nslte = (NoSuchListTypeException) e; SessionErrors.add(actionRequest, e.getClass().getName() + nslte.getType()); } else { SessionErrors.add(actionRequest, e.getClass().getName(), e); } if (e instanceof RequiredUserException) { String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } } } else { throw e; } } }