xmlBlaster 2.1.0 API

org.xmlBlaster.contrib.dbwriter
Class XmlParserBase

java.lang.Object
  extended by org.xmlBlaster.util.SaxHandlerBase
      extended by org.xmlBlaster.contrib.dbwriter.XmlParserBase
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler
Direct Known Subclasses:
SqlInfoParser

public class XmlParserBase
extends SaxHandlerBase

In good old C days this would have been named a 'flag' (with bit wise setting)
But this allows to specify QoS (quality of service) in XML syntax.

With XML there are no problems to extend the services of the xmlBlaster in unlimited ways.
The xml string is parsed with a SAX parser, since no persistent DOM tree is needed and SAX is much faster.

You may use this as a base class for your specialized QoS.
The <qos> tag is parsed here, and you provide the parsing of the inner tags.


Field Summary
protected  java.util.Set allowedTagNames
           
protected  ClientProperty clientProperty
           
protected  int inClientProperty
           
protected  boolean inRootTag
           
private static java.util.logging.Logger log
           
protected  java.lang.String qosTag
           
 
Fields inherited from class org.xmlBlaster.util.SaxHandlerBase
character, glob, locator, xmlLiteral, xmlSource
 
Constructor Summary
XmlParserBase(Global glob, java.lang.String qosTag)
           
 
Method Summary
 void addAllowedTag(java.lang.String key)
           
protected static void addTagToString(java.lang.StringBuffer buf, java.lang.String tagName, org.xml.sax.Attributes attrs)
           
 void endCDATA()
          Report the end of a CDATA section.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String name)
          End element.
protected  boolean endElementBase(java.lang.String uri, java.lang.String localName, java.lang.String name)
          End element callback, does handling of tag <qos>.
protected  boolean isEmpty(java.lang.String qos)
          To avoid SAX parsing (which costs many CPU cycles) check the QoS string here if it contains anything useful.
static int protectionNeeded(java.lang.String value)
          If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.
 void startCDATA()
          Report the start of a CDATA section.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attrs)
          Start element.
protected  boolean startElementBase(java.lang.String uri, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes attrs)
          Start element callback, does handling of tag <qos>.
 
Methods inherited from class org.xmlBlaster.util.SaxHandlerBase
characters, comment, endDocument, endDTD, endEntity, endPrefixMapping, error, fatalError, getUseLexicalHandler, ignorableWhitespace, init, init, init, notationDecl, processingInstruction, setDocumentLocator, setUseLexicalHandler, skippedEntity, startDocument, startDTD, startEntity, startPrefixMapping, toString, toXml, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

inRootTag

protected boolean inRootTag

clientProperty

protected ClientProperty clientProperty

allowedTagNames

protected java.util.Set allowedTagNames

qosTag

protected java.lang.String qosTag

inClientProperty

protected int inClientProperty
Constructor Detail

XmlParserBase

public XmlParserBase(Global glob,
                     java.lang.String qosTag)
Method Detail

addTagToString

protected static void addTagToString(java.lang.StringBuffer buf,
                                     java.lang.String tagName,
                                     org.xml.sax.Attributes attrs)

addAllowedTag

public void addAllowedTag(java.lang.String key)

isEmpty

protected boolean isEmpty(java.lang.String qos)
To avoid SAX parsing (which costs many CPU cycles) check the QoS string here if it contains anything useful.

Parameters:
qos - The literal ASCII xml string

startElementBase

protected final boolean startElementBase(java.lang.String uri,
                                         java.lang.String localName,
                                         java.lang.String name,
                                         org.xml.sax.Attributes attrs)
Start element callback, does handling of tag <qos>.

You may include this into your derived startElement() method like this:

  if (super.startElementBase(name, attrs) == true)
     return;
 

Returns:
true if the tag is parsed here, the derived class doesn't need to look at this tag anymore false this tag is not handled by this Base class

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String name,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Start element.

Default implementation, knows how to parse <qos> but knows nothing about the tags inside of qos

Specified by:
startElement in interface org.xml.sax.ContentHandler
Overrides:
startElement in class SaxHandlerBase
Throws:
org.xml.sax.SAXException

endElementBase

protected final boolean endElementBase(java.lang.String uri,
                                       java.lang.String localName,
                                       java.lang.String name)
End element callback, does handling of tag <qos>.

You may include this into your derived endElement() method like this:

  if (super.endElementBase(name) == true)
     return;
 

Returns:
true if the tag is parsed here, the derived class doesn't need to look at this tag anymore false this tag is not handled by this Base class

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String name)
                throws org.xml.sax.SAXException
End element.

Default implementation, knows how to parse <qos> but knows nothing about the tags inside of qos

Specified by:
endElement in interface org.xml.sax.ContentHandler
Overrides:
endElement in class SaxHandlerBase
Throws:
org.xml.sax.SAXException

startCDATA

public void startCDATA()
Description copied from class: SaxHandlerBase
Report the start of a CDATA section. (interface LexicalHandler)

Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
startCDATA in class SaxHandlerBase

endCDATA

public void endCDATA()
Description copied from class: SaxHandlerBase
Report the end of a CDATA section. (interface LexicalHandler)

Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler
Overrides:
endCDATA in class SaxHandlerBase

protectionNeeded

public static int protectionNeeded(java.lang.String value)
If value contains XML harmful characters it needs to be wrapped by CDATA or encoded to Base64.

Parameters:
value - The string to verify
Returns:
0 No protection necessary 1 Protection with CDATA is needed 2 Protection with Base64 is needed

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.