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/config.h>
00020 #include <zorba/api_shared_types.h>
00021 
00022 namespace zorba{
00023 
00024 class SAX2_Attributes;
00025 
00026 /** \brief Receive notification of events that result from serializing
00027  *         a query result as XML.
00028  *
00029  * This is an interface that is used to receive notifications resulting
00030  * from parsing a query result that was serialized as XML.
00031  *
00032  * Instances of classes that implement this interface can be registered for
00033  * a query by calling the XQuery::registerSAXHandler or XQuery::executeSAX
00034  * function.
00035  */
00036 class ZORBA_DLL_PUBLIC SAX2_ContentHandler
00037 {
00038   public:
00039 
00040     /** \brief Destructor
00041      */
00042     virtual
00043     ~SAX2_ContentHandler() {}
00044 
00045     /** \brief Receive notification of the beginning of a document.
00046      */
00047     virtual void
00048     startDocument() = 0;
00049 
00050     /** \brief Receive notification of the end of a document.
00051      */
00052     virtual void
00053     endDocument() = 0;
00054 
00055     /** \brief Receive notification of the beginning of an element.
00056      *
00057      * Zorba's serializer will invoke this method at the beginning of every element 
00058      * of the serialized query result; there will be a corresponding endElement() 
00059      * event for every startElement() event (even when the element is empty). 
00060      * All of the element's content will be reported, in order, before the 
00061      * corresponding endElement() event.
00062      *
00063      * @param aURI the URI of the associated namespace for this element.
00064      * @param aLocalname thee local part of the element name.
00065      * @param aQName the QName of this element.
00066      * @param aAttrs the attributes attached to the element, if any.
00067      */
00068     virtual void
00069     startElement( const String& aURI, const String& aLocalname,
00070                   const String& aQName, const SAX2_Attributes& aAttrs ) = 0;
00071 
00072     /** \brief Receive notification of the end of an element.
00073      *
00074      * Zorba's serializerwill invoke this method at the end of every element in the serialized 
00075      * query result document;  there will be a corresponding startElement() event for 
00076      * every endElement() event (even when the element is empty).
00077      *
00078      * @param aURI the URI of the asscioated namespace for this element
00079      * @param aLocalname the local part of the element name
00080      * @param aQName the QName of this element
00081      */
00082     virtual void
00083     endElement( const String& aURI, const String& aLocalname, const String& aQName ) = 0;
00084     
00085     /** \brief Receive notification of character data.
00086      *
00087      * The serializer will call this method to report each chunk of character data.
00088      *
00089      * @param aText the characters from the serialized result.
00090      */
00091     virtual void
00092     characters( const String& aText ) = 0;
00093     
00094     /** \brief Receive notification of a processing instruction.
00095      *
00096      * The serializer will invoke this method once for each processing instruction found.
00097      *
00098      * @param aTarget the processing instruction target.
00099      * @param aData the processing instruction data, or null if none was supplied.
00100      */
00101     virtual void
00102     processingInstruction( const String& aTarget, const String& aData ) = 0;
00103 
00104     /** \brief Receive notification of ignorable whitespace in element content.
00105      *
00106      * @param aText the characters from the serialized query result.
00107      */
00108     virtual void
00109     ignorableWhitespace( const String& aText ) = 0;
00110 
00111     /** \brief Receive notification of the start of an namespace prefix mapping.
00112      *
00113      * @param aPrefix the namespace prefix used
00114      * @param aURI the namespace URI used.
00115      */
00116     virtual void
00117     startPrefixMapping( const String& aPrefix, const String& aURI ) = 0;
00118 
00119     /** \brief Receive notification of the end of an namespace prefix mapping.
00120      *
00121      * @param aPrefix the namespace prefix used.
00122      */
00123     virtual void
00124     endPrefixMapping( const String& aPrefix ) = 0;
00125 
00126     /** \brief Receive notification of a skipped entity. 
00127      *
00128      * @param aName the name of the skipped entity.
00129      */
00130     virtual void
00131     skippedEntity( const  String& aName ) = 0;
00132 };
00133 
00134 class ZORBA_DLL_PUBLIC SAX2_Attributes
00135 {
00136   public:
00137     virtual
00138     ~SAX2_Attributes() {}
00139     
00140     virtual unsigned int
00141     getLength() const = 0;
00142 
00143     virtual const String
00144     getURI( const unsigned int index) const = 0;
00145 
00146     virtual const String
00147     getLocalName( const unsigned int index) const = 0;
00148 
00149     virtual const String
00150     getQName( const unsigned int index) const = 0;
00151 
00152     virtual const String
00153     getType( const unsigned int index) const = 0;
00154 
00155     virtual const String
00156     getValue( const unsigned int index) const = 0;
00157 
00158     virtual int
00159     getIndex( const String & uri, const String & localPart ) const = 0 ;
00160 
00161     virtual int
00162     getIndex(const String & qName ) const = 0 ;
00163 
00164     virtual const
00165     String getType(const String & uri, const String & localPart ) const = 0 ;
00166 
00167     virtual const
00168     String getType( const String & qName ) const = 0;
00169 
00170     virtual const
00171     String getValue( const String & uri, const String & localPart ) const = 0 ;
00172 
00173     virtual const
00174     String getValue( const String & qName ) const = 0;
00175 };
00176 
00177 class ZORBA_DLL_PUBLIC SAX2_LexicalHandler
00178 {
00179   public:
00180     virtual
00181     ~SAX2_LexicalHandler () {}
00182 
00183     virtual void
00184     comment ( const String & chars ) = 0;
00185 
00186     virtual void
00187     endCDATA () = 0;
00188 
00189     virtual void
00190     endDTD () = 0;
00191 
00192     virtual void
00193     endEntity ( const String & name ) = 0;
00194 
00195     virtual void
00196     startCDATA () = 0;
00197 
00198     virtual void
00199     startDTD ( const String & name, const String & publicId,
00200                const String & systemId ) = 0;
00201 
00202     virtual void
00203     startEntity ( const String & name ) = 0;
00204 };
00205 }
00206 //end namespace zorba
00207 #endif
00208 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus