View Javadoc
1   /**
2    * Copyright (C) 2012 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 2.1 of
7    * the License, or (at your option) any later version.
8    *
9    * This software is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  package org.exoplatform.platform.navigation.component.help;
20  
21  import org.exoplatform.platform.navigation.component.utils.DashboardUtils;
22  import org.exoplatform.platform.navigation.component.utils.NavigationUtils;
23  import org.exoplatform.portal.mop.SiteKey;
24  import org.exoplatform.portal.mop.SiteType;
25  import org.exoplatform.portal.mop.user.UserNode;
26  import org.exoplatform.portal.webui.util.Util;
27  import org.exoplatform.services.log.ExoLogger;
28  import org.exoplatform.services.log.Log;
29  import org.exoplatform.social.core.space.model.Space;
30  import org.exoplatform.social.core.space.spi.SpaceService;
31  import org.exoplatform.social.webui.Utils;
32  
33  /**
34   * @author <a href="kmenzli@exoplatform.com">Kmenzli</a>
35   */
36  
37  public class Helper {
38  
39      private static final Log LOG = ExoLogger.getExoLogger(Helper.class);
40      public static final String DEFAULT_HELP_ID = "default";
41  
42      public static boolean present (String theString) {
43          boolean present = false;
44          if (theString != null && theString.length()!=0) {
45              present = true;
46          }
47          return present;
48      }
49  
50      public static String getCurrentNavigation(SpaceService spaceService){
51          try {
52              String nav=Util.getUIPortal().getNavPath().getName();
53              String url = Util.getPortalRequestContext().getRequest().getRequestURL().toString();
54              if((url.contains("/:spaces:"))||(url.contains("/spaces/")))   {
55                  if(url.contains("documents"))  {
56                      return "space:document";
57                  }
58                  else if(url.contains("wiki")) {
59                      return "space:wiki";
60                  }
61                  else if(url.contains("tasks")) {
62                      return "space:tasks";
63                  }
64                  else if((url.toLowerCase().contains("answer"))||(url.contains("faq")) || (url.contains("poll"))) {
65                      return "space:faq_annswer";
66                  }
67                  else if(url.contains("calendar")) {
68                      return "space:calendar";
69                  }
70                  else if(url.contains("forum")) {
71                      return "space:forum";
72                  }
73                  else if(nav.equals("settings")) {
74                      return "space:manager";
75                  }
76                  else {
77                          String spaceUrl=getSelectedPageNode().getURI();
78                          Space space = spaceService.getSpaceByUrl(spaceUrl);
79                          if (space != null) {
80                              if(space.getPrettyName().equals(nav)){
81                                  return "space:activity_stream";
82                              }
83                          } else {
84                              return DEFAULT_HELP_ID;
85                          }
86                      }
87                  }
88              else if(url.contains("wiki")&&(isProfileOwner())){
89                  return "personnal:wiki";
90              }
91              else if((url.contains("profile"))&&(isProfileOwner())){
92                  return "personnal:profile";
93              }
94              else if((url.contains("connections"))&&(isProfileOwner())){
95                  return "personnal:connections";
96              }
97              else if((url.contains("activities"))&&(isProfileOwner())){
98                return "personnal:activities";
99              }
100             else if((url.contains("notifications"))&&(isProfileOwner())){
101               return "personnal:notifications";
102             }
103             else if(url.contains("all-spaces")){
104                 return "personnal:all-spaces";
105             }
106             else if((nav!=null)&&(nav.equals("home"))){
107              if((SiteKey.portal(getCurrentPortal())!=null) &&(SiteKey.portal(getCurrentPortal()).getName().equals("intranet"))){
108                     return "Company Context Home";
109               }
110             }
111             else if((nav!=null)&&(nav.equals("calendar"))){
112                 return "Company Context Calendar";
113             }
114             else if((nav!=null)&&(nav.equals("forum"))){
115                 return "Company Context Forum";
116             }
117             else if((nav!=null)&&(nav.equals("wiki"))){
118                 return "Company Context Wiki";
119             }
120             else if((nav!=null)&&(nav.equals("tasks"))){
121                 return "Company Context Tasks";
122             }
123             else if((nav!=null)&&(nav.equals("documents"))){
124                 return "Company Context Documents";
125             }
126             else if((nav!=null)&&((nav.equals("FAQ"))||(nav.equals("answers")))){
127                 return "Company Context FAQ:Answers";
128             }
129             else if((nav!=null)&&((nav.equals("connexions")))){
130                 return "Company Context Connections";
131             }
132             SiteType siteType = Util.getUIPortal().getSiteType();
133             if (siteType != null && siteType.equals(SiteType.USER)) {
134               String dashboardUrl = DashboardUtils.getDashboardURL();
135               if(url.contains(dashboardUrl.substring(0, dashboardUrl.lastIndexOf("/")))){
136                   return "dashboard";
137               }
138             }
139             return DEFAULT_HELP_ID;
140         } catch (Exception E) {
141             LOG.warn("Can not load the currentNavigation ", E);
142             return null;
143         }
144     }
145     public static boolean isProfileOwner() {
146         return Utils.getViewerRemoteId().equals(NavigationUtils.getCurrentUser());
147     }
148     public static String getCurrentPortal()
149     {
150         return Util.getPortalRequestContext().getPortalOwner();
151     }
152     public static UserNode getSelectedPageNode() throws Exception {
153         return Util.getUIPortal().getSelectedUserNode();
154     }
155 }