com.rometools.rome.io.SyndFeedOutput Java Examples
The following examples show how to use
com.rometools.rome.io.SyndFeedOutput.
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: ITunesGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
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 #2
Source File: RSSFeedServlet.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); feed.setTitle("WildFly-Camel Test RSS Feed"); feed.setLink("http://localhost:8080/rss-tests"); feed.setDescription("Test RSS feed for the camel-rss component"); List<SyndEntry> entries = new ArrayList<>(); for (int i = 1; i <= 5; i++) { entries.add(createFeedEntry("Test entry: ", "Test content: ", i)); } feed.setEntries(entries); SyndFeedOutput output = new SyndFeedOutput(); try { output.output(feed, response.getWriter()); } catch (FeedException e) { throw new IllegalStateException("Error generating RSS feed", e); } }
Example #3
Source File: GeneratorTest.java From rome with Apache License 2.0 | 6 votes |
/** * Test of generate method, of class com.rometools.rome.feed.module.photocast.io.Generator. */ public void testGenerate() throws Exception { final SyndFeedInput input = new SyndFeedInput(); final SyndFeed feed = input.build(new File(super.getTestFile("index.rss"))); final List<SyndEntry> entries = feed.getEntries(); for (int i = 0; i < entries.size(); i++) { LOG.debug("{}", entries.get(i).getModule(PhotocastModule.URI)); } final SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, new File("target/index.rss")); final SyndFeed feed2 = input.build(new File("target/index.rss")); final List<SyndEntry> entries2 = feed2.getEntries(); for (int i = 0; i < entries.size(); i++) { assertEquals("Module test", entries.get(i).getModule(PhotocastModule.URI), entries2.get(i).getModule(PhotocastModule.URI)); } }
Example #4
Source File: PodloveSimpleChapterGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testGenerateAtom() throws Exception { log.debug("testGenerateAtom"); 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); entry.getModule(PodloveSimpleChapterModule.URI); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter writer = new StringWriter(); output.output(feed, writer); final String xml = writer.toString(); log.debug("{}", writer); assertTrue(xml.contains("xmlns:psc=\"http://podlove.org/simple-chapters\"")); assertTrue(xml.contains("<psc:chapters version=\"1.2\">")); assertTrue(xml.contains("<psc:chapter start=\"00:00:00.000\" title=\"Lorem Ipsum\" href=\"http://example.org\" image=\"http://example.org/cover\" />")); }
Example #5
Source File: PodloveSimpleChapterGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testGenerateRss() throws Exception { log.debug("testGenerateRss"); final SyndFeedInput input = new SyndFeedInput(); final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("psc/rss.xml")).toURI().toURL())); final SyndEntry entry = feed.getEntries().get(0); entry.getModule(PodloveSimpleChapterModule.URI); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter writer = new StringWriter(); output.output(feed, writer); final String xml = writer.toString(); log.debug("{}", writer); assertTrue(xml.contains("xmlns:psc=\"http://podlove.org/simple-chapters\"")); assertTrue(xml.contains("<psc:chapters version=\"1.2\">")); assertTrue(xml.contains("<psc:chapter start=\"00:00:00.000\" title=\"Lorem Ipsum\" href=\"http://example.org\" image=\"http://example.org/cover\" />")); }
Example #6
Source File: ITunesGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
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("target/" + feed.getName()); 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)); assertEquals("Entry Level: ", entry.getModule(AbstractITunesObject.URI).toString(), check.getModule(AbstractITunesObject.URI).toString()); } }
Example #7
Source File: SSEParserTest.java From rome with Apache License 2.0 | 6 votes |
public void xtestParseGenerateV5() throws Exception { final URL feedURL = new File(getTestFile("xml/v/v5.xml")).toURI().toURL(); // parse the document for comparison final SAXBuilder builder = new SAXBuilder(); final Document directlyBuilt = builder.build(feedURL); // generate the feed back into a document final SyndFeedInput input = new SyndFeedInput(); final SyndFeed inputFeed = input.build(new XmlReader(feedURL)); final SyndFeedOutput output = new SyndFeedOutput(); final Document parsedAndGenerated = output.outputJDom(inputFeed); // XMLOutputter outputter = new XMLOutputter(); // outputter.setFormat(Format.getPrettyFormat()); // outputter.output(directlyBuilt, new // FileOutputStream("c:\\cygwin\\tmp\\sync-direct.xml")); // outputter.output(parsedAndGenerated, new // FileOutputStream("c:\\cygwin\\tmp\\sync-pg.xml")); assertDocumentsEqual(directlyBuilt, parsedAndGenerated); }
Example #8
Source File: ContentModuleGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
/** * 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 #9
Source File: ITunesGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testImageUri() 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.setImageUri(new java.net.URI("https://example.org/test.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 java.net.URI("https://example.org/test.png"), parsedItunesFeed.getImageUri()); assertEquals(new URL("https://example.org/test.png"), parsedItunesFeed.getImage()); }
Example #10
Source File: ITunesGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testImage() 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/test.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/test.png"), parsedItunesFeed.getImage()); assertEquals(new java.net.URI("https://example.org/test.png"), parsedItunesFeed.getImageUri()); }
Example #11
Source File: ITunesGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testCreate() throws Exception { final SyndFeed feed = new SyndFeedImpl(); final String feedType = "rss_2.0"; feed.setFeedType(feedType); feed.setLanguage("en-us"); feed.setTitle("sales.com on the Radio!"); feed.setDescription("sales.com radio shows in MP3 format"); feed.setLink("http://foo/rss/podcasts.rss"); final FeedInformation fi = new FeedInformationImpl(); fi.setOwnerName("sales.com"); fi.getCategories().add(new Category("Shopping")); fi.setOwnerEmailAddress("[email protected]"); fi.setType("serial"); feed.getModules().add(fi); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter writer = new StringWriter(); output.output(feed, writer); LOG.debug("{}", writer); }
Example #12
Source File: GeoRSSModuleTest.java From rome with Apache License 2.0 | 6 votes |
/** * @throws Exception if file not found or not accessible */ public void testProduceAndReadSimple() throws Exception { final SyndFeed feed = createFeed(); final GeoRSSModule geoRSSModule = new SimpleModuleImpl(); final double latitude = 47.0; final double longitude = 9.0; final Position position = new Position(); position.setLatitude(latitude); position.setLongitude(longitude); geoRSSModule.setPosition(position); final SyndEntry entry = feed.getEntries().get(0); entry.getModules().add(geoRSSModule); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter stringWriter = new StringWriter(); output.output(feed, stringWriter); final InputStream in = new ByteArrayInputStream(stringWriter.toString().getBytes("UTF8")); final Double[] lat = { latitude }; final Double[] lng = { longitude }; assertTestInputStream(in, lat, lng); }
Example #13
Source File: GeoRSSModuleTest.java From rome with Apache License 2.0 | 6 votes |
/** * @throws Exception if file not found or not accessible */ public void xtestProduceAndReadGML() throws Exception { final SyndFeed feed = createFeed(); final GeoRSSModule geoRSSModule = new GMLModuleImpl(); final double latitude = 47.0; final double longitude = 9.0; final Position position = new Position(); position.setLatitude(latitude); position.setLongitude(longitude); geoRSSModule.setPosition(position); final SyndEntry entry = feed.getEntries().get(0); entry.getModules().add(geoRSSModule); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter stringWriter = new StringWriter(); output.output(feed, stringWriter); final InputStream in = new ByteArrayInputStream(stringWriter.toString().getBytes("UTF8")); final Double[] lat = { latitude }; final Double[] lng = { longitude }; assertTestInputStream(in, lat, lng); }
Example #14
Source File: OpenSearchModuleTest.java From rome with Apache License 2.0 | 6 votes |
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 #15
Source File: CustomTagGeneratorTest.java From rome with Apache License 2.0 | 6 votes |
public void testGenerate() throws Exception { final SyndFeedInput input = new SyndFeedInput(); final SyndFeed feed = input.build(new File(super.getTestFile("xml/custom-tags-example.xml"))); final SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, new File("target/custom-tags-example.xml")); final SyndFeed feed2 = input.build(new File("target/custom-tags-example.xml")); final List<SyndEntry> entries = feed.getEntries(); final SyndEntry entry = entries.get(0); final CustomTags customTags = (CustomTags) entry.getModule(CustomTags.URI); final List<SyndEntry> entries2 = feed2.getEntries(); final SyndEntry entry2 = entries2.get(0); final CustomTags customTags2 = (CustomTags) entry2.getModule(CustomTags.URI); final Iterator<CustomTag> it = customTags.getValues().iterator(); final Iterator<CustomTag> it2 = customTags2.getValues().iterator(); while (it.hasNext()) { final CustomTag tag = it.next(); final CustomTag tag2 = it2.next(); LOG.debug("tag1: {}", tag); LOG.debug("tag2: {}", tag2); Assert.assertEquals(tag, tag2); } }
Example #16
Source File: ITunesGeneratorTest.java From rome with Apache License 2.0 | 5 votes |
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 #17
Source File: GeoRSSModuleTest.java From rome with Apache License 2.0 | 5 votes |
/** * @throws Exception if file not found or not accessible */ public void testProduceAndReadSimpleLine() throws Exception { SyndFeed feed = createFeed(); final double[] latitudes = new double[] { 45.256, 46.46, 43.84 }; final double[] longitudes = new double[] { -110.45, -109.48, -109.86 }; // 45.256 -110.45 46.46 -109.48 43.84 -109.86 PositionList positionList = new PositionList(); positionList.add(latitudes[0], longitudes[0]); positionList.add(latitudes[1], longitudes[1]); positionList.add(latitudes[2], longitudes[2]); SimpleModuleImpl geoRSSModule = new SimpleModuleImpl(); geoRSSModule.setGeometry(new LineString(positionList)); SyndEntry entry = feed.getEntries().get(0); entry.getModules().add(geoRSSModule); final SyndFeedOutput output = new SyndFeedOutput(); final StringWriter stringWriter = new StringWriter(); output.output(feed, stringWriter); final InputStream in = new ByteArrayInputStream(stringWriter.toString().getBytes("UTF8")); final SyndFeedInput input = new SyndFeedInput(); feed = input.build(new XmlReader(in)); final List<SyndEntry> entries = feed.getEntries(); for (int i = 0; i < entries.size(); i++) { entry = entries.get(i); geoRSSModule = (SimpleModuleImpl) GeoRSSUtils.getGeoRSS(entry); final LineString lineString = (LineString) geoRSSModule.getGeometry(); positionList = lineString.getPositionList(); assertEquals(latitudes[i], positionList.getLatitude(i), DELTA); assertEquals(longitudes[i], positionList.getLongitude(i), DELTA); } }
Example #18
Source File: SyndicationServlet.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException { long poid = Long.parseLong(request.getParameter("poid")); SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid); SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(FEED_TYPE); feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'"); feed.setLink(request.getContextPath()); feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'"); List<SyndEntry> entries = new ArrayList<SyndEntry>(); try { List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid); Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false)); for (SRevision sVirtualRevision : allRevisionsOfProject) { SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId()); SyndEntry entry = new SyndEntryImpl(); entry.setTitle("Revision " + sVirtualRevision.getOid()); entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid()); entry.setPublishedDate(sVirtualRevision.getDate()); SyndContent description = new SyndContentImpl(); description.setType("text/html"); description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment() + "</td></tr></table>"); entry.setDescription(description); entries.add(entry); } } catch (ServiceException e) { LOGGER.error("", e); } feed.setEntries(entries); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, response.getWriter()); }
Example #19
Source File: ThreadingModuleTest.java From rome with Apache License 2.0 | 5 votes |
public void testGenerate() throws IOException, FeedException { final SyndFeed feed = getSyndFeed("thr/threading-main.xml"); List<SyndEntry> entries = feed.getEntries(); // create a new "root" entry that the next entry will reference to SyndEntry newRootEntry = new SyndEntryImpl(); newRootEntry.setTitle("New, 2nd root entry"); newRootEntry.setUri("tag:example.org,2005:2"); newRootEntry.setLink("http://www.example.org/entries/2"); entries.add(newRootEntry); // create a new reply entry that will reference the new root entry SyndEntry newReplyEntry = new SyndEntryImpl(); newReplyEntry.setTitle("New test reply entry"); newReplyEntry.setUri("tag:example.org,2005:2,1"); ThreadingModule threadingModule = new ThreadingModuleImpl(); threadingModule.setRef("tag:example.org,2005:2"); threadingModule.setType("application/xhtml+xml"); threadingModule.setHref("http://www.example.org/entries/2"); threadingModule.setSource("http://example.org/entries/2"); newReplyEntry.getModules().add(threadingModule); entries.add(newReplyEntry); File outputFile = new File("target/threading-testGenerate.xml"); final SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, outputFile); // read back in and validate final SyndFeed generatedFeed = getSyndFeed(outputFile); SyndEntry generatedReplyEntry = generatedFeed.getEntries().get(3); assertNotNull(generatedReplyEntry); ThreadingModule generatedReplyThreadingModule = (ThreadingModule) generatedReplyEntry.getModule(ThreadingModule.URI); assertEquals("tag:example.org,2005:2", generatedReplyThreadingModule.getRef()); assertEquals("application/xhtml+xml", generatedReplyThreadingModule.getType()); assertEquals("http://www.example.org/entries/2", generatedReplyThreadingModule.getHref()); assertEquals("http://example.org/entries/2", generatedReplyThreadingModule.getSource()); }
Example #20
Source File: ThreadingModuleTest.java From rome with Apache License 2.0 | 5 votes |
public void testEnd2End() throws IOException, FeedException { final SyndFeed feed = getSyndFeed("thr/threading-main.xml"); final SyndFeedOutput output = new SyndFeedOutput(); File outputFile = new File("target/threading-main-generated.xml"); output.output(feed, outputFile); final SyndFeed feedOut = getSyndFeed(outputFile); ThreadingModule moduleSrc = (ThreadingModule) feed.getEntries().get(1).getModule(ThreadingModule.URI); ThreadingModule moduleOut = (ThreadingModule) feedOut.getEntries().get(1).getModule(ThreadingModule.URI); assertEquals(moduleSrc, moduleOut); assertEquals("tag:example.org,2005:1", moduleSrc.getRef()); assertEquals("tag:example.org,2005:1", moduleOut.getRef()); }
Example #21
Source File: WeatherGeneratorTest.java From rome with Apache License 2.0 | 5 votes |
/** * Test of generate method, of class com.totsp.xml.syndication.base.io.SlashGenerator. * * @throws Exception on error */ 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("processing" + testFiles[h]); final SyndFeed feed = input.build(testFiles[h]); output.output(feed, new File("target/" + testFiles[h].getName())); final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName())); final YWeatherModule weather = (YWeatherModule) feed.getModule(YWeatherModule.URI); final YWeatherModule weather2 = (YWeatherModule) feed2.getModule(YWeatherModule.URI); Assert.assertEquals(testFiles[h].getName(), weather, weather2); for (int i = 0; i < feed.getEntries().size(); i++) { final SyndEntry entry = feed.getEntries().get(i); final SyndEntry entry2 = feed2.getEntries().get(i); final YWeatherModule weatherEntry = (YWeatherModule) entry.getModule(YWeatherModule.URI); final YWeatherModule weatherEntry2 = (YWeatherModule) entry2.getModule(YWeatherModule.URI); assertEquals(testFiles[h].getName(), weatherEntry, weatherEntry2); } } }
Example #22
Source File: CCModuleGeneratorTest.java From rome with Apache License 2.0 | 5 votes |
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 #23
Source File: GoogleBaseGeneratorTest.java From rome with Apache License 2.0 | 5 votes |
/** * Test of generate method, of class com.totsp.xml.syndication.base.io.GoogleBaseGenerator. */ 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]); try { output.output(feed, new File("target/" + testFiles[h].getName())); } catch (final Exception e) { throw new RuntimeException(testFiles[h].getAbsolutePath(), e); } final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName())); for (int i = 0; i < feed.getEntries().size(); i++) { final SyndEntry entry = feed.getEntries().get(i); final SyndEntry entry2 = feed2.getEntries().get(i); final GoogleBase base = (GoogleBase) entry.getModule(GoogleBase.URI); final GoogleBase base2 = (GoogleBase) entry2.getModule(GoogleBase.URI); Assert.assertEquals(testFiles[h].getName(), base, base2); } } }
Example #24
Source File: SleUtility.java From rome with Apache License 2.0 | 5 votes |
/** * 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 #25
Source File: SyndicationServlet.java From BIMserver with GNU Affero General Public License v3.0 | 5 votes |
private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException { long poid = Long.parseLong(request.getParameter("poid")); SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid); SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(FEED_TYPE); feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'"); feed.setLink(request.getContextPath()); feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'"); List<SyndEntry> entries = new ArrayList<SyndEntry>(); try { List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid); for (SCheckout sCheckout : allCheckoutsOfProject) { SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid()); SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId()); SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId()); SyndEntry entry = new SyndEntryImpl(); entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId()); entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid()); entry.setPublishedDate(sCheckout.getDate()); SyndContent description = new SyndContentImpl(); description.setType("text/plain"); description .setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>"); entry.setDescription(description); entries.add(entry); } } catch (UserException e) { LOGGER.error("", e); } feed.setEntries(entries); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, response.getWriter()); }
Example #26
Source File: FeedAggregator.java From rome with Apache License 2.0 | 4 votes |
public static void main(final String[] args) { boolean ok = false; if (args.length >= 2) { try { final String outputType = args[0]; final SyndFeed feed = new SyndFeedImpl(); feed.setFeedType(outputType); feed.setTitle("Aggregated Feed"); feed.setDescription("Anonymous Aggregated Feed"); feed.setAuthor("anonymous"); feed.setLink("http://www.anonymous.com"); final List<SyndEntry> entries = new ArrayList<SyndEntry>(); feed.setEntries(entries); final FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); final FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache); for (int i = 1; i < args.length; i++) { final URL inputUrl = new URL(args[i]); final SyndFeed inFeed = feedFetcher.retrieveFeed(inputUrl); entries.addAll(inFeed.getEntries()); } final SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, new PrintWriter(System.out)); ok = true; } catch (final Exception ex) { System.out.println("ERROR: " + ex.getMessage()); ex.printStackTrace(); } } if (!ok) { System.out.println(); System.out.println("FeedAggregator aggregates different feeds into a single one."); System.out.println("The first parameter must be the feed type for the aggregated feed."); System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]"); System.out.println(" [ rss_0.94, rss_1.0, rss_2.0 & atom_0.3 ]"); System.out.println("The second to last parameters are the URLs of feeds to aggregate."); System.out.println(); } }