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 request, response, null, getRSS(request),
57 ContentTypes.TEXT_XML_UTF8);
58
59 return null;
60 }
61 catch (Exception e) {
62 PortalUtil.sendError(e, request, response);
63
64 return null;
65 }
66 }
67
68 protected byte[] getRSS(HttpServletRequest request) throws Exception {
69 ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
70 WebKeys.THEME_DISPLAY);
71
72 long companyId = ParamUtil.getLong(request, "companyId");
73 long groupId = ParamUtil.getLong(request, "groupId");
74 int max = ParamUtil.getInteger(
75 request, "max", SearchContainer.DEFAULT_DELTA);
76 String type = ParamUtil.getString(
77 request, "type", RSSUtil.DEFAULT_TYPE);
78 double version = ParamUtil.getDouble(
79 request, "version", RSSUtil.DEFAULT_VERSION);
80 String displayStyle = ParamUtil.getString(
81 request, "displayStyle", RSSUtil.DISPLAY_STYLE_FULL_CONTENT);
82
83 String feedURL = StringPool.BLANK;
84
85 String entryURL =
86 themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
87 "/tags/find_asset?";
88
89 String rss = StringPool.BLANK;
90
91 if (companyId > 0) {
92 rss = TagsAssetServiceUtil.getCompanyAssetsRSS(
93 companyId, max, type, version, displayStyle, feedURL, entryURL);
94 }
95 else if (groupId > 0) {
96 Group group = GroupLocalServiceUtil.getGroup(groupId);
97
98 companyId = group.getCompanyId();
99
100 long[] classNameIds = new long[0];
101
102 String[] allEntries = StringUtil.split(
103 ParamUtil.getString(request, "tags"));
104
105 long[] entryIds = TagsEntryLocalServiceUtil.getEntryIds(
106 companyId, allEntries);
107
108 String[] notEntries = StringUtil.split(
109 ParamUtil.getString(request, "noTags"));
110
111 long[] notEntryIds = TagsEntryLocalServiceUtil.getEntryIds(
112 companyId, notEntries);
113
114 boolean andOperator = false;
115 String orderByCol1 = null;
116 String orderByCol2 = null;
117 String orderByType1 = null;
118 String orderByType2 = null;
119 boolean excludeZeroViewCount = false;
120 Date publishDate = null;
121 Date expirationDate = null;
122
123 rss = TagsAssetServiceUtil.getAssetsRSS(
124 groupId, classNameIds, entryIds, notEntryIds, andOperator,
125 orderByCol1, orderByCol2, orderByType1, orderByType2,
126 excludeZeroViewCount, publishDate, expirationDate, max, type,
127 version, displayStyle, feedURL, entryURL);
128 }
129
130 return rss.getBytes(StringPool.UTF8);
131 }
132
133 }