public void onStartRequest(final Application app, final WebuiRequestContext context)
      throws Exception {
    PortalRequestContext pcontext = (PortalRequestContext) context;
    String requestPath =
        pcontext.getControllerContext().getParameter(RequestNavigationData.REQUEST_PATH);
    if (pcontext.getSiteType().equals(SiteType.GROUP)
        && pcontext.getSiteName().startsWith("/spaces")
        && (requestPath != null)
        && (requestPath.length() > 0)) {

      // Check if user want to access to wiki application
      String currentUser = Utils.getCurrentUser();
      String[] params = requestPath.split("/");
      if ((params.length > 1) && params[1].equals(WIKI_PORTLET_NAME)) {
        String spaceId = params[0];
        String owner = "/spaces/" + spaceId;
        String pageId = "WikiHome";
        if (params.length > 2) {
          pageId = params[2];
        }

        // Get page
        WikiService wikiService = (WikiService) PortalContainer.getComponent(WikiService.class);

        // If user is not member of space but has view permission
        if (!wikiService.isHiddenSpace(owner) && !wikiService.isSpaceMember(spaceId, currentUser)) {
          WikiPageParams wikiPageParams =
              new WikiPageParams(PortalConfig.GROUP_TYPE, owner, pageId);
          String permalink = Utils.getPermanlink(wikiPageParams);
          redirect(permalink);
        }
      }
    }
  }
 public SelectOptionGroup getGroupWikiOptions() throws Exception {
   SelectOptionGroup groupSpaceOptions = new SelectOptionGroup(getLabel("GroupWikis"));
   Collection<Wiki> groupWikis = Utils.getWikisByType(WikiType.GROUP);
   for (Wiki wiki : groupWikis) {
     groupSpaceOptions.addOption(
         new SelectOption(
             wiki.getOwner(),
             PortalConfig.GROUP_TYPE
                 + "/"
                 + Utils.validateWikiOwner(wiki.getType(), wiki.getOwner())));
   }
   return groupSpaceOptions;
 }
 public SelectOptionGroup getPortalWikiOptions() throws Exception {
   SelectOptionGroup portalSpaceOptions = new SelectOptionGroup(getLabel("PortalWikis"));
   Collection<Wiki> portalWikis = Utils.getWikisByType(WikiType.PORTAL);
   for (Wiki wiki : portalWikis) {
     portalSpaceOptions.addOption(
         new SelectOption(wiki.getOwner(), PortalConfig.PORTAL_TYPE + "/" + wiki.getOwner()));
   }
   return portalSpaceOptions;
 }
 public SelectOptionGroup getUserWikiOptions() throws Exception {
   SelectOptionGroup userSpaceOptions = new SelectOptionGroup(getLabel("UserWikis"));
   Collection<Wiki> userWikis = Utils.getWikisByType(WikiType.USER);
   for (Wiki wiki : userWikis) {
     userSpaceOptions.addOption(
         new SelectOption(wiki.getOwner(), PortalConfig.USER_TYPE + "/" + wiki.getOwner()));
   }
   return userSpaceOptions;
 }
 public static List<JsonRelatedData> pageToJson(List<Page> pages) {
   List<JsonRelatedData> jsonObjs = new ArrayList<>();
   for (Page page : pages) {
     String name = page.getName();
     String title = page.getTitle();
     String path = TreeUtils.getPathFromPageParams(Utils.getWikiPageParams(page));
     JsonRelatedData dataObj = new JsonRelatedData(name, title, path);
     jsonObjs.add(dataObj);
   }
   return jsonObjs;
 }
 /**
  * convert wiki page info to path string. <br>
  * The format: [wiki type]/[wiki owner]/[page id]
  *
  * @param params
  * @return
  */
 public static String getPath(WikiPageParams params) {
   StringBuilder sb = new StringBuilder();
   if (params.getType() != null) {
     sb.append(params.getType());
   }
   if (params.getOwner() != null) {
     sb.append("/").append(Utils.validateWikiOwner(params.getType(), params.getOwner()));
   }
   if (params.getPageName() != null) {
     sb.append("/").append(params.getPageName());
   }
   return sb.toString();
 }
 private String getDefaultSelectWikiValue() throws Exception {
   WikiPageParams currentParams = org.exoplatform.wiki.commons.Utils.getCurrentWikiPageParams();
   String wikiType = currentParams.getType();
   String owner = currentParams.getOwner();
   return wikiType + "/" + Utils.validateWikiOwner(wikiType, owner);
 }
 /**
  * Get the permalink of current wiki page <br>
  *
  * <ul>
  *   With the current page param:
  * </ul>
  *
  * <li>type = "group"
  * <li>owner = "spaces/test_space"
  * <li>pageId = "test_page" <br>
  *
  *     <ul>
  *       The permalink will be:
  * </ul>
  *
  * <li>http://int.exoplatform.org/portal/intranet/wiki/group/spaces/test_space/test_page <br>
  *
  * @return The permalink of current wiki page
  * @throws Exception
  */
 protected static String getPermanlink() throws Exception {
   WikiPageParams params = Utils.getCurrentWikiPageParams();
   return org.exoplatform.wiki.utils.Utils.getPermanlink(params, true);
 }