sax2.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef ZORBA_SAX2_API_H
00017 #define ZORBA_SAX2_API_H
00018 
00019 #include <zorba/api_shared_types.h>
00020 
00021 namespace zorba{
00022 
00023 class SAX2_Attributes;
00024 
00025 /** \brief Receive notification of events that result from serializing
00026  *         a query result as XML.
00027  *
00028  * This is an interface that is used to receive notifications resulting
00029  * from parsing a query result that was serialized as XML.
00030  *
00031  * Instances of classes that implement this interface can be registered for
00032  * a query by calling the XQuery::registerSAXHandler or XQuery::executeSAX
00033  * function.
00034  */
00035 class SAX2_ContentHandler
00036 {
00037   public:
00038 
00039     /** \brief Destructor
00040      */
00041     virtual
00042     ~SAX2_ContentHandler() {}
00043 
00044     /** \brief Receive notification of the beginning of a document.
00045      */
00046     virtual void
00047     startDocument() = 0;
00048 
00049     /** \brief Receive notification of the end of a document.
00050      */
00051     virtual void
00052     endDocument() = 0;
00053 
00054     /** \brief Receive notification of the beginning of an element.
00055      *
00056      * Zorba's serializer will invoke this method at the beginning of every element 
00057      * of the serialized query result; there will be a corresponding endElement() 
00058      * event for every startElement() event (even when the element is empty). 
00059      * All of the element's content will be reported, in order, before the 
00060      * corresponding endElement() event.
00061      *
00062      * @param aURI the URI of the associated namespace for this element.
00063      * @param aLocalname thee local part of the element name.
00064      * @param aQName the QName of this element.
00065      * @param aAttrs the attributes attached to the element, if any.
00066      */
00067     virtual void
00068     startElement( const String& aURI, const String& aLocalname,
00069                   const String& aQName, const SAX2_Attributes& aAttrs ) = 0;
00070 
00071     /** \brief Receive notification of the end of an element.
00072      *
00073      * Zorba's serializerwill invoke this method at the end of every element in the serialized 
00074      * query result document;  there will be a corresponding startElement() event for 
00075      * every endElement() event (even when the element is empty).
00076      *
00077      * @param aURI the URI of the asscioated namespace for this element
00078      * @param aLocalname the local part of the element name
00079      * @param aQName the QName of this element
00080      */
00081     virtual void
00082     endElement( const String& aURI, const String& aLocalname, const String& aQName ) = 0;
00083     
00084     /** \brief Receive notification of character data.
00085      *
00086      * The serializer will call this method to report each chunk of character data.
00087      *
00088      * @param aText the characters from the serialized result.
00089      */
00090     virtual void
00091     characters( const String& aText ) = 0;
00092     
00093     /** \brief Receive notification of a processing instruction.
00094      *
00095      * The serializer will invoke this method once for each processing instruction found.
00096      *
00097      * @param aTarget the processing instruction target.
00098      * @param aData the processing instruction data, or null if none was supplied.
00099      */
00100     virtual void
00101     processingInstruction( const String& aTarget, const String& aData ) = 0;
00102 
00103     /** \brief Receive notification of ignorable whitespace in element content.
00104      *
00105      * @param aText the characters from the serialized query result.
00106      */
00107     virtual void
00108     ignorableWhitespace( const String& aText ) = 0;
00109 
00110     /** \brief Receive notification of the start of an namespace prefix mapping.
00111      *
00112      * @param aPrefix the namespace prefix used
00113      * @param aURI the namespace URI used.
00114      */
00115     virtual void
00116     startPrefixMapping( const String& aPrefix, const String& aURI ) = 0;
00117 
00118     /** \brief Receive notification of the end of an namespace prefix mapping.
00119      *
00120      * @param aPrefix the namespace prefix used.
00121      */
00122     virtual void
00123     endPrefixMapping( const String& aPrefix ) = 0;
00124 
00125     /** \brief Receive notification of a skipped entity. 
00126      *
00127      * @param aName the name of the skipped entity.
00128      */
00129     virtual void
00130     skippedEntity( const  String& aName ) = 0;
00131 };
00132 
00133 class SAX2_Attributes
00134 {
00135   public:
00136     virtual
00137     ~SAX2_Attributes() {}
00138     
00139     virtual unsigned int
00140     getLength() const = 0;
00141 
00142     virtual const String
00143     getURI( const unsigned int index) const = 0;
00144 
00145     virtual const String
00146     getLocalName( const unsigned int index) const = 0;
00147 
00148     virtual const String
00149     getQName( const unsigned int index) const = 0;
00150 
00151     virtual const String
00152     getType( const unsigned int index) const = 0;
00153 
00154     virtual const String
00155     getValue( const unsigned int index) const = 0;
00156 
00157     virtual int
00158     getIndex( const String & uri, const String & localPart ) const = 0 ;
00159 
00160     virtual int
00161     getIndex(const String & qName ) const = 0 ;
00162 
00163     virtual const
00164     String getType(const String & uri, const String & localPart ) const = 0 ;
00165 
00166     virtual const
00167     String getType( const String & qName ) const = 0;
00168 
00169     virtual const
00170     String getValue( const String & uri, const String & localPart ) const = 0 ;
00171 
00172     virtual const
00173     String getValue( const String & qName ) const = 0;
00174 };
00175 
00176 class SAX2_LexicalHandler
00177 {
00178   public:
00179     virtual
00180     ~SAX2_LexicalHandler () {}
00181 
00182     virtual void
00183     comment ( const String & chars ) = 0;
00184 
00185     virtual void
00186     endCDATA () = 0;
00187 
00188     virtual void
00189     endDTD () = 0;
00190 
00191     virtual void
00192     endEntity ( const String & name ) = 0;
00193 
00194     virtual void
00195     startCDATA () = 0;
00196 
00197     virtual void
00198     startDTD ( const String & name, const String & publicId,
00199                const String & systemId ) = 0;
00200 
00201     virtual void
00202     startEntity ( const String & name ) = 0;
00203 };
00204 }
00205 //end namespace zorba
00206 #endif