1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
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  /**
43   * <a href="RSSAction.java.html"><b><i>View Source</i></b></a>
44   *
45   * @author Brian Wing Shun Chan
46   */
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 }