1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.wiki.social;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.Validator;
24  import com.liferay.portal.security.permission.ActionKeys;
25  import com.liferay.portal.security.permission.PermissionChecker;
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  import com.liferay.portlet.wiki.service.permission.WikiPagePermission;
34  
35  /**
36   * <a href="WikiActivityInterpreter.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Samuel Kong
39   * @author Ryan Park
40   *
41   */
42  public class WikiActivityInterpreter extends BaseSocialActivityInterpreter {
43  
44      public String[] getClassNames() {
45          return _CLASS_NAMES;
46      }
47  
48      protected SocialActivityFeedEntry doInterpret(
49              SocialActivity activity, ThemeDisplay themeDisplay)
50          throws Exception {
51  
52          PermissionChecker permissionChecker =
53              themeDisplay.getPermissionChecker();
54  
55          if (!WikiPagePermission.contains(
56                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
57  
58              return null;
59          }
60  
61          String groupName = StringPool.BLANK;
62  
63          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
64              groupName = getGroupName(activity.getGroupId(), themeDisplay);
65          }
66  
67          String creatorUserName = getUserName(
68              activity.getUserId(), themeDisplay);
69  
70          int activityType = activity.getType();
71  
72          // Link
73  
74          WikiPageResource pageResource =
75              WikiPageResourceLocalServiceUtil.getPageResource(
76                  activity.getClassPK());
77  
78          String link =
79              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
80                  "/wiki/find_page?pageResourcePrimKey=" + activity.getClassPK();
81  
82          // Title
83  
84          String titlePattern = null;
85  
86          if (activityType == WikiActivityKeys.ADD_PAGE) {
87              titlePattern = "activity-wiki-add-page";
88          }
89          else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
90              titlePattern = "activity-wiki-update-page";
91          }
92  
93          if (Validator.isNotNull(groupName)) {
94              titlePattern += "-in";
95          }
96  
97          String pageTitle = wrapLink(
98              link, cleanContent(pageResource.getTitle()));
99  
100         Object[] titleArguments = new Object[] {
101             groupName, creatorUserName, pageTitle
102         };
103 
104         String title = themeDisplay.translate(titlePattern, titleArguments);
105 
106         // Body
107 
108         String body = StringPool.BLANK;
109 
110         return new SocialActivityFeedEntry(link, title, body);
111     }
112 
113     private static final String[] _CLASS_NAMES = new String[] {
114         WikiPage.class.getName()
115     };
116 
117 }