public List parse(String url, int size) throws Exception { List entries = new ArrayList(); URL feedSource = new URL(url); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(feedSource)); int i = 0; for (Object f : feed.getEntries()) { if (i == size) { break; } entries.add(f); i++; } return entries; } }
@Override @SuppressWarnings("unchecked") protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { WireFeedInput feedInput = new WireFeedInput(); MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : DEFAULT_CHARSET); try { Reader reader = new InputStreamReader(inputMessage.getBody(), charset); return (T) feedInput.build(reader); } catch (FeedException ex) { throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex, inputMessage); } }
@Override protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET); MediaType contentType = outputMessage.getHeaders().getContentType(); if (contentType != null) { contentType = new MediaType(contentType.getType(), contentType.getSubtype(), charset); outputMessage.getHeaders().setContentType(contentType); } WireFeedOutput feedOutput = new WireFeedOutput(); try { Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset); feedOutput.output(wireFeed, writer); } catch (FeedException ex) { throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex); } }
SyndFeed feed = new SyndFeedInput().build( new InputSource(new CloseShieldInputStream(stream)));
private SyndFeed getFeed() { try { synchronized (this.feedMonitor) { Reader reader = this.feedUrl != null ? new XmlReader(this.feedUrl) : new XmlReader(this.feedResource.getInputStream()); SyndFeed feed = this.syndFeedInput.build(reader); if (logger.isDebugEnabled()) { logger.debug("Retrieved feed for [" + this + "]"); } if (feed == null) { if (logger.isDebugEnabled()) { logger.debug("No feeds updated for [" + this + "], returning null"); } } return feed; } } catch (Exception e) { throw new MessagingException("Failed to retrieve feed for '" + this + "'", e); } }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { T wireFeed = newFeed(); buildFeedMetadata(model, wireFeed, request); buildFeedEntries(model, wireFeed, request, response); setResponseContentType(request, response); if (!StringUtils.hasText(wireFeed.getEncoding())) { wireFeed.setEncoding("UTF-8"); } WireFeedOutput feedOutput = new WireFeedOutput(); ServletOutputStream out = response.getOutputStream(); feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding())); out.flush(); }
SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, response.getWriter());
/** * Creates a SyndFeedInput instance. * <p> * * @param validate indicates if the input should be validated. NOT IMPLEMENTED YET (validation * does not happen) * */ public SyndFeedInput(final boolean validate, final Locale locale) { feedInput = new WireFeedInput(validate, locale); }
/** * Specify a flag to indication if {@code WireFeed} should be preserved in the target {@link SyndFeed}. * @param preserveWireFeed the {@code boolean} flag. * @since 5.0 * @see SyndFeedInput#setPreserveWireFeed(boolean) */ public void setPreserveWireFeed(boolean preserveWireFeed) { Assert.isTrue(!this.syndFeedInputSet, "'preserveWireFeed' must be configured on the provided [" + this.syndFeedInput + "]"); this.syndFeedInput.setPreserveWireFeed(preserveWireFeed); }
private void setFeature(SAXBuilder saxBuilder, XMLReader parser, String feature, boolean value) { if (isFeatureSupported(parser, feature, value)) { saxBuilder.setFeature(feature, value); } }
/** * Since ROME 1.5.1 we fixed a security vulnerability by disallowing Doctype declarations by default. * This change breaks the compatibility with at least RSS 0.91N because it requires a Doctype declaration. * You are able to allow Doctype declarations again with this property. You should only activate it * when the feeds that you process are absolutely trustful. * * @param allowDoctypes true when Doctype declarations should be allowed again, false otherwise */ public void setAllowDoctypes(boolean allowDoctypes) { feedInput.setAllowDoctypes(allowDoctypes); }
/** * Indicates whether Doctype declarations are allowed. * * @return true when Doctype declarations are allowed, false otherwise */ public boolean isAllowDoctypes() { return feedInput.isAllowDoctypes(); }
@Test public void validateSuccessfulFileConfigurationWithCustomMetadataStore() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "FeedInboundChannelAdapterParserTests-file-context.xml", this.getClass()); SourcePollingChannelAdapter adapter = context.getBean("feedAdapter", SourcePollingChannelAdapter.class); FeedEntryMessageSource source = (FeedEntryMessageSource) TestUtils.getPropertyValue(adapter, "source"); assertSame(context.getBean(MetadataStore.class), TestUtils.getPropertyValue(source, "metadataStore")); SyndFeedInput syndFeedInput = TestUtils.getPropertyValue(source, "syndFeedInput", SyndFeedInput.class); assertSame(context.getBean(SyndFeedInput.class), syndFeedInput); assertFalse(syndFeedInput.isPreserveWireFeed()); context.close(); }
@Override protected void writeInternal(T wireFeed, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { Charset charset = (StringUtils.hasLength(wireFeed.getEncoding()) ? Charset.forName(wireFeed.getEncoding()) : DEFAULT_CHARSET); MediaType contentType = outputMessage.getHeaders().getContentType(); if (contentType != null) { contentType = new MediaType(contentType.getType(), contentType.getSubtype(), charset); outputMessage.getHeaders().setContentType(contentType); } WireFeedOutput feedOutput = new WireFeedOutput(); try { Writer writer = new OutputStreamWriter(outputMessage.getBody(), charset); feedOutput.output(wireFeed, writer); } catch (FeedException ex) { throw new HttpMessageNotWritableException("Could not write WireFeed: " + ex.getMessage(), ex); } }
@Override @SuppressWarnings("unchecked") protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { WireFeedInput feedInput = new WireFeedInput(); MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : DEFAULT_CHARSET); try { Reader reader = new InputStreamReader(inputMessage.getBody(), charset); return (T) feedInput.build(reader); } catch (FeedException ex) { throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex, inputMessage); } }
@Override protected final void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { T wireFeed = newFeed(); buildFeedMetadata(model, wireFeed, request); buildFeedEntries(model, wireFeed, request, response); setResponseContentType(request, response); if (!StringUtils.hasText(wireFeed.getEncoding())) { wireFeed.setEncoding("UTF-8"); } WireFeedOutput feedOutput = new WireFeedOutput(); ServletOutputStream out = response.getOutputStream(); feedOutput.output(wireFeed, new OutputStreamWriter(out, wireFeed.getEncoding())); out.flush(); }
SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, response.getWriter());
private void setFeature(SAXBuilder saxBuilder, XMLReader parser, String feature, boolean value) { if (isFeatureSupported(parser, feature, value)) { saxBuilder.setFeature(feature, value); } }
/** * Since ROME 1.5.1 we fixed a security vulnerability by disallowing Doctype declarations by default. * This change breaks the compatibility with at least RSS 0.91N because it requires a Doctype declaration. * You are able to allow Doctype declarations again with this property. You should only activate it * when the feeds that you process are absolutely trustful. * * @param allowDoctypes true when Doctype declarations should be allowed again, false otherwise */ public void setAllowDoctypes(boolean allowDoctypes) { feedInput.setAllowDoctypes(allowDoctypes); }
SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, response.getWriter());