Package net.n3.nanoxml
Class StdXMLReader
java.lang.Object
net.n3.nanoxml.StdXMLReader
- All Implemented Interfaces:
IXMLReader
StdXMLReader reads the data to be parsed.
- Version:
- $Name: RELEASE_2_2_1 $, $Revision: 1.4 $
- Author:
- Marc De Scheemaecker
-
Constructor Summary
ConstructorsConstructorDescriptionStdXMLReader(InputStream stream) Initializes the XML reader.StdXMLReader(Reader reader) Initializes the XML reader.StdXMLReader(String publicID, String systemID) Initializes the reader from a system and public ID. -
Method Summary
Modifier and TypeMethodDescriptionbooleanatEOF()Returns true if there are no more characters left to be read.booleanReturns true if the current stream has no more characters left to be read.static IXMLReaderfileReader(String filename) Creates a new reader using a file as input.protected voidfinalize()Cleans up the object when it's destroyed.protected StringgetEncoding(String str) Scans the encoding from an <?xml...?> tag.intReturns the line number of the data in the current stream.Returns the current public ID.intReturns the current "level" of the stream on the stack of streams.Returns the current system ID.openStream(String publicID, String systemID) Opens a stream from a public and system ID.charread()Reads a character.voidsetPublicID(String publicID) Sets the public ID of the current stream.voidsetSystemID(String systemID) Sets the system ID of the current stream.voidstartNewStream(Reader reader) Starts a new stream from a Java reader.voidstartNewStream(Reader reader, boolean isInternalEntity) Starts a new stream from a Java reader.protected Readerstream2reader(InputStream stream, StringBuffer charsRead) Converts a stream to a reader while detecting the encoding.static IXMLReaderstringReader(String str) Creates a new reader using a string as input.voidunread(char ch) Pushes the last character read back to the stream.
-
Constructor Details
-
StdXMLReader
public StdXMLReader(String publicID, String systemID) throws MalformedURLException, FileNotFoundException, IOException Initializes the reader from a system and public ID.- Parameters:
publicID- the public ID which may be null.systemID- the non-null system ID.- Throws:
MalformedURLException- if the system ID does not contain a valid URLFileNotFoundException- if the system ID refers to a local file which does not existIOException- if an error occurred opening the stream
-
StdXMLReader
Initializes the XML reader.- Parameters:
reader- the input for the XML data.
-
StdXMLReader
Initializes the XML reader.- Parameters:
stream- the input for the XML data.- Throws:
IOException- if an I/O error occurred
-
-
Method Details
-
stringReader
Creates a new reader using a string as input.- Parameters:
str- the string containing the XML data
-
fileReader
Creates a new reader using a file as input.- Parameters:
filename- the name of the file containing the XML data- Throws:
FileNotFoundException- if the file could not be foundIOException- if an I/O error occurred
-
finalize
Cleans up the object when it's destroyed. -
getEncoding
Scans the encoding from an <?xml...?> tag.- Parameters:
str- the first tag in the XML data.- Returns:
- the encoding, or null if no encoding has been specified.
-
stream2reader
Converts a stream to a reader while detecting the encoding.- Parameters:
stream- the input for the XML data.charsRead- buffer where to put characters that have been read- Throws:
IOException- if an I/O error occurred
-
read
Reads a character.- Specified by:
readin interfaceIXMLReader- Returns:
- the character
- Throws:
IOException- if no character could be read
-
atEOFOfCurrentStream
Returns true if the current stream has no more characters left to be read.- Specified by:
atEOFOfCurrentStreamin interfaceIXMLReader- Throws:
IOException- if an I/O error occurred
-
atEOF
Returns true if there are no more characters left to be read.- Specified by:
atEOFin interfaceIXMLReader- Throws:
IOException- if an I/O error occurred
-
unread
Pushes the last character read back to the stream.- Specified by:
unreadin interfaceIXMLReader- Parameters:
ch- the character to push back.- Throws:
IOException- if an I/O error occurred
-
openStream
public Reader openStream(String publicID, String systemID) throws MalformedURLException, FileNotFoundException, IOException Opens a stream from a public and system ID.- Specified by:
openStreamin interfaceIXMLReader- Parameters:
publicID- the public ID, which may be nullsystemID- the system ID, which is never null- Throws:
MalformedURLException- if the system ID does not contain a valid URLFileNotFoundException- if the system ID refers to a local file which does not existIOException- if an error occurred opening the stream
-
startNewStream
Starts a new stream from a Java reader. The new stream is used temporary to read data from. If that stream is exhausted, control returns to the parent stream.- Specified by:
startNewStreamin interfaceIXMLReader- Parameters:
reader- the non-null reader to read the new data from
-
startNewStream
Starts a new stream from a Java reader. The new stream is used temporary to read data from. If that stream is exhausted, control returns to the parent stream.- Specified by:
startNewStreamin interfaceIXMLReader- Parameters:
reader- the non-null reader to read the new data fromisInternalEntity- true if the reader is produced by resolving an internal entity
-
getStreamLevel
public int getStreamLevel()Returns the current "level" of the stream on the stack of streams.- Specified by:
getStreamLevelin interfaceIXMLReader
-
getLineNr
public int getLineNr()Returns the line number of the data in the current stream.- Specified by:
getLineNrin interfaceIXMLReader
-
setSystemID
Sets the system ID of the current stream.- Specified by:
setSystemIDin interfaceIXMLReader- Parameters:
systemID- the system ID- Throws:
MalformedURLException- if the system ID does not contain a valid URL
-
setPublicID
Sets the public ID of the current stream.- Specified by:
setPublicIDin interfaceIXMLReader- Parameters:
publicID- the public ID
-
getSystemID
Returns the current system ID.- Specified by:
getSystemIDin interfaceIXMLReader
-
getPublicID
Returns the current public ID.- Specified by:
getPublicIDin interfaceIXMLReader
-