001
014
015 package com.liferay.portlet.announcements.action;
016
017 import com.liferay.portal.kernel.util.GetterUtil;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.kernel.util.StringUtil;
020 import com.liferay.portal.model.User;
021 import com.liferay.portal.struts.PortletAction;
022 import com.liferay.portal.theme.ThemeDisplay;
023 import com.liferay.portal.util.WebKeys;
024 import com.liferay.portlet.announcements.model.AnnouncementsEntry;
025 import com.liferay.portlet.announcements.model.impl.AnnouncementsEntryImpl;
026
027 import java.util.Date;
028
029 import javax.portlet.ActionRequest;
030 import javax.portlet.ActionResponse;
031 import javax.portlet.PortletConfig;
032 import javax.portlet.RenderRequest;
033 import javax.portlet.RenderResponse;
034
035 import org.apache.struts.action.ActionForm;
036 import org.apache.struts.action.ActionForward;
037 import org.apache.struts.action.ActionMapping;
038
039
042 public class PreviewEntryAction extends PortletAction {
043
044 public void processAction(
045 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
046 ActionRequest actionRequest, ActionResponse actionResponse)
047 throws Exception {
048
049 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
050 WebKeys.THEME_DISPLAY);
051
052 User user = themeDisplay.getUser();
053 Date now = new Date();
054
055 String[] distributionScopeParts = StringUtil.split(
056 ParamUtil.getString(actionRequest, "distributionScope"));
057
058 long classNameId = 0;
059 long classPK = 0;
060
061 if (distributionScopeParts.length == 2) {
062 classNameId = GetterUtil.getLong(distributionScopeParts[0]);
063
064 if (classNameId > 0) {
065 classPK = GetterUtil.getLong(distributionScopeParts[1]);
066 }
067 }
068
069 String title = ParamUtil.getString(actionRequest, "title");
070 String content = ParamUtil.getString(actionRequest, "content");
071 String url = ParamUtil.getString(actionRequest, "url");
072 String type = ParamUtil.getString(actionRequest, "type");
073 int priority = ParamUtil.getInteger(actionRequest, "priority");
074 boolean alert = ParamUtil.getBoolean(actionRequest, "alert");
075
076 AnnouncementsEntry entry = new AnnouncementsEntryImpl();
077
078 entry.setCompanyId(user.getCompanyId());
079 entry.setUserId(user.getUserId());
080 entry.setUserName(user.getFullName());
081 entry.setCreateDate(now);
082 entry.setModifiedDate(now);
083 entry.setClassNameId(classNameId);
084 entry.setClassPK(classPK);
085 entry.setTitle(title);
086 entry.setContent(content);
087 entry.setUrl(url);
088 entry.setType(type);
089 entry.setDisplayDate(now);
090 entry.setExpirationDate(now);
091 entry.setPriority(priority);
092 entry.setAlert(alert);
093
094 actionRequest.setAttribute(WebKeys.ANNOUNCEMENTS_ENTRY, entry);
095 }
096
097 public ActionForward render(
098 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
099 RenderRequest renderRequest, RenderResponse renderResponse)
100 throws Exception {
101
102 return mapping.findForward(
103 getForward(renderRequest, "portlet.announcements.preview_entry"));
104 }
105
106 }