com.trolltech.qt.xml
Class QXmlDefaultHandler

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.xml.QXmlDefaultHandler
All Implemented Interfaces:
QtJambiInterface, QXmlContentHandlerInterface, QXmlDeclHandlerInterface, QXmlDTDHandlerInterface, QXmlEntityResolverInterface, QXmlErrorHandlerInterface, QXmlLexicalHandlerInterface

public class QXmlDefaultHandler
extends QtJambiObject
implements QXmlContentHandlerInterface, QXmlErrorHandlerInterface, QXmlDTDHandlerInterface, QXmlEntityResolverInterface, QXmlLexicalHandlerInterface, QXmlDeclHandlerInterface

The QXmlDefaultHandler class provides a default implementation of all the XML handler classes.

This class gathers together the features of the specialized handler classes, making it a convenient starting point when implementing custom handlers for subclasses of QXmlReader, particularly QXmlSimpleReader. The virtual functions from each of the base classes are reimplemented in this class, providing sensible default behavior for many common cases. By subclassing this class, and overriding these functions, you can concentrate on implementing the parts of the handler relevant to your application.

The XML reader must be told which handler to use for different kinds of events during parsing. This means that, although QXmlDefaultHandler provides default implementations of functions inherited from all its base classes, we can still use specialized handlers for particular kinds of events.

For example, QXmlDefaultHandler subclasses both QXmlContentHandler and QXmlErrorHandler, so by subclassing it we can use the same handler for both of the following reader functions:

        xmlReader.setContentHandler(handler);
        xmlReader.setErrorHandler(handler);

Since the reader will inform the handler of parsing errors, it is necessary to reimplement QXmlErrorHandler::fatalError() if, for example, we want to stop parsing when such an error occurs:

    bool Handler::fatalError (const QXmlParseException & exception)
    {
        qWarning() << "Fatal error on line" << exception.lineNumber()
                   << ", column" << exception.columnNumber() << ":"
                   << exception.message();

        return false;
    }

The above function returns false, which tells the reader to stop parsing. To continue to use the same reader, it is necessary to create a new handler instance, and set up the reader to use it in the manner described above.

It is useful to examine some of the functions inherited by QXmlDefaultHandler, and consider why they might be reimplemented in a custom handler. Custom handlers will typically reimplement QXmlContentHandler::startDocument() to prepare the handler for new content. Document elements and the text within them can be processed by reimplementing QXmlContentHandler::startElement(), QXmlContentHandler::endElement(), and QXmlContentHandler::characters(). You may want to reimplement QXmlContentHandler::endDocument() to perform some finalization or validation on the content once the document has been read completely.

See Also:
QXmlDTDHandler, QXmlDeclHandler, QXmlContentHandler, QXmlEntityResolver, QXmlErrorHandler, QXmlLexicalHandler, to SAX2

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QXmlDefaultHandler()
          Constructs a handler for use with subclasses of QXmlReader.
 
Method Summary
 boolean attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
          This function is reimplemented for internal reasons.
 boolean characters(java.lang.String ch)
          This function is reimplemented for internal reasons.
 boolean comment(java.lang.String ch)
          This function is reimplemented for internal reasons.
 boolean endCDATA()
          This function is reimplemented for internal reasons.
 boolean endDocument()
          This function is reimplemented for internal reasons.
 boolean endDTD()
          This function is reimplemented for internal reasons.
 boolean endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName)
          This function is reimplemented for internal reasons.
 boolean endEntity(java.lang.String name)
          This function is reimplemented for internal reasons.
 boolean endPrefixMapping(java.lang.String prefix)
          This function is reimplemented for internal reasons.
 boolean error(QXmlParseException exception)
          This function is reimplemented for internal reasons.
 java.lang.String errorString()
          This function is reimplemented for internal reasons.
 boolean externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          This function is reimplemented for internal reasons.
 boolean fatalError(QXmlParseException exception)
          This function is reimplemented for internal reasons.
static QXmlDefaultHandler fromNativePointer(QNativePointer nativePointer)
          This function returns the QXmlDefaultHandler instance pointed to by nativePointer
 boolean ignorableWhitespace(java.lang.String ch)
          This function is reimplemented for internal reasons.
 boolean internalEntityDecl(java.lang.String name, java.lang.String value)
          This function is reimplemented for internal reasons.
 boolean notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          This function is reimplemented for internal reasons.
 boolean processingInstruction(java.lang.String target, java.lang.String data)
          This function is reimplemented for internal reasons.
 boolean resolveEntity(java.lang.String publicId, java.lang.String systemId, QXmlInputSource ret)
          This function is reimplemented for internal reasons.
 void setDocumentLocator(QXmlLocator locator)
          This function is reimplemented for internal reasons.
 boolean skippedEntity(java.lang.String name)
          This function is reimplemented for internal reasons.
 boolean startCDATA()
          This function is reimplemented for internal reasons.
 boolean startDocument()
          This function is reimplemented for internal reasons.
 boolean startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          This function is reimplemented for internal reasons.
 boolean startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qName, QXmlAttributes atts)
          This function is reimplemented for internal reasons.
 boolean startEntity(java.lang.String name)
          This function is reimplemented for internal reasons.
 boolean startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          This function is reimplemented for internal reasons.
 boolean unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          This function is reimplemented for internal reasons.
 boolean warning(QXmlParseException exception)
          This function is reimplemented for internal reasons.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QXmlDefaultHandler

public QXmlDefaultHandler()

Constructs a handler for use with subclasses of QXmlReader.

Method Detail

attributeDecl

public boolean attributeDecl(java.lang.String eName,
                             java.lang.String aName,
                             java.lang.String type,
                             java.lang.String valueDefault,
                             java.lang.String value)

This function is reimplemented for internal reasons.

Specified by:
attributeDecl in interface QXmlDeclHandlerInterface

characters

public boolean characters(java.lang.String ch)

This function is reimplemented for internal reasons.

Specified by:
characters in interface QXmlContentHandlerInterface

comment

public boolean comment(java.lang.String ch)

This function is reimplemented for internal reasons.

Specified by:
comment in interface QXmlLexicalHandlerInterface

endCDATA

public boolean endCDATA()

This function is reimplemented for internal reasons.

Specified by:
endCDATA in interface QXmlLexicalHandlerInterface
See Also:
startCDATA, QXmlContentHandler::characters

endDTD

public boolean endDTD()

This function is reimplemented for internal reasons.

Specified by:
endDTD in interface QXmlLexicalHandlerInterface
See Also:
startDTD

endDocument

public boolean endDocument()

This function is reimplemented for internal reasons.

Specified by:
endDocument in interface QXmlContentHandlerInterface
See Also:
startDocument

endElement

public boolean endElement(java.lang.String namespaceURI,
                          java.lang.String localName,
                          java.lang.String qName)

This function is reimplemented for internal reasons.

Specified by:
endElement in interface QXmlContentHandlerInterface
See Also:
startElement, Support via Features

endEntity

public boolean endEntity(java.lang.String name)

This function is reimplemented for internal reasons.

Specified by:
endEntity in interface QXmlLexicalHandlerInterface
See Also:
startEntity, QXmlContentHandler::skippedEntity, QXmlSimpleReader::setFeature

endPrefixMapping

public boolean endPrefixMapping(java.lang.String prefix)

This function is reimplemented for internal reasons.

Specified by:
endPrefixMapping in interface QXmlContentHandlerInterface
See Also:
startPrefixMapping, Support via Features

error

public boolean error(QXmlParseException exception)

This function is reimplemented for internal reasons.

Specified by:
error in interface QXmlErrorHandlerInterface

errorString

public java.lang.String errorString()

This function is reimplemented for internal reasons.

Specified by:
errorString in interface QXmlContentHandlerInterface
Specified by:
errorString in interface QXmlDeclHandlerInterface
Specified by:
errorString in interface QXmlDTDHandlerInterface
Specified by:
errorString in interface QXmlEntityResolverInterface
Specified by:
errorString in interface QXmlErrorHandlerInterface
Specified by:
errorString in interface QXmlLexicalHandlerInterface

externalEntityDecl

public boolean externalEntityDecl(java.lang.String name,
                                  java.lang.String publicId,
                                  java.lang.String systemId)

This function is reimplemented for internal reasons.

Specified by:
externalEntityDecl in interface QXmlDeclHandlerInterface

fatalError

public boolean fatalError(QXmlParseException exception)

This function is reimplemented for internal reasons.

Specified by:
fatalError in interface QXmlErrorHandlerInterface

ignorableWhitespace

public boolean ignorableWhitespace(java.lang.String ch)

This function is reimplemented for internal reasons.

Specified by:
ignorableWhitespace in interface QXmlContentHandlerInterface

internalEntityDecl

public boolean internalEntityDecl(java.lang.String name,
                                  java.lang.String value)

This function is reimplemented for internal reasons.

Specified by:
internalEntityDecl in interface QXmlDeclHandlerInterface

notationDecl

public boolean notationDecl(java.lang.String name,
                            java.lang.String publicId,
                            java.lang.String systemId)

This function is reimplemented for internal reasons.

Specified by:
notationDecl in interface QXmlDTDHandlerInterface

processingInstruction

public boolean processingInstruction(java.lang.String target,
                                     java.lang.String data)

This function is reimplemented for internal reasons.

Specified by:
processingInstruction in interface QXmlContentHandlerInterface

resolveEntity

public boolean resolveEntity(java.lang.String publicId,
                             java.lang.String systemId,
                             QXmlInputSource ret)

This function is reimplemented for internal reasons.

Specified by:
resolveEntity in interface QXmlEntityResolverInterface

setDocumentLocator

public void setDocumentLocator(QXmlLocator locator)

This function is reimplemented for internal reasons.

Specified by:
setDocumentLocator in interface QXmlContentHandlerInterface

skippedEntity

public boolean skippedEntity(java.lang.String name)

This function is reimplemented for internal reasons.

Specified by:
skippedEntity in interface QXmlContentHandlerInterface

startCDATA

public boolean startCDATA()

This function is reimplemented for internal reasons.

Specified by:
startCDATA in interface QXmlLexicalHandlerInterface
See Also:
endCDATA

startDTD

public boolean startDTD(java.lang.String name,
                        java.lang.String publicId,
                        java.lang.String systemId)

This function is reimplemented for internal reasons.

Specified by:
startDTD in interface QXmlLexicalHandlerInterface
See Also:
endDTD

startDocument

public boolean startDocument()

This function is reimplemented for internal reasons.

Specified by:
startDocument in interface QXmlContentHandlerInterface
See Also:
endDocument

startElement

public boolean startElement(java.lang.String namespaceURI,
                            java.lang.String localName,
                            java.lang.String qName,
                            QXmlAttributes atts)

This function is reimplemented for internal reasons.

Specified by:
startElement in interface QXmlContentHandlerInterface
See Also:
endElement, Support via Features

startEntity

public boolean startEntity(java.lang.String name)

This function is reimplemented for internal reasons.

Specified by:
startEntity in interface QXmlLexicalHandlerInterface
See Also:
endEntity, QXmlSimpleReader::setFeature

startPrefixMapping

public boolean startPrefixMapping(java.lang.String prefix,
                                  java.lang.String uri)

This function is reimplemented for internal reasons.

Specified by:
startPrefixMapping in interface QXmlContentHandlerInterface
See Also:
endPrefixMapping, Support via Features

unparsedEntityDecl

public boolean unparsedEntityDecl(java.lang.String name,
                                  java.lang.String publicId,
                                  java.lang.String systemId,
                                  java.lang.String notationName)

This function is reimplemented for internal reasons.

Specified by:
unparsedEntityDecl in interface QXmlDTDHandlerInterface

warning

public boolean warning(QXmlParseException exception)

This function is reimplemented for internal reasons.

Specified by:
warning in interface QXmlErrorHandlerInterface

fromNativePointer

public static QXmlDefaultHandler fromNativePointer(QNativePointer nativePointer)
This function returns the QXmlDefaultHandler instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.