예제 #1
0
  protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {

    String baseURI = null;
    try {
      baseURI = findBaseURI(eFeed);
    } catch (final Exception e) {
      throw new FeedException("ERROR while finding base URI of feed", e);
    }

    final Feed feed = parseFeedMetadata(baseURI, eFeed, locale);
    feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));

    final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE);
    if (xmlBase != null) {
      feed.setXmlBase(xmlBase);
    }

    feed.setModules(parseFeedModules(eFeed, locale));

    final List<Element> eList = eFeed.getChildren("entry", getAtomNamespace());
    if (eList.size() > 0) {
      feed.setEntries(parseEntries(feed, baseURI, eList, locale));
    }

    final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (foreignMarkup.size() > 0) {
      feed.setForeignMarkup(foreignMarkup);
    }
    return feed;
  }
  /** Utility method to serialize an entry to writer. */
  public static void serializeEntry(Entry entry, Writer writer)
      throws IllegalArgumentException, FeedException, IOException {

    // Build a feed containing only the entry
    List entries = new ArrayList();
    entries.add(entry);
    Feed feed1 = new Feed();
    feed1.setFeedType("atom_1.0");
    feed1.setEntries(entries);

    // Get Rome to output feed as a JDOM document
    WireFeedOutput wireFeedOutput = new WireFeedOutput();
    Document feedDoc = wireFeedOutput.outputJDom(feed1);

    // Grab entry element from feed and get JDOM to serialize it
    Element entryElement = (Element) feedDoc.getRootElement().getChildren().get(0);

    XMLOutputter outputter = new XMLOutputter();
    outputter.output(entryElement, writer);
  }
예제 #3
0
  protected WireFeed parseFeed(Element eFeed) {

    com.sun.syndication.feed.atom.Feed feed = new com.sun.syndication.feed.atom.Feed(getType());

    Element e = eFeed.getChild("title", getAtomNamespace());
    if (e != null) {
      feed.setTitleEx(parseContent(e));
    }

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

    e = eFeed.getChild("author", getAtomNamespace());
    if (e != null) {
      List<Person> authors = new ArrayList<Person>();
      authors.add(parsePerson(e));
      feed.setAuthors(authors);
    }

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

    e = eFeed.getChild("tagline", getAtomNamespace());
    if (e != null) {
      feed.setTagline(parseContent(e));
    }

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

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

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

    e = eFeed.getChild("info", getAtomNamespace());
    if (e != null) {
      feed.setInfo(parseContent(e));
    }

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

    feed.setModules(parseFeedModules(eFeed));

    eList = eFeed.getChildren("entry", getAtomNamespace());
    if (eList.size() > 0) {
      feed.setEntries(parseEntries(eList));
    }

    List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
    if (foreignMarkup.size() > 0) {
      feed.setForeignMarkup(foreignMarkup);
    }
    return feed;
  }