Package com.rometools.rome.io

Examples of com.rometools.rome.io.FeedException


    try {
      String encoding = FeedUtils.guessEncoding(xml);
      String xmlString = FeedUtils.trimInvalidXmlCharacters(new String(xml, encoding));
      if (xmlString == null) {
        throw new FeedException("Input string is null for url " + feedUrl);
      }
      xmlString = FeedUtils.replaceHtmlEntitiesWithNumericEntities(xmlString);
      InputSource source = new InputSource(new StringReader(xmlString));
      SyndFeed rss = new SyndFeedInput().build(source);
      handleForeignMarkup(rss);

      fetchedFeed.setTitle(rss.getTitle());
      feed.setPushHub(findHub(rss));
      feed.setPushTopic(findSelf(rss));
      feed.setUrl(feedUrl);
      feed.setLink(rss.getLink());
      List<SyndEntry> items = rss.getEntries();

      for (SyndEntry item : items) {
        FeedEntry entry = new FeedEntry();

        String guid = item.getUri();
        if (StringUtils.isBlank(guid)) {
          guid = item.getLink();
        }
        if (StringUtils.isBlank(guid)) {
          // no guid and no link, skip entry
          continue;
        }
        entry.setGuid(FeedUtils.truncate(guid, 2048));
        entry.setUpdated(validateDate(getEntryUpdateDate(item), true));
        entry.setUrl(FeedUtils.truncate(FeedUtils.toAbsoluteUrl(item.getLink(), feed.getLink(), feed.getUrlAfterRedirect()), 2048));

        // if link is empty but guid is used as url
        if (StringUtils.isBlank(entry.getUrl()) && StringUtils.startsWith(entry.getGuid(), "http")) {
          entry.setUrl(entry.getGuid());
        }

        FeedEntryContent content = new FeedEntryContent();
        content.setContent(getContent(item));
        content.setTitle(getTitle(item));
        content.setAuthor(StringUtils.trimToNull(item.getAuthor()));
        SyndEnclosure enclosure = Iterables.getFirst(item.getEnclosures(), null);
        if (enclosure != null) {
          content.setEnclosureUrl(FeedUtils.truncate(enclosure.getUrl(), 2048));
          content.setEnclosureType(enclosure.getType());
        }
        entry.setContent(content);

        entries.add(entry);
      }
      Date lastEntryDate = null;
      Date publishedDate = validateDate(rss.getPublishedDate(), false);
      if (!entries.isEmpty()) {
        List<Long> sortedTimestamps = FeedUtils.getSortedTimestamps(entries);
        Long timestamp = sortedTimestamps.get(0);
        lastEntryDate = new Date(timestamp);
        publishedDate = (publishedDate == null || publishedDate.before(lastEntryDate)) ? lastEntryDate : publishedDate;
      }
      feed.setLastPublishedDate(publishedDate);
      feed.setAverageEntryInterval(FeedUtils.averageTimeBetweenEntries(entries));
      feed.setLastEntryDate(lastEntryDate);

    } catch (Exception e) {
      throw new FeedException(String.format("Could not parse feed from %s : %s", feedUrl, e.getMessage()), e);
    }
    return fetchedFeed;
  }
View Full Code Here


                try {
                    final SAXBuilder saxBuilder = new SAXBuilder();
                    tmpDoc = saxBuilder.build(tmpDocReader);
                } catch (final Exception ex) {
                    throw new FeedException("Invalid XML", ex);
                }

                final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent();
                contentElement.addContent(children);
            }
View Full Code Here

    // maxLen == -1 means unlimited.
    protected void checkNotNullAndLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException {
        final Element child = parent.getChild(childName, getFeedNamespace());
        if (child == null) {
            throw new FeedException("Invalid " + getType() + " feed, missing " + parent.getName() + " " + childName);
        }
        checkLength(parent, childName, minLen, maxLen);
    }
View Full Code Here

    // maxLen == -1 means unlimited.
    protected void checkLength(final Element parent, final String childName, final int minLen, final int maxLen) throws FeedException {
        final Element child = parent.getChild(childName, getFeedNamespace());
        if (child != null) {
            if (minLen > 0 && child.getText().length() < minLen) {
                throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "short of " + minLen + " length");
            }
            if (maxLen > -1 && child.getText().length() > maxLen) {
                throw new FeedException("Invalid " + getType() + " feed, " + parent.getName() + " " + childName + "exceeds " + maxLen + " length");
            }
        }
    }
View Full Code Here

    }

    protected void checkItemsConstraints(final Element parent) throws FeedException {
        final int count = parent.getChildren("item", getFeedNamespace()).size();
        if (count < 1 || count > 15) {
            throw new FeedException("Invalid " + getType() + " feed, item count is " + count + " it must be between 1 an 15");
        }
    }
View Full Code Here

        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()));
View Full Code Here

                final int value = Integer.parseInt(hour.getText().trim());

                if (isHourFormat24()) {
                    if (value < 1 || value > 24) {
                        throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24");
                    }
                } else {
                    if (value < 0 || value > 23) {
                        throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
                    }
                }

            }
View Full Code Here

                Document tmpDoc;
                try {
                    final SAXBuilder saxBuilder = new SAXBuilder();
                    tmpDoc = saxBuilder.build(tmpDocReader);
                } catch (final Exception ex) {
                    throw new FeedException("Invalid XML", ex);
                }
                final List<org.jdom2.Content> children = tmpDoc.getRootElement().removeContent();
                contentElement.addContent(children);

            } else {
View Full Code Here

TOP

Related Classes of com.rometools.rome.io.FeedException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.