com.rometools.rome.feed.synd.SyndFeed Java Examples

The following examples show how to use com.rometools.rome.feed.synd.SyndFeed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleRSSPortlet.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Get the feed content
 * @param request
 * @param response
 * @return Map of params or null if any required data is missing
 */
private SyndFeed getFeedContent(RenderRequest request, RenderResponse response) {
	
	SyndFeed feed;
	
	//check cache, otherwise get fresh
	//we use the feedUrl as the cacheKey
	String feedUrl = getConfiguredFeedUrl(request);
	if(StringUtils.isBlank(feedUrl)) {
		log.debug("No feed URL configured");
		doError("error.no.config", "error.heading.config", getPortletModeUrl(response, PortletMode.EDIT), request, response);
		return null;
	}
	
	String cacheKey = feedUrl;
	
	feed = feedCache.get(cacheKey);
	if(feed != null) {
		log.debug("Fetching data from feed cache for: " + cacheKey);
	} else {
		//get from remote
		feed = getRemoteFeed(feedUrl, request, response);
	}
	
	return feed;
}
 
Example #2
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testNews2Parse() throws Exception {
    LOG.debug("testNews2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/news2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Article module = (Article) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2007, 2, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "news", "old" }, module.getLabels());
    Assert.assertEquals("Source", "Journal", module.getNewsSource());
    cal.set(1961, 3, 12, 0, 0, 0);
    Assert.assertEquals("Pub Date", cal.getTime(), module.getPublishDate());
    this.assertEquals("Authors", new String[] { "James Smith" }, module.getAuthors());
    Assert.assertEquals("Pages", new Integer(1), module.getPages());

}
 
Example #3
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testPersona2Parse() throws Exception {
    LOG.debug("testPerson2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/personals2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Person module = (Person) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2005, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Personals", "m4w" }, module.getLabels());
    this.assertEquals("Ethnicity", new String[] { "South Asian" }, module.getEthnicities());
    Assert.assertEquals("Gender", GenderEnumeration.MALE, module.getGender());
    Assert.assertEquals("Sexual Orientation", "straight", module.getSexualOrientation());
    this.assertEquals("Interested In", new String[] { "Single Women" }, module.getInterestedIn());
    Assert.assertEquals("Marital Status", "single", module.getMaritalStatus());
    Assert.assertEquals("Occupation", "Sales", module.getOccupation());
    Assert.assertEquals("Employer", "Google, Inc.", module.getEmployer());
    Assert.assertEquals("Age", new Integer(23), module.getAge());
    Assert.assertEquals("Location", "Anytown, 12345, USA", module.getLocation());

}
 
Example #4
Source File: SimpleRSSPortlet.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Helper to get the remote feed data and cache it
 * @param feedUrl
 * @param request
 * @param response
 * @return
 */
private SyndFeed getRemoteFeed(String feedUrl, RenderRequest request, RenderResponse response) {
	
	//get feed data
	SyndFeed feed = new FeedParser().parseFeed(feedUrl);
	if(feed == null) {
		log.error("No data was returned from remote server.");
		doError("error.no.remote.data", "error.heading.general", request, response);
		return null;
	}
	
	//cache the data,
	log.debug("Adding data to feed cache for: " + feedUrl);
	feedCache.put(feedUrl, feed);
	
	return feed;
}
 
Example #5
Source File: ModuleParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.rometools.rome.feed.module.sle.io.ModuleParser.
 */
public void testParse() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new File(super.getTestFile("data/bookexample.xml")));
    final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);

    assertEquals("list", sle.getTreatAs());
    final Group[] groups = sle.getGroupFields();
    assertEquals("genre", groups[0].getElement());
    assertEquals("Genre", groups[0].getLabel());
    final Sort[] sorts = sle.getSortFields();
    assertEquals("Relevance", sorts[0].getLabel());
    assertTrue(sorts[0].getDefaultOrder());
    assertEquals(sorts[1].getNamespace(), Namespace.getNamespace("http://www.example.com/book"));
    assertEquals(sorts[1].getDataType(), Sort.DATE_TYPE);
    assertEquals(sorts[1].getElement(), "firstedition");
    final SyndEntry entry = feed.getEntries().get(0);
    final SleEntry sleEntry = (SleEntry) entry.getModule(SleEntry.URI);
    LOG.debug("{}", sleEntry);
    LOG.debug("getGroupByElement");
    LOG.debug("{}", sleEntry.getGroupByElement(groups[0]));
    LOG.debug("getSortByElement");
    LOG.debug("{}", sleEntry.getSortByElement(sorts[0]));
}
 
Example #6
Source File: OpenSearchModuleTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testEndToEnd() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final File test = new File(super.getTestFile("os"));
    final File[] files = test.listFiles();
    for (int j = 0; j < files.length; j++) {
        if (!files[j].getName().endsWith(".xml")) {
            continue;
        }
        final SyndFeed feed = input.build(files[j]);
        final Module m = feed.getModule(OpenSearchModule.URI);
        final SyndFeedOutput output = new SyndFeedOutput();
        final File outfile = new File("target/" + files[j].getName());
        output.output(feed, outfile);
        final SyndFeed feed2 = input.build(outfile);
        assertEquals(m, feed2.getModule(OpenSearchModule.URI));
    }
}
 
Example #7
Source File: GeoRSSUtils.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * This convenience method checks whether there is any geoRss Element and will return it (georss
 * simple or W3GGeo).
 *
 * @param feed the element in the feed which might have a georss element
 * @return a georssmodule or null if none is present
 */
public static GeoRSSModule getGeoRSS(final SyndFeed feed) {
    final GeoRSSModule simple = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_GEORSS_URI);
    final GeoRSSModule w3cGeo = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_W3CGEO_URI);
    final GeoRSSModule gml = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_GML_URI);

    if (gml != null) {
        return gml;
    }
    if (simple != null) {
        return simple;
    }
    if (w3cGeo != null) {
        return w3cGeo;
    }

    return null;
    /*
     * if (geoRSSModule == null && w3cGeo != null) { geoRSSModule = w3cGeo; } else if
     * (geoRSSModule == null && gml != null) { geoRSSModule = gml; } else if (geoRSSModule !=
     * null && w3cGeo != null) { // sanity check if
     * (!geoRSSModule.getGeometry().equals(w3cGeo.getGeometry())) { throw new
     * Error("geometry of simple and w3c do not match"); } } return geoRSSModule;
     */
}
 
Example #8
Source File: PodloveSimpleChapterParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testParseAtom() throws Exception {

        log.debug("testParseAtom");

        final SyndFeedInput input = new SyndFeedInput();
        final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("psc/atom.xml")).toURI().toURL()));
        final SyndEntry entry = feed.getEntries().get(0);
        final PodloveSimpleChapterModule simpleChapters = (PodloveSimpleChapterModule) entry.getModule(PodloveSimpleChapterModule.URI);

        assertNotNull(simpleChapters);
        for (SimpleChapter c : simpleChapters.getChapters()) {
            assertEquals("00:00:00.000", c.getStart());
            assertEquals("Lorem Ipsum", c.getTitle());
            assertEquals("http://example.org", c.getHref());
            assertEquals("http://example.org/cover", c.getImage());
        }
    }
 
Example #9
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

    final Channel channel = (Channel) feed;

    super.copyInto(channel, syndFeed);

    final String uri = channel.getUri();
    if (uri != null) {
        syndFeed.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = channel.getLink();
        syndFeed.setUri(link);
    }
}
 
Example #10
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {

    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);

    final String uri = syndFeed.getUri();
    if (uri != null) {
        channel.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = syndFeed.getLink();
        channel.setUri(link);
    }

    return channel;
}
 
Example #11
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testImageTakesPrecedenceOverImageUri() throws Exception {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("title");
    feed.setDescription("description");
    feed.setLink("https://example.org");

    FeedInformation itunesFeed = new FeedInformationImpl();
    itunesFeed.setImage(new URL("https://example.org/test1.png"));
    itunesFeed.setImageUri(new java.net.URI("https://example.org/test2.png"));
    feed.getModules().add(itunesFeed);

    String xml = new SyndFeedOutput().outputString(feed);

    AbstractITunesObject parsedItunesFeed =
            (AbstractITunesObject) new SyndFeedInput()
                    .build(new XmlReader(new ByteArrayInputStream(xml.getBytes("UTF-8"))))
                    .getModule(AbstractITunesObject.URI);
    assertEquals(new URL("https://example.org/test1.png"), parsedItunesFeed.getImage());
    assertEquals(new java.net.URI("https://example.org/test1.png"),
            parsedItunesFeed.getImageUri());
}
 
Example #12
Source File: ContentModuleGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of generate method, of class com.totsp.xml.syndication.content.ContentModuleGenerator.
 */
public void testGenerate() throws Exception {

    LOG.debug("testGenerate");

    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("xml/test-rdf.xml")).toURI().toURL()));
    final SyndEntry entry = feed.getEntries().get(0);
    entry.getModule(ContentModule.URI);
    final SyndFeedOutput output = new SyndFeedOutput();
    final StringWriter writer = new StringWriter();
    output.output(feed, writer);

    LOG.debug("{}", writer);

}
 
Example #13
Source File: DeltaSyndFeedInfo.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Gets a filtered version of the SyndFeed that only has entries that were changed in the last
 * setSyndFeed() call.
 *
 * @return
 */
@Override
public synchronized SyndFeed getSyndFeed() {
    try {
        final SyndFeed feed = (SyndFeed) super.getSyndFeed().clone();

        final List<SyndEntry> changedEntries = new ArrayList<SyndEntry>();

        final List<SyndEntry> entries = feed.getEntries();
        for (final SyndEntry entry : entries) {
            if (changedMap.containsKey(entry.getUri())) {
                changedEntries.add(entry);
            }
        }

        feed.setEntries(changedEntries);

        return feed;
    } catch (final CloneNotSupportedException ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #14
Source File: Publisher.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Asyncronously sends a notification for a feed. The feed MUST contain rel="hub" and rel="self"
 * links.
 *
 * @param feed The feed to notify
 * @param callback A callback invoked when the notification completes.
 * @throws NotificationException Any failure
 */
public void sendUpdateNotificationAsyncronously(final SyndFeed feed, final AsyncNotificationCallback callback) {
    final Runnable r = new Runnable() {
        @Override
        public void run() {
            try {
                sendUpdateNotification(feed);
                callback.onSuccess();
            } catch (final Throwable t) {
                callback.onFailure(t);
            }
        }
    };

    if (executor != null) {
        executor.execute(r);
    } else {
        new Thread(r).start();
    }
}
 
Example #15
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testDurationBad() throws Exception {
    SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration-bad.xml")));
    SyndEntry entry = feed.getEntries().get(0);
    EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

    assertNull(module.getDuration());
}
 
Example #16
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = new Channel(type);
    channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
    channel.setStyleSheet(syndFeed.getStyleSheet());
    channel.setEncoding(syndFeed.getEncoding());

    channel.setTitle(syndFeed.getTitle());
    final String link = syndFeed.getLink();
    final List<SyndLink> links = syndFeed.getLinks();
    if (link != null) {
        channel.setLink(link);
    } else if (!links.isEmpty()) {
        channel.setLink(links.get(0).getHref());
    }

    channel.setDescription(syndFeed.getDescription());

    final SyndImage sImage = syndFeed.getImage();
    if (sImage != null) {
        channel.setImage(createRSSImage(sImage));
    }

    final List<SyndEntry> sEntries = syndFeed.getEntries();
    if (sEntries != null) {
        channel.setItems(createRSSItems(sEntries));
    }

    final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;
}
 
Example #17
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testExplicitnessTrue() throws Exception {
    ArrayList<String> xmlFiles = new ArrayList<String>();
    xmlFiles.add("explicitness-capital-yes.xml");
    xmlFiles.add("explicitness-yes.xml");

    for (String xml : xmlFiles) {
        SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource(xml)));
        FeedInformationImpl module = (FeedInformationImpl) feed.getModule(AbstractITunesObject.URI);

        assertTrue(module.getExplicitNullable());
    }
}
 
Example #18
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testDuration() throws Exception {
    SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration.xml")));
    SyndEntry entry = feed.getEntries().get(0);
    EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

    assertEquals(1000, module.getDuration().getMilliseconds());
}
 
Example #19
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testExplicitnessFalse() throws Exception {
    ArrayList<String> xmlFiles = new ArrayList<String>();
    xmlFiles.add("explicitness-no.xml");
    xmlFiles.add("explicitness-clean.xml");

    for (String xml : xmlFiles) {
        SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource(xml)));
        FeedInformationImpl module = (FeedInformationImpl) feed.getModule(AbstractITunesObject.URI);

        assertFalse(module.getExplicitNullable());
    }
}
 
Example #20
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testParseNonHttpUris() throws Exception {
    File feed = new File(getTestFile("itunes/no-http-uris.xml"));
    final SyndFeedInput input = new SyndFeedInput();
    SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL()));

    final FeedInformationImpl feedInfo = (FeedInformationImpl) syndfeed.getModule(AbstractITunesObject.URI);

    assertEquals(URI.create("file://some-location/1.jpg"), feedInfo.getImageUri());

    SyndEntry entry = syndfeed.getEntries().get(0);
    EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

    assertEquals(URI.create("gs://some-location/2.jpg"), module.getImageUri());
}
 
Example #21
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 5 votes vote down vote up
private void testFile(final String filename) throws Exception {
    final File feed = new File(getTestFile(filename));
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL()));

    final SyndFeedOutput output = new SyndFeedOutput();
    final File outfeed = new File(feed.getAbsolutePath() + ".output");
    output.output(syndfeed, outfeed);

    final SyndFeed syndCheck = input.build(new XmlReader(outfeed.toURI().toURL()));
    LOG.debug(syndCheck.getModule(AbstractITunesObject.URI).toString());
    assertEquals("Feed Level: ", syndfeed.getModule(AbstractITunesObject.URI).toString(), syndCheck.getModule(AbstractITunesObject.URI).toString());

    final List<SyndEntry> syndEntries = syndfeed.getEntries();
    final List<SyndEntry> syndChecks = syndCheck.getEntries();

    for (int i = 0; i < syndEntries.size(); i++) {
        final SyndEntry entry = syndEntries.get(i);
        final SyndEntry check = syndChecks.get(i);
        LOG.debug("Original: " + entry.getModule(AbstractITunesObject.URI));
        LOG.debug("Check:    " + check.getModule(AbstractITunesObject.URI));
        LOG.debug(entry.getModule(AbstractITunesObject.URI).toString());
        LOG.debug("-----------------------------------------");
        LOG.debug(check.getModule(AbstractITunesObject.URI).toString());
        assertEquals("Entry Level: ", entry.getModule(AbstractITunesObject.URI).toString(), check.getModule(AbstractITunesObject.URI).toString());
    }
}
 
Example #22
Source File: AbstractJettyTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testRetrieveFeed() {
    final FeedFetcher feedFetcher = getFeedFetcher();
    try {
        final SyndFeed feed = feedFetcher.retrieveFeed(new URL("http://localhost:" + testPort + "/rome/FetcherTestServlet/"));
        assertNotNull(feed);
        assertEquals("atom_1.0.feed.title", feed.getTitle());
    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example #23
Source File: GoogleTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public static void testGoogleVideo() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new InputStreamReader(new URL("http://video.google.com/videofeed?type=top100new&num=20&output=rss").openStream()));
    for (final Object element : feed.getEntries()) {
        final SyndEntry entry = (SyndEntry) element;
        final MediaEntryModule m = (MediaEntryModule) entry.getModule(MediaModule.URI);
        System.out.print(m);
    }
}
 
Example #24
Source File: FeedTest.java    From rome with Apache License 2.0 5 votes vote down vote up
protected SyndFeed getCachedSyndFeed(final boolean preserveWireFeed) throws Exception {

        if (syndFeed == null || preservingWireFeed != preserveWireFeed) {
            syndFeed = getSyndFeed(preserveWireFeed);
            preservingWireFeed = preserveWireFeed;
        }
        return syndFeed;

    }
 
Example #25
Source File: CCModuleGeneratorTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testGenerate() throws Exception {
    LOG.debug("testGenerate");
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeedOutput output = new SyndFeedOutput();
    final File testDir = new File(super.getTestFile("xml"));
    final File[] testFiles = testDir.listFiles();
    for (int h = 0; h < testFiles.length; h++) {
        if (!testFiles[h].getName().endsWith(".xml")) {
            continue;
        }
        LOG.debug(testFiles[h].getName());
        final SyndFeed feed = input.build(testFiles[h]);
        // if( !feed.getFeedType().equals("rss_1.0"))
        {
            feed.setFeedType("rss_2.0");
            if (feed.getDescription() == null) {
                feed.setDescription("test file");
            }
            output.output(feed, new File("target/" + testFiles[h].getName()));
            final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName()));
            for (int i = 0; i < feed.getEntries().size(); i++) {
                // FIXME
                // final SyndEntry entry = feed.getEntries().get(i);
                final SyndEntry entry2 = feed2.getEntries().get(i);
                // / FIXME
                // final CreativeCommons base = (CreativeCommons)
                // entry.getModule(CreativeCommons.URI);
                final CreativeCommons base2 = (CreativeCommons) entry2.getModule(CreativeCommons.URI);
                LOG.debug("{}", base2);
                // FIXME
                // if( base != null)
                // this.assertEquals( testFiles[h].getName(), base.getLicenses(),
                // base2.getLicenses() );
            }
        }
    }

}
 
Example #26
Source File: HttpClientFeedFetcher.java    From rome with Apache License 2.0 5 votes vote down vote up
private SyndFeed getFeed(final SyndFeedInfo syndFeedInfo, final String urlStr, final HttpMethod method, final int statusCode) throws IOException,
        HttpException, FetcherException, FeedException {

    if (statusCode == HttpURLConnection.HTTP_NOT_MODIFIED && syndFeedInfo != null) {
        fireEvent(FetcherEvent.EVENT_TYPE_FEED_UNCHANGED, urlStr);
        return syndFeedInfo.getSyndFeed();
    }

    final SyndFeed feed = retrieveFeed(urlStr, method);
    fireEvent(FetcherEvent.EVENT_TYPE_FEED_RETRIEVED, urlStr, feed);
    return feed;
}
 
Example #27
Source File: SleUtility.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * This method will take a SyndFeed object with a SimpleListExtension on it and populate the
 * entries with current SleEntry values for sorting and grouping. <b>NB</b>: This basically does
 * this by re-generating the XML for all the entries then re-parsing them into the SLE data
 * structures. It is a very heavy operation and should not be called frequently!
 */
public static void initializeForSorting(final SyndFeed feed) throws FeedException {
    // TODO: the null parameter below will break delegating parsers and generators
    // final ModuleGenerators g = new ModuleGenerators(feed.getFeedType() +
    // ITEM_MODULE_GENERATORS_POSFIX_KEY, null);
    final SyndFeedOutput output = new SyndFeedOutput();
    final Document document = output.outputJDom(feed);
    final SyndFeed copy = new SyndFeedInput().build(document);
    feed.copyFrom(copy);
}
 
Example #28
Source File: AtomLinkTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {

        final File testdata = new File(super.getTestFile("atom/atom.xml"));
        final SyndFeed feed = new SyndFeedInput().build(testdata);

        final AtomLinkModule atomLinkModule = (AtomLinkModule) feed.getModule(AtomLinkModule.URI);
        List<Link> links = atomLinkModule.getLinks();
        for (int i = 0; i < links.size(); i++) {
            Link link = links.get(i);
            assertEquals(href[i], link.getHref());
            assertEquals(rel[i], link.getRel());
            assertEquals(type[i], link.getType());
        }

    }
 
Example #29
Source File: FeedParser.java    From commafeed with Apache License 2.0 5 votes vote down vote up
/**
 * Adds atom links for rss feeds
 */
private void handleForeignMarkup(SyndFeed feed) {
	List<Element> foreignMarkup = feed.getForeignMarkup();
	if (foreignMarkup == null) {
		return;
	}
	for (Element element : foreignMarkup) {
		if ("link".equals(element.getName()) && ATOM_10_NS.equals(element.getNamespace())) {
			SyndLink link = new SyndLinkImpl();
			link.setRel(element.getAttributeValue("rel"));
			link.setHref(element.getAttributeValue("href"));
			feed.getLinks().add(link);
		}
	}
}
 
Example #30
Source File: Publisher.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a notification for a feed located at "topic". The feed MUST contain rel="hub".
 *
 * @param topic URL for the feed
 * @param feed The feed itself
 * @throws NotificationException Any failure
 */
public void sendUpdateNotification(final String topic, final SyndFeed feed) throws NotificationException {
    for (final SyndLink link : feed.getLinks()) {
        if ("hub".equals(link.getRel())) {
            sendUpdateNotification(link.getRel(), topic);

            return;
        }
    }
    throw new NotificationException("Hub link not found.");
}