1   /**
2    * Copyright (c) 2000-2010 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   *
12   *
13   */
14  
15  package com.liferay.portlet.documentlibrary.social;
16  
17  import com.liferay.portal.kernel.util.HtmlUtil;
18  import com.liferay.portal.kernel.util.StringBundler;
19  import com.liferay.portal.kernel.util.StringPool;
20  import com.liferay.portal.kernel.util.Validator;
21  import com.liferay.portal.security.permission.ActionKeys;
22  import com.liferay.portal.security.permission.PermissionChecker;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portlet.documentlibrary.model.DLFileEntry;
25  import com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil;
26  import com.liferay.portlet.documentlibrary.service.permission.DLFileEntryPermission;
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  
31  /**
32   * <a href="DLActivityInterpreter.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Ryan Park
35   */
36  public class DLActivityInterpreter extends BaseSocialActivityInterpreter {
37  
38      public String[] getClassNames() {
39          return _CLASS_NAMES;
40      }
41  
42      protected SocialActivityFeedEntry doInterpret(
43              SocialActivity activity, ThemeDisplay themeDisplay)
44          throws Exception {
45  
46          PermissionChecker permissionChecker =
47              themeDisplay.getPermissionChecker();
48  
49          DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getDLFileEntry(
50              activity.getClassPK());
51  
52          if (!DLFileEntryPermission.contains(
53                  permissionChecker, fileEntry, ActionKeys.VIEW)) {
54  
55              return null;
56          }
57  
58          String groupName = StringPool.BLANK;
59  
60          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
61              groupName = getGroupName(activity.getGroupId(), themeDisplay);
62          }
63  
64          String creatorUserName = getUserName(
65              activity.getUserId(), themeDisplay);
66  
67          int activityType = activity.getType();
68  
69          // Link
70  
71          String link =
72              themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
73                  "/document_library/get_file?folderId=" +
74                      fileEntry.getFolderId() + "&name=" + fileEntry.getName();
75  
76          // Title
77  
78          String titlePattern = null;
79  
80          if (activityType == DLActivityKeys.ADD_FILE_ENTRY) {
81              titlePattern = "activity-document-library-add-file";
82          }
83          else if (activityType == DLActivityKeys.UPDATE_FILE_ENTRY) {
84              titlePattern = "activity-document-library-update-file";
85          }
86  
87          if (Validator.isNotNull(groupName)) {
88              titlePattern += "-in";
89          }
90  
91          String fileTitle = wrapLink(
92              link, HtmlUtil.escape(cleanContent(fileEntry.getTitle())));
93  
94          Object[] titleArguments = new Object[] {
95              groupName, creatorUserName, fileTitle
96          };
97  
98          String title = themeDisplay.translate(titlePattern, titleArguments);
99  
100         // Body
101 
102         StringBundler sb = new StringBundler(3);
103 
104         String fileEntryLink =
105             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
106                 "/document_library/find_file_entry?fileEntryId=" +
107                     fileEntry.getFileEntryId();
108 
109         sb.append(wrapLink(fileEntryLink, "view-document", themeDisplay));
110         sb.append(StringPool.SPACE);
111 
112         String folderLink =
113             themeDisplay.getPortalURL() + themeDisplay.getPathMain() +
114                 "/document_library/find_folder?folderId=" +
115                     fileEntry.getFolderId();
116 
117         sb.append(wrapLink(folderLink, "go-to-folder", themeDisplay));
118 
119         String body = sb.toString();
120 
121         return new SocialActivityFeedEntry(link, title, body);
122     }
123 
124     private static final String[] _CLASS_NAMES = new String[] {
125         DLFileEntry.class.getName()
126     };
127 
128 }