org.apache.xerces.xinclude

Class XIncludeTextReader

Known Direct Subclasses:
XInclude11TextReader

public class XIncludeTextReader
extends java.lang.Object

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.

Version:
$Id: XIncludeTextReader.java,v 1.7 2004/01/21 17:07:30 mrglavas Exp $

Authors:
Michael Glavassevich, IBM
Peter McCracken, IBM
Arun Yadav, Sun Microsystems Inc.

See Also:
XIncludeHandler

Constructor Summary

XIncludeTextReader(org.apache.xerces.xni.parser.XMLInputSource source, XIncludeHandler handler)
Construct the XIncludeReader using the XMLInputSource and XIncludeHandler.

Method Summary

void
close()
Closes the stream.
protected void
consumeBOM(InputStream stream, String encoding)
Removes the byte order mark from the stream, if it exists.
protected String
getEncodingName(InputStream stream)
XMLEntityManager cares about endian-ness, since it creates its own optimized readers.
protected String
getEncodingName(byte[] b4)
REVISIT: This code is taken from org.apache.xerces.impl.XMLEntityManager.
protected Reader
getReader(org.apache.xerces.xni.parser.XMLInputSource source)
Return the Reader for given XMLInputSource.
protected boolean
isValid(int ch)
Returns true if the specified character is a valid XML character as per the rules of XML 1.0.
void
parse()
Read the input stream as text, and pass the text on to the XIncludeHandler using calls to characters().
void
setErrorReporter(XMLErrorReporter errorReporter)
Sets the XMLErrorReporter used for reporting errors while reading the text include.
void
setHttpProperties(String accept, String acceptCharset, String acceptLanguage)
Sets content negotation parameters to be attached to an HTTP request.

Constructor Details

XIncludeTextReader

public XIncludeTextReader(org.apache.xerces.xni.parser.XMLInputSource source,
                          XIncludeHandler handler)
            throws IOException
Construct the XIncludeReader using the XMLInputSource and XIncludeHandler.

Parameters:
source - The XMLInputSource to use.
handler - The XIncludeHandler to use.

Method Details

close

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


consumeBOM

protected void consumeBOM(InputStream stream,
                          String encoding)
            throws IOException
Removes the byte order mark from the stream, if it exists.

Parameters:
stream -
encoding -


getEncodingName

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


getEncodingName

protected String getEncodingName(byte[] b4)
REVISIT: This code is taken from org.apache.xerces.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 - The first four bytes of the input.

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


getReader

protected Reader getReader(org.apache.xerces.xni.parser.XMLInputSource source)
            throws IOException
Return the Reader for given XMLInputSource.

Parameters:
source - The XMLInputSource to use.


isValid

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 - The character to check.


parse

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.


setErrorReporter

public void setErrorReporter(XMLErrorReporter errorReporter)
Sets the XMLErrorReporter used for reporting errors while reading the text include.

Parameters:
errorReporter - the XMLErrorReporter to be used for reporting errors.


setHttpProperties

public void setHttpProperties(String accept,
                              String acceptCharset,
                              String acceptLanguage)
Sets content negotation parameters to be attached to an HTTP request.

Parameters:
accept - the Accept HTTP request property
acceptCharset - the Accept-Charset HTTP request property
acceptLanguage - the Accept-Language HTTP request property


Copyright B) 1999-2004 Apache XML Project. All Rights Reserved.