public class SourceReader
extends java.lang.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 |
---|---|
org.w3c.dom.Node |
getDOM(javax.xml.transform.Source src)
Returns a DOM Node representing the given source.
|
org.w3c.dom.Element |
getElement(javax.xml.transform.Source src)
Returns a DOM Element representing the given source.
|
javax.xml.transform.Transformer |
getTransformer()
Returns a reference to the Transformer object used for transformations
used by this object.
|
java.io.InputStream |
getXMLStream(javax.xml.transform.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(javax.xml.transform.Transformer trans)
Sets the transformer object used for transformations.
|
void |
writeSource(javax.xml.transform.Source src,
java.io.OutputStream ostrm)
Writes the contents of a given Source into a given OutputStream.
|
void |
writeSource(javax.xml.transform.Source src,
java.io.Writer wr)
Writes the contents of a given Source into a given Writer.
|
public javax.xml.transform.Transformer getTransformer()
public void setTransformer(javax.xml.transform.Transformer trans)
trans
- the transformer object to be used when transformation is
necessary. If null is supplied, a default
transformer will be used.public org.w3c.dom.Node getDOM(javax.xml.transform.Source src) throws javax.xml.transform.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 requiredjavax.xml.transform.TransformerException
- if some error occurs in transformation
or I/Opublic org.w3c.dom.Element getElement(javax.xml.transform.Source src) throws javax.xml.transform.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 requiredjavax.xml.transform.TransformerException
- if some error occurs in transformation
or I/Ojava.lang.IllegalArgumentException
- if src does not represent a
Document or Elementpublic void writeSource(javax.xml.transform.Source src, java.io.Writer wr) throws javax.xml.transform.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 srcjavax.xml.transform.TransformerException
- if some error occurs in transformation
or I/Opublic void writeSource(javax.xml.transform.Source src, java.io.OutputStream ostrm) throws javax.xml.transform.TransformerException
src
- the Source to be writtenostrm
- the destination for the content of srcjavax.xml.transform.TransformerException
- if some error occurs in transformation
or I/Opublic java.io.InputStream getXMLStream(javax.xml.transform.Source src)
src
- the Source to be readpublic SourceReader setIndent(int indent)
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 methodspublic SourceReader setIncludeDeclaration(boolean flag)
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 to