java.lang.Object
net.i2p.router.news.NewsXMLParser
Parser for I2P news feeds in Atom format with security filtering.
Processes news.xml files following RFC4287 Atom specification using the UPnP XML parser library with enhanced security features. Handles news entries, metadata, CRL entries, and blocklist data with configurable XHTML filtering.
Provides comprehensive validation and sanitization of news content with support for multiple content types and security levels. Includes configurable handling of potentially dangerous XHTML elements and attributes.
Nested Class Summary
Modifier and TypeClassDescriptionprivate static classExtend IOE since cybergarage ParserException extends Exception.static enumThe action taken when encountering a non-whitelisted XHTML element or blacklisted attribute in the feed content.Field Summary
FieldsModifier and TypeFieldDescriptionprivate BlocklistEntriesThe blocklist entries parsed from the feed.private final I2PAppContextThe app context.The CRL entries parsed from the feed.The news entries parsed from the feed.private final LogLogger for the news parser.private NewsMetadataThe feed metadata parsed from the feed.private NewsXMLParser.XHTMLModeThe XHTML sanitizing mode of the parser.The HTML attributes stripped from feed content.The XHTML tags allowed in feed content.Constructor Summary
ConstructorsConstructorDescriptionCreates a new NewsXMLParser with the given context.Method Summary
Modifier and TypeMethodDescriptionprivate voidExtracts the feed contents from the root node.private BlocklistEntriesextractBlocklistEntries(Node feed) This does not check for any missing values.extractCRLEntries(Node feed) This does not check for any missing values.extractNewsEntries(Node feed) This does not check for any missing values.private static NewsMetadataextractNewsMetadata(Node feed) Extracts the metadata of the feed.The blocklist entries.The news CRL entries.The news entries.The news metatdata.Helper to get all Nodes matching the name.static voidCommand-line entry point for testing.Process the XML file.parse(InputStream in) Process the XML input stream.voidSets the action taken when encountering a non-whitelisted XHTML element in the feed content.private booleanValidate an XML node, throwing if it is invalid.
Field Details
_context
The app context._log
Logger for the news parser._entries
_crlEntries
_blocklistEntries
The blocklist entries parsed from the feed._metadata
The feed metadata parsed from the feed._mode
The XHTML sanitizing mode of the parser.xhtmlWhitelist
attributeBlacklist
The HTML attributes stripped from feed content. See also: global HTML attributes
Constructor Details
NewsXMLParser
Creates a new NewsXMLParser with the given context.- Parameters:
ctx- the application context supplying the log manager and property lookups
Method Details
setXHTMLMode
Sets the action taken when encountering a non-whitelisted XHTML element in the feed content. Must be set beforeparse(File). Default REMOVE_ELEMENT.- Parameters:
mode- the XHTML mode to set
parse
Process the XML file.- Parameters:
file- XML content only. Any su3 or gunzip handling must have already happened.- Returns:
- the root node
- Throws:
IOException- on any parse error
parse
Process the XML input stream.- Parameters:
in- XML content only. Any su3 or gunzip handling must have already happened.- Returns:
- the root node
- Throws:
IOException- on any parse error
getEntries
getMetadata
The news metatdata. Must call parse() first.- Returns:
- null if parse failed
getCRLEntries
getBlocklistEntries
The blocklist entries. Must call parse() first.- Returns:
- null if none
extract
Extracts the feed contents from the root node.- Parameters:
root- the feed's root node- Throws:
NewsXMLParser.I2PParserException- if the feed structure is invalid
extractNewsMetadata
Extracts the metadata of the feed.- Parameters:
feed- the feed node- Returns:
- the parsed metadata
- Throws:
NewsXMLParser.I2PParserException- if the metadata is invalid
extractNewsEntries
This does not check for any missing values. Any field in any NewsEntry may be null.- Parameters:
feed- the feed node containing the entry elements- Returns:
- the sorted entries, empty if none
- Throws:
NewsXMLParser.I2PParserException- in ABORT mode if an entry's content contains a node not in the XHTML whitelist
extractCRLEntries
extractBlocklistEntries
This does not check for any missing values. Any field in a BlocklistEntry may be null. Signature is verified here.- Parameters:
feed- the feed node containing the i2p:blocklist element- Returns:
- null if none
getNodes
validate
Validate an XML node, throwing if it is invalid.- Parameters:
node- the node to check against the XHTML whitelist- Returns:
- true if node was removed from parent (only for REMOVE_ELEMENT mode)
- Throws:
NewsXMLParser.I2PParserException- if any node not in whitelist (depends on mode)
main
Command-line entry point for testing.- Parameters:
args- the feed file to parse, optionally followed by an XHTMLMode name