1
19
20 package com.liferay.portlet.tags.action;
21
22 import com.liferay.portal.kernel.dao.search.SearchContainer;
23 import com.liferay.portal.kernel.util.ContentTypes;
24 import com.liferay.portal.kernel.util.ParamUtil;
25 import com.liferay.portal.kernel.util.StringPool;
26 import com.liferay.portal.kernel.util.StringUtil;
27 import com.liferay.portal.model.Group;
28 import com.liferay.portal.service.GroupLocalServiceUtil;
29 import com.liferay.portal.theme.ThemeDisplay;
30 import com.liferay.portal.util.PortalUtil;
31 import com.liferay.portal.util.WebKeys;
32 import com.liferay.portlet.tags.service.TagsAssetServiceUtil;
33 import com.liferay.portlet.tags.service.TagsEntryLocalServiceUtil;
34 import com.liferay.util.RSSUtil;
35 import com.liferay.util.servlet.ServletResponseUtil;
36
37 import java.util.Date;
38
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41
42 import org.apache.struts.action.Action;
43 import org.apache.struts.action.ActionForm;
44 import org.apache.struts.action.ActionForward;
45 import org.apache.struts.action.ActionMapping;
46
47
53 public class RSSAction extends Action {
54
55 public ActionForward execute(
56 ActionMapping mapping, ActionForm form, HttpServletRequest request,
57 HttpServletResponse response)
58 throws Exception {
59
60 try {
61 ServletResponseUtil.sendFile(
62 response, null, getRSS(request), ContentTypes.TEXT_XML_UTF8);
63
64 return null;
65 }
66 catch (Exception e) {
67 PortalUtil.sendError(e, request, response);
68
69 return null;
70 }
71 }
72
73 protected byte[] getRSS(HttpServletRequest request) throws Exception {
74 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
75 WebKeys.THEME_DISPLAY);
76
77 long companyId = ParamUtil.getLong(request, "companyId");
78 long groupId = ParamUtil.getLong(request, "groupId");
79 int max = ParamUtil.getInteger(
80 request, "max", SearchContainer.DEFAULT_DELTA);
81 String type = ParamUtil.getString(
82 request, "type", RSSUtil.DEFAULT_TYPE);
83 double version = ParamUtil.getDouble(
84 request, "version", RSSUtil.DEFAULT_VERSION);
85 String displayStyle = ParamUtil.getString(
86 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
87
88 String feedURL = StringPool.BLANK;
89
90 String entryURL =
91 themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
92 "/tags/find_asset?";
93
94 String rss = StringPool.BLANK;
95
96 if (companyId > 0) {
97 rss = TagsAssetServiceUtil.getCompanyAssetsRSS(
98 companyId, max, type, version, displayStyle, feedURL, entryURL);
99 }
100 else if (groupId > 0) {
101 Group group = GroupLocalServiceUtil.getGroup(groupId);
102
103 companyId = group.getCompanyId();
104
105 long[] classNameIds = new long[0];
106
107 String[] allEntries = StringUtil.split(
108 ParamUtil.getString(request, "tags"));
109
110 long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(
111 companyId, allEntries);
112
113 String[] notEntries = StringUtil.split(
114 ParamUtil.getString(request, "noTags"));
115
116 long[] notEntryIds = TagsEntryLocalServiceUtil.getEntryIds(
117 companyId, notEntries);
118
119 boolean andOperator = false;
120 String orderByCol1 = null;
121 String orderByCol2 = null;
122 String orderByType1 = null;
123 String orderByType2 = null;
124 boolean excludeZeroViewCount = false;
125 Date publishDate = null;
126 Date expirationDate = null;
127
128 rss = TagsAssetServiceUtil.getAssetsRSS(
129 groupId, classNameIds, entryIds, notEntryIds, andOperator,
130 orderByCol1, orderByCol2, orderByType1, orderByType2,
131 excludeZeroViewCount, publishDate, expirationDate, max, type,
132 version, displayStyle, feedURL, entryURL);
133 }
134
135 return rss.getBytes(StringPool.UTF8);
136 }
137
138 }