1   /**
2    * Copyright (c) 2000-2007 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.JournalStructure;
31  import com.liferay.portlet.journal.model.JournalTemplate;
32  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
33  import com.liferay.portlet.journal.service.JournalArticleServiceUtil;
34  import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
35  import com.liferay.portlet.journal.service.JournalTemplateServiceUtil;
36  import com.liferay.portlet.journal.util.JournalUtil;
37  
38  import javax.portlet.ActionRequest;
39  import javax.portlet.RenderRequest;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  /**
44   * <a href="ActionUtil.java.html"><b><i>View Source</i></b></a>
45   *
46   * @author Brian Wing Shun Chan
47   *
48   */
49  public class ActionUtil {
50  
51      public static void getArticle(ActionRequest req) throws Exception {
52          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
53  
54          getArticle(httpReq);
55  
56          JournalArticle article =
57              (JournalArticle)req.getAttribute(WebKeys.JOURNAL_ARTICLE);
58  
59          JournalUtil.addRecentArticle(req, article);
60      }
61  
62      public static void getArticle(RenderRequest req) throws Exception {
63          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
64  
65          getArticle(httpReq);
66  
67          JournalArticle article =
68              (JournalArticle)req.getAttribute(WebKeys.JOURNAL_ARTICLE);
69  
70          JournalUtil.addRecentArticle(req, article);
71      }
72  
73      public static void getArticle(HttpServletRequest req) throws Exception {
74          long groupId = ParamUtil.getLong(req, "groupId");
75          String articleId = ParamUtil.getString(req, "articleId");
76          double version = ParamUtil.getDouble(
77              req, "version", JournalArticleImpl.DEFAULT_VERSION);
78  
79          JournalArticle article = null;
80  
81          if (Validator.isNotNull(articleId)) {
82              article = JournalArticleServiceUtil.getArticle(
83                  groupId, articleId, version);
84          }
85  
86          req.setAttribute(WebKeys.JOURNAL_ARTICLE, article);
87      }
88  
89      public static void getStructure(ActionRequest req) throws Exception {
90          HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
91  
92          getStructure(httpReq);
93  
94          JournalStructure structure =
95              (JournalStructure)req.getAttribute(WebKeys.JOURNAL_STRUCTURE);
96  
97          JournalUtil.addRecentStructure(req, structure);
98      }
99  
100     public static void getStructure(RenderRequest req) throws Exception {
101         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
102 
103         getStructure(httpReq);
104 
105         JournalStructure structure =
106             (JournalStructure)req.getAttribute(WebKeys.JOURNAL_STRUCTURE);
107 
108         JournalUtil.addRecentStructure(req, structure);
109     }
110 
111     public static void getStructure(HttpServletRequest req) throws Exception {
112         long groupId = ParamUtil.getLong(req, "groupId");
113         String structureId = ParamUtil.getString(req, "structureId");
114 
115         JournalStructure structure = null;
116 
117         if (Validator.isNotNull(structureId)) {
118             structure = JournalStructureServiceUtil.getStructure(
119                 groupId, structureId);
120         }
121 
122         req.setAttribute(WebKeys.JOURNAL_STRUCTURE, structure);
123     }
124 
125     public static void getTemplate(ActionRequest req) throws Exception {
126         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
127 
128         getTemplate(httpReq);
129 
130         JournalTemplate template =
131             (JournalTemplate)req.getAttribute(WebKeys.JOURNAL_TEMPLATE);
132 
133         JournalUtil.addRecentTemplate(req, template);
134     }
135 
136     public static void getTemplate(RenderRequest req) throws Exception {
137         HttpServletRequest httpReq = PortalUtil.getHttpServletRequest(req);
138 
139         getTemplate(httpReq);
140 
141         JournalTemplate template =
142             (JournalTemplate)req.getAttribute(WebKeys.JOURNAL_TEMPLATE);
143 
144         JournalUtil.addRecentTemplate(req, template);
145     }
146 
147     public static void getTemplate(HttpServletRequest req) throws Exception {
148         long groupId = ParamUtil.getLong(req, "groupId");
149         String templateId = ParamUtil.getString(req, "templateId");
150 
151         JournalTemplate template = null;
152 
153         if (Validator.isNotNull(templateId)) {
154             template = JournalTemplateServiceUtil.getTemplate(
155                 groupId, templateId);
156         }
157 
158         req.setAttribute(WebKeys.JOURNAL_TEMPLATE, template);
159     }
160 
161 }