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