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: RELEASE_2_2_1 $, $Revision: 1.5 $
Author:
Marc De Scheemaecker

Constructor Summary
XMLUtil()
           
 
Method Summary
(package private) static boolean checkLiteral(IXMLReader reader, 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 entity)
          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 errorUnexpectedCDATA(java.lang.String systemID, int lineNr)
          Throws an XMLParseException to indicate that a CDATA section is unexpected at this point.
(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 errorUnexpectedEntity(java.lang.String systemID, int lineNr, java.lang.String entity)
          Throws an XMLParseException to indicate that an entity reference is unexpected at this point.
(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 processCharLiteral(java.lang.String entity)
          Processes a character literal.
(package private) static void processEntity(java.lang.String entity, IXMLReader reader, IXMLEntityResolver entityResolver)
          Processes an entity.
(package private) static java.lang.String read(IXMLReader reader, char entityChar)
          Reads a character from the reader.
(package private) static char readChar(IXMLReader reader, char entityChar)
          Reads a character from the reader disallowing entities.
(package private) static java.lang.String scanIdentifier(IXMLReader reader)
          Retrieves an identifier from the data.
(package private) static java.lang.String scanPublicID(java.lang.StringBuffer publicID, IXMLReader reader)
          Scans a public ID.
(package private) static java.lang.String scanString(IXMLReader reader, char entityChar, IXMLEntityResolver entityResolver)
          Retrieves a delimited string from the data.
(package private) static java.lang.String scanSystemID(IXMLReader reader)
          Scans a system ID.
(package private) static void skipComment(IXMLReader reader)
          Skips the remainder of a comment.
(package private) static void skipTag(IXMLReader reader)
          Skips the remainder of the current XML tag.
(package private) static void skipWhitespace(IXMLReader reader, java.lang.StringBuffer buffer)
          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)
                 throws java.io.IOException,
                        XMLParseException
Skips the remainder of a comment. It is assumed that <!- is already read.

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

skipTag

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

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

scanPublicID

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

Parameters:
publicID - will contain the public ID
reader - the reader
Returns:
the system ID
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanSystemID

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

Parameters:
reader - the reader
Returns:
the system ID
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

scanIdentifier

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

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

scanString

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

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

processEntity

static void processEntity(java.lang.String entity,
                          IXMLReader reader,
                          IXMLEntityResolver entityResolver)
                   throws java.io.IOException,
                          XMLParseException
Processes an entity.

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

processCharLiteral

static char processCharLiteral(java.lang.String entity)
                        throws java.io.IOException,
                               XMLParseException
Processes a character literal.

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

skipWhitespace

static void skipWhitespace(IXMLReader reader,
                           java.lang.StringBuffer buffer)
                    throws java.io.IOException
Skips whitespace from the reader.

Parameters:
reader - the reader
buffer - where to put the whitespace; null if the whitespace does not have to be stored.
Throws:
java.io.IOException - if an error occurred reading the data

read

static java.lang.String read(IXMLReader reader,
                             char entityChar)
                      throws java.io.IOException,
                             XMLParseException
Reads a character from the reader.

Parameters:
reader - the reader
entityChar - the escape character (& or %) used to indicate an entity
Returns:
the character, or an entity expression (like e.g. &lt;)
Throws:
java.io.IOException - if an error occurred reading the data
XMLParseException

readChar

static char readChar(IXMLReader reader,
                     char entityChar)
              throws java.io.IOException,
                     XMLParseException
Reads a character from the reader disallowing entities.

Parameters:
reader - the reader
entityChar - the escape character (& or %) used to indicate an entity
Throws:
java.io.IOException
XMLParseException

checkLiteral

static boolean checkLiteral(IXMLReader reader,
                            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
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 of the data source
lineNr - the line number in the data source
expectedString - the string that is expected
Throws:
XMLParseException

errorInvalidEntity

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

Parameters:
systemID - the system ID of the data source
lineNr - the line number in the data source
entity - the name of the entity
Throws:
XMLParseException

errorUnexpectedEntity

static void errorUnexpectedEntity(java.lang.String systemID,
                                  int lineNr,
                                  java.lang.String entity)
                           throws XMLParseException
Throws an XMLParseException to indicate that an entity reference is unexpected at this point.

Parameters:
systemID - the system ID of the data source
lineNr - the line number in the data source
entity - the name of the entity
Throws:
XMLParseException

errorUnexpectedCDATA

static void errorUnexpectedCDATA(java.lang.String systemID,
                                 int lineNr)
                          throws XMLParseException
Throws an XMLParseException to indicate that a CDATA section is unexpected at this point.

Parameters:
systemID - the system ID of the data source
lineNr - the line number in the data source
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 of the data source
lineNr - the line number in the data source
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 of the data source
lineNr - the line number in the data source
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 of the data source
lineNr - the line number in the data source
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 of the data source
lineNr - the line number in the data source
parentElementName - the name of the parent element
missingElementName - the name of the missing element
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 of the data source
lineNr - the line number in the data source
parentElementName - the name of the parent element
unexpectedElementName - the name of the unexpected element
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 of the data source
lineNr - the line number in the data source
elementName - the name of the element
attributeName - the name of the missing 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 of the data source
lineNr - the line number in the data source
elementName - the name of the element
attributeName - the name of the unexpected 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 of the data source
lineNr - the line number in the data source
elementName - the name of the element
attributeName - the name of the attribute
attributeValue - the value of that 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 of the data source
lineNr - the line number in the data source
parentElementName - the name of the parent 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 of the data source
lineNr - the line number in the data source
parentElementName - the name of the parent 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 of the data source
lineNr - the line number in the data source
message - the error message
elementName - the name of the element
attributeName - the name of the attribute
attributeValue - the value of that attribute
Throws:
XMLValidationException