Top Description Inners Fields Constructors Methods
com.rometools.rome.io

public Class WireFeedInput

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .File, .FileNotFoundException, .FileReader, .IOException, .Reader, java.util.List, .Locale, .Map, .WeakHashMap, org.jdom2.Document, .JDOMException, org.jdom2.input.DOMBuilder, .JDOMParseException, org.jdom2.input.sax.XMLReaders, org.xml.sax.EntityResolver, .InputSource, .SAXNotRecognizedException, .SAXNotSupportedException, .XMLReader, com.rometools.rome.feed.WireFeed, com.rometools.rome.feed.impl.ConfigurableClassLoader, com.rometools.rome.io.impl.FeedParsers, .XmlFixerReader

Parses an XML document (File, InputStream, Reader, W3C SAX InputSource, W3C DOM Document or JDom DOcument) into an WireFeed (RSS/Atom).

It accepts all flavors of RSS (0.90, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) and Atom 0.3 feeds. Parsers are plugable (they must implement the WireFeedParser interface).

The WireFeedInput useds liberal parsers.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private static Map<ClassLoader, FeedParsers>
private static final InputSource
private final Locale
private static final EntityResolver
private final boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
WireFeedInput()

Creates a WireFeedInput instance with input validation turned off.

public
WireFeedInput(final boolean
indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)
validate
,
final Locale locale)

Creates a WireFeedInput instance.

Method Summary

Modifier and TypeMethod and Description
public WireFeed

Returns:

the WireFeed read from the file.
build
(final File
file to read to create the WireFeed.
file
)

Builds an WireFeed (RSS or Atom) from a file.

public WireFeed

Returns:

the WireFeed read from the Reader.
build
(Reader
Reader to read to create the WireFeed.
reader
)

Builds an WireFeed (RSS or Atom) from an Reader.

public WireFeed

Returns:

the WireFeed read from the W3C SAX InputSource.
build
(final InputSource
W3C SAX InputSource to read to create the WireFeed.
is
)

Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource.

public WireFeed

Returns:

the WireFeed read from the W3C DOM document.
build
(final Document
W3C DOM document to read to create the WireFeed.
document
)

Builds an WireFeed (RSS or Atom) from an W3C DOM document.

public WireFeed

Returns:

the WireFeed read from the JDOM document.
build
(final Document
JDOM document to read to create the WireFeed.
document
)

Builds an WireFeed (RSS or Atom) from an JDOM document.

protected SAXBuilder

Returns:

a new org.jdom2.input.SAXBuilder object
createSAXBuilder
()

Creates and sets up a org.jdom2.input.SAXBuilder for parsing.

private static FeedParsers
public static List<String>

Returns:

a list of String elements with the supported input feed types.
getSupportedFeedTypes
()

Returns the list of supported input feed types.

public boolean

Returns:

TRUE if healing is enabled, FALSE if not.
getXmlHealerOn
()

Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream.

public boolean

Returns:

true when Doctype declarations are allowed, false otherwise
isAllowDoctypes
()

Indicates whether Doctype declarations are allowed.

private boolean
isFeatureSupported(XMLReader parser, String feature, boolean value)

public void
setAllowDoctypes(boolean
true when Doctype declarations should be allowed again, false otherwise
allowDoctypes
)

Since ROME 1.5.1 we fixed a security vulnerability by disallowing Doctype declarations by default.

private void
setFeature(SAXBuilder saxBuilder, XMLReader parser, String feature, boolean value)

public void
setXmlHealerOn(final boolean
TRUE enables stream healing, FALSE disables it.
heals
)

Enables XML healing in the WiredFeedInput instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowDoctypesback to summary
private boolean allowDoctypes
clMapback to summary
private static Map<ClassLoader, FeedParsers> clMap
EMPTY_INPUTSOURCEback to summary
private static final InputSource EMPTY_INPUTSOURCE
localeback to summary
private final Locale locale
RESOLVERback to summary
private static final EntityResolver RESOLVER
validateback to summary
private final boolean validate
xmlHealerOnback to summary
private boolean xmlHealerOn

Constructor Detail

WireFeedInputback to summary
public WireFeedInput()

Creates a WireFeedInput instance with input validation turned off.

WireFeedInputback to summary
public WireFeedInput(final boolean validate, final Locale locale)

Creates a WireFeedInput instance.

Parameters
validate:boolean

indicates if the input should be validated. NOT IMPLEMENTED YET (validation does not happen)

Method Detail

buildback to summary
public WireFeed build(final File file) throws FileNotFoundException, IOException, IllegalArgumentException, FeedException

Builds an WireFeed (RSS or Atom) from a file.

Note

This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.

Parameters
file:File

file to read to create the WireFeed.

Returns:WireFeed

the WireFeed read from the file.

Exceptions
FileNotFoundException:
thrown if the file could not be found.
IOException:
thrown if there is problem reading the file.
IllegalArgumentException:
thrown if feed type could not be understood by any of the underlying parsers.
FeedException:
if the feed could not be parsed
buildback to summary
public WireFeed build(Reader reader) throws IllegalArgumentException, FeedException

Builds an WireFeed (RSS or Atom) from an Reader.

Note

This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.

Parameters
reader:Reader

Reader to read to create the WireFeed.

Returns:WireFeed

the WireFeed read from the Reader.

Exceptions
IllegalArgumentException:
thrown if feed type could not be understood by any of the underlying parsers.
FeedException:
if the feed could not be parsed
buildback to summary
public WireFeed build(final InputSource is) throws IllegalArgumentException, FeedException

Builds an WireFeed (RSS or Atom) from an W3C SAX InputSource.

Note

This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.

Parameters
is:InputSource

W3C SAX InputSource to read to create the WireFeed.

Returns:WireFeed

the WireFeed read from the W3C SAX InputSource.

Exceptions
IllegalArgumentException:
thrown if feed type could not be understood by any of the underlying parsers.
FeedException:
if the feed could not be parsed
buildback to summary
public WireFeed build(final Document document) throws IllegalArgumentException, FeedException

Builds an WireFeed (RSS or Atom) from an W3C DOM document.

Note

This method delages to the 'AsbtractFeed WireFeedInput#build(org.jdom2.Document)'.

Parameters
document:Document

W3C DOM document to read to create the WireFeed.

Returns:WireFeed

the WireFeed read from the W3C DOM document.

Exceptions
IllegalArgumentException:
thrown if feed type could not be understood by any of the underlying parsers.
FeedException:
if the feed could not be parsed
buildback to summary
public WireFeed build(final Document document) throws IllegalArgumentException, FeedException

Builds an WireFeed (RSS or Atom) from an JDOM document.

Note

All other build methods delegate to this method.

Parameters
document:Document

JDOM document to read to create the WireFeed.

Returns:WireFeed

the WireFeed read from the JDOM document.

Exceptions
IllegalArgumentException:
thrown if feed type could not be understood by any of the underlying parsers.
FeedException:
if the feed could not be parsed
createSAXBuilderback to summary
protected SAXBuilder createSAXBuilder()

Creates and sets up a org.jdom2.input.SAXBuilder for parsing.

Returns:SAXBuilder

a new org.jdom2.input.SAXBuilder object

getFeedParsersback to summary
private static FeedParsers getFeedParsers()
getSupportedFeedTypesback to summary
public static List<String> getSupportedFeedTypes()

Returns the list of supported input feed types.

Returns:List<String>

a list of String elements with the supported input feed types.

See Also
{@link WireFeed} for details on the format of these strings.

getXmlHealerOnback to summary
public boolean getXmlHealerOn()

Indicates if the WiredFeedInput instance will XML heal (if necessary) the character stream.

Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.

Healing resolves HTML entities (from literal to code number) in the reader.

The healing is done only with the build(File) and build(Reader) signatures.

By default is TRUE.

Returns:boolean

TRUE if healing is enabled, FALSE if not.

isAllowDoctypesback to summary
public boolean isAllowDoctypes()

Indicates whether Doctype declarations are allowed.

Returns:boolean

true when Doctype declarations are allowed, false otherwise

isFeatureSupportedback to summary
private boolean isFeatureSupported(XMLReader parser, String feature, boolean value)
setAllowDoctypesback to summary
public void setAllowDoctypes(boolean allowDoctypes)

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.

Parameters
allowDoctypes:boolean

true when Doctype declarations should be allowed again, false otherwise

setFeatureback to summary
private void setFeature(SAXBuilder saxBuilder, XMLReader parser, String feature, boolean value)
setXmlHealerOnback to summary
public void setXmlHealerOn(final boolean heals)

Enables XML healing in the WiredFeedInput instance.

Healing trims leading chars from the stream (empty spaces and comments) until the XML prolog.

Healing resolves HTML entities (from literal to code number) in the reader.

The healing is done only with the build(File) and build(Reader) signatures.

By default is TRUE.

Parameters
heals:boolean

TRUE enables stream healing, FALSE disables it.

com.rometools.rome.io back to summary

private Class WireFeedInput.EmptyEntityResolver

extends Object
implements EntityResolver
Class Inheritance
All Implemented Interfaces
org.xml.sax.EntityResolver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public InputSource
resolveEntity(final String
The public identifier of the external entity being referenced, or null if none was supplied.
publicId
,
final String
The system identifier of the external entity being referenced.
systemId
)

Implements org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyEntityResolverback to summary
private EmptyEntityResolver()

Method Detail

resolveEntityback to summary
public InputSource resolveEntity(final String publicId, final String systemId)

Implements org.xml.sax.EntityResolver.resolveEntity.

Doc from org.xml.sax.EntityResolver.resolveEntity.

Allow the application to resolve external entities.

The parser will call this method before opening any external entity except the top-level document entity. Such entities include the external DTD subset and external parameter entities referenced within the DTD (in either case, only if the parser reads external parameter entities), and external general entities referenced within the document element (if the parser reads external general entities). The application may request that the parser locate the entity itself, that it use an alternative URI, or that it use data provided by the application (as a character or byte input stream).

Application writers can use this method to redirect external system identifiers to secure and/or local URIs, to look up public identifiers in a catalogue, or to read an entity from a database or other input source (including, for example, a dialog box). Neither XML nor SAX specifies a preferred policy for using public or system IDs to resolve resources. However, SAX specifies how to interpret any InputSource returned by this method, and that if none is returned, then the system ID will be dereferenced as a URL.

If the system identifier is a URL, the SAX parser must resolve it fully before reporting it to the application.

Parameters
publicId:String

The public identifier of the external entity being referenced, or null if none was supplied.

systemId:String

The system identifier of the external entity being referenced.

Returns:InputSource

An InputSource object describing the new input source, or null to request that the parser open a regular URI connection to the system identifier.

Annotations
@Override