00001 /* 00002 * Copyright (c) 2009, Czech Technical University in Prague 00003 * All rights reserved. 00004 * 00005 * Authors/Contact: 00006 * 00007 * Petr Vlacil 00008 * (vlacipet@fel.cvut.cz) 00009 * R&D Centre (RDC) for Mobile Applications 00010 * Dept of Telecommunications Engineering 00011 * Faculty of Electrical Engineering 00012 * Czech Technical University in Prague 00013 * Technicka 2, 166 27 Prague 6, Czech Republic 00014 * 00015 * Redistribution and use in source and binary forms, with or 00016 * without modification, are permitted provided that the following 00017 * conditions are met: 00018 * 00019 * 1. Redistributions of source code must retain the above copyright 00020 * notice, this list of conditions and the following disclaimer. 00021 * 2. Redistributions in binary form must reproduce the above copyright 00022 * notice, this list of conditions and the following disclaimer in 00023 * the documentation and/or other materials provided with the 00024 * distribution. 00025 * 3. Neither the name of the Czech Technical University in Prague nor 00026 * the names of its contributors may be used to endorse or promote 00027 * products derived from this software without specific prior 00028 * written permission. 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00031 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00032 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00033 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00034 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00035 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00036 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00037 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00038 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00039 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00040 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00041 * 00042 */ 00043 00044 00045 #ifndef MLP_PARSE_HANDLERS_H 00046 #define MLP_PARSE_HANDLERS_H 00047 00048 00049 /** 00050 * \file 00051 * \brief MlpParseHandlers declaration 00052 * 00053 * This file contains MlpParseHandlers class declaration. 00054 * 00055 * \author Petr Vláčil 00056 */ 00057 00058 00059 //-------------------------------------------------------------------------- 00060 // Standard libraries 00061 //-------------------------------------------------------------------------- 00062 #include <stack> 00063 #include <sstream> 00064 00065 //-------------------------------------------------------------------------- 00066 // Xercesc libraries 00067 //-------------------------------------------------------------------------- 00068 #include <xercesc/sax2/ContentHandler.hpp> 00069 00070 //-------------------------------------------------------------------------- 00071 // MLP-Lib-Cpp library files 00072 //-------------------------------------------------------------------------- 00073 #include <libmlp-cpp/MlpConstants.hpp> 00074 #include <libmlp-cpp/MlpTagNames.hpp> 00075 #include <libmlp-cpp/MlpMessage.hpp> 00076 #include <libmlp-cpp/MlpShape.hpp> 00077 00078 00079 /** 00080 * \brief Class that do the most of work. 00081 * 00082 * This class is passed to Xerces SAX2 XMLReader and its member functions 00083 * are called to process XML. 00084 */ 00085 class MlpParseHandlers : public xercesc::ContentHandler 00086 { 00087 private: 00088 00089 /** Stack for tag constants. 00090 * 00091 * It is used to hold the current XML 00092 * element on the top of the stack. 00093 */ 00094 std::stack<int> _tagStack; 00095 00096 /** Tag string names */ 00097 MlpTagNames _tagNames; 00098 00099 /** Resulting parsed message */ 00100 MlpMessage* _inMsg; 00101 00102 /** Temporary pointer to resulting header of MLP message */ 00103 MlpHdr* _newHdr; 00104 00105 /** Temporary pointer to resulting list of Subscribers to locate */ 00106 MlpSubscriberList* _newSubscriberList; 00107 00108 /** Temporary pointer to resulting list of positions of subscribers */ 00109 MlpPositionList* _newPositionList; 00110 00111 /** Temporary pointer to object containing subscribes location */ 00112 MlpShape* _newShape; 00113 00114 /** Temporary pointer to GSM parameters */ 00115 MlpGsmNetParams* _newMlpGsmNetParams; 00116 00117 /** Buffer for CDATA and PCDATA characters */ 00118 std::ostringstream _charBuf; 00119 00120 public: 00121 /** Constructor */ 00122 MlpParseHandlers(); 00123 /** Destructor */ 00124 ~MlpParseHandlers(); 00125 00126 00127 /** Processes each starting XML element */ 00128 void startElement ( 00129 const XMLCh* const uri, 00130 const XMLCh* const localname, 00131 const XMLCh* const qname, 00132 const xercesc::Attributes& attrs 00133 ) ; 00134 00135 /** Processes each closing XML element */ 00136 void endElement ( 00137 const XMLCh* const uri, 00138 const XMLCh* const localname, 00139 const XMLCh* const qname 00140 ) ; 00141 00142 /** Processes CDATA and PCDATA between starting and closing XML elements */ 00143 void characters ( 00144 const XMLCh *const chars, 00145 const unsigned int length 00146 ) ; 00147 00148 /** not used */ 00149 void ignorableWhitespace ( 00150 const XMLCh *const chars, 00151 const unsigned int length 00152 ) ; 00153 00154 /** not used */ 00155 void processingInstruction ( 00156 const XMLCh *const target, 00157 const XMLCh *const data 00158 ) ; 00159 00160 /** not used */ 00161 void resetDocument () ; 00162 00163 /** not used */ 00164 void setDocumentLocator (const xercesc::Locator *const locator) ; 00165 00166 /** not used */ 00167 void startDocument () ; 00168 00169 /** not used */ 00170 void endDocument () ; 00171 00172 /** not used */ 00173 void startPrefixMapping ( 00174 const XMLCh *const prefix, 00175 const XMLCh *const uri 00176 ) ; 00177 00178 /** not used */ 00179 void endPrefixMapping ( const XMLCh *const prefix ) ; 00180 00181 /** not used */ 00182 void skippedEntity ( const XMLCh *const name ) ; 00183 00184 void clean (); 00185 00186 void setNewMsg ( MlpMessage* emptyMsg ); 00187 00188 private: 00189 /** Push function for tag stack. */ 00190 void pushTag ( const XMLCh* const localName ); 00191 void popTag (); 00192 int currentTag (); 00193 00194 std::string getAttDataValue( 00195 const char* uri, 00196 const char* localPart, 00197 const xercesc::Attributes& attrs 00198 ); 00199 00200 int getAttConstValue( 00201 const char* uri, 00202 const char* localPart, 00203 const xercesc::Attributes& attrs 00204 ); 00205 00206 00207 00208 00209 }; 00210 00211 #endif