1   /**
2    * Copyright (c) 2000-2009 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.wiki.social;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.security.permission.ActionKeys;
28  import com.liferay.portal.security.permission.PermissionChecker;
29  import com.liferay.portal.theme.ThemeDisplay;
30  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
31  import com.liferay.portlet.social.model.SocialActivity;
32  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
33  import com.liferay.portlet.wiki.model.WikiPage;
34  import com.liferay.portlet.wiki.model.WikiPageResource;
35  import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
36  import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
37  
38  /**
39   * <a href="WikiActivityInterpreter.java.html"><b><i>View Source</i></b></a>
40   *
41   * @author Samuel Kong
42   * @author Ryan Park
43   *
44   */
45  public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
46  
47      public String[] getClassNames() {
48          return _CLASS_NAMES;
49      }
50  
51      protected SocialActivityFeedEntry doInterpret(
52              SocialActivity activity, ThemeDisplay themeDisplay)
53          throws Exception {
54  
55          PermissionChecker permissionChecker =
56              themeDisplay.getPermissionChecker();
57  
58          if (!WikiPagePermission.contains(
59                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
60  
61              return null;
62          }
63  
64          String groupName = StringPool.BLANK;
65  
66          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
67              groupName = getGroupName(activity.getGroupId(), themeDisplay);
68          }
69  
70          String creatorUserName = getUserName(
71              activity.getUserId(), themeDisplay);
72  
73          int activityType = activity.getType();
74  
75          // Link
76  
77          WikiPageResource pageResource =
78              WikiPageResourceLocalServiceUtil.getPageResource(
79                  activity.getClassPK());
80  
81          String link =
82              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
83                  "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
84  
85          // Title
86  
87          String titlePattern = null;
88  
89          if (activityType == WikiActivityKeys.ADD_PAGE) {
90              titlePattern = "activity-wiki-add-page";
91          }
92          else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
93              titlePattern = "activity-wiki-update-page";
94          }
95  
96          if (Validator.isNotNull(groupName)) {
97              titlePattern += "-in";
98          }
99  
100         String pageTitle = wrapLink(
101             link, cleanContent(pageResource.getTitle()));
102 
103         Object[] titleArguments = new Object[] {
104             groupName, creatorUserName, pageTitle
105         };
106 
107         String title = themeDisplay.translate(titlePattern, titleArguments);
108 
109         // Body
110 
111         String body = StringPool.BLANK;
112 
113         return new SocialActivityFeedEntry(link, title, body);
114     }
115 
116     private static final String[] _CLASS_NAMES = new String[] {
117         WikiPage.class.getName()
118     };
119 
120 }