/**
   * This method will first indicate which is the start date and the end date. It will then parse
   * the date to DateParser to get an date object
   *
   * @return
   */
  protected Date[] extractDates() {
    Date[] startEnd = new Date[2];
    for (Field f : fields) {
      if (f.getName().equals(FIELD_IDENTIFIERS[START_INDEX])) {
        startEnd[0] = DateParser.parseDate(f.getContent());

      } else if (f.getName().equals(FIELD_IDENTIFIERS[END_INDEX])) {
        startEnd[1] = DateParser.parseDate(f.getContent());
      }
    }
    if (startEnd[0] != null && startEnd[1] != null) {
      Arrays.sort(startEnd);
    }
    return startEnd;
  }
Beispiel #2
0
  /**
   * Utility method to parse a list of dates out of a list of elements.
   *
   * <p>
   *
   * @param eList the list of elements to parse.
   * @return the list of dates.
   */
  protected final List parseElementListDate(List eList) {
    List values = new ArrayList();
    for (Iterator i = eList.iterator(); i.hasNext(); ) {
      Element e = (Element) i.next();
      values.add(DateParser.parseDate(e.getText()));
    }

    return values;
  }
 protected Item parseItem(Element rssRoot, Element eItem) {
   Item item = super.parseItem(rssRoot, eItem);
   Element e = eItem.getChild("pubDate", getRSSNamespace());
   if (e != null) {
     item.setPubDate(DateParser.parseDate(e.getText()));
   }
   e = eItem.getChild("expirationDate", getRSSNamespace());
   if (e != null) {
     item.setExpirationDate(DateParser.parseDate(e.getText()));
   }
   e = eItem.getChild("description", getRSSNamespace());
   if (e != null) {
     String type = e.getAttributeValue("type");
     if (type != null) {
       item.getDescription().setType(type);
     }
   }
   return item;
 }
  public Module parse(Element syndRoot) {
    boolean foundSomething = false;
    SyModule sm = new SyModuleImpl();

    Element e = syndRoot.getChild("updatePeriod", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdatePeriod(e.getText());
    }
    e = syndRoot.getChild("updateFrequency", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdateFrequency(Integer.parseInt(e.getText().trim()));
    }
    e = syndRoot.getChild("updateBase", getDCNamespace());
    if (e != null) {
      foundSomething = true;
      sm.setUpdateBase(DateParser.parseDate(e.getText()));
    }
    return (foundSomething) ? sm : null;
  }
  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;
  }
  private Entry parseEntry(Element eEntry) {
    Entry entry = new Entry();

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

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

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

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

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

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

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

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

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

    eList = eEntry.getChildren("content", getAtomNamespace());
    if (eList.size() > 0) {
      List<Content> content = new ArrayList<Content>();
      for (int i = 0; i < eList.size(); i++) {
        content.add(parseContent(eList.get(i)));
      }
      entry.setContents(content);
    }

    entry.setModules(parseItemModules(eEntry));

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