java.lang.Object
org.cybergarage.xml.Parser
- Direct Known Subclasses:
JaxpParser
Abstract base class for XML parsers.
This class provides the foundation for parsing XML documents from various sources including URLs, files, and strings. It includes security measures specific to I2P to prevent access to localhost and private networks.
Key features:
- Abstract parse method for InputStream implementation
- URL parsing with security checks
- File parsing support
- String parsing support
- I2P-specific security restrictions
Field Summary
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionParses XML content from the specified file.abstract Nodeparse(InputStream inStream) Parses XML content from the specified input stream.Parses XML content from the specified string.Parses XML content from the specified URL.
Field Details
USER_AGENT
Agent name sent when fetching a description.- See Also:
PROP_HURLC_PROXY1
Property naming the HttpURLConnection proxy used to fetch a description. Socks and system proxies are checked in TransportManager. See also: Proxies- See Also:
HURLC_PROXY_ENABLED
private static final boolean HURLC_PROXY_ENABLEDTrue when a proxy is configured for fetching descriptions.
Constructor Details
Parser
public Parser()Creates a new Parser instance.
Method Details
parse
Parses XML content from the specified input stream.This is the core parsing method that must be implemented by subclasses. The implementation should parse the XML content and return the root node of the parsed XML document.
- Parameters:
inStream- the input stream containing XML content- Returns:
- the root node of the parsed XML document
- Throws:
ParserException- if parsing fails
parse
Parses XML content from the specified URL.This method includes I2P-specific security checks to prevent access to localhost and private networks. Only HTTP URLs are supported.
- Parameters:
locationURL- the URL to fetch and parse XML content from- Returns:
- the root node of the parsed XML document
- Throws:
ParserException- if URL validation fails, HTTP request fails, or parsing fails
parse
Parses XML content from the specified file.- Parameters:
descriptionFile- the file containing XML content to parse- Returns:
- the root node of the parsed XML document
- Throws:
ParserException- if file reading fails or parsing fails
parse
Parses XML content from the specified string.The string is assumed to contain UTF-8 encoded XML content.
- Parameters:
descr- the string containing XML content to parse- Returns:
- the root node of the parsed XML document
- Throws:
ParserException- if parsing fails