1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef _XML_H_ 17 #define _XML_H_ 18 19 #include <expat.h> 20 #include <ustring.h> 21 #include <Drm2CommonTypes.h> 22 23 using namespace ustl; 24 25 class ExpatWrapper { 26 public: 27 /** 28 * Constructor for ExpatWrapper. 29 */ 30 ExpatWrapper(); 31 32 /** 33 * Destructor for ExpatWrapper. 34 */ 35 virtual ~ExpatWrapper(); 36 37 /** 38 * decode call expat to parse the xml. 39 * @param buf The buffer to be parsed. 40 * @param len The length of the buffer. 41 * @param isFinal The flag to indicate whether the buffer 42 * is a fragment or whole xml. 43 */ 44 int decode(const char* buf, int len, int isFinal); 45 46 /** 47 * virtual funtion to deal with the start element in expat, need implement by child class. 48 */ 49 virtual void startElement(const XML_Char *name, const XML_Char **atts); 50 51 /** 52 * virtual funtion to deal with the end element in expat, need implement by child class. 53 */ 54 virtual void endElement(const XML_Char *name); 55 56 /** 57 * virtual funtion to deal with the data handler in expat, need implement by child class. 58 */ 59 virtual void dataHandler(const XML_Char *s, int len); 60 61 PRIVATE: 62 /** 63 * Callback for Expat startElement. 64 */ 65 static void startElementCallback(void *userData, const XML_Char *name, const XML_Char **atts); 66 67 /** 68 * Callback for Expat endElement. 69 */ 70 static void endElementCallback(void *userData, const XML_Char *name); 71 72 /** 73 * Callback for Expat dataHandler. 74 */ 75 static void dataHandlerCallback(void *userData, const XML_Char *s, int len); 76 77 PRIVATE: 78 XML_Parser mParser; /**< The expat parser object. */ 79 }; 80 81 #endif 82