APIdia Launch Partner
Top Description Fields Constructors Methods
com.sun.org.apache.xerces.internal.xinclude

public Class XIncludeTextReader

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.org.apache.xerces.internal.xinclude.XInclude11TextReader
Imports
com.sun.org.apache.xerces.internal.impl.XMLEntityManager, .XMLErrorReporter, com.sun.org.apache.xerces.internal.impl.io.ASCIIReader, .Latin1Reader, .UTF16Reader, .UTF8Reader, com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter, com.sun.org.apache.xerces.internal.util.EncodingMap, .HTTPInputSource, .MessageFormatter, .XMLChar, com.sun.org.apache.xerces.internal.xni.XMLString, com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource, java.io.BufferedInputStream, .IOException, .InputStream, .InputStreamReader, .Reader, java.net.HttpURLConnection, .URL, .URLConnection, java.util.Iterator, .Locale, .Map

This class is used for reading resources requested in <include> elements, when the parse attribute of the <include> element is "text". Using this class will open the location, detect the encoding, and discard the byte order mark, if applicable.

Revisit

Much of the code in this class is taken from XMLEntityManager. It would be nice if this code could be shared in some way. However, since XMLEntityManager is used for reading files as XML, and this needs to read files as text, there would need to be some refactoring done.

Authors
Michael Glavassevich, IBM, Peter McCracken, IBM, Ankit Pasricha, IBM, Arun Yadav, Sun Microsystems Inc.
See Also
XIncludeHandler

Field Summary

Modifier and TypeField and Description
private XMLErrorReporter
private final XIncludeHandler
private Reader
private XMLInputSource
private XMLString

Constructor Summary

AccessConstructor and Description
public
XIncludeTextReader(XMLInputSource
The XMLInputSource to use.
source
,
XIncludeHandler
The XIncludeHandler to use.
handler
,
int
The size of this text reader's buffer.
bufferSize
)

Construct the XIncludeReader using the XMLInputSource and XIncludeHandler.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Closes the stream.

protected String
consumeBOM(InputStream stream, String encoding)

Removes the byte order mark from the stream, if it exists and returns the encoding name.

private Reader
createASCIIReader(InputStream stream)

Create a new ASCII reader from the InputStream.

private Reader
createLatin1Reader(InputStream stream)

Create a new ISO-8859-1 reader from the InputStream.

private Reader
createUTF16Reader(InputStream stream, boolean isBigEndian)

Create a new UTF-16 reader from the InputStream.

private Reader
createUTF8Reader(InputStream stream)

Create a new UTF-8 reader from the InputStream.

protected String
getEncodingName(InputStream stream)

XMLEntityManager cares about endian-ness, since it creates its own optimized readers.

protected String

Returns:

the encoding name, or null if no encoding could be detected
getEncodingName
(byte[]
The first four bytes of the input.
b4
)

Revisit

This code is taken from com.sun.org.apache.xerces.internal.impl.XMLEntityManager.

protected Reader
getReader(XMLInputSource
The XMLInputSource to use.
source
)

Return the Reader for given XMLInputSource.

protected boolean
isValid(int
The character to check.
ch
)

Returns true if the specified character is a valid XML character as per the rules of XML 1.0.

public void
parse()

Read the input stream as text, and pass the text on to the XIncludeHandler using calls to characters().

protected void
setBufferSize(int
The size of the buffer desired
bufferSize
)

Sets the buffer size property for the reader which decides the chunk sizes that are parsed by the reader at a time and passed to the handler

public void
setErrorReporter(XMLErrorReporter
the XMLErrorReporter to be used for reporting errors.
errorReporter
)

Sets the XMLErrorReporter used for reporting errors while reading the text include.

public void
setInputSource(XMLInputSource
The XMLInputSource to use.
source
)

Sets the input source on this text reader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

fErrorReporterback to summary
private XMLErrorReporter fErrorReporter
fHandlerback to summary
private final XIncludeHandler fHandler
fReaderback to summary
private Reader fReader
fSourceback to summary
private XMLInputSource fSource
fTempStringback to summary
private XMLString fTempString

Constructor Detail

XIncludeTextReaderback to summary
public XIncludeTextReader(XMLInputSource source, XIncludeHandler handler, int bufferSize) throws IOException

Construct the XIncludeReader using the XMLInputSource and XIncludeHandler.

Parameters
source:XMLInputSource

The XMLInputSource to use.

handler:XIncludeHandler

The XIncludeHandler to use.

bufferSize:int

The size of this text reader's buffer.

Method Detail

closeback to summary
public void close() throws IOException

Closes the stream. Call this after parse(), or when there is no longer any need for this object.

consumeBOMback to summary
protected String consumeBOM(InputStream stream, String encoding) throws IOException

Removes the byte order mark from the stream, if it exists and returns the encoding name.

createASCIIReaderback to summary
private Reader createASCIIReader(InputStream stream)

Create a new ASCII reader from the InputStream.

createLatin1Readerback to summary
private Reader createLatin1Reader(InputStream stream)

Create a new ISO-8859-1 reader from the InputStream.

createUTF16Readerback to summary
private Reader createUTF16Reader(InputStream stream, boolean isBigEndian)

Create a new UTF-16 reader from the InputStream.

createUTF8Readerback to summary
private Reader createUTF8Reader(InputStream stream)

Create a new UTF-8 reader from the InputStream.

getEncodingNameback to summary
protected String getEncodingName(InputStream stream) throws IOException

XMLEntityManager cares about endian-ness, since it creates its own optimized readers. Since we're just using generic Java readers for now, we're not caring about endian-ness. If this changes, even more code needs to be copied from XMLEntity manager. -- PJM

getEncodingNameback to summary
protected String getEncodingName(byte[] b4)

Revisit

This code is taken from com.sun.org.apache.xerces.internal.impl.XMLEntityManager. Is there any way we can share the code, without having it implemented twice? I think we should make it public and static in XMLEntityManager. --PJM Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.

Parameters
b4:byte[]

The first four bytes of the input.

Returns:String

the encoding name, or null if no encoding could be detected

getReaderback to summary
protected Reader getReader(XMLInputSource source) throws IOException

Return the Reader for given XMLInputSource.

Parameters
source:XMLInputSource

The XMLInputSource to use.

isValidback to summary
protected boolean isValid(int ch)

Returns true if the specified character is a valid XML character as per the rules of XML 1.0.

Parameters
ch:int

The character to check.

parseback to summary
public void parse() throws IOException

Read the input stream as text, and pass the text on to the XIncludeHandler using calls to characters(). This will read all of the text it can from the resource.

setBufferSizeback to summary
protected void setBufferSize(int bufferSize)

Sets the buffer size property for the reader which decides the chunk sizes that are parsed by the reader at a time and passed to the handler

Parameters
bufferSize:int

The size of the buffer desired

setErrorReporterback to summary
public void setErrorReporter(XMLErrorReporter errorReporter)

Sets the XMLErrorReporter used for reporting errors while reading the text include.

Parameters
errorReporter:XMLErrorReporter

the XMLErrorReporter to be used for reporting errors.

setInputSourceback to summary
public void setInputSource(XMLInputSource source)

Sets the input source on this text reader.

Parameters
source:XMLInputSource

The XMLInputSource to use.