JHotDraw 7.4.1

net.n3.nanoxml
Class StdXMLReader

java.lang.Object
  extended by net.n3.nanoxml.StdXMLReader
All Implemented Interfaces:
IXMLReader

public class StdXMLReader
extends java.lang.Object
implements IXMLReader

StdXMLReader reads the data to be parsed.

Version:
$Name: RELEASE_2_2_1 $, $Revision: 1.4 $
Author:
Marc De Scheemaecker

Constructor Summary
StdXMLReader(java.io.InputStream stream)
          Initializes the XML reader.
StdXMLReader(java.io.Reader reader)
          Initializes the XML reader.
StdXMLReader(java.lang.String publicID, java.lang.String systemID)
          Initializes the reader from a system and public ID.
 
Method Summary
 boolean atEOF()
          Returns true if there are no more characters left to be read.
 boolean atEOFOfCurrentStream()
          Returns true if the current stream has no more characters left to be read.
static IXMLReader fileReader(java.lang.String filename)
          Creates a new reader using a file as input.
protected  void finalize()
          Cleans up the object when it's destroyed.
protected  java.lang.String getEncoding(java.lang.String str)
          Scans the encoding from an <?
 int getLineNr()
          Returns the line number of the data in the current stream.
 java.lang.String getPublicID()
          Returns the current public ID.
 int getStreamLevel()
          Returns the current "level" of the stream on the stack of streams.
 java.lang.String getSystemID()
          Returns the current system ID.
 java.io.Reader openStream(java.lang.String publicID, java.lang.String systemID)
          Opens a stream from a public and system ID.
 char read()
          Reads a character.
 void setPublicID(java.lang.String publicID)
          Sets the public ID of the current stream.
 void setSystemID(java.lang.String systemID)
          Sets the system ID of the current stream.
 void startNewStream(java.io.Reader reader)
          Starts a new stream from a Java reader.
 void startNewStream(java.io.Reader reader, boolean isInternalEntity)
          Starts a new stream from a Java reader.
protected  java.io.Reader stream2reader(java.io.InputStream stream, java.lang.StringBuffer charsRead)
          Converts a stream to a reader while detecting the encoding.
static IXMLReader stringReader(java.lang.String str)
          Creates a new reader using a string as input.
 void unread(char ch)
          Pushes the last character read back to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StdXMLReader

public StdXMLReader(java.lang.String publicID,
                    java.lang.String systemID)
             throws java.net.MalformedURLException,
                    java.io.FileNotFoundException,
                    java.io.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:
java.net.MalformedURLException - if the system ID does not contain a valid URL
java.io.FileNotFoundException - if the system ID refers to a local file which does not exist
java.io.IOException - if an error occurred opening the stream

StdXMLReader

public StdXMLReader(java.io.Reader reader)
Initializes the XML reader.

Parameters:
reader - the input for the XML data.

StdXMLReader

public StdXMLReader(java.io.InputStream stream)
             throws java.io.IOException
Initializes the XML reader.

Parameters:
stream - the input for the XML data.
Throws:
java.io.IOException - if an I/O error occurred
Method Detail

stringReader

public static IXMLReader stringReader(java.lang.String str)
Creates a new reader using a string as input.

Parameters:
str - the string containing the XML data

fileReader

public static IXMLReader fileReader(java.lang.String filename)
                             throws java.io.FileNotFoundException,
                                    java.io.IOException
Creates a new reader using a file as input.

Parameters:
filename - the name of the file containing the XML data
Throws:
java.io.FileNotFoundException - if the file could not be found
java.io.IOException - if an I/O error occurred

finalize

protected void finalize()
                 throws java.lang.Throwable
Cleans up the object when it's destroyed.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

getEncoding

protected java.lang.String getEncoding(java.lang.String str)
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

protected java.io.Reader stream2reader(java.io.InputStream stream,
                                       java.lang.StringBuffer charsRead)
                                throws java.io.IOException
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:
java.io.IOException - if an I/O error occurred

read

public char read()
          throws java.io.IOException
Reads a character.

Specified by:
read in interface IXMLReader
Returns:
the character
Throws:
java.io.IOException - if no character could be read

atEOFOfCurrentStream

public boolean atEOFOfCurrentStream()
                             throws java.io.IOException
Returns true if the current stream has no more characters left to be read.

Specified by:
atEOFOfCurrentStream in interface IXMLReader
Throws:
java.io.IOException - if an I/O error occurred

atEOF

public boolean atEOF()
              throws java.io.IOException
Returns true if there are no more characters left to be read.

Specified by:
atEOF in interface IXMLReader
Throws:
java.io.IOException - if an I/O error occurred

unread

public void unread(char ch)
            throws java.io.IOException
Pushes the last character read back to the stream.

Specified by:
unread in interface IXMLReader
Parameters:
ch - the character to push back.
Throws:
java.io.IOException - if an I/O error occurred

openStream

public java.io.Reader openStream(java.lang.String publicID,
                                 java.lang.String systemID)
                          throws java.net.MalformedURLException,
                                 java.io.FileNotFoundException,
                                 java.io.IOException
Opens a stream from a public and system ID.

Specified by:
openStream in interface IXMLReader
Parameters:
publicID - the public ID, which may be null
systemID - the system ID, which is never null
Throws:
java.net.MalformedURLException - if the system ID does not contain a valid URL
java.io.FileNotFoundException - if the system ID refers to a local file which does not exist
java.io.IOException - if an error occurred opening the stream

startNewStream

public void startNewStream(java.io.Reader reader)
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:
startNewStream in interface IXMLReader
Parameters:
reader - the non-null reader to read the new data from

startNewStream

public void startNewStream(java.io.Reader reader,
                           boolean isInternalEntity)
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:
startNewStream in interface IXMLReader
Parameters:
reader - the non-null reader to read the new data from
isInternalEntity - 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:
getStreamLevel in interface IXMLReader

getLineNr

public int getLineNr()
Returns the line number of the data in the current stream.

Specified by:
getLineNr in interface IXMLReader

setSystemID

public void setSystemID(java.lang.String systemID)
                 throws java.net.MalformedURLException
Sets the system ID of the current stream.

Specified by:
setSystemID in interface IXMLReader
Parameters:
systemID - the system ID
Throws:
java.net.MalformedURLException - if the system ID does not contain a valid URL

setPublicID

public void setPublicID(java.lang.String publicID)
Sets the public ID of the current stream.

Specified by:
setPublicID in interface IXMLReader
Parameters:
publicID - the public ID

getSystemID

public java.lang.String getSystemID()
Returns the current system ID.

Specified by:
getSystemID in interface IXMLReader

getPublicID

public java.lang.String getPublicID()
Returns the current public ID.

Specified by:
getPublicID in interface IXMLReader

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.