1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
51   * <a href="RSSAction.java.html"><b><i>View Source</i></b></a>
52   *
53   * @author Brian Wing Shun Chan
54   */
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 }