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.wiki.social;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
28  import com.liferay.portlet.social.model.SocialActivity;
29  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
30  import com.liferay.portlet.wiki.model.WikiPage;
31  import com.liferay.portlet.wiki.model.WikiPageResource;
32  import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
33  
34  /**
35   * <a href="WikiActivityInterpreter.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Samuel Kong
38   *
39   */
40  public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
41  
42      public String[] getClassNames() {
43          return _CLASS_NAMES;
44      }
45  
46      protected SocialActivityFeedEntry doInterpret(
47              SocialActivity activity, ThemeDisplay themeDisplay)
48          throws Exception {
49  
50          String creatorUserName = getUserName(
51              activity.getUserId(), themeDisplay);
52  
53          int activityType = activity.getType();
54  
55          // Link
56  
57          WikiPageResource pageResource =
58              WikiPageResourceLocalServiceUtil.getPageResource(
59                  activity.getClassPK());
60  
61          String link =
62              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
63                  "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
64  
65          // Title
66  
67          String title = StringPool.BLANK;
68  
69          if (activityType == WikiActivityKeys.ADD_PAGE) {
70              title = themeDisplay.translate(
71                  "activity-wiki-add-page", creatorUserName);
72          }
73          else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
74              title = themeDisplay.translate(
75                  "activity-wiki-update-page", creatorUserName);
76          }
77  
78          // Body
79  
80          StringBuilder sb = new StringBuilder();
81  
82          sb.append("<a href=\"");
83          sb.append(link);
84          sb.append("\">");
85          sb.append(cleanContent(pageResource.getTitle()));
86          sb.append("</a>");
87  
88          String body = sb.toString();
89  
90          return new SocialActivityFeedEntry(link, title, body);
91      }
92  
93      private static final String[] _CLASS_NAMES = new String[] {
94          WikiPage.class.getName()
95      };
96  
97  }