Package tigase.xml

# Class SimpleParser

java.lang.Object
tigase.xml.SimpleParser

public class SimpleParser extends Object
`SimpleParser` - implementation of SAX parser. This is very basic implementation of XML parser designed especially to be light and parse XML streams like jabber XML stream. It is very efficient, capable of parsing parts of XML document received from the network connection as well as handling a few XML documents in one buffer. This is especially useful when parsing data received from the network. Packets received from the network can contain non-comlete XML document as well as a few complete XML documents. It doesn't support XML comments, processing instructions, document inclussions. Actually it supports only:

- Start element event (with all attributes found).
- End element even.
- Character data event.
- 'OtherXML' data event - everything between '<' and '>' if after < is '?' or '!'. So it can 'catch' doctype declaration, processing instructions but it can't process correctly commented blocks.

Although very simple this imlementation is sufficient for Jabber protocol needs and is even used by some other packages of this server like implementation of `UserRepository` based on XML file or server configuration.

It is worth to note also that this class is fully thread safe. It means that one instance of this class can be simultanously used by many threads. This is to improve resources usage when processing many client connections at the same time.

Created: Fri Oct 1 23:02:15 2004

Version:
  $Rev$
Author:
  Artur Hefczyc

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected static enum`
  `SimpleParser.EntityType`
  `protected static class`
  `SimpleParser.ParserState`
  `protected static enum`
  `SimpleParser.State`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `int`
  `ATTRIBUTES_NUMBER_LIMIT`
  `static final String`
  `ATTRIBUTES_NUMBER_LIMIT_PROP_KEY`
  `int`
  `MAX_ATTRIBS_NUMBER`
  Variable constant `MAX_ATTRIBS_NUMBER` keeps value of maximum possible attributes number.
  `static final String`
  `MAX_ATTRIBS_NUMBER_PROP_KEY`
  `int`
  `MAX_ATTRIBUTE_NAME_SIZE`
  `static final String`
  `MAX_ATTRIBUTE_NAME_SIZE_PROP_KEY`
  `int`
  `MAX_ATTRIBUTE_VALUE_SIZE`
  `static final String`
  `MAX_ATTRIBUTE_VALUE_SIZE_PROP_KEY`
  `int`
  `MAX_CDATA_SIZE`
  `static final String`
  `MAX_CDATA_SIZE_PROP_KEY`
  `int`
  `MAX_ELEMENT_NAME_SIZE`
  `static final String`
  `MAX_ELEMENT_NAME_SIZE_PROP_KEY`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SimpleParser()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected boolean`
  `checkIsCharValidInXML(SimpleParser.ParserState parserState, char chr)`
  `final void`
  `parse(SimpleHandler handler, char[] data, int off, int len)`
  `final void`
  `parse(SimpleHandler handler, String input)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ATTRIBUTES_NUMBER_LIMIT_PROP_KEY

    public static final String ATTRIBUTES_NUMBER_LIMIT_PROP_KEY
    See Also:
      - Constant Field Values

  - ### MAX_ATTRIBS_NUMBER_PROP_KEY

    public static final String MAX_ATTRIBS_NUMBER_PROP_KEY
    See Also:
      - Constant Field Values

  - ### MAX_ELEMENT_NAME_SIZE_PROP_KEY

    public static final String MAX_ELEMENT_NAME_SIZE_PROP_KEY
    See Also:
      - Constant Field Values

  - ### MAX_ATTRIBUTE_NAME_SIZE_PROP_KEY

    public static final String MAX_ATTRIBUTE_NAME_SIZE_PROP_KEY
    See Also:
      - Constant Field Values

  - ### MAX_ATTRIBUTE_VALUE_SIZE_PROP_KEY

    public static final String MAX_ATTRIBUTE_VALUE_SIZE_PROP_KEY
    See Also:
      - Constant Field Values

  - ### MAX_CDATA_SIZE_PROP_KEY

    public static final String MAX_CDATA_SIZE_PROP_KEY
    See Also:
      - Constant Field Values

  - ### ATTRIBUTES_NUMBER_LIMIT

    public int ATTRIBUTES_NUMBER_LIMIT

  - ### MAX_ATTRIBS_NUMBER

    public int MAX_ATTRIBS_NUMBER
    Variable constant `MAX_ATTRIBS_NUMBER` keeps value of maximum possible attributes number. Real XML parser shouldn't have such limit but in most cases XML elements don't have too many attributes. For efficiency it is better to use fixed number of attributes and operate on arrays than on lists. Data structures will automaticly grow if real attributes number is bigger so there should be no problem with processing XML streams different than expected.

  - ### MAX_ATTRIBUTE_NAME_SIZE

    public int MAX_ATTRIBUTE_NAME_SIZE

  - ### MAX_ATTRIBUTE_VALUE_SIZE

    public int MAX_ATTRIBUTE_VALUE_SIZE

  - ### MAX_CDATA_SIZE

    public int MAX_CDATA_SIZE

  - ### MAX_ELEMENT_NAME_SIZE

    public int MAX_ELEMENT_NAME_SIZE

- ## Constructor Details

  - ### SimpleParser

    public SimpleParser()

- ## Method Details

  - ### parse

    public final void parse(SimpleHandler handler, String input)

  - ### parse

    @TODO(note="1. Better XML errors detection. 2. Add XML comments handling. 3. Character overflow detection i.e. limit max number of characters for each entity.") public final void parse(SimpleHandler handler, char[] data, int off, int len)

  - ### checkIsCharValidInXML

    protected boolean checkIsCharValidInXML(SimpleParser.ParserState parserState, char chr)