List of usage examples for com.liferay.portal.struts ActionConstants COMMON_NULL
String COMMON_NULL
To view the source code for com.liferay.portal.struts ActionConstants COMMON_NULL.
Click Source Link
From source file:com.liferay.portlet.blogs.action.EditEntryAction.java
License:Open Source License
public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String cmd = ParamUtil.getString(actionRequest, Constants.CMD); try {// www .j a va 2s .c o m BlogsEntry entry = null; String oldUrlTitle = StringPool.BLANK; if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) { Object[] returnValue = updateEntry(actionRequest); entry = (BlogsEntry) returnValue[0]; oldUrlTitle = ((String) returnValue[1]); } else if (cmd.equals(Constants.DELETE)) { deleteEntry(actionRequest); } String redirect = ParamUtil.getString(actionRequest, "redirect"); boolean updateRedirect = false; if (redirect.indexOf("/blogs/" + oldUrlTitle + "/maximized") != -1) { oldUrlTitle += "/maximized"; } if ((entry != null) && (Validator.isNotNull(oldUrlTitle)) && (redirect.endsWith("/blogs/" + oldUrlTitle) || redirect.indexOf("/blogs/" + oldUrlTitle + "?") != -1)) { int pos = redirect.indexOf("?"); if (pos == -1) { pos = redirect.length(); } String newRedirect = redirect.substring(0, pos - oldUrlTitle.length()); newRedirect += entry.getUrlTitle(); if (oldUrlTitle.indexOf("/maximized") != -1) { newRedirect += "/maximized"; } if (pos < redirect.length()) { newRedirect += "?" + redirect.substring(pos + 1, redirect.length()); } redirect = newRedirect; updateRedirect = true; } if ((entry != null) && entry.isDraft()) { JSONObject jsonObj = JSONFactoryUtil.createJSONObject(); jsonObj.put("entryId", entry.getEntryId()); jsonObj.put("redirect", redirect); jsonObj.put("updateRedirect", updateRedirect); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); InputStream is = new ByteArrayInputStream(jsonObj.toString().getBytes()); String contentType = ContentTypes.TEXT_JAVASCRIPT; ServletResponseUtil.sendFile(response, null, is, contentType); setForward(actionRequest, ActionConstants.COMMON_NULL); } else { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet(); if (layoutTypePortlet.hasPortletId(portletConfig.getPortletName())) { sendRedirect(actionRequest, actionResponse, redirect); } else { actionResponse.sendRedirect(redirect); } } } catch (Exception e) { if (e instanceof NoSuchEntryException || e instanceof PrincipalException) { SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, "portlet.blogs.error"); } else if (e instanceof EntryContentException || e instanceof EntryDisplayDateException || e instanceof EntryTitleException) { SessionErrors.add(actionRequest, e.getClass().getName()); } else if (e instanceof TagsEntryException) { SessionErrors.add(actionRequest, e.getClass().getName(), e); } else { throw e; } } }
From source file:com.liferay.portlet.blogs.action.TrackbackAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from w ww . j av a 2 s .c om addTrackback(actionRequest, actionResponse); } catch (NoSuchEntryException nsee) { if (_log.isWarnEnabled()) { _log.warn(nsee, nsee); } } catch (Exception e) { _log.error(e, e); } setForward(actionRequest, ActionConstants.COMMON_NULL); }
From source file:com.liferay.portlet.calendar.action.ExportEventsAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { File file = null;/*from w w w . j av a 2 s .com*/ try { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long eventId = ParamUtil.getLong(actionRequest, "eventId"); String exportFileName = ParamUtil.getString(actionRequest, "exportFileName"); if (Validator.isNull(exportFileName)) { exportFileName = "liferay.ics"; } else { exportFileName = FileUtil.getShortFileName(exportFileName); } if (eventId > 0) { file = CalEventServiceUtil.exportEvent(eventId); } else { file = CalEventServiceUtil.exportGroupEvents(themeDisplay.getScopeGroupId(), exportFileName); } HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); ServletResponseUtil.sendFile(request, response, exportFileName, new FileInputStream(file), ContentTypes.TEXT_CALENDAR); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { _log.error(e, e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.portlet.documentlibrary.action.GetFileAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); try {//w ww .java2 s .c o m long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); long folderId = ParamUtil.getLong(actionRequest, "folderId"); String title = ParamUtil.getString(actionRequest, "title"); String version = ParamUtil.getString(actionRequest, "version"); long fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId"); String uuid = ParamUtil.getString(actionRequest, "uuid"); String targetExtension = ParamUtil.getString(actionRequest, "targetExtension"); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId", themeDisplay.getScopeGroupId()); getFile(fileEntryId, folderId, title, version, fileShortcutId, uuid, groupId, targetExtension, themeDisplay, request, response); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (NoSuchFileEntryException nsfee) { PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nsfee, actionRequest, actionResponse); } catch (PrincipalException pe) { processPrincipalException(pe, request, response); } catch (Exception e) { PortalUtil.sendError(e, actionRequest, actionResponse); } }
From source file:com.liferay.portlet.flags.action.EditEntryAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { String className = ParamUtil.getString(actionRequest, "className"); long classPK = ParamUtil.getLong(actionRequest, "classPK"); String reporterEmailAddress = ParamUtil.getString(actionRequest, "reporterEmailAddress"); long reportedUserId = ParamUtil.getLong(actionRequest, "reportedUserId"); String contentTitle = ParamUtil.getString(actionRequest, "contentTitle"); String contentURL = ParamUtil.getString(actionRequest, "contentURL"); String reason = ParamUtil.getString(actionRequest, "reason"); ServiceContext serviceContext = ServiceContextFactory .getInstance("com.liferay.portlet.flags.model.FlagsEntry", actionRequest); FlagsEntryServiceUtil.addEntry(className, classPK, reporterEmailAddress, reportedUserId, contentTitle, contentURL, reason, serviceContext); setForward(actionRequest, ActionConstants.COMMON_NULL); }
From source file:com.liferay.portlet.journalcontent.action.ExportArticleAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from w w w . j a v a2s.c o m long groupId = ParamUtil.getLong(actionRequest, "groupId"); String articleId = ParamUtil.getString(actionRequest, "articleId"); String targetExtension = ParamUtil.getString(actionRequest, "targetExtension"); PortletPreferences preferences = actionRequest.getPreferences(); String[] allowedExtensions = preferences.getValues("extensions", null); String languageId = LanguageUtil.getLanguageId(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); getFile(groupId, articleId, targetExtension, allowedExtensions, languageId, themeDisplay, request, response); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { PortalUtil.sendError(e, actionRequest, actionResponse); } }
From source file:com.liferay.portlet.layoutsadmin.action.ExportLayoutsAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//ww w .j a va2 s. c om ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId"); boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout"); long[] layoutIds = ParamUtil.getLongValues(actionRequest, "layoutIds"); String fileName = ParamUtil.getString(actionRequest, "exportFileName"); String range = ParamUtil.getString(actionRequest, "range"); Date startDate = null; Date endDate = null; if (range.equals("dateRange")) { int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth"); int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay"); int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear"); int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour"); int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute"); int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm"); if (startDateAmPm == Calendar.PM) { startDateHour += 12; } startDate = PortalUtil.getDate(startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, themeDisplay.getTimeZone(), new PortalException()); int endDateMonth = ParamUtil.getInteger(actionRequest, "endDateMonth"); int endDateDay = ParamUtil.getInteger(actionRequest, "endDateDay"); int endDateYear = ParamUtil.getInteger(actionRequest, "endDateYear"); int endDateHour = ParamUtil.getInteger(actionRequest, "endDateHour"); int endDateMinute = ParamUtil.getInteger(actionRequest, "endDateMinute"); int endDateAmPm = ParamUtil.getInteger(actionRequest, "endDateAmPm"); if (endDateAmPm == Calendar.PM) { endDateHour += 12; } endDate = PortalUtil.getDate(endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute, themeDisplay.getTimeZone(), new PortalException()); } else if (range.equals("fromLastPublishDate")) { LayoutSet layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); UnicodeProperties settingsProperties = layoutSet.getSettingsProperties(); long lastPublishDate = GetterUtil.getLong(settingsProperties.getProperty("last-publish-date")); if (lastPublishDate > 0) { Calendar cal = Calendar.getInstance(themeDisplay.getTimeZone(), themeDisplay.getLocale()); endDate = cal.getTime(); cal.setTimeInMillis(lastPublishDate); startDate = cal.getTime(); } } else if (range.equals("last")) { int rangeLast = ParamUtil.getInteger(actionRequest, "last"); Date now = new Date(); startDate = new Date(now.getTime() - (rangeLast * Time.HOUR)); endDate = now; } File file = LayoutServiceUtil.exportLayoutsAsFile(groupId, privateLayout, layoutIds, actionRequest.getParameterMap(), startDate, endDate); HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); ServletResponseUtil.sendFile(request, response, fileName, new FileInputStream(file), ContentTypes.APPLICATION_ZIP); FileUtil.delete(file); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { _log.error(e, e); SessionErrors.add(actionRequest, e.getClass().getName()); String pagesRedirect = ParamUtil.getString(actionRequest, "pagesRedirect"); sendRedirect(actionRequest, actionResponse, pagesRedirect); } }
From source file:com.liferay.portlet.messageboards.action.GetMessageAttachmentAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { try {//from www .j av a2 s .c o m long messageId = ParamUtil.getLong(actionRequest, "messageId"); String fileName = ParamUtil.getString(actionRequest, "attachment"); HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); getFile(messageId, fileName, request, response); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { PortalUtil.sendError(e, actionRequest, actionResponse); } }
From source file:com.liferay.portlet.messageboards.action.RSSAction.java
License:Open Source License
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from w w w. j a v a 2 s .co m ServletResponseUtil.sendFile(request, response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8); return mapping.findForward(ActionConstants.COMMON_NULL); } catch (Exception e) { PortalUtil.sendError(e, request, response); return null; } }
From source file:com.liferay.portlet.portletconfiguration.action.ExportImportAction.java
License:Open Source License
protected void exportData(ActionRequest actionRequest, ActionResponse actionResponse, Portlet portlet) throws Exception { try {//from w ww . j av a 2 s . c om ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long plid = ParamUtil.getLong(actionRequest, "plid"); long groupId = ParamUtil.getLong(actionRequest, "groupId"); String fileName = ParamUtil.getString(actionRequest, "exportFileName"); String range = ParamUtil.getString(actionRequest, "range"); Date startDate = null; Date endDate = null; if (range.equals("dateRange")) { int startDateMonth = ParamUtil.getInteger(actionRequest, "startDateMonth"); int startDateDay = ParamUtil.getInteger(actionRequest, "startDateDay"); int startDateYear = ParamUtil.getInteger(actionRequest, "startDateYear"); int startDateHour = ParamUtil.getInteger(actionRequest, "startDateHour"); int startDateMinute = ParamUtil.getInteger(actionRequest, "startDateMinute"); int startDateAmPm = ParamUtil.getInteger(actionRequest, "startDateAmPm"); if (startDateAmPm == Calendar.PM) { startDateHour += 12; } startDate = PortalUtil.getDate(startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, themeDisplay.getTimeZone(), new PortalException()); int endDateMonth = ParamUtil.getInteger(actionRequest, "endDateMonth"); int endDateDay = ParamUtil.getInteger(actionRequest, "endDateDay"); int endDateYear = ParamUtil.getInteger(actionRequest, "endDateYear"); int endDateHour = ParamUtil.getInteger(actionRequest, "endDateHour"); int endDateMinute = ParamUtil.getInteger(actionRequest, "endDateMinute"); int endDateAmPm = ParamUtil.getInteger(actionRequest, "endDateAmPm"); if (endDateAmPm == Calendar.PM) { endDateHour += 12; } endDate = PortalUtil.getDate(endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute, themeDisplay.getTimeZone(), new PortalException()); } else if (range.equals("fromLastPublishDate")) { Layout layout = LayoutLocalServiceUtil.getLayout(plid); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK); long lastPublishDate = GetterUtil .getLong(preferences.getValue("last-publish-date", StringPool.BLANK)); if (lastPublishDate > 0) { Calendar cal = Calendar.getInstance(themeDisplay.getTimeZone(), themeDisplay.getLocale()); endDate = cal.getTime(); cal.setTimeInMillis(lastPublishDate); startDate = cal.getTime(); } } File file = LayoutServiceUtil.exportPortletInfoAsFile(plid, groupId, portlet.getPortletId(), actionRequest.getParameterMap(), startDate, endDate); HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); ServletResponseUtil.sendFile(request, response, fileName, new FileInputStream(file), ContentTypes.APPLICATION_ZIP); FileUtil.delete(file); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } SessionErrors.add(actionRequest, e.getClass().getName()); } }