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.calendar.social;
21  
22  import com.liferay.portal.kernel.util.StringPool;
23  import com.liferay.portal.kernel.util.Validator;
24  import com.liferay.portal.model.Group;
25  import com.liferay.portal.service.GroupLocalServiceUtil;
26  import com.liferay.portal.theme.ThemeDisplay;
27  import com.liferay.portlet.calendar.model.CalEvent;
28  import com.liferay.portlet.calendar.service.CalEventLocalServiceUtil;
29  import com.liferay.portlet.social.model.BaseSocialActivityInterpreter;
30  import com.liferay.portlet.social.model.SocialActivity;
31  import com.liferay.portlet.social.model.SocialActivityFeedEntry;
32  
33  /**
34   * <a href="CalendarActivityInterpreter.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class CalendarActivityInterpreter extends BaseSocialActivityInterpreter {
40  
41      public String[] getClassNames() {
42          return _CLASS_NAMES;
43      }
44  
45      protected SocialActivityFeedEntry doInterpret(
46              SocialActivity activity, ThemeDisplay themeDisplay)
47          throws Exception {
48  
49          String creatorUserName = getUserName(
50              activity.getUserId(), themeDisplay);
51  
52          int activityType = activity.getType();
53  
54          // Link
55  
56          CalEvent event = CalEventLocalServiceUtil.getEvent(
57              activity.getClassPK());
58  
59          String link =
60              themeDisplay.getURLPortal() + themeDisplay.getPathMain() +
61                  "/calendar/find_event?eventId=" + activity.getClassPK();
62  
63          // Title
64  
65          String groupName = StringPool.BLANK;
66  
67          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
68              Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
69  
70              groupName = group.getDescriptiveName();
71          }
72  
73          String titlePattern = null;
74          Object[] titleArguments = null;
75  
76          if (activityType == CalendarActivityKeys.ADD_EVENT) {
77              titlePattern = "activity-calendar-add-event";
78  
79              if (Validator.isNotNull(groupName)) {
80                  titlePattern += "-in";
81              }
82  
83              titleArguments = new Object[] {creatorUserName, groupName};
84          }
85          else if (activityType == CalendarActivityKeys.UPDATE_EVENT) {
86              titlePattern = "activity-calendar-update-event";
87  
88              if (Validator.isNotNull(groupName)) {
89                  titlePattern += "-in";
90              }
91  
92              titleArguments = new Object[] {creatorUserName, groupName};
93          }
94  
95          String title = themeDisplay.translate(titlePattern, titleArguments);
96  
97          // Body
98  
99          StringBuilder sb = new StringBuilder();
100 
101         sb.append("<a href=\"");
102         sb.append(link);
103         sb.append("\">");
104         sb.append(cleanContent(event.getTitle()));
105         sb.append("</a><br />");
106         sb.append(cleanContent(event.getDescription()));
107 
108         String body = sb.toString();
109 
110         return new SocialActivityFeedEntry(link, title, body);
111     }
112 
113     private static final String[] _CLASS_NAMES = new String[] {
114         CalEvent.class.getName()
115     };
116 
117 }