Example #1
0
  protected void visitArticles(Element element, Layout layout, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    List<JournalArticle> journalArticles =
        JournalArticleServiceUtil.getArticlesByLayoutUuid(layout.getGroupId(), layout.getUuid());

    if (journalArticles.isEmpty()) {
      return;
    }

    Set<String> processedArticleIds = new HashSet<String>();

    for (JournalArticle journalArticle : journalArticles) {
      if (processedArticleIds.contains(journalArticle.getArticleId())
          || (journalArticle.getStatus() != WorkflowConstants.STATUS_APPROVED)) {

        continue;
      }

      String portalURL = PortalUtil.getPortalURL(layout, themeDisplay);

      String groupFriendlyURL =
          PortalUtil.getGroupFriendlyURL(
              GroupLocalServiceUtil.getGroup(journalArticle.getGroupId()), false, themeDisplay);

      StringBundler sb = new StringBundler(4);

      if (!groupFriendlyURL.startsWith(portalURL)) {
        sb.append(portalURL);
      }

      sb.append(groupFriendlyURL);
      sb.append(JournalArticleConstants.CANONICAL_URL_SEPARATOR);
      sb.append(journalArticle.getUrlTitle());

      String articleURL = PortalUtil.getCanonicalURL(sb.toString(), themeDisplay, layout);

      addURLElement(
          element,
          articleURL,
          null,
          journalArticle.getModifiedDate(),
          articleURL,
          getAlternateURLs(articleURL, themeDisplay, layout));

      Locale[] availableLocales = LanguageUtil.getAvailableLocales(layout.getGroupId());

      if (availableLocales.length > 1) {
        Locale defaultLocale = LocaleUtil.getSiteDefault();

        for (Locale availableLocale : availableLocales) {
          if (!availableLocale.equals(defaultLocale)) {
            String alternateURL =
                PortalUtil.getAlternateURL(articleURL, themeDisplay, availableLocale, layout);

            addURLElement(
                element,
                alternateURL,
                null,
                journalArticle.getModifiedDate(),
                articleURL,
                getAlternateURLs(articleURL, themeDisplay, layout));
          }
        }
      }

      processedArticleIds.add(journalArticle.getArticleId());
    }
  }