1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.journal.action;
24  
25  import com.liferay.portal.kernel.util.ParamUtil;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.util.PortalUtil;
28  import com.liferay.portal.util.WebKeys;
29  import com.liferay.portlet.journal.model.JournalArticle;
30  import com.liferay.portlet.journal.model.JournalFeed;
31  import com.liferay.portlet.journal.model.JournalStructure;
32  import com.liferay.portlet.journal.model.JournalTemplate;
33  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
34  import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
35  import com.liferay.portlet.journal.service.JournalFeedServiceUtil;
36  import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
37  import com.liferay.portlet.journal.service.JournalTemplateServiceUtil;
38  import com.liferay.portlet.journal.util.JournalUtil;
39  
40  import javax.portlet.ActionRequest;
41  import javax.portlet.RenderRequest;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  /**
46   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   */
51  public class ActionUtil {
52  
53      public static void getArticle(ActionRequest req) throws Exception {
54          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
55  
56          getArticle(httpReq);
57  
58          JournalArticle article =
59              (JournalArticle)req.getAttribute(WebKeys.JOURNAL_ARTICLE);
60  
61          JournalUtil.addRecentArticle(req, article);
62      }
63  
64      public static void getArticle(RenderRequest req) throws Exception {
65          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
66  
67          getArticle(httpReq);
68  
69          JournalArticle article =
70              (JournalArticle)req.getAttribute(WebKeys.JOURNAL_ARTICLE);
71  
72          JournalUtil.addRecentArticle(req, article);
73      }
74  
75      public static void getArticle(HttpServletRequest req) throws Exception {
76          long groupId = ParamUtil.getLong(req, "groupId");
77          String articleId = ParamUtil.getString(req, "articleId");
78          double version = ParamUtil.getDouble(
79              req, "version", JournalArticleImpl.DEFAULT_VERSION);
80  
81          JournalArticle article = null;
82  
83          if (Validator.isNotNull(articleId)) {
84              article = JournalArticleServiceUtil.getArticle(
85                  groupId, articleId, version);
86          }
87  
88          req.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
89      }
90  
91      public static void getFeed(ActionRequest req) throws Exception {
92          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
93  
94          getFeed(httpReq);
95      }
96  
97      public static void getFeed(RenderRequest req) throws Exception {
98          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
99  
100         getFeed(httpReq);
101     }
102 
103     public static void getFeed(HttpServletRequest req) throws Exception {
104         long groupId = ParamUtil.getLong(req, "groupId");
105         String feedId = ParamUtil.getString(req, "feedId");
106 
107         JournalFeed feed = null;
108 
109         if (Validator.isNotNull(feedId)) {
110             feed = JournalFeedServiceUtil.getFeed(groupId, feedId);
111         }
112 
113         req.setAttribute(WebKeys.JOURNAL_FEED, feed);
114     }
115 
116     public static void getStructure(ActionRequest req) throws Exception {
117         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
118 
119         getStructure(httpReq);
120 
121         JournalStructure structure =
122             (JournalStructure)req.getAttribute(WebKeys.JOURNAL_STRUCTURE);
123 
124         JournalUtil.addRecentStructure(req, structure);
125     }
126 
127     public static void getStructure(RenderRequest req) throws Exception {
128         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
129 
130         getStructure(httpReq);
131 
132         JournalStructure structure =
133             (JournalStructure)req.getAttribute(WebKeys.JOURNAL_STRUCTURE);
134 
135         JournalUtil.addRecentStructure(req, structure);
136     }
137 
138     public static void getStructure(HttpServletRequest req) throws Exception {
139         long groupId = ParamUtil.getLong(req, "groupId");
140         String structureId = ParamUtil.getString(req, "structureId");
141 
142         JournalStructure structure = null;
143 
144         if (Validator.isNotNull(structureId)) {
145             structure = JournalStructureServiceUtil.getStructure(
146                 groupId, structureId);
147         }
148 
149         req.setAttribute(WebKeys.JOURNAL_STRUCTURE, structure);
150     }
151 
152     public static void getTemplate(ActionRequest req) throws Exception {
153         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
154 
155         getTemplate(httpReq);
156 
157         JournalTemplate template =
158             (JournalTemplate)req.getAttribute(WebKeys.JOURNAL_TEMPLATE);
159 
160         JournalUtil.addRecentTemplate(req, template);
161     }
162 
163     public static void getTemplate(RenderRequest req) throws Exception {
164         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
165 
166         getTemplate(httpReq);
167 
168         JournalTemplate template =
169             (JournalTemplate)req.getAttribute(WebKeys.JOURNAL_TEMPLATE);
170 
171         JournalUtil.addRecentTemplate(req, template);
172     }
173 
174     public static void getTemplate(HttpServletRequest req) throws Exception {
175         long groupId = ParamUtil.getLong(req, "groupId");
176         String templateId = ParamUtil.getString(req, "templateId");
177 
178         JournalTemplate template = null;
179 
180         if (Validator.isNotNull(templateId)) {
181             template = JournalTemplateServiceUtil.getTemplate(
182                 groupId, templateId);
183         }
184 
185         req.setAttribute(WebKeys.JOURNAL_TEMPLATE, template);
186     }
187 
188 }