private Content parseContent(Element e) {
    String value = null;
    String type = getAttributeValue(e, "type");
    type = (type != null) ? type : "text/plain";
    String mode = getAttributeValue(e, "mode");
    if (mode == null) {
      mode = Content.XML; // default to xml content
    }
    if (mode.equals(Content.ESCAPED)) {
      // do nothing XML Parser took care of this
      value = e.getText();
    } else if (mode.equals(Content.BASE64)) {
      value = Base64.decode(e.getText());
    } else if (mode.equals(Content.XML)) {
      XMLOutputter outputter = new XMLOutputter();
      List<org.jdom2.Content> eContent = e.getContent();
      Iterator<org.jdom2.Content> i = eContent.iterator();
      while (i.hasNext()) {
        org.jdom2.Content c = i.next();
        if (c instanceof Element) {
          Element eC = (Element) c;
          if (eC.getNamespace().equals(getAtomNamespace())) {
            ((Element) c).setNamespace(Namespace.NO_NAMESPACE);
          }
        }
      }
      value = outputter.outputString(eContent);
    }

    Content content = new Content();
    content.setType(type);
    content.setMode(mode);
    content.setValue(value);
    return content;
  }
Esempio n. 2
0
 /**
  * Set content of entry.
  *
  * @param contentString content string.
  * @param type Must be "text" for plain text, "html" for escaped HTML, "xhtml" for XHTML or a
  *     valid MIME content-type.
  */
 public void setContent(String contentString, String type) {
   Content newContent = new Content();
   newContent.setType(type == null ? Content.HTML : type);
   newContent.setValue(contentString);
   ArrayList contents = new ArrayList();
   contents.add(newContent);
   setContents(contents);
 }
Esempio n. 3
0
 private Content parseContent(final Element e) {
   final String value = parseTextConstructToString(e);
   final String src = getAttributeValue(e, "src");
   final String type = getAttributeValue(e, "type");
   final Content content = new Content();
   content.setSrc(src);
   content.setType(type);
   content.setValue(value);
   return content;
 }
Esempio n. 4
0
  protected Entry parseEntry(
      final Feed feed, final Element eEntry, final String baseURI, final Locale locale) {
    final Entry entry = new Entry();

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

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

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

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

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

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

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

    e = eEntry.getChild("published", getAtomNamespace());
    if (e != null) {
      entry.setPublished(DateParser.parseDate(e.getText(), locale));
    }

    e = eEntry.getChild("summary", getAtomNamespace());
    if (e != null) {
      entry.setSummary(parseContent(e));
    }

    e = eEntry.getChild("content", getAtomNamespace());
    if (e != null) {
      final List<Content> contents = new ArrayList<Content>();
      contents.add(parseContent(e));
      entry.setContents(contents);
    }

    e = eEntry.getChild("rights", getAtomNamespace());
    if (e != null) {
      entry.setRights(e.getText());
    }

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

    // TODO: SHOULD handle Atom entry source element
    e = eEntry.getChild("source", getAtomNamespace());
    if (e != null) {
      entry.setSource(parseFeedMetadata(baseURI, e, locale));
    }

    entry.setModules(parseItemModules(eEntry, locale));

    final List<Element> foreignMarkup = extractForeignMarkup(eEntry, entry, getAtomNamespace());
    if (foreignMarkup.size() > 0) {
      entry.setForeignMarkup(foreignMarkup);
    }
    return entry;
  }
Esempio n. 5
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;
  }