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