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.blogs.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.blogs.model.BlogsEntry;
28  import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
29  import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission;
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  
34  /**
35   * <a href="BlogsActivityInterpreter.java.html"><b><i>View Source</i></b></a>
36   *
37   * @author Brian Wing Shun Chan
38   * @author Ryan Park
39   *
40   */
41  public class BlogsActivityInterpreter extends BaseSocialActivityInterpreter {
42  
43      public String[] getClassNames() {
44          return _CLASS_NAMES;
45      }
46  
47      protected SocialActivityFeedEntry doInterpret(
48              SocialActivity activity, ThemeDisplay themeDisplay)
49          throws Exception {
50  
51          PermissionChecker permissionChecker =
52              themeDisplay.getPermissionChecker();
53  
54          if (!BlogsEntryPermission.contains(
55                  permissionChecker, activity.getClassPK(), ActionKeys.VIEW)) {
56  
57              return null;
58          }
59  
60          String groupName = StringPool.BLANK;
61  
62          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
63              groupName = getGroupName(activity.getGroupId(), themeDisplay);
64          }
65  
66          String creatorUserName = getUserName(
67              activity.getUserId(), themeDisplay);
68          String receiverUserName = getUserName(
69              activity.getReceiverUserId(), themeDisplay);
70  
71          int activityType = activity.getType();
72  
73          // Link
74  
75          BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(
76              activity.getClassPK());
77  
78          String link =
79              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
80                  "/blogs/find_entry?entryId=" + activity.getClassPK();
81  
82          // Title
83  
84          String titlePattern = null;
85  
86          if (activityType == BlogsActivityKeys.ADD_COMMENT) {
87              titlePattern = "activity-blogs-add-comment";
88          }
89          else if (activityType == BlogsActivityKeys.ADD_ENTRY) {
90              titlePattern = "activity-blogs-add-entry";
91          }
92  
93          if (Validator.isNotNull(groupName)) {
94              titlePattern += "-in";
95          }
96  
97          String entryTitle = wrapLink(link, cleanContent(entry.getTitle()));
98  
99          Object[] titleArguments = new Object[] {
100             groupName, creatorUserName, receiverUserName, entryTitle
101         };
102 
103         String title = themeDisplay.translate(titlePattern, titleArguments);
104 
105         // Body
106 
107         String body = StringPool.BLANK;
108 
109         return new SocialActivityFeedEntry(link, title, body);
110     }
111 
112     private static final String[] _CLASS_NAMES = new String[] {
113         BlogsEntry.class.getName()
114     };
115 
116 }