Exemplo n.º 1
0
  public NextHeaders(Map<String, List<String>> rawHeaders) {
    this.rawHeaders = rawHeaders;

    for (String key : rawHeaders.keySet()) {
      String value = rawHeaders.get(key).get(0);
      if (CACHE_CONTROL.equalsIgnoreCase(key)) {
        cacheControl = value;
      } else if (DATE.equalsIgnoreCase(key)) {
        servedDate = DateParser.parse(value);
      } else if (EXPIRES.equalsIgnoreCase(key)) {
        expires = DateParser.parse(value);
      } else if (LAST_MODIFIED.equalsIgnoreCase(key)) {
        lastModified = DateParser.parse(value);
      } else if (ETAG.equalsIgnoreCase(key)) {
        etag = value;
      } else if (PRAGMA.equalsIgnoreCase(key)) {
        if ("no-cache".equalsIgnoreCase(value)) {
          noCache = true;
        }
      } else if (SET_COOKIE.equals(key)) {
        rawCookies = rawHeaders.get(key);
      } else if ("Age".equalsIgnoreCase(key)) {
        ageSeconds = parseSeconds(value);
      } else if (CONTENT_TYPE.equalsIgnoreCase(key)) {
        contentType = value;
      } else if (CONTENT_ENCODING.equalsIgnoreCase(key)) {
        contentEncoding = value;
      } else if (TRANSFER_ENCODING.equalsIgnoreCase(key)) {
        transferEncoding = value;
      } else if (CONTENT_LENGTH.equalsIgnoreCase(key)) {
        contentLength = parseInt(value);
      }
    }
  }
Exemplo n.º 2
0
  // start date before end date
  static LocalDateTime[] parse(String startDateTimeString, String endDateTimeString) {
    LocalDateTime[] dates = new LocalDateTime[2];
    String startDateString = null;
    String startTimeString = null;
    String endDateString = null;
    String endTimeString = null;

    Pattern pattern = Pattern.compile(DATE_TIME_PATTERN);

    Matcher matcher = pattern.matcher(startDateTimeString);
    matcher.find();
    startDateString = matcher.group(1);
    startTimeString = matcher.group(2);

    matcher = pattern.matcher(endDateTimeString);
    matcher.find();
    endDateString = matcher.group(1);
    endTimeString = matcher.group(2);

    if (startDateString == null) {
      startDateString = processNullStartDate(endDateString);
    }

    if (startDateString.equals("now")) {
      startTimeString = getCurrentTime();
    }

    if (endDateString == null) {
      endDateString = startDateString;
    }

    if (startTimeString == null) {
      startTimeString = processNullStartTime(startDateString);
    }

    if (endTimeString == null) {
      endTimeString = processNullEndTime(startDateString, endDateString, startTimeString);
    }

    LocalDate startDate = DateParser.parse(startDateString);
    LocalTime startTime = TimeParser.parse(startTimeString);
    LocalDateTime startDateTime = startDate.atTime(startTime);

    LocalDate endDate = DateParser.parse(endDateString);
    LocalTime endTime = TimeParser.parse(endTimeString);
    LocalDateTime endDateTime = endDate.atTime(endTime);

    if (endDateTime.isBefore(startDateTime)) {
      endDateTime.plusDays(1);
    }

    dates[0] = startDateTime;
    dates[1] = endDateTime;

    return dates;
  }
Exemplo n.º 3
0
  protected void populateItem(Item item, Element eItem, int index) {
    super.populateItem(item, eItem, index);

    Date pubDate = item.getPubDate();
    if (pubDate != null) {
      eItem.addContent(generateSimpleElement("pubDate", DateParser.formatRFC822(pubDate)));
    }

    Date expirationDate = item.getExpirationDate();
    if (expirationDate != null) {
      eItem.addContent(
          generateSimpleElement("expirationDate", DateParser.formatRFC822(expirationDate)));
    }
  }
Exemplo n.º 4
0
  /**
   * 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;
  }
Exemplo n.º 5
0
  static LocalDateTime parse(String endDateTimeString) {

    String endDateString = null;
    String endTimeString = null;

    Pattern pattern = Pattern.compile(DATE_TIME_PATTERN);
    Matcher matcher = pattern.matcher(endDateTimeString);

    matcher.find();
    endDateString = matcher.group(1);
    endTimeString = matcher.group(2);

    if (endDateString == null) {
      endDateString = "today";
    }

    if (endTimeString == null) {
      endTimeString = END_TIME_DEFAULT;
    }

    LocalDate endDate = DateParser.parse(endDateString);
    LocalTime endTime = TimeParser.parse(endTimeString);

    LocalDateTime endDateTime = endDate.atTime(endTime);

    if (endDateTime.isBefore(LocalDateTime.now())) {
      endDateTime = endDateTime.plusDays(1);
    }

    return endDateTime;
  }
Exemplo n.º 6
0
 @Deprecated
 public static String ISO8601DateToString(java.util.Date dt) {
   String rv = null;
   if (dt != null) {
     rv = DateParser.getIsoDate(dt);
   }
   return rv;
 }
Exemplo n.º 7
0
  static long computeExpires(String expires) {
    if (expires != null) {
      Date expiresDate = DateParser.parse(expires);
      if (expiresDate != null) return expiresDate.getTime();
    }

    return Long.MIN_VALUE;
  }
Exemplo n.º 8
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;
  }
Exemplo n.º 9
0
 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;
 }
Exemplo n.º 10
0
 @Deprecated
 public static java.util.Date ISO8601DateFromString(String formatted) {
   java.util.Date rv = null;
   if (formatted != null) {
     // try {
     rv = DateParser.parse(formatted);
     // } catch (InvalidDateException ide) {
     //	if (ERROR_ENABLED) logger.error("ComHelper.ISO8601DateFromString caught
     // InvalidDateException "+ide.getMessage()+" parsing "+formatted);
     // }
   }
   return rv;
 }
Exemplo n.º 11
0
  /**
   * this method find the start and the end of the search dates pass it to dateparser and process
   *
   * @return
   */
  protected Date[] extractSearchDates() {

    String[] startEnd = new String[2];

    for (Field f : fields) {
      if (f.getName().equals(FIELD_IDENTIFIERS[START_INDEX])) {
        startEnd[0] = f.getContent();
      } else if (f.getName().equals(FIELD_IDENTIFIERS[END_INDEX])) {
        startEnd[1] = f.getContent();
      }
    }

    return DateParser.parseSearchDate(startEnd);
  }
Exemplo n.º 12
0
  static boolean isDateTime(String dateTimeString) {
    boolean isValidDateTime;

    if (dateTimeString.matches(DATE_TIME_PATTERN)) {
      if (dateTimeString.matches(DATE_PATTERN0)) {
        isValidDateTime = DateParser.isValidDay(dateTimeString);
      } else {
        isValidDateTime = true;
      }
    } else {
      isValidDateTime = false;
    }

    return isValidDateTime;
  }
  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 void populateEntry(Entry entry, Element eEntry) throws FeedException {
    if (entry.getTitleEx() != null) {
      Element titleElement = new Element("title", getFeedNamespace());
      fillContentElement(titleElement, entry.getTitleEx());
      eEntry.addContent(titleElement);
    }
    List links = entry.getAlternateLinks();
    if (links != null) {
      for (int i = 0; i < links.size(); i++) {
        eEntry.addContent(generateLinkElement((Link) links.get(i)));
      }
    }
    links = entry.getOtherLinks();
    if (links != null) {
      for (int i = 0; i < links.size(); i++) {
        eEntry.addContent(generateLinkElement((Link) links.get(i)));
      }
    }

    List cats = entry.getCategories();
    if (cats != null) {
      for (int i = 0; i < cats.size(); i++) {
        eEntry.addContent(generateCategoryElement((Category) cats.get(i)));
      }
    }

    List authors = entry.getAuthors();
    if (authors != null && authors.size() > 0) {
      for (int i = 0; i < authors.size(); i++) {
        Element authorElement = new Element("author", getFeedNamespace());
        fillPersonElement(authorElement, (Person) entry.getAuthors().get(i));
        eEntry.addContent(authorElement);
      }
    }

    List contributors = entry.getContributors();
    if (contributors != null && contributors.size() > 0) {
      for (int i = 0; i < contributors.size(); i++) {
        Element contributorElement = new Element("contributor", getFeedNamespace());
        fillPersonElement(contributorElement, (Person) contributors.get(i));
        eEntry.addContent(contributorElement);
      }
    }
    if (entry.getId() != null) {
      eEntry.addContent(generateSimpleElement("id", entry.getId()));
    }

    if (entry.getUpdated() != null) {
      Element updatedElement = new Element("updated", getFeedNamespace());
      updatedElement.addContent(DateParser.formatW3CDateTime(entry.getUpdated()));
      eEntry.addContent(updatedElement);
    }

    if (entry.getPublished() != null) {
      Element publishedElement = new Element("published", getFeedNamespace());
      publishedElement.addContent(DateParser.formatW3CDateTime(entry.getPublished()));
      eEntry.addContent(publishedElement);
    }

    if (entry.getContents() != null && entry.getContents().size() > 0) {
      Element contentElement = new Element("content", getFeedNamespace());
      Content content = (Content) entry.getContents().get(0);
      fillContentElement(contentElement, content);
      eEntry.addContent(contentElement);
    }

    if (entry.getSummary() != null) {
      Element summaryElement = new Element("summary", getFeedNamespace());
      fillContentElement(summaryElement, entry.getSummary());
      eEntry.addContent(summaryElement);
    }

    if (entry.getSource() != null) {
      Element sourceElement = new Element("source", getFeedNamespace());
      populateFeedHeader(entry.getSource(), sourceElement);
      eEntry.addContent(sourceElement);
    }
  }
  protected void populateFeedHeader(Feed feed, Element eFeed) throws FeedException {
    if (feed.getTitleEx() != null) {
      Element titleElement = new Element("title", getFeedNamespace());
      fillContentElement(titleElement, feed.getTitleEx());
      eFeed.addContent(titleElement);
    }

    List links = feed.getAlternateLinks();
    if (links != null)
      for (int i = 0; i < links.size(); i++) {
        eFeed.addContent(generateLinkElement((Link) links.get(i)));
      }
    links = feed.getOtherLinks();
    if (links != null)
      for (int j = 0; j < links.size(); j++) {
        eFeed.addContent(generateLinkElement((Link) links.get(j)));
      }

    List cats = feed.getCategories();
    if (cats != null)
      for (Iterator iter = cats.iterator(); iter.hasNext(); ) {
        eFeed.addContent(generateCategoryElement((Category) iter.next()));
      }

    List authors = feed.getAuthors();
    if (authors != null && authors.size() > 0) {
      for (int i = 0; i < authors.size(); i++) {
        Element authorElement = new Element("author", getFeedNamespace());
        fillPersonElement(authorElement, (Person) feed.getAuthors().get(i));
        eFeed.addContent(authorElement);
      }
    }

    List contributors = feed.getContributors();
    if (contributors != null && contributors.size() > 0) {
      for (int i = 0; i < contributors.size(); i++) {
        Element contributorElement = new Element("contributor", getFeedNamespace());
        fillPersonElement(contributorElement, (Person) contributors.get(i));
        eFeed.addContent(contributorElement);
      }
    }

    if (feed.getSubtitle() != null) {
      Element subtitleElement = new Element("subtitle", getFeedNamespace());
      fillContentElement(subtitleElement, feed.getSubtitle());
      eFeed.addContent(subtitleElement);
    }

    if (feed.getId() != null) {
      eFeed.addContent(generateSimpleElement("id", feed.getId()));
    }

    if (feed.getGenerator() != null) {
      eFeed.addContent(generateGeneratorElement(feed.getGenerator()));
    }

    if (feed.getRights() != null) {
      eFeed.addContent(generateSimpleElement("rights", feed.getRights()));
    }

    if (feed.getIcon() != null) {
      eFeed.addContent(generateSimpleElement("icon", feed.getIcon()));
    }

    if (feed.getLogo() != null) {
      eFeed.addContent(generateSimpleElement("logo", feed.getLogo()));
    }

    if (feed.getUpdated() != null) {
      Element updatedElement = new Element("updated", getFeedNamespace());
      updatedElement.addContent(DateParser.formatW3CDateTime(feed.getUpdated()));
      eFeed.addContent(updatedElement);
    }
  }
Exemplo n.º 16
0
  /**
   * Create Field instances, according to the attribute configurations inside the fieldConfig
   * parameter
   *
   * @param strAttName the attributes name
   * @param strAttValue the attributes value
   * @param fieldConfig the field configuration. Here you can specify whether a specific field
   *     should be analyzed, etc. You can also set default values.
   * @return the field, with Store, Index and TermVector configuration as given in fieldConfig. Null
   *     in the case the field could'nt generated
   */
  public static AbstractField createField(
      String strAttName, String strAttValue, FieldConfig fieldConfig) {

    // Der Store

    Store store = fieldConfig.defaultFieldMapping.store;

    FieldMapping fieldMapping4Att = fieldConfig.hsFieldName2FieldMapping.get(strAttName);

    Index index = fieldMapping4Att != null ? fieldMapping4Att.index : null;

    if (index == null) index = fieldConfig.defaultFieldMapping.index;

    TermVector termVector = fieldMapping4Att != null ? fieldMapping4Att.termVector : null;
    if (termVector == null) termVector = fieldConfig.defaultFieldMapping.termVector;

    // welches Field erzeugt wird, steht ebenfalls in der config
    FieldType fieldType = fieldMapping4Att != null ? fieldMapping4Att.fieldType : null;
    if (fieldType == null) fieldType = fieldConfig.defaultFieldMapping.fieldType;

    AbstractField newField = null;
    if (strAttValue == null) strAttValue = "";

    if (FieldType.STRING.equals(fieldType)) {
      newField = new Field(strAttName, strAttValue, store, index, termVector);
    } else if (StringUtils.nullOrWhitespace(strAttValue)) {
      // wir können keine leeren numericValues eintragen - wir probieren, ob man string und number
      // mit einem attributnamen mischen kann^^
      // scheint zu gehen
      // wenn das value leer ist und wir ein numerisches Field haben, dann indexieren wir dieses
      // value nicht - ansonsten gibt es
      // Probleme beim Sortieren nach diesem numerischen Field
      newField = new Field(strAttName, strAttValue, store, Index.NO, TermVector.NO);
    } else if (m_llNumberTypes.contains(fieldType)) {
      boolean bIndex = false;
      if (index == Index.ANALYZED || index == Index.ANALYZED_NO_NORMS) bIndex = true;
      newField = new NumericField(strAttName, store, bIndex);

      if (FieldType.INTEGER.equals(fieldType))
        ((NumericField) newField).setIntValue(Integer.parseInt(strAttValue));
      else if (FieldType.LONG.equals(fieldType))
        ((NumericField) newField).setLongValue(Long.parseLong(strAttValue));
      else if (FieldType.FLOAT.equals(fieldType))
        ((NumericField) newField).setFloatValue(Float.parseFloat(strAttValue));
      else if (FieldType.DOUBLE.equals(fieldType))
        ((NumericField) newField).setDoubleValue(Double.parseDouble(strAttValue));
    } else if (FieldType.DATE.equals(fieldType)) {
      boolean bIndex = false;
      if (index == Index.ANALYZED || index == Index.ANALYZED_NO_NORMS) bIndex = true;
      newField = new NumericField(strAttName, store, bIndex);

      Date parsedDate = DateParser.parseDateString(strAttValue);
      if (parsedDate == null) {
        return null;
      }
      ((NumericField) newField).setLongValue(DateUtils.date2Number(parsedDate));
    } else if (FieldType.TIME.equals(fieldType)) {
      boolean bIndex = false;
      if (index == Index.ANALYZED || index == Index.ANALYZED_NO_NORMS) bIndex = true;
      newField = new NumericField(strAttName, store, bIndex);

      Date parsedDate = DateParser.parseDateString(strAttValue);
      ((NumericField) newField)
          .setIntValue(Integer.parseInt(new SimpleDateFormat("HHmmssSSS").format(parsedDate)));
    }

    return newField;
  }
Exemplo n.º 17
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;
  }
Exemplo n.º 18
0
  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;
  }
Exemplo n.º 19
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;
  }
Exemplo n.º 20
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;
  }