コード例 #1
0
  /**
   * A helper function to print out the contents of an entry to log.trace
   *
   * @param entry
   */
  public static void printEntry(SyndEntry entry) {
    if (!log.isTraceEnabled()) {
      return;
    }

    StringBuffer pr =
        new StringBuffer(
            "URI: "
                + entry.getUri()
                + "\n"
                + "Title: "
                + entry.getTitle()
                + "\n"
                + "\n"
                + "Date: "
                + entry.getPublishedDate()
                + "\n"
                + "Modified: "
                + entry.getUpdatedDate()
                + "\n");

    pr.append("Creators: \n");

    for (SyndPerson author : FeedHelper.getAuthors(entry)) {
      pr.append("  - " + author.getName() + "\n");
    }

    pr.append("Links: \n");
    for (SyndLink link : FeedHelper.getLinks(entry)) {
      pr.append("  - " + link.getTitle() + ": " + link.getHref() + "\n");
    }

    SyndContent description = entry.getDescription();
    if (description != null) {
      pr.append("\nDescription(" + description.getType() + "): " + description.getValue());
    }

    pr.append("Contents: \n");
    for (SyndContent content : FeedHelper.getContents(entry)) {
      pr.append(" Type: " + content.getType());
      pr.append(" Body: " + content.getValue());
      try {
        pr.append(
            " Body (Plain text): "
                + PlainTextExtractor.getPlainText(content.getType(), content.getValue()));
      } catch (ParserException e) {
        pr.append("Failed to parse content");
      }
    }

    pr.append("Categories: \n");
    for (SyndCategory category : FeedHelper.getCategories(entry)) {
      pr.append(category.getName() + "(" + category.getTaxonomyUri() + ")");
    }
    log.trace(pr.toString());
  }
コード例 #2
0
  protected String exportToRSS(
      ResourceRequest resourceRequest,
      ResourceResponse resourceResponse,
      String title,
      String description,
      String format,
      double version,
      String displayStyle,
      List<SocialActivity> socialActivities,
      ServiceContext serviceContext)
      throws Exception {

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

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(GetterUtil.getString(description, title));

    List<SyndEntry> syndEntries = new ArrayList<>();

    syndFeed.setEntries(syndEntries);

    for (SocialActivity socialActivity : socialActivities) {
      SocialActivityFeedEntry socialActivityFeedEntry =
          _socialActivityInterpreterLocalService.interpret(
              StringPool.BLANK, socialActivity, serviceContext);

      if (socialActivityFeedEntry == null) {
        continue;
      }

      SyndEntry syndEntry = new SyndEntryImpl();

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else {
        value = socialActivityFeedEntry.getBody();
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      if (Validator.isNotNull(socialActivityFeedEntry.getLink())) {
        syndEntry.setLink(socialActivityFeedEntry.getLink());
      }

      syndEntry.setPublishedDate(new Date(socialActivity.getCreateDate()));
      syndEntry.setTitle(HtmlUtil.extractText(socialActivityFeedEntry.getTitle()));
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(RSSUtil.getFeedType(format, version));

    List<SyndLink> syndLinks = new ArrayList<>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    LiferayPortletResponse liferayPortletResponse = (LiferayPortletResponse) resourceResponse;

    ResourceURL rssURL = liferayPortletResponse.createResourceURL();

    rssURL.setParameter("feedTitle", title);
    rssURL.setResourceID("rss");

    selfSyndLink.setHref(rssURL.toString());

    selfSyndLink.setRel("self");

    SyndLink alternateSyndLink = new SyndLinkImpl();

    syndLinks.add(alternateSyndLink);

    alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay));
    alternateSyndLink.setRel("alternate");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(title);
    syndFeed.setUri(rssURL.toString());

    return RSSUtil.export(syndFeed);
  }
コード例 #3
0
  protected static String exportToRSS(
      PortletRequest portletRequest,
      PortletResponse portletResponse,
      String name,
      String description,
      String format,
      double version,
      String displayStyle,
      String linkBehavior,
      List<AssetEntry> assetEntries)
      throws Exception {

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

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(GetterUtil.getString(description, name));

    List<SyndEntry> syndEntries = new ArrayList<>();

    syndFeed.setEntries(syndEntries);

    for (AssetEntry assetEntry : assetEntries) {
      SyndEntry syndEntry = new SyndEntryImpl();

      String author = PortalUtil.getUserName(assetEntry);

      syndEntry.setAuthor(author);

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      String languageId = LanguageUtil.getLanguageId(portletRequest);

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else {
        value = assetEntry.getSummary(languageId, true);
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      String link = getEntryURL(portletRequest, portletResponse, linkBehavior, assetEntry);

      syndEntry.setLink(link);

      syndEntry.setPublishedDate(assetEntry.getPublishDate());
      syndEntry.setTitle(assetEntry.getTitle(languageId, true));
      syndEntry.setUpdatedDate(assetEntry.getModifiedDate());
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(RSSUtil.getFeedType(format, version));

    List<SyndLink> syndLinks = new ArrayList<>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    String feedURL = getFeedURL(portletRequest);

    selfSyndLink.setHref(feedURL);

    selfSyndLink.setRel("self");

    SyndLink alternateSyndLink = new SyndLinkImpl();

    syndLinks.add(alternateSyndLink);

    alternateSyndLink.setHref(PortalUtil.getLayoutFullURL(themeDisplay));
    alternateSyndLink.setRel("alternate");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);

    return RSSUtil.export(syndFeed);
  }
コード例 #4
0
  protected String exportToRSS(
      String name,
      String description,
      String type,
      double version,
      String displayStyle,
      String feedURL,
      String entryURL,
      List<MBMessage> messages,
      ThemeDisplay themeDisplay)
      throws SystemException {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(description);

    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();

    syndFeed.setEntries(syndEntries);

    for (MBMessage message : messages) {
      SyndEntry syndEntry = new SyndEntryImpl();

      if (!message.isAnonymous()) {
        String author = PortalUtil.getUserName(message);

        syndEntry.setAuthor(author);
      }

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = null;

      if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
        value =
            StringUtil.shorten(
                HtmlUtil.extractText(message.getBody()),
                PropsValues.MESSAGE_BOARDS_RSS_ABSTRACT_LENGTH,
                StringPool.BLANK);
      } else if (displayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
        value = StringPool.BLANK;
      } else if (message.isFormatBBCode()) {
        value = BBCodeTranslatorUtil.getHTML(message.getBody());

        value = MBUtil.replaceMessageBodyPaths(themeDisplay, value);
      } else {
        value = message.getBody();
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      syndEntry.setLink(entryURL + "&messageId=" + message.getMessageId());
      syndEntry.setPublishedDate(message.getCreateDate());
      syndEntry.setTitle(message.getSubject());
      syndEntry.setUpdatedDate(message.getModifiedDate());
      syndEntry.setUri(syndEntry.getLink());

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(RSSUtil.getFeedType(type, version));

    List<SyndLink> syndLinks = new ArrayList<SyndLink>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    selfSyndLink.setHref(feedURL);
    selfSyndLink.setRel("self");

    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);

    try {
      return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
      throw new SystemException(fe);
    }
  }
コード例 #5
0
  protected String exportToRSS(
      ResourceRequest resourceRequest,
      ResourceResponse resourceResponse,
      JournalFeed feed,
      String languageId,
      Layout layout,
      ThemeDisplay themeDisplay)
      throws Exception {

    SyndFeed syndFeed = new SyndFeedImpl();

    syndFeed.setDescription(feed.getDescription());

    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();

    syndFeed.setEntries(syndEntries);

    List<JournalArticle> articles = JournalRSSUtil.getArticles(feed);

    if (_log.isDebugEnabled()) {
      _log.debug("Syndicating " + articles.size() + " articles");
    }

    for (JournalArticle article : articles) {
      SyndEntry syndEntry = new SyndEntryImpl();

      String author = PortalUtil.getUserName(article);

      syndEntry.setAuthor(author);

      SyndContent syndContent = new SyndContentImpl();

      syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);

      String value = article.getDescription(languageId);

      try {
        value = processContent(feed, article, languageId, themeDisplay, syndEntry, syndContent);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(e, e);
        }
      }

      syndContent.setValue(value);

      syndEntry.setDescription(syndContent);

      String link = getEntryURL(resourceRequest, feed, article, layout, themeDisplay);

      syndEntry.setLink(link);

      syndEntry.setPublishedDate(article.getDisplayDate());
      syndEntry.setTitle(article.getTitle(languageId));
      syndEntry.setUpdatedDate(article.getModifiedDate());
      syndEntry.setUri(link);

      syndEntries.add(syndEntry);
    }

    syndFeed.setFeedType(feed.getFeedType() + "_" + feed.getFeedVersion());

    List<SyndLink> syndLinks = new ArrayList<SyndLink>();

    syndFeed.setLinks(syndLinks);

    SyndLink selfSyndLink = new SyndLinkImpl();

    syndLinks.add(selfSyndLink);

    ResourceURL feedURL = resourceResponse.createResourceURL();

    feedURL.setCacheability(ResourceURL.FULL);
    feedURL.setParameter("struts_action", "/journal/rss");
    feedURL.setParameter("groupId", String.valueOf(feed.getGroupId()));
    feedURL.setParameter("feedId", String.valueOf(feed.getFeedId()));

    String link = feedURL.toString();

    selfSyndLink.setHref(link);

    selfSyndLink.setRel("self");

    syndFeed.setTitle(feed.getName());
    syndFeed.setPublishedDate(new Date());
    syndFeed.setUri(feedURL.toString());

    try {
      return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
      throw new SystemException(fe);
    }
  }