net.n3.nanoxml
Class XMLUtil

java.lang.Object
  extended by net.n3.nanoxml.XMLUtil

 class XMLUtil
extends java.lang.Object

Utility methods for NanoXML.

Version:
$Name$, $Revision: 2163 $
Author:
Marc De Scheemaecker

Constructor Summary
XMLUtil()
           
 
Method Summary
(package private) static boolean checkLiteral(IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver, java.lang.String literal)
          Returns true if the data starts with literal.
(package private) static void errorClosingTagNotEmpty(java.lang.String systemID, int lineNr)
          Throws an XMLParseException to indicate that extra data is encountered in a closing tag.
(package private) static void errorExpectedInput(java.lang.String systemID, int lineNr, java.lang.String expectedString)
          Throws an XMLParseException to indicate that an expected string is not encountered.
(package private) static void errorInvalidAttributeValue(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Throws an XMLValidationException to indicate that an attribute has an invalid value.
(package private) static void errorInvalidEntity(java.lang.String systemID, int lineNr, java.lang.String key)
          Throws an XMLParseException to indicate that an entity could not be resolved.
(package private) static void errorInvalidInput(java.lang.String systemID, int lineNr, java.lang.String unexpectedString)
          Throws an XMLParseException to indicate that a string is not expected at this point.
(package private) static void errorMissingAttribute(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName)
          Throws an XMLValidationException to indicate that an attribute is missing.
(package private) static void errorMissingElement(java.lang.String systemID, int lineNr, java.lang.String parentElementName, java.lang.String missingElementName)
          Throws an XMLValidationException to indicate that an element is missing.
(package private) static void errorMissingPCData(java.lang.String systemID, int lineNr, java.lang.String parentElementName)
          Throws an XMLValidationException to indicate that a #PCDATA element was missing.
(package private) static void errorUnexpectedAttribute(java.lang.String systemID, int lineNr, java.lang.String elementName, java.lang.String attributeName)
          Throws an XMLValidationException to indicate that an attribute is unexpected.
(package private) static void errorUnexpectedElement(java.lang.String systemID, int lineNr, java.lang.String parentElementName, java.lang.String unexpectedElementName)
          Throws an XMLValidationException to indicate that an element is unexpected.
(package private) static void errorUnexpectedPCData(java.lang.String systemID, int lineNr, java.lang.String parentElementName)
          Throws an XMLValidationException to indicate that a #PCDATA element was unexpected.
(package private) static void errorWrongClosingTag(java.lang.String systemID, int lineNr, java.lang.String expectedName, java.lang.String wrongName)
          Throws an XMLParseException to indicate that the closing tag of an element does not match the opening tag.
(package private) static char read(IXMLReader reader, boolean[] isEntityValue, char escapeChar, IXMLEntityResolver entityResolver)
          Reads a character from the reader.
(package private) static java.io.Reader scanEntity(boolean[] isCharLiteral, IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver)
          Processes an entity.
(package private) static java.lang.String scanIdentifier(IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver)
          Retrieves an identifier from the data.
(package private) static java.lang.String scanPublicID(java.lang.StringBuffer publicID, IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver)
          Scans a public ID.
(package private) static java.lang.String scanString(IXMLReader reader, char escapeChar, boolean normalizeWhitespace, IXMLEntityResolver entityResolver)
          Retrieves a delimited string from the data.
(package private) static java.lang.String scanSystemID(IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver)
          Scans a system ID.
(package private) static void skipComment(IXMLReader reader, IXMLEntityResolver entityResolver)
          Skips the remainder of a comment.
(package private) static void skipTag(IXMLReader reader, char escapeChar, IXMLEntityResolver entityResolver)
          Skips the remainder of the current XML tag.
(package private) static void skipWhitespace(IXMLReader reader, char escapeChar, java.lang.StringBuffer buffer, boolean[] isEntity)
          Skips whitespace from the reader.
(package private) static void validationError(java.lang.String systemID, int lineNr, java.lang.String message, java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
          Throws an XMLValidationException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

XMLUtil()
Method Detail

skipComment

static void skipComment(IXMLReader reader,
                        IXMLEntityResolver entityResolver)
                 throws java.io.IOException,
                        XMLParseException
Skips the remainder of a comment. It is assumed that <!- is already read.

Parameters:
reader - the reader
entityResolver - the entity resolver
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

skipTag

static void skipTag(IXMLReader reader,
                    char escapeChar,
                    IXMLEntityResolver entityResolver)
             throws java.io.IOException,
                    XMLParseException
Skips the remainder of the current XML tag.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanPublicID

static java.lang.String scanPublicID(java.lang.StringBuffer publicID,
                                     IXMLReader reader,
                                     char escapeChar,
                                     IXMLEntityResolver entityResolver)
                              throws java.io.IOException,
                                     XMLParseException
Scans a public ID.

Parameters:
publicID - will contain the public ID
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Returns:
the system ID
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanSystemID

static java.lang.String scanSystemID(IXMLReader reader,
                                     char escapeChar,
                                     IXMLEntityResolver entityResolver)
                              throws java.io.IOException,
                                     XMLParseException
Scans a system ID.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Returns:
the system ID
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanIdentifier

static java.lang.String scanIdentifier(IXMLReader reader,
                                       char escapeChar,
                                       IXMLEntityResolver entityResolver)
                                throws java.io.IOException,
                                       XMLParseException
Retrieves an identifier from the data.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanString

static java.lang.String scanString(IXMLReader reader,
                                   char escapeChar,
                                   boolean normalizeWhitespace,
                                   IXMLEntityResolver entityResolver)
                            throws java.io.IOException,
                                   XMLParseException
Retrieves a delimited string from the data.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
normalizeWhitespace - if all whitespace chars need to be converted to spaces
entityResolver - the entity resolver
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanEntity

static java.io.Reader scanEntity(boolean[] isCharLiteral,
                                 IXMLReader reader,
                                 char escapeChar,
                                 IXMLEntityResolver entityResolver)
                          throws java.io.IOException,
                                 XMLParseException
Processes an entity.

Parameters:
isCharLiteral - will contain true if the entity is a char literal
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Returns:
a reader from which the entity value can be retrieved
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

skipWhitespace

static void skipWhitespace(IXMLReader reader,
                           char escapeChar,
                           java.lang.StringBuffer buffer,
                           boolean[] isEntity)
                    throws java.io.IOException
Skips whitespace from the reader.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
buffer - where to put the whitespace; null if the whitespace does not have to be stored.
isEntity - if not null, will contain true if the data following the whitespace is an entity
Throws:
java.io.IOException - if an error occurred reading the data

read

static char read(IXMLReader reader,
                 boolean[] isEntityValue,
                 char escapeChar,
                 IXMLEntityResolver entityResolver)
          throws java.io.IOException,
                 XMLParseException
Reads a character from the reader.

Parameters:
reader - the reader
isEntityValue - if the character is the first character in an entity
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

checkLiteral

static boolean checkLiteral(IXMLReader reader,
                            char escapeChar,
                            IXMLEntityResolver entityResolver,
                            java.lang.String literal)
                     throws java.io.IOException,
                            XMLParseException
Returns true if the data starts with literal. Enough chars are read to determine this result.

Parameters:
reader - the reader
escapeChar - the escape character (& or %)
entityResolver - the entity resolver
literal - the literal to check
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

errorExpectedInput

static void errorExpectedInput(java.lang.String systemID,
                               int lineNr,
                               java.lang.String expectedString)
                        throws XMLParseException
Throws an XMLParseException to indicate that an expected string is not encountered.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
expectedString - the string that is expected
Throws:
XMLParseException

errorInvalidEntity

static void errorInvalidEntity(java.lang.String systemID,
                               int lineNr,
                               java.lang.String key)
                        throws XMLParseException
Throws an XMLParseException to indicate that an entity could not be resolved.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
key - the name of the entity
Throws:
XMLParseException

errorInvalidInput

static void errorInvalidInput(java.lang.String systemID,
                              int lineNr,
                              java.lang.String unexpectedString)
                       throws XMLParseException
Throws an XMLParseException to indicate that a string is not expected at this point.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
unexpectedString - the string that is unexpected
Throws:
XMLParseException

errorWrongClosingTag

static void errorWrongClosingTag(java.lang.String systemID,
                                 int lineNr,
                                 java.lang.String expectedName,
                                 java.lang.String wrongName)
                          throws XMLParseException
Throws an XMLParseException to indicate that the closing tag of an element does not match the opening tag.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
expectedName - the name of the opening tag
wrongName - the name of the closing tag
Throws:
XMLParseException

errorClosingTagNotEmpty

static void errorClosingTagNotEmpty(java.lang.String systemID,
                                    int lineNr)
                             throws XMLParseException
Throws an XMLParseException to indicate that extra data is encountered in a closing tag.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
Throws:
XMLParseException

errorMissingElement

static void errorMissingElement(java.lang.String systemID,
                                int lineNr,
                                java.lang.String parentElementName,
                                java.lang.String missingElementName)
                         throws XMLValidationException
Throws an XMLValidationException to indicate that an element is missing.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
parentElementName - the name of the offending element
missingElementName - the name of the offending attribute
Throws:
XMLValidationException

errorUnexpectedElement

static void errorUnexpectedElement(java.lang.String systemID,
                                   int lineNr,
                                   java.lang.String parentElementName,
                                   java.lang.String unexpectedElementName)
                            throws XMLValidationException
Throws an XMLValidationException to indicate that an element is unexpected.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
parentElementName - the name of the parent attribute
unexpectedElementName - the name of the offending attribute
Throws:
XMLValidationException

errorMissingAttribute

static void errorMissingAttribute(java.lang.String systemID,
                                  int lineNr,
                                  java.lang.String elementName,
                                  java.lang.String attributeName)
                           throws XMLValidationException
Throws an XMLValidationException to indicate that an attribute is missing.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
elementName - the name of the offending element
attributeName - the name of the offending attribute
Throws:
XMLValidationException

errorUnexpectedAttribute

static void errorUnexpectedAttribute(java.lang.String systemID,
                                     int lineNr,
                                     java.lang.String elementName,
                                     java.lang.String attributeName)
                              throws XMLValidationException
Throws an XMLValidationException to indicate that an attribute is unexpected.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
elementName - the name of the offending element
attributeName - the name of the offending attribute
Throws:
XMLValidationException

errorInvalidAttributeValue

static void errorInvalidAttributeValue(java.lang.String systemID,
                                       int lineNr,
                                       java.lang.String elementName,
                                       java.lang.String attributeName,
                                       java.lang.String attributeValue)
                                throws XMLValidationException
Throws an XMLValidationException to indicate that an attribute has an invalid value.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
elementName - the name of the offending element
attributeName - the name of the offending attribute
attributeValue - the value of the offending attribute
Throws:
XMLValidationException

errorMissingPCData

static void errorMissingPCData(java.lang.String systemID,
                               int lineNr,
                               java.lang.String parentElementName)
                        throws XMLValidationException
Throws an XMLValidationException to indicate that a #PCDATA element was missing.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
parentElementName - the name of the offending element
Throws:
XMLValidationException

errorUnexpectedPCData

static void errorUnexpectedPCData(java.lang.String systemID,
                                  int lineNr,
                                  java.lang.String parentElementName)
                           throws XMLValidationException
Throws an XMLValidationException to indicate that a #PCDATA element was unexpected.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
parentElementName - the name of the offending element
Throws:
XMLValidationException

validationError

static void validationError(java.lang.String systemID,
                            int lineNr,
                            java.lang.String message,
                            java.lang.String elementName,
                            java.lang.String attributeName,
                            java.lang.String attributeValue)
                     throws XMLValidationException
Throws an XMLValidationException.

Parameters:
systemID - the system ID from where the data came
lineNr - the line number in the XML data where the exception occurred.
message - the message of the exception.
elementName - the name of the offending element
attributeName - the name of the offending attribute
attributeValue - the value of the offending attribute
Throws:
XMLValidationException