List of usage examples for com.liferay.portal.kernel.util HttpUtil addParameter
public static String addParameter(String url, String name, String value)
From source file:com.beorn.paypalpaymentplugin.util.PayPalUtil.java
License:Open Source License
public static String getReturnUrl(ServletContext servletContext, String successUrl, String errorUrl) { String returnUrl = HttpUtil.getProtocol(successUrl) + "://" + HttpUtil.getDomain(successUrl); returnUrl += servletContext.getContextPath() + _returnServletPath; returnUrl = HttpUtil.addParameter(returnUrl, "successUrl", successUrl); returnUrl = HttpUtil.addParameter(returnUrl, "errorUrl", errorUrl); return returnUrl; }
From source file:com.ext.portal.servlet.filters.sso.cas.CASFilterExt.java
License:Open Source License
@Override protected void processFilter(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws Exception { HttpSession session = request.getSession(); long companyId = PortalUtil.getCompanyId(request); String pathInfo = request.getPathInfo(); Object forceLogout = session.getAttribute(WebKeys.CAS_FORCE_LOGOUT); if (forceLogout != null) { session.removeAttribute(WebKeys.CAS_FORCE_LOGOUT); String logoutUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGOUT_URL, PropsValues.CAS_LOGOUT_URL); response.sendRedirect(logoutUrl); return;//from w w w .jav a 2s . c o m } if (pathInfo.contains("/portal/logout")) { session.invalidate(); String logoutUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGOUT_URL, PropsValues.CAS_LOGOUT_URL); response.sendRedirect(logoutUrl); return; } else { String login = (String) session.getAttribute(WebKeys.CAS_LOGIN); if (Validator.isNotNull(login)) { processFilter(CASFilterExt.class, request, response, filterChain); return; } String serverName = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVER_NAME, PropsValues.CAS_SERVER_NAME); String serviceUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_SERVICE_URL, PropsValues.CAS_SERVICE_URL); if (Validator.isNull(serviceUrl)) { serviceUrl = CommonUtils.constructServiceUrl(request, response, serviceUrl, serverName, "ticket", false); } String ticket = ParamUtil.getString(request, "ticket"); if (Validator.isNull(ticket)) { String loginUrl = PrefsPropsUtil.getString(companyId, PropsKeys.CAS_LOGIN_URL, PropsValues.CAS_LOGIN_URL); loginUrl = HttpUtil.addParameter(loginUrl, "service", serviceUrl); response.sendRedirect(loginUrl); return; } TicketValidator ticketValidator = getTicketValidator(companyId); Assertion assertion = ticketValidator.validate(ticket, serviceUrl); if (assertion != null) { AttributePrincipal attributePrincipal = assertion.getPrincipal(); login = attributePrincipal.getName(); session.setAttribute(WebKeys.CAS_LOGIN, login); // Try to add user if it doesn't exist //_log.info(attributePrincipal); _createUserFromCAS(companyId, login, assertion); } } processFilter(CASFilterExt.class, request, response, filterChain); }
From source file:com.liferay.asset.browser.web.internal.display.context.AssetBrowserDisplayContext.java
License:Open Source License
public String getAddButtonURL() throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = getGroupId(); if (groupId == 0) { groupId = themeDisplay.getScopeGroupId(); }/*from w w w . j a va 2s . co m*/ LiferayPortletRequest liferayPortletRequest = PortalUtil.getLiferayPortletRequest(_renderRequest); LiferayPortletResponse liferayPortletResponse = PortalUtil.getLiferayPortletResponse(_renderResponse); AssetRendererFactory assetRendererFactory = getAssetRendererFactory(); PortletURL addPortletURL = null; if (assetRendererFactory.isSupportsClassTypes() && (getSubtypeSelectionId() > 0)) { addPortletURL = _assetHelper.getAddPortletURL(liferayPortletRequest, liferayPortletResponse, groupId, getTypeSelection(), getSubtypeSelectionId(), null, null, getPortletURL().toString()); } else { addPortletURL = _assetHelper.getAddPortletURL(liferayPortletRequest, liferayPortletResponse, groupId, getTypeSelection(), 0, null, null, getPortletURL().toString()); } if (addPortletURL == null) { return StringPool.BLANK; } addPortletURL.setParameter("groupId", String.valueOf(groupId)); return HttpUtil.addParameter(addPortletURL.toString(), "refererPlid", themeDisplay.getPlid()); }
From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {//from w w w .j a va2 s .co m BlogsEntry entry = null; List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null; UploadException uploadException = (UploadException) actionRequest .getAttribute(WebKeys.UPLOAD_EXCEPTION); if (uploadException != null) { Throwable cause = uploadException.getCause(); if (uploadException.isExceededFileSizeLimit()) { throw new FileSizeException(cause); } if (uploadException.isExceededLiferayFileItemSizeLimit()) { throw new LiferayFileItemException(cause); } if (uploadException.isExceededUploadRequestSizeLimit()) { throw new UploadRequestSizeException(cause); } throw new PortalException(cause); } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) { Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest); Object[] returnValue = TransactionInvokerUtil.invoke(_transactionConfig, updateEntryCallable); entry = (BlogsEntry) returnValue[0]; blogsEntryAttachmentFileEntryReferences = (List<BlogsEntryAttachmentFileEntryReference>) returnValue[1]; } else if (cmd.equals(Constants.DELETE)) { deleteEntries(actionRequest, false); } else if (cmd.equals(Constants.MOVE_TO_TRASH)) { deleteEntries(actionRequest, true); } else if (cmd.equals(Constants.RESTORE)) { restoreTrashEntries(actionRequest); } else if (cmd.equals(Constants.SUBSCRIBE)) { subscribe(actionRequest); } else if (cmd.equals(Constants.UNSUBSCRIBE)) { unsubscribe(actionRequest); } String redirect = ParamUtil.getString(actionRequest, "redirect"); String portletId = HttpUtil.getParameter(redirect, "p_p_id", false); int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction", WorkflowConstants.ACTION_SAVE_DRAFT); boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax"); if (ajax) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference : blogsEntryAttachmentFileEntryReferences) { JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject(); blogsEntryFileEntryReferencesJSONObject.put("attributeDataImageId", EditorConstants.ATTRIBUTE_DATA_IMAGE_ID); blogsEntryFileEntryReferencesJSONObject.put("fileEntryId", String.valueOf( blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId())); blogsEntryFileEntryReferencesJSONObject.put("fileEntryUrl", PortletFileRepositoryUtil.getPortletFileEntryURL(null, blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(), StringPool.BLANK)); jsonArray.put(blogsEntryFileEntryReferencesJSONObject); } jsonObject.put("blogsEntryAttachmentReferences", jsonArray); jsonObject.put("coverImageFileEntryId", entry.getCoverImageFileEntryId()); jsonObject.put("entryId", entry.getEntryId()); jsonObject.put("redirect", redirect); JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject); return; } if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) { redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect); sendRedirect(actionRequest, actionResponse, redirect); } else { WindowState windowState = actionRequest.getWindowState(); if (!windowState.equals(LiferayWindowState.POP_UP)) { sendRedirect(actionRequest, actionResponse, redirect); } else { redirect = PortalUtil.escapeRedirect(redirect); if (Validator.isNotNull(redirect)) { if (cmd.equals(Constants.ADD) && (entry != null)) { String namespace = PortalUtil.getPortletNamespace(portletId); redirect = HttpUtil.addParameter(redirect, namespace + "className", BlogsEntry.class.getName()); redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId()); } actionRequest.setAttribute(WebKeys.REDIRECT, redirect); } } } } catch (AssetCategoryException | AssetTagException e) { SessionErrors.add(actionRequest, e.getClass(), e); actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry"); hideDefaultSuccessMessage(actionRequest); } catch (EntryContentException | EntryCoverImageCropException | EntryDescriptionException | EntryDisplayDateException | EntrySmallImageNameException | EntrySmallImageScaleException | EntryTitleException | EntryUrlTitleException | FileSizeException | LiferayFileItemException | SanitizerException | UploadRequestSizeException e) { SessionErrors.add(actionRequest, e.getClass()); actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry"); hideDefaultSuccessMessage(actionRequest); } catch (NoSuchEntryException | PrincipalException e) { SessionErrors.add(actionRequest, e.getClass()); actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp"); hideDefaultSuccessMessage(actionRequest); } catch (Throwable t) { _log.error(t, t); actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp"); hideDefaultSuccessMessage(actionRequest); } }
From source file:com.liferay.bookmarks.web.internal.portlet.action.EditEntryMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {/*from www .jav a2s .c o m*/ BookmarksEntry entry = null; if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) { entry = updateEntry(actionRequest); } else if (cmd.equals(Constants.DELETE)) { deleteEntry(actionRequest, false); } else if (cmd.equals(Constants.MOVE)) { moveEntries(actionRequest); } else if (cmd.equals(Constants.MOVE_TO_TRASH)) { deleteEntry(actionRequest, true); } else if (cmd.equals(Constants.RESTORE)) { restoreTrashEntries(actionRequest); } else if (cmd.equals(Constants.SUBSCRIBE)) { subscribeEntry(actionRequest); } else if (cmd.equals(Constants.UNSUBSCRIBE)) { unsubscribeEntry(actionRequest); } WindowState windowState = actionRequest.getWindowState(); if (windowState.equals(LiferayWindowState.POP_UP)) { String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect")); if (Validator.isNotNull(redirect)) { if (cmd.equals(Constants.ADD) && (entry != null)) { String portletId = HttpUtil.getParameter(redirect, "p_p_id", false); String namespace = PortalUtil.getPortletNamespace(portletId); redirect = HttpUtil.addParameter(redirect, namespace + "className", BookmarksEntry.class.getName()); redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId()); } actionRequest.setAttribute(WebKeys.REDIRECT, redirect); } } } catch (Exception e) { if (e instanceof NoSuchEntryException || e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass()); actionResponse.setRenderParameter("mvcPath", "/bookmarks/error.jsp"); } else if (e instanceof EntryURLException || e instanceof NoSuchFolderException) { SessionErrors.add(actionRequest, e.getClass()); } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) { SessionErrors.add(actionRequest, e.getClass(), e); } else { throw e; } } }
From source file:com.liferay.calendar.notification.impl.NotificationTemplateContextFactory.java
License:Open Source License
private static String _getCalendarBookingURL(User user, long calendarBookingId) throws PortalException { Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST); Layout layout = LayoutLocalServiceUtil.fetchLayout(group.getDefaultPublicPlid()); String portalURL = _getPortalURL(group.getCompanyId(), group.getGroupId()); String layoutActualURL = PortalUtil.getLayoutActualURL(layout); String url = portalURL + layoutActualURL; String namespace = PortalUtil.getPortletNamespace(CalendarPortletKeys.CALENDAR); url = HttpUtil.addParameter(url, namespace + "mvcPath", "/view_calendar_booking.jsp"); url = HttpUtil.addParameter(url, "p_p_id", CalendarPortletKeys.CALENDAR); url = HttpUtil.addParameter(url, "p_p_lifecycle", "0"); url = HttpUtil.addParameter(url, "p_p_state", WindowState.MAXIMIZED.toString()); url = HttpUtil.addParameter(url, namespace + "calendarBookingId", calendarBookingId); return url;//from www.ja v a 2 s. c om }
From source file:com.liferay.calendar.notification.NotificationTemplateContextFactory.java
License:Open Source License
private static String _getCalendarBookingURL(User user, long calendarBookingId) throws PortalException { Group group = user.getGroup(); Layout layout = LayoutLocalServiceUtil.getLayout(group.getDefaultPrivatePlid()); String portalURL = _getPortalURL(group.getCompanyId(), group.getGroupId()); String layoutActualURL = PortalUtil.getLayoutActualURL(layout); String url = portalURL + layoutActualURL; String namespace = PortalUtil.getPortletNamespace(PortletKeys.CALENDAR); url = HttpUtil.addParameter(url, namespace + "mvcPath", "/view_calendar_booking.jsp"); url = HttpUtil.addParameter(url, "p_p_id", PortletKeys.CALENDAR); url = HttpUtil.addParameter(url, "p_p_lifecycle", "0"); url = HttpUtil.addParameter(url, "p_p_state", WindowState.MAXIMIZED.toString()); url = HttpUtil.addParameter(url, namespace + "calendarBookingId", calendarBookingId); return url;/*w w w . jav a 2 s . com*/ }
From source file:com.liferay.content.targeting.analytics.hook.filter.YoutubeVideoHtmlFilter.java
License:Open Source License
protected String getContent(HttpServletRequest request, String content) { Matcher youtubeEmbedVideoIframeMatcher = _youtubeEmbedVideoIframePattern.matcher(content); StringBuffer stringBuffer = new StringBuffer(); while (youtubeEmbedVideoIframeMatcher.find()) { String youtubeEmbededVideoUrl = youtubeEmbedVideoIframeMatcher.group(4); Matcher youtubeEmbedVideoUrlIdMatcher = _youtubeEmbedVideoUrlIdPattern.matcher(youtubeEmbededVideoUrl); if (!youtubeEmbedVideoUrlIdMatcher.matches()) { continue; }/*from ww w . ja va 2s . c o m*/ // Prevent Youtube security errors youtubeEmbededVideoUrl = sanitizeURL(youtubeEmbededVideoUrl, true); youtubeEmbededVideoUrl = HttpUtil.addParameter(youtubeEmbededVideoUrl, "enablejsapi", 1); String youtubeEmbedVideoIframeAtributtes = youtubeEmbedVideoIframeMatcher.group(2) + " id=" + youtubeEmbedVideoUrlIdMatcher.group(1); StringBundler sb = new StringBundler(5); sb.append(youtubeEmbedVideoIframeMatcher.group(1)); sb.append(youtubeEmbedVideoIframeAtributtes); sb.append(youtubeEmbedVideoIframeMatcher.group(3)); sb.append(youtubeEmbededVideoUrl); sb.append(youtubeEmbedVideoIframeMatcher.group(5)); youtubeEmbedVideoIframeMatcher.appendReplacement(stringBuffer, sb.toString()); } youtubeEmbedVideoIframeMatcher.appendTail(stringBuffer); if (stringBuffer.length() != 0) { return stringBuffer.toString(); } return content; }
From source file:com.liferay.content.targeting.rule.weather.WeatherRule.java
License:Open Source License
protected String getUserWeather(AnonymousUser anonymousUser) throws PortalException, SystemException { //User user = anonymousUser.getUser(); //String city = getCityFromUserProfile(user.getContactId(), user.getCompanyId()); String city = getCityFromIPAddress(anonymousUser.getLastIp()); Http.Options options = new Http.Options(); String location = HttpUtil.addParameter(API_URL, "q", city); location = HttpUtil.addParameter(location, "format", "json"); options.setLocation(location);//from w w w. j a v a2 s . c om int weatherCode = 0; try { String text = HttpUtil.URLtoString(options); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(text); weatherCode = jsonObject.getJSONArray("weather").getJSONObject(0).getInt("id"); } catch (Exception e) { _log.error(e); } return getWeatherFromCode(weatherCode); }
From source file:com.liferay.content.targeting.util.ContentTargetingContextUtil.java
License:Open Source License
public static String getSiteAdministrationPortletURL(Map<String, Object> context, String portletId, Map<String, String> params) { String portletURLString = getControlPanelPortletURL(context, portletId, params); if (Validator.isNull(portletURLString)) { return null; }//from ww w.j a v a 2 s .c o m long scopeGroupId = GetterUtil.getLong(context.get("scopeGroupId")); portletURLString = HttpUtil.addParameter(portletURLString, "doAsGroupId", scopeGroupId); return HttpUtil.addParameter(portletURLString, "controlPanelCategory", "current_site"); }