@SuppressWarnings("unchecked")
  public String getFeedContent(Feed feed) {
    if (feed == null) {
      LOGGER.warning("Feed is unknown!");
      return null;
    }

    Date updated = new Date(System.currentTimeMillis());
    feed.setUpdated(updated);
    List<Module> modules = feed.getModules();
    if (!ListUtil.isEmpty(modules)) {
      for (Module module : modules) {
        if (module instanceof DCModule) {
          ((DCModule) module).setDate(updated);
        }
      }
    }

    try {
      return wfo.outputString(feed);
    } catch (Exception e) {
      LOGGER.log(Level.WARNING, "Error while outputing feed to string: " + feed, e);
      return null;
    }
  }
Example #2
0
  private Feed parseFeedMetadata(final String baseURI, final Element eFeed, final Locale locale) {
    final com.sun.syndication.feed.atom.Feed feed =
        new com.sun.syndication.feed.atom.Feed(getType());

    Element e = eFeed.getChild("title", getAtomNamespace());
    if (e != null) {
      final Content c = new Content();
      c.setValue(parseTextConstructToString(e));
      c.setType(getAttributeValue(e, "type"));
      feed.setTitleEx(c);
    }

    List<Element> eList = eFeed.getChildren("link", getAtomNamespace());
    feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, eList));
    feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, eList));

    final List<Element> cList = eFeed.getChildren("category", getAtomNamespace());
    feed.setCategories(parseCategories(baseURI, cList));

    eList = eFeed.getChildren("author", getAtomNamespace());
    if (eList.size() > 0) {
      feed.setAuthors(parsePersons(baseURI, eList, locale));
    }

    eList = eFeed.getChildren("contributor", getAtomNamespace());
    if (eList.size() > 0) {
      feed.setContributors(parsePersons(baseURI, eList, locale));
    }

    e = eFeed.getChild("subtitle", getAtomNamespace());
    if (e != null) {
      final Content subtitle = new Content();
      subtitle.setValue(parseTextConstructToString(e));
      subtitle.setType(getAttributeValue(e, "type"));
      feed.setSubtitle(subtitle);
    }

    e = eFeed.getChild("id", getAtomNamespace());
    if (e != null) {
      feed.setId(e.getText());
    }

    e = eFeed.getChild("generator", getAtomNamespace());
    if (e != null) {
      final Generator gen = new Generator();
      gen.setValue(e.getText());
      String att = getAttributeValue(e, "uri");
      if (att != null) {
        gen.setUrl(att);
      }
      att = getAttributeValue(e, "version");
      if (att != null) {
        gen.setVersion(att);
      }
      feed.setGenerator(gen);
    }

    e = eFeed.getChild("rights", getAtomNamespace());
    if (e != null) {
      feed.setRights(parseTextConstructToString(e));
    }

    e = eFeed.getChild("icon", getAtomNamespace());
    if (e != null) {
      feed.setIcon(e.getText());
    }

    e = eFeed.getChild("logo", getAtomNamespace());
    if (e != null) {
      feed.setLogo(e.getText());
    }

    e = eFeed.getChild("updated", getAtomNamespace());
    if (e != null) {
      feed.setUpdated(DateParser.parseDate(e.getText(), locale));
    }

    return feed;
  }