Java Doc for XmlParser.java in  » Swing-Library » jEdit » com » microstar » xml » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Swing Library » jEdit » com.microstar.xml 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   com.microstar.xml.XmlParser

XmlParser
public class XmlParser (Code)
Parse XML documents and return parse events through call-backs.

You need to define a class implementing the XmlHandler interface: an object belonging to this class will receive the callbacks for the events. (As an alternative to implementing the full XmlHandler interface, you can simply extend the HandlerBase convenience class.)

Usage (assuming that MyHandler is your implementation of the XmlHandler interface):

 XmlHandler handler = new MyHandler();
 XmlParser parser = new XmlParser();
 parser.setHandler(handler);
 try {
 parser.parse("http://www.host.com/doc.xml", null);
 } catch (Exception e) {
 [do something interesting]
 }
 

Alternatively, you can use the standard SAX interfaces with the SAXDriver class as your entry point.
author:
   Copyright (c) 1997, 1998 by Microstar Software Ltd.
author:
   Written by David Megginson <dmeggins@microstar.com>
version:
   1.1
See Also:   XmlHandler
See Also:   HandlerBase
See Also:   SAXDriver



Field Summary
final public static  intATTRIBUTE_CDATA
     Constant: the attribute value is a string value.
final public static  intATTRIBUTE_DEFAULT_FIXED
     Constant: the attribute was declared #FIXED.
final public static  intATTRIBUTE_DEFAULT_IMPLIED
     Constant: the attribute was declared #IMPLIED.
final public static  intATTRIBUTE_DEFAULT_REQUIRED
     Constant: the attribute was declared #REQUIRED.
final public static  intATTRIBUTE_DEFAULT_SPECIFIED
     Constant: the attribute has a literal default value specified.
final public static  intATTRIBUTE_DEFAULT_UNDECLARED
     Constant: the attribute is not declared.
final public static  intATTRIBUTE_ENTITIES
     Constant: the attribute value is a list of entity names.
final public static  intATTRIBUTE_ENTITY
     Constant: the attribute value is the name of an entity.
final public static  intATTRIBUTE_ENUMERATED
     Constant: the attribute value is a token from an enumeration.
final public static  intATTRIBUTE_ID
     Constant: the attribute value is a unique identifier.
final public static  intATTRIBUTE_IDREF
     Constant: the attribute value is a reference to a unique identifier.
final public static  intATTRIBUTE_IDREFS
     Constant: the attribute value is a list of ID references.
final public static  intATTRIBUTE_NMTOKEN
     Constant: the attribute value is a name token.
final public static  intATTRIBUTE_NMTOKENS
     Constant: the attribute value is a list of name tokens.
final public static  intATTRIBUTE_NOTATION
     Constant: the attribute is the name of a notation.
final public static  intATTRIBUTE_UNDECLARED
     Constant: the attribute has not been declared for this element type.
final public static  intCONTENT_ANY
     Constant: the element has a content model of ANY.
final public static  intCONTENT_ELEMENTS
     Constant: the element has element content.
final public static  intCONTENT_EMPTY
     Constant: the element has declared content of EMPTY.
final public static  intCONTENT_MIXED
     Constant: the element has mixed content.
final public static  intCONTENT_UNDECLARED
     Constant: an element has not been declared.
final public static  intENTITY_INTERNAL
     Constant: the entity is internal.
final public static  intENTITY_NDATA
     Constant: the entity is external, non-XML data.
final public static  intENTITY_TEXT
     Constant: the entity is external XML data.
final public static  intENTITY_UNDECLARED
     Constant: the entity has not been declared.
 XmlHandlerhandler
    

Constructor Summary
public  XmlParser()
     Construct a new parser with no associated handler.

Method Summary
 voidcheckEncoding(String encodingName, boolean ignoreEncoding)
     Check that the encoding specified makes sense.
 voidcleanupVariables()
     Clean up after the parse to allow some garbage collection.
 voidcopyIso8859_1ReadBuffer(int count)
     Convert a buffer of ISO-8859-1-encoded bytes into UTF-16 characters.
 voidcopyUcs2ReadBuffer(int count, int shift1, int shift2)
     Convert a buffer of UCS-2-encoded bytes into UTF-16 characters.
 voidcopyUcs4ReadBuffer(int count, int shift1, int shift2, int shift3, int shift4)
     Convert a buffer of UCS-4-encoded bytes into UTF-16 characters.
 voidcopyUtf8ReadBuffer(int count)
     Convert a buffer of UTF-8-encoded bytes into UTF-16 characters.
 voiddataBufferAppend(char c)
     Add a character to the data buffer.
 voiddataBufferAppend(String s)
     Add a string to the data buffer.
 voiddataBufferAppend(char ch, int start, int length)
     Append (part of) a character array to the data buffer.
 voiddataBufferFlush()
     Flush the contents of the data buffer to the handler, if appropriate, and reset the buffer for new input.
 voiddataBufferNormalize()
     Normalise whitespace in the data buffer.
 StringdataBufferToString()
     Convert the data buffer to a string.
public  EnumerationdeclaredAttributes(String elname)
     Get the declared attributes for an element type.
Parameters:
  elname - The name of the element type.
public  EnumerationdeclaredElements()
     Get the declared elements for an XML document.
public  EnumerationdeclaredEntities()
     Get declared entities. An Enumeration of all the entities declared forthis XML document.
public  EnumerationdeclaredNotations()
     Get declared notations. An Enumeration of all the notations declared forthis XML document.
 voiddetectEncoding()
     Attempt to detect the encoding of an entity.

The trick here (as suggested in the XML standard) is that any entity not in UTF-8, or in UCS-2 with a byte-order mark, must begin with an XML declaration or an encoding declaration; we simply have to look for "<?XML" in various encodings.

This method has no way to distinguish among 8-bit encodings. Instead, it assumes UTF-8, then (possibly) revises its assumption later in checkEncoding().

 voidencodingError(String message, int value, int offset)
     Report a character encoding error.
 voiderror(String message, String textFound, String textExpected)
     Report an error.
 voiderror(String message, char textFound, String textExpected)
     Report a serious error.
 ObjectextendArray(Object array, int currentSize, int requiredSize)
     Ensure the capacity of an array, allocating a new one if necessary.
 voidfilterCR()
     Filter carriage returns in the read buffer.
 Object[]getAttribute(String elName, String name)
     Retrieve the three-member array representing an attribute declaration.
public  StringgetAttributeDefaultValue(String name, String aname)
     Retrieve the default value of a declared attribute.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute.
public  intgetAttributeDefaultValueType(String name, String aname)
     Retrieve the default value type of a declared attribute.
public  StringgetAttributeEnumeration(String name, String aname)
     Retrieve the allowed values for an enumerated attribute type.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute.
public  StringgetAttributeExpandedValue(String name, String aname)
     Retrieve the expanded value of a declared attribute.

All general entities will be expanded.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute.

public  intgetAttributeType(String name, String aname)
     Retrieve the declared type of an attribute.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute.
public  intgetColumnNumber()
     Return the current column number.
 HashtablegetElementAttributes(String name)
     Look up the attribute hash table for an element.
public  StringgetElementContentModel(String name)
     Look up the content model of an element.

The result will always be null unless the content type is CONTENT_ELEMENTS or CONTENT_MIXED.
Parameters:
  name - The element type name.

public  intgetElementContentType(String name)
     Look up the content type of an element.
Parameters:
  name - The element type name.
public  StringgetEntityNotationName(String eName)
     Get the notation name associated with an NDATA entity.
Parameters:
  ename - The NDATA entity name.
public  StringgetEntityPublicId(String ename)
     Return an external entity's public identifier, if any.
Parameters:
  ename - The name of the external entity.
public  StringgetEntitySystemId(String ename)
     Return an external entity's system identifier.
Parameters:
  ename - The name of the external entity.
public  intgetEntityType(String ename)
     Find the type of an entity.
public  StringgetEntityValue(String ename)
     Return the value of an internal entity.
Parameters:
  ename - The name of the internal entity.
public  intgetLineNumber()
     Return the current line number.
 intgetNextUtf8Byte(int pos, int count)
     Return the next byte value in a UTF-8 sequence.
public  StringgetNotationPublicId(String nname)
     Look up the public identifier for a notation. You will normally use this method to look up a notation that was provided as an attribute value or for an NDATA entity.
Parameters:
  nname - The name of the notation.
public  StringgetNotationSystemId(String nname)
     Look up the system identifier for a notation. You will normally use this method to look up a notation that was provided as an attribute value or for an NDATA entity.
Parameters:
  nname - The name of the notation.
 voidinitializeVariables()
     Re-initialize the variables for each parse.
public  Stringintern(String s)
     Return an internalised version of a string.

Ælfred uses this method to create an internalised version of all names and attribute values, so that it can test equality with == instead of String.equals().

If you want to be able to test for equality in the same way, you can use this method to internalise your own strings first:

 String PARA = handler.intern("PARA");
 

Note that this will not return the same results as String.intern().
Parameters:
  s - The string to internalise.

public  Stringintern(char ch, int start, int length)
     Create an internalised string from a character array.

This is much more efficient than constructing a non-internalised string first, and then internalising it.

Note that this will not return the same results as String.intern().
Parameters:
  ch - an array of characters for building the string.
Parameters:
  start - the starting position in the array.
Parameters:
  length - the number of characters to place in the string.

final  booleanisWhitespace(char c)
     Test if a character is whitespace.
 [1] S ::= (#x20 | #x9 | #xd | #xa)+
 

Parameters:
  c - The character to test.
public  voidparse(String systemId, String publicId, String encoding)
     Parse an XML document from a URI.
public  voidparse(String systemId, String publicId, InputStream stream, String encoding)
     Parse an XML document from a byte stream.
public  voidparse(String systemId, String publicId, Reader reader)
     Parse an XML document from a character stream.
 voidparseAttDef(String elementName)
     Parse a single attribute definition.
 voidparseAttlistDecl()
     Parse an attribute list declaration.
 voidparseAttribute(String name)
     Parse an attribute assignment.
 voidparseCDSect()
     Parse a CDATA marked section.
 voidparseCharRef()
     Read a character reference.
 voidparseComment()
     Skip a comment.
 voidparseConditionalSect()
     Parse a conditional section.
 voidparseContent()
     Parse the content of an element.
 voidparseContentspec(String name)
     Content specification.
 voidparseCp()
     Parse a content particle.
 voidparseDefault(String elementName, String name, int type, String enumeration)
     Parse the default value for an attribute.
 voidparseDoctypedecl()
     Parse a document type declaration.
 voidparseDocument()
     Parse an XML document.
 [1] document ::= prolog element Misc*
 

This is the top-level parsing function for a single XML document.

 voidparseETag()
     Parse an end tag.
 voidparseElement()
     Parse an element, with its tags.
 voidparseElementdecl()
     Parse an element type declaration.
 voidparseElements()
     Parse an element-content model.
 voidparseEntityDecl()
     Parse an entity declaration.
 voidparseEntityRef(boolean externalAllowed)
     Parse a reference.
 voidparseEnumeration()
     Parse an enumeration.
 voidparseEq()
     Parse an equals sign surrounded by optional whitespace.
 voidparseMarkupdecl()
     Parse a markup declaration in the internal or external DTD subset.
 voidparseMisc()
     Parse miscellaneous markup outside the document element and DOCTYPE declaration.
 voidparseMixed()
     Parse mixed content.
 voidparseNotationDecl()
     Parse a notation declaration.
 voidparseNotationType()
     Parse a notation type for an attribute.
 voidparsePCData()
     Parse PCDATA.
 voidparsePEReference(boolean isEntityValue)
     Parse a parameter entity reference.
 voidparsePI()
     Parse a processing instruction and do a call-back.
 voidparseProlog()
     Parse the prolog of an XML document.
 [24] prolog ::= XMLDecl? Misc* (Doctypedecl Misc*)?
 

There are a couple of tricks here.

 voidparseTextDecl(boolean ignoreEncoding)
     Parse the Encoding PI.
 voidparseUntil(String delim)
     Read all data until we find the specified string.
 voidparseWhitespace()
     Parse whitespace characters, and leave them in the data buffer.
 voidparseXMLDecl(boolean ignoreEncoding)
     Parse the XML declaration.
 voidpopInput()
     Restore a previous input source.
 voidpushCharArray(String ename, char ch, int start, int length)
     Push a new internal input source.

This method is useful for expanding an internal entity, or for unreading a string of characters.

 voidpushInput(String ename)
     Save the current input source onto the stack.

This method saves all of the global variables associated with the current input source, so that they can be restored when a new input source has finished.

 voidpushString(String ename, String s)
     This method pushes a string back onto input.
 voidpushURL(String ename, String publicId, String systemId, Reader reader, InputStream stream, String encoding)
     Push a new external input source.
 voidread8bitEncodingDeclaration()
     Read just the encoding declaration (or XML declaration) at the start of an external entity. When this method is called, we know that the declaration is present (or appears to be).
 intreadAttType()
     Parse the attribute type.
 charreadCh()
     Read a single character from the readBuffer.
 voidreadDataChunk()
     Read a chunk of data from an external input source.
 String[]readExternalIds(boolean inNotation)
     Try reading external identifiers.
 StringreadLiteral(int flags)
     Read a literal.
 StringreadNmtoken(boolean isName)
     Read a name or name token.
 voidrequire(String delim)
     Require a string to appear, or throw an exception.
 voidrequire(char delim)
     Require a character to appear, or throw an exception.
 voidrequireWhitespace()
     Require whitespace characters.
 voidsetAttribute(String elName, String name, int type, String enumeration, String value, int valueType)
     Register an attribute declaration for later retrieval.
 voidsetElement(String name, int contentType, String contentModel, Hashtable attributes)
     Register an element.
 voidsetEntity(String eName, int eClass, String pubid, String sysid, String value, String nName)
     Register an entity declaration for later retrieval.
 voidsetExternalDataEntity(String eName, String pubid, String sysid, String nName)
     Register an external data entity.
 voidsetExternalTextEntity(String eName, String pubid, String sysid)
     Register an external text entity.
public  voidsetHandler(XmlHandler handler)
     Set the handler that will receive parsing events.
 voidsetInternalEntity(String eName, String value)
     Register an entity declaration for later retrieval.
 voidsetNotation(String nname, String pubid, String sysid)
     Register a notation declaration for later retrieval.
 voidskipUntil(String delim)
     Skip all data until we find the specified string.
 voidskipWhitespace()
     Skip whitespace characters.
 booleantryEncoding(byte sig, byte b1, byte b2, byte b3, byte b4)
     Check for a four-byte signature.
 booleantryEncoding(byte sig, byte b1, byte b2)
     Check for a two-byte signature.
 voidtryEncodingDecl(boolean ignoreEncoding)
     Check for an encoding declaration.
 booleantryRead(char delim)
     Return true if we can read the expected character.

Note that the character will be removed from the input stream on success, but will be put back on failure.

 booleantryRead(String delim)
     Return true if we can read the expected string.

This is simply a convenience method.

Note that the string will be removed from the input stream on success, but will be put back on failure.

 booleantryWhitespace()
     Return true if we can read some whitespace.
 voidunread(char c)
     Push a single character back onto the current input stream.
 voidunread(char ch, int length)
     Push a char array back onto the current input stream.

Field Detail
ATTRIBUTE_CDATA
final public static int ATTRIBUTE_CDATA(Code)
Constant: the attribute value is a string value.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_DEFAULT_FIXED
final public static int ATTRIBUTE_DEFAULT_FIXED(Code)
Constant: the attribute was declared #FIXED.
See Also:   XmlParser.getAttributeDefaultValueType
See Also:   XmlParser.getAttributeDefaultValue



ATTRIBUTE_DEFAULT_IMPLIED
final public static int ATTRIBUTE_DEFAULT_IMPLIED(Code)
Constant: the attribute was declared #IMPLIED.
See Also:   XmlParser.getAttributeDefaultValueType



ATTRIBUTE_DEFAULT_REQUIRED
final public static int ATTRIBUTE_DEFAULT_REQUIRED(Code)
Constant: the attribute was declared #REQUIRED.
See Also:   XmlParser.getAttributeDefaultValueType



ATTRIBUTE_DEFAULT_SPECIFIED
final public static int ATTRIBUTE_DEFAULT_SPECIFIED(Code)
Constant: the attribute has a literal default value specified.
See Also:   XmlParser.getAttributeDefaultValueType
See Also:   XmlParser.getAttributeDefaultValue



ATTRIBUTE_DEFAULT_UNDECLARED
final public static int ATTRIBUTE_DEFAULT_UNDECLARED(Code)
Constant: the attribute is not declared.
See Also:   XmlParser.getAttributeDefaultValueType



ATTRIBUTE_ENTITIES
final public static int ATTRIBUTE_ENTITIES(Code)
Constant: the attribute value is a list of entity names.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_ENTITY
final public static int ATTRIBUTE_ENTITY(Code)
Constant: the attribute value is the name of an entity.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_ENUMERATED
final public static int ATTRIBUTE_ENUMERATED(Code)
Constant: the attribute value is a token from an enumeration.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_ID
final public static int ATTRIBUTE_ID(Code)
Constant: the attribute value is a unique identifier.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_IDREF
final public static int ATTRIBUTE_IDREF(Code)
Constant: the attribute value is a reference to a unique identifier.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_IDREFS
final public static int ATTRIBUTE_IDREFS(Code)
Constant: the attribute value is a list of ID references.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_NMTOKEN
final public static int ATTRIBUTE_NMTOKEN(Code)
Constant: the attribute value is a name token.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_NMTOKENS
final public static int ATTRIBUTE_NMTOKENS(Code)
Constant: the attribute value is a list of name tokens.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_NOTATION
final public static int ATTRIBUTE_NOTATION(Code)
Constant: the attribute is the name of a notation.
See Also:   XmlParser.getAttributeType



ATTRIBUTE_UNDECLARED
final public static int ATTRIBUTE_UNDECLARED(Code)
Constant: the attribute has not been declared for this element type.
See Also:   XmlParser.getAttributeType



CONTENT_ANY
final public static int CONTENT_ANY(Code)
Constant: the element has a content model of ANY.
See Also:   XmlParser.getElementContentType



CONTENT_ELEMENTS
final public static int CONTENT_ELEMENTS(Code)
Constant: the element has element content.
See Also:   XmlParser.getElementContentType



CONTENT_EMPTY
final public static int CONTENT_EMPTY(Code)
Constant: the element has declared content of EMPTY.
See Also:   XmlParser.getElementContentType



CONTENT_MIXED
final public static int CONTENT_MIXED(Code)
Constant: the element has mixed content.
See Also:   XmlParser.getElementContentType



CONTENT_UNDECLARED
final public static int CONTENT_UNDECLARED(Code)
Constant: an element has not been declared.
See Also:   XmlParser.getElementContentType



ENTITY_INTERNAL
final public static int ENTITY_INTERNAL(Code)
Constant: the entity is internal.
See Also:   XmlParser.getEntityType



ENTITY_NDATA
final public static int ENTITY_NDATA(Code)
Constant: the entity is external, non-XML data.
See Also:   XmlParser.getEntityType



ENTITY_TEXT
final public static int ENTITY_TEXT(Code)
Constant: the entity is external XML data.
See Also:   XmlParser.getEntityType



ENTITY_UNDECLARED
final public static int ENTITY_UNDECLARED(Code)
Constant: the entity has not been declared.
See Also:   XmlParser.getEntityType



handler
XmlHandler handler(Code)




Constructor Detail
XmlParser
public XmlParser()(Code)
Construct a new parser with no associated handler.
See Also:   XmlParser.setHandler
See Also:   XmlParser.parse




Method Detail
checkEncoding
void checkEncoding(String encodingName, boolean ignoreEncoding) throws java.lang.Exception(Code)
Check that the encoding specified makes sense.

Compare what the author has specified in the XML declaration or encoding PI with what we have detected.

This is also important for distinguishing among the various 7- and 8-bit encodings, such as ISO-LATIN-1 (I cannot autodetect those).
Parameters:
  encodingName - The name of the encoding specified by the user.
See Also:   XmlParser.parseXMLDecl
See Also:   XmlParser.parseTextDecl




cleanupVariables
void cleanupVariables()(Code)
Clean up after the parse to allow some garbage collection. Leave around anything that might be useful for queries.



copyIso8859_1ReadBuffer
void copyIso8859_1ReadBuffer(int count)(Code)
Convert a buffer of ISO-8859-1-encoded bytes into UTF-16 characters.

When readDataChunk() calls this method, the raw bytes are in rawReadBuffer, and the final characters will appear in readBuffer.

This is a direct conversion, with no tricks.
Parameters:
  count - The number of bytes to convert.
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.rawReadBuffer
See Also:   XmlParser.readBuffer




copyUcs2ReadBuffer
void copyUcs2ReadBuffer(int count, int shift1, int shift2) throws java.lang.Exception(Code)
Convert a buffer of UCS-2-encoded bytes into UTF-16 characters.

When readDataChunk() calls this method, the raw bytes are in rawReadBuffer, and the final characters will appear in readBuffer.
Parameters:
  count - The number of bytes to convert.
Parameters:
  shift1 - The number of bits to shift byte 1.
Parameters:
  shift2 - The number of bits to shift byte 2
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.rawReadBuffer
See Also:   XmlParser.readBuffer




copyUcs4ReadBuffer
void copyUcs4ReadBuffer(int count, int shift1, int shift2, int shift3, int shift4) throws java.lang.Exception(Code)
Convert a buffer of UCS-4-encoded bytes into UTF-16 characters.

When readDataChunk() calls this method, the raw bytes are in rawReadBuffer, and the final characters will appear in readBuffer.

Java has 16-bit chars, but this routine will attempt to use surrogates to encoding values between 0x00010000 and 0x000fffff.
Parameters:
  count - The number of bytes to convert.
Parameters:
  shift1 - The number of bits to shift byte 1.
Parameters:
  shift2 - The number of bits to shift byte 2
Parameters:
  shift3 - The number of bits to shift byte 2
Parameters:
  shift4 - The number of bits to shift byte 2
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.rawReadBuffer
See Also:   XmlParser.readBuffer




copyUtf8ReadBuffer
void copyUtf8ReadBuffer(int count) throws java.lang.Exception(Code)
Convert a buffer of UTF-8-encoded bytes into UTF-16 characters.

When readDataChunk() calls this method, the raw bytes are in rawReadBuffer, and the final characters will appear in readBuffer.

The tricky part of this is dealing with UTF-8 multi-byte sequences, but it doesn't seem to slow things down too much.
Parameters:
  count - The number of bytes to convert.
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.rawReadBuffer
See Also:   XmlParser.readBuffer
See Also:   XmlParser.getNextUtf8Byte




dataBufferAppend
void dataBufferAppend(char c)(Code)
Add a character to the data buffer.



dataBufferAppend
void dataBufferAppend(String s)(Code)
Add a string to the data buffer.



dataBufferAppend
void dataBufferAppend(char ch, int start, int length)(Code)
Append (part of) a character array to the data buffer.



dataBufferFlush
void dataBufferFlush() throws java.lang.Exception(Code)
Flush the contents of the data buffer to the handler, if appropriate, and reset the buffer for new input.



dataBufferNormalize
void dataBufferNormalize()(Code)
Normalise whitespace in the data buffer.



dataBufferToString
String dataBufferToString()(Code)
Convert the data buffer to a string.
Parameters:
  internFlag - true if the contents should be interned.
See Also:   XmlParser.intern(char[],int,int)



declaredAttributes
public Enumeration declaredAttributes(String elname)(Code)
Get the declared attributes for an element type.
Parameters:
  elname - The name of the element type. An Enumeration of all the attributes declared fora specific element type. The results will be valid onlyafter the DTD (if any) has been parsed.
See Also:   XmlParser.getAttributeType
See Also:   XmlParser.getAttributeEnumeration
See Also:   XmlParser.getAttributeDefaultValueType
See Also:   XmlParser.getAttributeDefaultValue
See Also:   XmlParser.getAttributeExpandedValue



declaredElements
public Enumeration declaredElements()(Code)
Get the declared elements for an XML document.

The results will be valid only after the DTD (if any) has been parsed. An enumeration of all element types declared for thisdocument (as Strings).
See Also:   XmlParser.getElementContentType
See Also:   XmlParser.getElementContentModel




declaredEntities
public Enumeration declaredEntities()(Code)
Get declared entities. An Enumeration of all the entities declared forthis XML document. The results will be valid onlyafter the DTD (if any) has been parsed.
See Also:   XmlParser.getEntityType
See Also:   XmlParser.getEntityPublicId
See Also:   XmlParser.getEntitySystemId
See Also:   XmlParser.getEntityValue
See Also:   XmlParser.getEntityNotationName



declaredNotations
public Enumeration declaredNotations()(Code)
Get declared notations. An Enumeration of all the notations declared forthis XML document. The results will be valid onlyafter the DTD (if any) has been parsed.
See Also:   XmlParser.getNotationPublicId
See Also:   XmlParser.getNotationSystemId



detectEncoding
void detectEncoding() throws java.lang.Exception(Code)
Attempt to detect the encoding of an entity.

The trick here (as suggested in the XML standard) is that any entity not in UTF-8, or in UCS-2 with a byte-order mark, must begin with an XML declaration or an encoding declaration; we simply have to look for "<?XML" in various encodings.

This method has no way to distinguish among 8-bit encodings. Instead, it assumes UTF-8, then (possibly) revises its assumption later in checkEncoding(). Any ASCII-derived 8-bit encoding should work, but most will be rejected later by checkEncoding().

I don't currently detect EBCDIC, since I'm concerned that it could also be a valid UTF-8 sequence; I'll have to do more checking later.
See Also:   XmlParser.tryEncoding(byte[],byte,byte,byte,byte)
See Also:   XmlParser.tryEncoding(byte[],byte,byte)
See Also:   XmlParser.checkEncoding
See Also:   XmlParser.read8bitEncodingDeclaration




encodingError
void encodingError(String message, int value, int offset) throws java.lang.Exception(Code)
Report a character encoding error.



error
void error(String message, String textFound, String textExpected) throws java.lang.Exception(Code)
Report an error.
Parameters:
  message - The error message.
Parameters:
  textFound - The text that caused the error (or null).
See Also:   XmlHandler.error
See Also:   XmlParser.line



error
void error(String message, char textFound, String textExpected) throws java.lang.Exception(Code)
Report a serious error.
Parameters:
  message - The error message.
Parameters:
  textFound - The text that caused the error (or null).



extendArray
Object extendArray(Object array, int currentSize, int requiredSize)(Code)
Ensure the capacity of an array, allocating a new one if necessary.



filterCR
void filterCR()(Code)
Filter carriage returns in the read buffer.

CRLF becomes LF; CR becomes LF.
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.readBuffer
See Also:   XmlParser.readBufferOverflow




getAttribute
Object[] getAttribute(String elName, String name)(Code)
Retrieve the three-member array representing an attribute declaration.



getAttributeDefaultValue
public String getAttributeDefaultValue(String name, String aname)(Code)
Retrieve the default value of a declared attribute.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute. The default value, or null if the attribute was#IMPLIED or simply undeclared and unspecified.
See Also:   XmlParser.getAttributeExpandedValue



getAttributeDefaultValueType
public int getAttributeDefaultValueType(String name, String aname)(Code)
Retrieve the default value type of a declared attribute.
See Also:   XmlParser.ATTRIBUTE_DEFAULT_SPECIFIED
See Also:   XmlParser.ATTRIBUTE_DEFAULT_IMPLIED
See Also:   XmlParser.ATTRIBUTE_DEFAULT_REQUIRED
See Also:   XmlParser.ATTRIBUTE_DEFAULT_FIXED



getAttributeEnumeration
public String getAttributeEnumeration(String name, String aname)(Code)
Retrieve the allowed values for an enumerated attribute type.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute. A string containing the token list.
See Also:   XmlParser.ATTRIBUTE_ENUMERATED
See Also:   XmlParser.ATTRIBUTE_NOTATION



getAttributeExpandedValue
public String getAttributeExpandedValue(String name, String aname)(Code)
Retrieve the expanded value of a declared attribute.

All general entities will be expanded.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute. The expanded default value, or null if the attribute was#IMPLIED or simply undeclared
See Also:   XmlParser.getAttributeDefaultValue




getAttributeType
public int getAttributeType(String name, String aname)(Code)
Retrieve the declared type of an attribute.
Parameters:
  name - The name of the associated element.
Parameters:
  aname - The name of the attribute. An integer constant representing the attribute type.
See Also:   XmlParser.ATTRIBUTE_UNDECLARED
See Also:   XmlParser.ATTRIBUTE_CDATA
See Also:   XmlParser.ATTRIBUTE_ID
See Also:   XmlParser.ATTRIBUTE_IDREF
See Also:   XmlParser.ATTRIBUTE_IDREFS
See Also:   XmlParser.ATTRIBUTE_ENTITY
See Also:   XmlParser.ATTRIBUTE_ENTITIES
See Also:   XmlParser.ATTRIBUTE_NMTOKEN
See Also:   XmlParser.ATTRIBUTE_NMTOKENS
See Also:   XmlParser.ATTRIBUTE_ENUMERATED
See Also:   XmlParser.ATTRIBUTE_NOTATION



getColumnNumber
public int getColumnNumber()(Code)
Return the current column number.



getElementAttributes
Hashtable getElementAttributes(String name)(Code)
Look up the attribute hash table for an element. The hash table is the second item in the element array.



getElementContentModel
public String getElementContentModel(String name)(Code)
Look up the content model of an element.

The result will always be null unless the content type is CONTENT_ELEMENTS or CONTENT_MIXED.
Parameters:
  name - The element type name. The normalised content model, as a string.
See Also:   XmlParser.getElementContentType




getElementContentType
public int getElementContentType(String name)(Code)
Look up the content type of an element.
Parameters:
  name - The element type name. An integer constant representing the content type.
See Also:   XmlParser.getElementContentModel
See Also:   XmlParser.CONTENT_UNDECLARED
See Also:   XmlParser.CONTENT_ANY
See Also:   XmlParser.CONTENT_EMPTY
See Also:   XmlParser.CONTENT_MIXED
See Also:   XmlParser.CONTENT_ELEMENTS



getEntityNotationName
public String getEntityNotationName(String eName)(Code)
Get the notation name associated with an NDATA entity.
Parameters:
  ename - The NDATA entity name. The associated notation name, or null if theentity was not declared, or if it is not anNDATA entity.
See Also:   XmlParser.getEntityType



getEntityPublicId
public String getEntityPublicId(String ename)(Code)
Return an external entity's public identifier, if any.
Parameters:
  ename - The name of the external entity. The entity's system identifier, or null if theentity was not declared, if it is not anexternal entity, or if no public identifier wasprovided.
See Also:   XmlParser.getEntityType



getEntitySystemId
public String getEntitySystemId(String ename)(Code)
Return an external entity's system identifier.
Parameters:
  ename - The name of the external entity. The entity's system identifier, or null if theentity was not declared, or if it is not anexternal entity.
See Also:   XmlParser.getEntityType



getEntityType
public int getEntityType(String ename)(Code)
Find the type of an entity.
See Also:   XmlParser.ENTITY_UNDECLARED
See Also:   XmlParser.ENTITY_INTERNAL
See Also:   XmlParser.ENTITY_NDATA
See Also:   XmlParser.ENTITY_TEXT



getEntityValue
public String getEntityValue(String ename)(Code)
Return the value of an internal entity.
Parameters:
  ename - The name of the internal entity. The entity's value, or null if the entity wasnot declared, or if it is not an internal entity.
See Also:   XmlParser.getEntityType



getLineNumber
public int getLineNumber()(Code)
Return the current line number.



getNextUtf8Byte
int getNextUtf8Byte(int pos, int count) throws java.lang.Exception(Code)
Return the next byte value in a UTF-8 sequence. If it is not possible to get a byte from the current entity, throw an exception.
Parameters:
  pos - The current position in the rawReadBuffer.
Parameters:
  count - The number of bytes in the rawReadBuffer The significant six bits of a non-initial byte ina UTF-8 sequence.
exception:
  EOFException - If the sequence is incomplete.



getNotationPublicId
public String getNotationPublicId(String nname)(Code)
Look up the public identifier for a notation. You will normally use this method to look up a notation that was provided as an attribute value or for an NDATA entity.
Parameters:
  nname - The name of the notation. A string containing the public identifier, or nullif none was provided or if no such notation wasdeclared.
See Also:   XmlParser.getNotationSystemId



getNotationSystemId
public String getNotationSystemId(String nname)(Code)
Look up the system identifier for a notation. You will normally use this method to look up a notation that was provided as an attribute value or for an NDATA entity.
Parameters:
  nname - The name of the notation. A string containing the system identifier, or nullif no such notation was declared.
See Also:   XmlParser.getNotationPublicId



initializeVariables
void initializeVariables()(Code)
Re-initialize the variables for each parse.



intern
public String intern(String s)(Code)
Return an internalised version of a string.

Ælfred uses this method to create an internalised version of all names and attribute values, so that it can test equality with == instead of String.equals().

If you want to be able to test for equality in the same way, you can use this method to internalise your own strings first:

 String PARA = handler.intern("PARA");
 

Note that this will not return the same results as String.intern().
Parameters:
  s - The string to internalise. An internalised version of the string.
See Also:   XmlParser.intern(char[],int,int)
See Also:   java.lang.String.intern




intern
public String intern(char ch, int start, int length)(Code)
Create an internalised string from a character array.

This is much more efficient than constructing a non-internalised string first, and then internalising it.

Note that this will not return the same results as String.intern().
Parameters:
  ch - an array of characters for building the string.
Parameters:
  start - the starting position in the array.
Parameters:
  length - the number of characters to place in the string. an internalised string.
See Also:   XmlParser.intern(String)
See Also:   java.lang.String.intern




isWhitespace
final boolean isWhitespace(char c)(Code)
Test if a character is whitespace.
 [1] S ::= (#x20 | #x9 | #xd | #xa)+
 

Parameters:
  c - The character to test. true if the character is whitespace.



parse
public void parse(String systemId, String publicId, String encoding) throws java.lang.Exception(Code)
Parse an XML document from a URI.

You may parse a document more than once, but only one thread may call this method for an object at one time.
Parameters:
  systemId - The URI of the document.
Parameters:
  publicId - The public identifier of the document, or null.
Parameters:
  encoding - The suggested encoding, or null if unknown.
exception:
  java.lang.Exception - Any exception thrown by yourown handlers, or any derivation of java.io.IOExceptionthrown by the parser itself.




parse
public void parse(String systemId, String publicId, InputStream stream, String encoding) throws java.lang.Exception(Code)
Parse an XML document from a byte stream.

The URI that you supply will become the base URI for resolving relative links, but Ælfred will actually read the document from the supplied input stream.

You may parse a document more than once, but only one thread may call this method for an object at one time.
Parameters:
  systemId - The base URI of the document, or null if notknown.
Parameters:
  publicId - The public identifier of the document, or nullif not known.
Parameters:
  stream - A byte input stream.
Parameters:
  encoding - The suggested encoding, or null if unknown.
exception:
  java.lang.Exception - Any exception thrown by yourown handlers, or any derivation of java.io.IOExceptionthrown by the parser itself.




parse
public void parse(String systemId, String publicId, Reader reader) throws java.lang.Exception(Code)
Parse an XML document from a character stream.

The URI that you supply will become the base URI for resolving relative links, but Ælfred will actually read the document from the supplied input stream.

You may parse a document more than once, but only one thread may call this method for an object at one time.
Parameters:
  systemId - The base URI of the document, or null if notknown.
Parameters:
  publicId - The public identifier of the document, or nullif not known.
Parameters:
  reader - A character stream.
exception:
  java.lang.Exception - Any exception thrown by yourown handlers, or any derivation of java.io.IOExceptionthrown by the parser itself.




parseAttDef
void parseAttDef(String elementName) throws java.lang.Exception(Code)
Parse a single attribute definition. [53] AttDef ::= S %Name S %AttType S %Default



parseAttlistDecl
void parseAttlistDecl() throws java.lang.Exception(Code)
Parse an attribute list declaration. [52] AttlistDecl ::= '' NOTE: the '



parseAttribute
void parseAttribute(String name) throws java.lang.Exception(Code)
Parse an attribute assignment.
 [34] Attribute ::= Name Eq AttValue
 

Parameters:
  name - The name of the attribute's element.
See Also:   XmlHandler.attribute



parseCDSect
void parseCDSect() throws java.lang.Exception(Code)
Parse a CDATA marked section.
 [20] CDSect ::= CDStart CData CDEnd
 [21] CDStart ::= '<![CDATA['
 [22] CData ::= (Char* - (Char* ']]>' Char*))
 [23] CDEnd ::= ']]>'
 

(The '<![CDATA[' has already been read.)

Note that this just appends characters to the dataBuffer, without actually generating an event.




parseCharRef
void parseCharRef() throws java.lang.Exception(Code)
Read a character reference. [67] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';' NOTE: the '&#' has already been read.



parseComment
void parseComment() throws java.lang.Exception(Code)
Skip a comment.
 [18] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* "-->"
 

(The <!-- has already been read.)




parseConditionalSect
void parseConditionalSect() throws java.lang.Exception(Code)
Parse a conditional section. [63] conditionalSect ::= includeSect || ignoreSect [64] includeSect ::= '' [65] ignoreSect ::= '' [66] ignoreSectContents ::= ((SkipLit | Comment | PI) -(Char* ']]>')) | ('') | (Char - (']' | [<'"])) | ('



parseContent
void parseContent() throws java.lang.Exception(Code)
Parse the content of an element. [37] content ::= (element | PCData | Reference | CDSect | PI | Comment)* [68] Reference ::= EntityRef | CharRef



parseContentspec
void parseContentspec(String name) throws java.lang.Exception(Code)
Content specification. [41] contentspec ::= 'EMPTY' | 'ANY' | Mixed | elements



parseCp
void parseCp() throws java.lang.Exception(Code)
Parse a content particle. [43] cp ::= (Name | choice | seq) ('?' | '*' | '+') NOTE: I actually use a slightly different production here: cp ::= (elements | (Name ('?' | '*' | '+')?))



parseDefault
void parseDefault(String elementName, String name, int type, String enumeration) throws java.lang.Exception(Code)
Parse the default value for an attribute. [62] Default ::= '#REQUIRED' | '#IMPLIED' | ((%'#FIXED' S)? %AttValue



parseDoctypedecl
void parseDoctypedecl() throws java.lang.Exception(Code)
Parse a document type declaration.
 [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
 ('[' %markupdecl* ']' S?)? '>'
 

(The <!DOCTYPE has already been read.)




parseDocument
void parseDocument() throws java.lang.Exception(Code)
Parse an XML document.
 [1] document ::= prolog element Misc*
 

This is the top-level parsing function for a single XML document. As a minimum, a well-formed document must have a document element, and a valid document must have a prolog as well.




parseETag
void parseETag() throws java.lang.Exception(Code)
Parse an end tag. [36] ETag ::= '' NOTE: parseContent() chains to here.



parseElement
void parseElement() throws java.lang.Exception(Code)
Parse an element, with its tags.
 [33] STag ::= '<' Name (S Attribute)* S? '>' [WFC: unique Att spec]
 [38] element ::= EmptyElement | STag content ETag
 [39] EmptyElement ::= '<' Name (S Attribute)* S? '/>'
 [WFC: unique Att spec]
 

(The '<' has already been read.)

NOTE: this method actually chains onto parseContent(), if necessary, and parseContent() will take care of calling parseETag().




parseElementdecl
void parseElementdecl() throws java.lang.Exception(Code)
Parse an element type declaration. [40] elementdecl ::= '' [VC: Unique Element Declaration] NOTE: the '



parseElements
void parseElements() throws java.lang.Exception(Code)
Parse an element-content model. [42] elements ::= (choice | seq) ('?' | '*' | '+')? [44] cps ::= S? %cp S? [45] choice ::= '(' S? %ctokplus (S? '|' S? %ctoks)* S? ')' [46] ctokplus ::= cps ('|' cps)+ [47] ctoks ::= cps ('|' cps)* [48] seq ::= '(' S? %stoks (S? ',' S? %stoks)* S? ')' [49] stoks ::= cps (',' cps)* NOTE: the opening '(' and S have already been read. TODO: go over parameter entity boundaries more carefully.



parseEntityDecl
void parseEntityDecl() throws java.lang.Exception(Code)
Parse an entity declaration. [71] EntityDecl ::= '' | '' [72] EntityDef ::= EntityValue | ExternalDef [73] ExternalDef ::= ExternalID %NDataDecl? [74] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral [75] NDataDecl ::= S %'NDATA' S %Name NOTE: the '



parseEntityRef
void parseEntityRef(boolean externalAllowed) throws java.lang.Exception(Code)
Parse a reference. [69] EntityRef ::= '&' Name ';' NOTE: the '&' has already been read.
Parameters:
  externalAllowed - External entities are allowed here.



parseEnumeration
void parseEnumeration() throws java.lang.Exception(Code)
Parse an enumeration. [60] Enumeration ::= '(' S? %Etoks (S? '|' S? %Etoks)* S? ')' [61] Etoks ::= %Nmtoken (S? '|' S? %Nmtoken)* NOTE: the '(' has already been read.



parseEq
void parseEq() throws java.lang.Exception(Code)
Parse an equals sign surrounded by optional whitespace. [35] Eq ::= S? '=' S?



parseMarkupdecl
void parseMarkupdecl() throws java.lang.Exception(Code)
Parse a markup declaration in the internal or external DTD subset.
 [29] markupdecl ::= ( %elementdecl | %AttlistDecl | %EntityDecl |
 %NotationDecl | %PI | %S | %Comment |
 InternalPERef )
 [30] InternalPERef ::= PEReference
 [31] extSubset ::= (%markupdecl | %conditionalSect)*
 



parseMisc
void parseMisc() throws java.lang.Exception(Code)
Parse miscellaneous markup outside the document element and DOCTYPE declaration.
 [27] Misc ::= Comment | PI | S
 



parseMixed
void parseMixed() throws java.lang.Exception(Code)
Parse mixed content. [50] Mixed ::= '(' S? %( %'#PCDATA' (S? '|' S? %Mtoks)* ) S? ')*' | '(' S? %('#PCDATA') S? ')' [51] Mtoks ::= %Name (S? '|' S? %Name)* NOTE: the S and '#PCDATA' have already been read.



parseNotationDecl
void parseNotationDecl() throws java.lang.Exception(Code)
Parse a notation declaration. [81] NotationDecl ::= '' NOTE: the '



parseNotationType
void parseNotationType() throws java.lang.Exception(Code)
Parse a notation type for an attribute. [58] NotationType ::= %'NOTATION' S '(' S? %Ntoks (S? '|' S? %Ntoks)* S? ')' [59] Ntoks ::= %Name (S? '|' S? %Name) NOTE: the 'NOTATION' has already been read



parsePCData
void parsePCData() throws java.lang.Exception(Code)
Parse PCDATA.
 [16] PCData ::= [^<&]*
 

The trick here is that the data stays in the dataBuffer without necessarily being converted to a string right away.




parsePEReference
void parsePEReference(boolean isEntityValue) throws java.lang.Exception(Code)
Parse a parameter entity reference. [70] PEReference ::= '%' Name ';' NOTE: the '%' has already been read.



parsePI
void parsePI() throws java.lang.Exception(Code)
Parse a processing instruction and do a call-back.
 [19] PI ::= '<?' Name (S (Char* - (Char* '?>' Char*)))? '?>'
 

(The <? has already been read.)

An XML processing instruction must begin with a Name, which is the instruction's target.




parseProlog
void parseProlog() throws java.lang.Exception(Code)
Parse the prolog of an XML document.
 [24] prolog ::= XMLDecl? Misc* (Doctypedecl Misc*)?
 

There are a couple of tricks here. First, it is necessary to declare the XML default attributes after the DTD (if present) has been read. Second, it is not possible to expand general references in attribute value literals until after the entire DTD (if present) has been parsed.

We do not look for the XML declaration here, because it is handled by pushURL().
See Also:   pushURL




parseTextDecl
void parseTextDecl(boolean ignoreEncoding) throws java.lang.Exception(Code)
Parse the Encoding PI.
 [78] EncodingDecl ::= S 'encoding' Eq QEncoding
 [79] EncodingPI ::= '<?xml' S 'encoding' Eq QEncoding S? '?>'
 [80] QEncoding ::= '"' Encoding '"' | "'" Encoding "'"
 [81] Encoding ::= LatinName
 [82] LatinName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
 

(The <?xml' and whitespace have already been read.)
See Also:   XmlParser.parseXMLDecl
See Also:   XmlParser.checkEncoding




parseUntil
void parseUntil(String delim) throws java.lang.Exception(Code)
Read all data until we find the specified string.

This is especially useful for scanning marked sections.

This is a a little inefficient right now, since it calls tryRead() for every character.
Parameters:
  delim - The string delimiter
See Also:   XmlParser.tryRead(String,boolean)
See Also:   XmlParser.readCh




parseWhitespace
void parseWhitespace() throws java.lang.Exception(Code)
Parse whitespace characters, and leave them in the data buffer.



parseXMLDecl
void parseXMLDecl(boolean ignoreEncoding) throws java.lang.Exception(Code)
Parse the XML declaration.
 [25] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
 [26] VersionInfo ::= S 'version' Eq ('"1.0"' | "'1.0'")
 [33] SDDecl ::= S 'standalone' Eq "'" ('yes' | 'no') "'"
 | S 'standalone' Eq '"' ("yes" | "no") '"'
 [78] EncodingDecl ::= S 'encoding' Eq QEncoding
 

([80] to [82] are also significant.)

(The <?xml and whitespace have already been read.)

TODO: validate value of standalone.
See Also:   XmlParser.parseTextDecl
See Also:   XmlParser.checkEncoding




popInput
void popInput() throws java.lang.Exception(Code)
Restore a previous input source.

This method restores all of the global variables associated with the current input source.
exception:
  java.io.EOFException - If there are no more entries on the input stack.
See Also:   XmlParser.pushInput
See Also:   XmlParser.sourceType
See Also:   XmlParser.externalEntity
See Also:   XmlParser.readBuffer
See Also:   XmlParser.readBufferPos
See Also:   XmlParser.readBufferLength
See Also:   XmlParser.line
See Also:   XmlParser.encoding




pushCharArray
void pushCharArray(String ename, char ch, int start, int length) throws java.lang.Exception(Code)
Push a new internal input source.

This method is useful for expanding an internal entity, or for unreading a string of characters. It creates a new readBuffer containing the characters in the array, instead of characters converted from an input byte stream.

I've added a couple of optimisations: don't push zero- length strings, and just push back a single character for 1-character strings; this should save some time and memory.
Parameters:
  ch - The char array to push.
See Also:   XmlParser.pushString
See Also:   XmlParser.pushURL
See Also:   XmlParser.readBuffer
See Also:   XmlParser.sourceType
See Also:   XmlParser.pushInput




pushInput
void pushInput(String ename) throws java.lang.Exception(Code)
Save the current input source onto the stack.

This method saves all of the global variables associated with the current input source, so that they can be restored when a new input source has finished. It also tests for entity recursion.

The method saves the following global variables onto a stack using a fixed-length array:

  1. sourceType
  2. externalEntity
  3. readBuffer
  4. readBufferPos
  5. readBufferLength
  6. line
  7. encoding

Parameters:
  ename - The name of the entity (if any) causing the new input.
See Also:   XmlParser.popInput
See Also:   XmlParser.sourceType
See Also:   XmlParser.externalEntity
See Also:   XmlParser.readBuffer
See Also:   XmlParser.readBufferPos
See Also:   XmlParser.readBufferLength
See Also:   XmlParser.line
See Also:   XmlParser.encoding



pushString
void pushString(String ename, String s) throws java.lang.Exception(Code)
This method pushes a string back onto input.

It is useful either as the expansion of an internal entity, or for backtracking during the parse.

Call pushCharArray() to do the actual work.
Parameters:
  s - The string to push back onto input.
See Also:   XmlParser.pushCharArray




pushURL
void pushURL(String ename, String publicId, String systemId, Reader reader, InputStream stream, String encoding) throws java.lang.Exception(Code)
Push a new external input source.

The source will be either an external text entity, or the DTD external subset.

TO DO: Right now, this method always attempts to autodetect the encoding; in the future, it should allow the caller to request an encoding explicitly, and it should also look at the headers with an HTTP connection.
Parameters:
  url - The java.net.URL object for the entity.
See Also:   XmlHandler.resolveEntity
See Also:   XmlParser.pushString
See Also:   XmlParser.sourceType
See Also:   XmlParser.pushInput
See Also:   XmlParser.detectEncoding
See Also:   XmlParser.sourceType
See Also:   XmlParser.readBuffer




read8bitEncodingDeclaration
void read8bitEncodingDeclaration() throws java.lang.Exception(Code)
Read just the encoding declaration (or XML declaration) at the start of an external entity. When this method is called, we know that the declaration is present (or appears to be). We also know that the entity is in some sort of ASCII-derived 8-bit encoding. The idea of this is to let us read what the 8-bit encoding is before we've committed to converting any more of the file; the XML or encoding declaration must be in 7-bit ASCII, so we're safe as long as we don't go past it.



readAttType
int readAttType() throws java.lang.Exception(Code)
Parse the attribute type. [54] AttType ::= StringType | TokenizedType | EnumeratedType [55] StringType ::= 'CDATA' [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' [57] EnumeratedType ::= NotationType | Enumeration TODO: validate the type!!



readCh
char readCh() throws java.lang.Exception(Code)
Read a single character from the readBuffer.

The readDataChunk() method maintains the buffer.

If we hit the end of an entity, try to pop the stack and keep going.

(This approach doesn't really enforce XML's rules about entity boundaries, but this is not currently a validating parser).

This routine also attempts to keep track of the current position in external entities, but it's not entirely accurate. The next available input character.
See Also:   XmlParser.unread(char)
See Also:   XmlParser.unread(String)
See Also:   XmlParser.readDataChunk
See Also:   XmlParser.readBuffer
See Also:   XmlParser.line The next character from the current input source.




readDataChunk
void readDataChunk() throws java.lang.Exception(Code)
Read a chunk of data from an external input source.

This is simply a front-end that fills the rawReadBuffer with bytes, then calls the appropriate encoding handler.
See Also:   XmlParser.encoding
See Also:   XmlParser.rawReadBuffer
See Also:   XmlParser.readBuffer
See Also:   XmlParser.filterCR
See Also:   XmlParser.copyUtf8ReadBuffer
See Also:   XmlParser.copyIso8859_1ReadBuffer
See Also:   XmlParser.copyUcs_2ReadBuffer
See Also:   XmlParser.copyUcs_4ReadBuffer




readExternalIds
String[] readExternalIds(boolean inNotation) throws java.lang.Exception(Code)
Try reading external identifiers.

The system identifier is not required for notations.
Parameters:
  inNotation - Are we in a notation? A two-member String array containing the identifiers.




readLiteral
String readLiteral(int flags) throws java.lang.Exception(Code)
Read a literal. [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" [11] SystemLiteral ::= '"' URLchar* '"' | "'" (URLchar - "'")* "'" [13] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' | "'" ([^%&'] | PEReference | Reference)* "'"



readNmtoken
String readNmtoken(boolean isName) throws java.lang.Exception(Code)
Read a name or name token. [5] Name ::= (Letter | '_' | ':') (NameChar)* [7] Nmtoken ::= (NameChar)+ NOTE: [6] is implemented implicitly where required.



require
void require(String delim) throws java.lang.Exception(Code)
Require a string to appear, or throw an exception.



require
void require(char delim) throws java.lang.Exception(Code)
Require a character to appear, or throw an exception.



requireWhitespace
void requireWhitespace() throws java.lang.Exception(Code)
Require whitespace characters. [1] S ::= (#x20 | #x9 | #xd | #xa)+



setAttribute
void setAttribute(String elName, String name, int type, String enumeration, String value, int valueType) throws java.lang.Exception(Code)
Register an attribute declaration for later retrieval. Format: - String type - String default value - int value type TODO: do something with attribute types.



setElement
void setElement(String name, int contentType, String contentModel, Hashtable attributes) throws java.lang.Exception(Code)
Register an element. Array format: element type attribute hash table



setEntity
void setEntity(String eName, int eClass, String pubid, String sysid, String value, String nName)(Code)
Register an entity declaration for later retrieval.



setExternalDataEntity
void setExternalDataEntity(String eName, String pubid, String sysid, String nName)(Code)
Register an external data entity.



setExternalTextEntity
void setExternalTextEntity(String eName, String pubid, String sysid)(Code)
Register an external text entity.



setHandler
public void setHandler(XmlHandler handler)(Code)
Set the handler that will receive parsing events.
Parameters:
  handler - The handler to receive callback events.
See Also:   XmlParser.parse
See Also:   XmlHandler



setInternalEntity
void setInternalEntity(String eName, String value)(Code)
Register an entity declaration for later retrieval.



setNotation
void setNotation(String nname, String pubid, String sysid) throws java.lang.Exception(Code)
Register a notation declaration for later retrieval. Format: - public id - system id



skipUntil
void skipUntil(String delim) throws java.lang.Exception(Code)
Skip all data until we find the specified string.

This is especially useful for scanning comments.

This is a a little inefficient right now, since it calls tryRead() for every character.
Parameters:
  delim - The string delimiter
See Also:   XmlParser.tryRead(String,boolean)
See Also:   XmlParser.readCh




skipWhitespace
void skipWhitespace() throws java.lang.Exception(Code)
Skip whitespace characters. [1] S ::= (#x20 | #x9 | #xd | #xa)+



tryEncoding
boolean tryEncoding(byte sig, byte b1, byte b2, byte b3, byte b4)(Code)
Check for a four-byte signature.

Utility routine for detectEncoding().

Always looks for some part of "Parameters:
  sig - The first four bytes read.
Parameters:
  b1 - The first byte of the signature
Parameters:
  b2 - The second byte of the signature
Parameters:
  b3 - The third byte of the signature
Parameters:
  b4 - The fourth byte of the signature
See Also:   XmlParser.detectEncoding




tryEncoding
boolean tryEncoding(byte sig, byte b1, byte b2)(Code)
Check for a two-byte signature.

Looks for a UCS-2 byte-order mark.

Utility routine for detectEncoding().
Parameters:
  sig - The first four bytes read.
Parameters:
  b1 - The first byte of the signature
Parameters:
  b2 - The second byte of the signature
See Also:   XmlParser.detectEncoding




tryEncodingDecl
void tryEncodingDecl(boolean ignoreEncoding) throws java.lang.Exception(Code)
Check for an encoding declaration.



tryRead
boolean tryRead(char delim) throws java.lang.Exception(Code)
Return true if we can read the expected character.

Note that the character will be removed from the input stream on success, but will be put back on failure. Do not attempt to read the character again if the method succeeds.
Parameters:
  delim - The character that should appear next. For ainsensitive match, you must supply this in upper-case. true if the character was successfully read, or false ifit was not.
See Also:   XmlParser.tryRead(String)




tryRead
boolean tryRead(String delim) throws java.lang.Exception(Code)
Return true if we can read the expected string.

This is simply a convenience method.

Note that the string will be removed from the input stream on success, but will be put back on failure. Do not attempt to read the string again if the method succeeds.

This method will push back a character rather than an array whenever possible (probably the majority of cases).

NOTE: This method currently has a hard-coded limit of 100 characters for the delimiter.
Parameters:
  delim - The string that should appear next. true if the string was successfully read, or false ifit was not.
See Also:   XmlParser.tryRead(char)




tryWhitespace
boolean tryWhitespace() throws java.lang.Exception(Code)
Return true if we can read some whitespace.

This is simply a convenience method.

This method will push back a character rather than an array whenever possible (probably the majority of cases). true if whitespace was found.




unread
void unread(char c) throws java.lang.Exception(Code)
Push a single character back onto the current input stream.

This method usually pushes the character back onto the readBuffer, while the unread(String) method treats the string as a new internal entity.

I don't think that this would ever be called with readBufferPos = 0, because the methods always reads a character before unreading it, but just in case, I've added a boundary condition.
Parameters:
  c - The character to push back.
See Also:   XmlParser.readCh
See Also:   XmlParser.unread(String)
See Also:   XmlParser.unread(char[])
See Also:   XmlParser.readBuffer




unread
void unread(char ch, int length) throws java.lang.Exception(Code)
Push a char array back onto the current input stream.

NOTE: you must never push back characters that you haven't actually read: use pushString() instead.
See Also:   XmlParser.readCh
See Also:   XmlParser.unread(char)
See Also:   XmlParser.unread(String)
See Also:   XmlParser.readBuffer
See Also:   XmlParser.pushString




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.