public class SourceReader extends Object
Source
.
Depending on the type of the input source this may involve an
XML transformation or it may not; such a transformation is not
performed if it is not required.
The transformer object used in the case that transformations are required may be accessed or set to permit some customisation of the way the transformation is done. Some convenience methods are provided for doing these settings as well.
Constructor and Description |
---|
SourceReader() |
Modifier and Type | Method and Description |
---|---|
Node |
getDOM(Source src)
Returns a DOM Node representing the given source.
|
Element |
getElement(Source src)
Returns a DOM Element representing the given source.
|
Transformer |
getTransformer()
Returns a reference to the Transformer object used for transformations
used by this object.
|
InputStream |
getXMLStream(Source src)
Returns an input stream from which the serialised XML text
corresponding to a given Source can be read.
|
SourceReader |
setIncludeDeclaration(boolean flag)
Sets whether the
writeSource methods will output an XML
declaration at the start of the XML output. |
SourceReader |
setIndent(int indent)
Tries to set the indent level used by the
writeSource
methods. |
void |
setTransformer(Transformer trans)
Sets the transformer object used for transformations.
|
void |
writeSource(Source src,
OutputStream ostrm)
Writes the contents of a given Source into a given OutputStream.
|
void |
writeSource(Source src,
Writer wr)
Writes the contents of a given Source into a given Writer.
|
public Transformer getTransformer()
DOMSource
) this transformer
will not be used.public void setTransformer(Transformer trans)
DOMSource
) this transformer
will not be used.trans
- the transformer object to be used when transformation is
necessary. If null
is supplied, a default
transformer will be used.public Node getDOM(Source src) throws TransformerException
Transformer
,
whose behaviour is in turn determined by its
ErrorListener
.
By default, this SourceReader
is installed as the
ErrorListener
.src
- the Source for which the DOM is requiredElement
) representing the
XML data in src
TransformerException
- if some error occurs in transformation
or I/Opublic Element getElement(Source src) throws TransformerException
getDOM(javax.xml.transform.Source)
and then finds
an element in the result - if the result is an element that is
returned, but if it is a Document then the top-level document
element is returned. Anything else throws an IllegalArgumentException.src
- the Source for which the DOM is requiredsrc
TransformerException
- if some error occurs in transformation
or I/OIllegalArgumentException
- if src does not represent a
Document or Elementpublic void writeSource(Source src, Writer wr) throws TransformerException
Hmm, not sure if the encoding is handled correctly here for SAXSources...
src
- the Source to be writtenwr
- the destination for the content of src
TransformerException
- if some error occurs in transformation
or I/Opublic void writeSource(Source src, OutputStream ostrm) throws TransformerException
src
- the Source to be writtenostrm
- the destination for the content of src
TransformerException
- if some error occurs in transformation
or I/Opublic InputStream getXMLStream(Source src)
src
- the Source to be readsrc
public SourceReader setIndent(int indent)
writeSource
methods.
This method modifies the output properties of the the
current transformer to affect the way it does the transformation
(so will be undone by a subsequent setTransformer
).
If the supplied indent
value is >=0 then the transformer
may add whitespace when producing the XML output; it will be encouraged
to prettyprint the XML using indent
spaces to indicate
element nesting, though whether this is actually done depends on
which parser is actually being used by JAXP.
If indent<0
then no whitespace will be added when
outputting XML.
By default, no whitespace is added.
For convenience the method returns this SourceReader
is returned.
indent
- indicates if and how whitespace should be added by
writeSource
methodsSourceReader
public SourceReader setIncludeDeclaration(boolean flag)
writeSource
methods will output an XML
declaration at the start of the XML output.
This method modifies the output properties of the the
current transformer to affect the way it does the transformation
(so will be undone by a subsequent setTransformer
).
By default, the declaration is included
For convenience the method returns this SourceReader
is returned.
flag
- true
if the writeSource
methods
are to output an XML declaration,
false
if they are not toSourceReader
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.