|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Factory interface for NewsML documents.
This is an abstract factory interface for creating NewsML
documents and nodes from external resources: it contains methods
that can create a top-level NewsML
object or any arbitrary
NewsML node (implementing the BaseNode
interface) given a
URL or a character stream. Normally, this will be the only public
point of access to subpackages that contain contain concrete
implementations, such as DOMNewsMLFactory
.
HINT: a Java Reader
can read from any source,
not just a file. For example, if you need to read NewsML document
from a string, try using a StringReader; if you need to parse data
coming from somewhere else in your program, try a PipedReader.
This class includes setValidation(boolean)
and getValidation()
methods for enabling or disabling DTD validation.
If the validation property is true
, the
factory will process the XML source with DTD-validation or throw an
exception if the underlying implementation does not support
validation; if it is false, the factory will process the XML source
without DTD-validation or throw an exception if the underlying
implementation does not support non-validating parsing. The
default value is system-dependent, but will usually be
false
for reasons explained below.
If validation is false (recommended), the implementation will not load any external XML entities, including the external DTD subset, and will not report validation errors; if validation is true (dangerous: see below), the implementation will attempt to load all externally-referenced XML entities, and will fail with an exception if there are any validation errors.
While DTD-validation is frequently promoted in XML books and workshops, it is almost always a bad idea for production applications: it has the potential to cause serious problems and should be used only with extreme caution (or better yet, not at all). DTD validation opens your applications and your organization to the following serious risks:
NewsMLException
Method Summary | |
NewsML |
createNewsML(Reader input,
String baseURL)
Create a top-level NewsML object from a character stream. |
NewsML |
createNewsML(String url)
Create a top-level NewsML object from a URL. |
BaseNode |
createNode(Reader input,
String baseURL)
Create a NewsML node from a URL. |
BaseNode |
createNode(String url)
Create a NewsML node from a URL. |
boolean |
getValidation()
Get the validation flag. |
void |
setValidation(boolean validation)
Set the validation flag. |
Method Detail |
public void setValidation(boolean validation) throws IOException
validation
- true if the factory is required to perform
DTD validation, false if it is required not to.IOException
- if the implementation does not
support the requested state.getValidation()
public boolean getValidation()
setValidation(boolean)
public NewsML createNewsML(String url) throws IOException
url
- A string in URL format.IOException
- if there is some kind of error reading
the document, including a validation error if validation is
requested.NewsMLException
- if the root element of the document
is not NewsML, or if the underlying implementation does not
support the requested validation type.public NewsML createNewsML(Reader input, String baseURL) throws IOException
input
- The character stream.baseURL
- The base URL for resolving relative links;
if null, will default to a file: URL based on the current
directory.IOException
- if there is some kind of error reading
the document.NewsMLException
- if the root element of the document
is not NewsML.public BaseNode createNode(String url) throws IOException
url
- A string in URL format.IOException
- if there is some kind of error reading
the document.public BaseNode createNode(Reader input, String baseURL) throws IOException
input
- The character stream.baseURL
- The base URL for resolving relative links;
if null, will default to a file: URL based on the current
directory.IOException
- if there is some kind of error reading
the document.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |