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.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  public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
45  
46      public String[] getClassNames() {
47          return _CLASS_NAMES;
48      }
49  
50      protected SocialActivityFeedEntry doInterpret(
51              SocialActivity activity, ThemeDisplay themeDisplay)
52          throws Exception {
53  
54          PermissionChecker permissionChecker =
55              themeDisplay.getPermissionChecker();
56  
57          if (!WikiPagePermission.contains(
58                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
59  
60              return null;
61          }
62  
63          String groupName = StringPool.BLANK;
64  
65          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
66              groupName = getGroupName(activity.getGroupId(), themeDisplay);
67          }
68  
69          String creatorUserName = getUserName(
70              activity.getUserId(), themeDisplay);
71  
72          int activityType = activity.getType();
73  
74          // Link
75  
76          WikiPageResource pageResource =
77              WikiPageResourceLocalServiceUtil.getPageResource(
78                  activity.getClassPK());
79  
80          String link =
81              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
82                  "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
83  
84          // Title
85  
86          String titlePattern = null;
87  
88          if (activityType == WikiActivityKeys.ADD_PAGE) {
89              titlePattern = "activity-wiki-add-page";
90          }
91          else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
92              titlePattern = "activity-wiki-update-page";
93          }
94  
95          if (Validator.isNotNull(groupName)) {
96              titlePattern += "-in";
97          }
98  
99          String pageTitle = wrapLink(
100             link, cleanContent(pageResource.getTitle()));
101 
102         Object[] titleArguments = new Object[] {
103             groupName, creatorUserName, pageTitle
104         };
105 
106         String title = themeDisplay.translate(titlePattern, titleArguments);
107 
108         // Body
109 
110         String body = StringPool.BLANK;
111 
112         return new SocialActivityFeedEntry(link, title, body);
113     }
114 
115     private static final String[] _CLASS_NAMES = new String[] {
116         WikiPage.class.getName()
117     };
118 
119 }