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.model.Group;
25  import com.liferay.portal.service.GroupLocalServiceUtil;
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 groupName = StringPool.BLANK;
68  
69          if (activity.getGroupId() != themeDisplay.getScopeGroupId()) {
70              Group group = GroupLocalServiceUtil.getGroup(activity.getGroupId());
71              groupName = group.getDescriptiveName();
72          }
73  
74          String titlePattern = null;
75          Object[] titleArguments = null;
76  
77          if (activityType == WikiActivityKeys.ADD_PAGE) {
78              titlePattern = "activity-wiki-add-page";
79  
80              if (Validator.isNotNull(groupName)) {
81                  titlePattern += "-in";
82              }
83  
84              titleArguments = new Object[] {creatorUserName, groupName};
85          }
86          else if (activityType == WikiActivityKeys.UPDATE_PAGE) {
87              titlePattern = "activity-wiki-update-page";
88  
89              if (Validator.isNotNull(groupName)) {
90                  titlePattern += "-in";
91              }
92  
93              titleArguments = new Object[] {creatorUserName, groupName};
94          }
95  
96          String title = themeDisplay.translate(titlePattern, titleArguments);
97  
98          // Body
99  
100         StringBuilder sb = new StringBuilder();
101 
102         sb.append("<a href=\"");
103         sb.append(link);
104         sb.append("\">");
105         sb.append(cleanContent(pageResource.getTitle()));
106         sb.append("</a>");
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         WikiPage.class.getName()
115     };
116 
117 }