com.rometools.rome.io.WireFeedInput Java Examples

The following examples show how to use com.rometools.rome.io.WireFeedInput. 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: AbstractWireFeedHttpMessageConverter.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
	}
}
 
Example #2
Source File: AbstractWireFeedHttpMessageConverter.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
	}
}
 
Example #3
Source File: AbstractWireFeedHttpMessageConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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);
	}
}
 
Example #4
Source File: AbstractWireFeedHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example #5
Source File: Atom10Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Parse entry from reader.
 */
public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException,
        FeedException {

    // Parse entry into JDOM tree
    final SAXBuilder builder = new SAXBuilder();
    final Document entryDoc = builder.build(rd);
    final Element fetchedEntryElement = entryDoc.getRootElement();
    fetchedEntryElement.detach();

    // Put entry into a JDOM document with 'feed' root so that Rome can
    // handle it
    final Feed feed = new Feed();
    feed.setFeedType("atom_1.0");
    final WireFeedOutput wireFeedOutput = new WireFeedOutput();
    final Document feedDoc = wireFeedOutput.outputJDom(feed);
    feedDoc.getRootElement().addContent(fetchedEntryElement);

    if (baseURI != null) {
        feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE);
    }

    final WireFeedInput input = new WireFeedInput(false, locale);
    final Feed parsedFeed = (Feed) input.build(feedDoc);
    return parsedFeed.getEntries().get(0);
}
 
Example #6
Source File: FileBasedCollection.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Get feed document representing collection.
 *
 * @throws com.rometools.rome.propono.atom.server.AtomException On error retrieving feed file.
 * @return Atom Feed representing collection.
 */
public Feed getFeedDocument() throws AtomException {
    InputStream in = null;
    synchronized (FileStore.getFileStore()) {
        in = FileStore.getFileStore().getFileInputStream(getFeedPath());
        if (in == null) {
            in = createDefaultFeedDocument(contextURI + servletPath + "/" + handle + "/" + collection);
        }
    }
    try {
        final WireFeedInput input = new WireFeedInput();
        final WireFeed wireFeed = input.build(new InputStreamReader(in, "UTF-8"));
        return (Feed) wireFeed;
    } catch (final Exception ex) {
        throw new AtomException(ex);
    }
}
 
Example #7
Source File: OpmlReader.java    From reactor-workshop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * TODO Return {@link reactor.core.publisher.Flux}
 */
public List<Outline> allFeeds() throws FeedException, IOException {
    WireFeedInput input = new WireFeedInput();
    try(final InputStream inputStream = OpmlReader.class.getResourceAsStream("/feed-jvm-bloggers.xml")) {
        final InputStreamReader streamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
        final Reader reader = new BufferedReader(streamReader);
        Opml feed = (Opml) input.build(reader);
        return feed.getOutlines();
    }
}
 
Example #8
Source File: TestXmlBomb.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testXmlBomb() throws Exception {

		// https://en.wikipedia.org/wiki/Billion_laughs
		// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
		String content = "<?xml version=\"1.0\"?>\n" +
				"<!DOCTYPE lolz [\n" +
				" <!ENTITY lol \"lol\">\n" +
				" <!ELEMENT lolz (#PCDATA)>\n" +
				" <!ENTITY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" +
				" <!ENTITY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" +
				" <!ENTITY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" +
				" <!ENTITY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" +
				" <!ENTITY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" +
				" <!ENTITY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" +
				" <!ENTITY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" +
				" <!ENTITY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" +
				" <!ENTITY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" +
				"]>\n" +
				"<feed>\n" +
				"    <title>&lol9;</title>\n" +
				"    <subtitle>subtitle</subtitle>\n" +
				"    <entry>\n" +
				"        <id>id1</id>\n" +
				"        <title>title1</title>\n" +
				"    </entry>\n" +
				"</feed>";

		InputStream is = new ByteArrayInputStream(content.getBytes("UTF-8"));
		WireFeedInput feedInput = new WireFeedInput();
		Reader reader = new InputStreamReader(is, Charset.forName("UTF-8"));
		try {
			feedInput.build(reader);
			fail("Expected exception");
		}
		catch (ParsingFeedException ex) {
		}
	}
 
Example #9
Source File: TestOpsOPML10links.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testTemp() throws Exception {
    final WireFeedInput input = new WireFeedInput();
    final WireFeed wf = input.build(TestUtil.loadFile("/opml_1.0_links.xml"));
    final WireFeedOutput output = new WireFeedOutput();

    final SyndFeedImpl sf = new SyndFeedImpl(wf);
    sf.setFeedType("rss_2.0");
    sf.setDescription("");
    sf.setLink("http://foo.com");
    sf.setFeedType("opml_1.0");
    output.output(sf.createWireFeed(), new NullWriter());
}
 
Example #10
Source File: EntryIterator.java    From rome with Apache License 2.0 5 votes vote down vote up
private void getNextEntries() throws ProponoException {
    if (nextURI == null) {
        return;
    }
    final GetMethod colGet = new GetMethod(collection.getHrefResolved(nextURI));
    collection.addAuthentication(colGet);
    try {
        collection.getHttpClient().executeMethod(colGet);
        final SAXBuilder builder = new SAXBuilder();
        final Document doc = builder.build(colGet.getResponseBodyAsStream());
        final WireFeedInput feedInput = new WireFeedInput();
        col = (Feed) feedInput.build(doc);
    } catch (final Exception e) {
        throw new ProponoException("ERROR: fetching or parsing next entries, HTTP code: " + (colGet != null ? colGet.getStatusCode() : -1), e);
    } finally {
        colGet.releaseConnection();
    }
    members = col.getEntries().iterator();
    col.getEntries().size();

    nextURI = null;
    final List<Link> altLinks = col.getOtherLinks();
    if (altLinks != null) {
        for (final Link link : altLinks) {
            if ("next".equals(link.getRel())) {
                nextURI = link.getHref();
            }
        }
    }
}
 
Example #11
Source File: OPMLImporter.java    From commafeed with Apache License 2.0 5 votes vote down vote up
public void importOpml(User user, String xml) {
	xml = xml.substring(xml.indexOf('<'));
	WireFeedInput input = new WireFeedInput();
	try {
		Opml feed = (Opml) input.build(new StringReader(xml));
		List<Outline> outlines = feed.getOutlines();
		for (int i = 0; i < outlines.size(); i++) {
			handleOutline(user, outlines.get(i), null, i);
		}
	} catch (Exception e) {
		log.error(e.getMessage(), e);
	}

}
 
Example #12
Source File: FeedTest.java    From rome with Apache License 2.0 4 votes vote down vote up
protected WireFeed getWireFeed() throws Exception {
    final WireFeedInput in = new WireFeedInput();
    in.setAllowDoctypes(allowDoctypes);
    return in.build(getFeedReader());
}
 
Example #13
Source File: FeedTest.java    From rome with Apache License 2.0 4 votes vote down vote up
protected WireFeed getWireFeed() throws Exception {
    final WireFeedInput in = new WireFeedInput();
    return in.build(getFeedReader());
}