Exemplo n.º 1
0
  @Override
  public String getDisplayURL(ThemeDisplay themeDisplay, boolean privateLayout) {

    if (!privateLayout && (getPublicLayoutsPageCount() > 0)) {
      try {
        String groupFriendlyURL =
            PortalUtil.getGroupFriendlyURL(getPublicLayoutSet(), themeDisplay);

        return PortalUtil.addPreservedParameters(themeDisplay, groupFriendlyURL);
      } catch (PortalException pe) {
        _log.error(pe, pe);
      }
    } else if (privateLayout && (getPrivateLayoutsPageCount() > 0)) {
      try {
        String groupFriendlyURL =
            PortalUtil.getGroupFriendlyURL(getPrivateLayoutSet(), themeDisplay);

        return PortalUtil.addPreservedParameters(themeDisplay, groupFriendlyURL);
      } catch (PortalException pe) {
        _log.error(pe);
      }
    }

    return StringPool.BLANK;
  }
  @Override
  public String getURLViewInContext(
      LiferayPortletRequest liferayPortletRequest,
      LiferayPortletResponse liferayPortletResponse,
      String noSuchEntryRedirect)
      throws Exception {

    ThemeDisplay themeDisplay =
        (ThemeDisplay) liferayPortletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    Layout layout = themeDisplay.getLayout();

    if (Validator.isNotNull(_article.getLayoutUuid())) {
      layout =
          LayoutLocalServiceUtil.getLayoutByUuidAndCompanyId(
              _article.getLayoutUuid(), _article.getCompanyId());
    }

    String portletId = (String) liferayPortletRequest.getAttribute(WebKeys.PORTLET_ID);

    PortletPreferences portletSetup =
        PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, portletId);

    String linkToLayoutUuid =
        GetterUtil.getString(portletSetup.getValue("portletSetupLinkToLayoutUuid", null));

    if (Validator.isNotNull(_article.getLayoutUuid()) && Validator.isNull(linkToLayoutUuid)) {

      Group group = themeDisplay.getScopeGroup();

      if (group.getGroupId() != _article.getGroupId()) {
        group = GroupLocalServiceUtil.getGroup(_article.getGroupId());
      }

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(group, layout.isPrivateLayout(), themeDisplay);

      return PortalUtil.addPreservedParameters(
          themeDisplay,
          groupFriendlyURL
              .concat(JournalArticleConstants.CANONICAL_URL_SEPARATOR)
              .concat(_article.getUrlTitle()));
    }

    List<Long> hitLayoutIds =
        JournalContentSearchLocalServiceUtil.getLayoutIds(
            _article.getGroupId(), layout.isPrivateLayout(), _article.getArticleId());

    if (!hitLayoutIds.isEmpty()) {
      Long hitLayoutId = hitLayoutIds.get(0);

      Layout hitLayout =
          LayoutLocalServiceUtil.getLayout(
              _article.getGroupId(), layout.isPrivateLayout(), hitLayoutId.longValue());

      return PortalUtil.getLayoutURL(hitLayout, themeDisplay);
    }

    return noSuchEntryRedirect;
  }
Exemplo n.º 3
0
  /**
   * Returns the user's display URL based on the theme display.
   *
   * <p>The logic for the display URL to return is as follows:
   *
   * <ol>
   *   <li>If the user is the guest user, return an empty string.
   *   <li>Else, if a friendly URL is available for the user's profile, return that friendly URL.
   *   <li>Else, if <code>privateLayout</code> is <code>true</code>, return the URL of the user's
   *       default intranet site home page.
   *   <li>Otherwise, return the URL of the user's default extranet site home page.
   * </ol>
   *
   * @param themeDisplay the theme display
   * @param privateLayout whether to use the URL of the user's default intranet (versus extranet)
   *     site home page, if no friendly URL is available for the user's profile
   * @return the user's display URL
   * @throws PortalException if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public String getDisplayURL(ThemeDisplay themeDisplay, boolean privateLayout)
      throws PortalException, SystemException {

    if (isDefaultUser()) {
      return StringPool.BLANK;
    }

    String portalURL = themeDisplay.getPortalURL();

    String profileFriendlyURL = getProfileFriendlyURL();

    if (Validator.isNotNull(profileFriendlyURL)) {
      return PortalUtil.addPreservedParameters(
          themeDisplay, portalURL.concat(PortalUtil.getPathContext()).concat(profileFriendlyURL));
    }

    Group group = getGroup();

    int publicLayoutsPageCount = group.getPublicLayoutsPageCount();

    if (publicLayoutsPageCount > 0) {
      StringBundler sb = new StringBundler(5);

      sb.append(portalURL);
      sb.append(themeDisplay.getPathMain());
      sb.append("/my_sites/view?groupId=");
      sb.append(group.getGroupId());

      if (privateLayout) {
        sb.append("&privateLayout=1");
      } else {
        sb.append("&privateLayout=0");
      }

      return PortalUtil.addPreservedParameters(themeDisplay, sb.toString());
    }

    return StringPool.BLANK;
  }