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