• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <util/xml/ExpatWrapper.h>
17 #include <ustring.h>
18 using namespace ustl;
19 
20 /** see ExpatWrapper.h */
ExpatWrapper()21 ExpatWrapper::ExpatWrapper()
22 {
23     mParser = XML_ParserCreate(NULL);
24     ::XML_SetUserData(mParser, this);
25     ::XML_SetElementHandler(mParser, startElementCallback, endElementCallback);
26     ::XML_SetCharacterDataHandler(mParser, dataHandlerCallback);
27 
28 }
29 
30 /** see ExpatWrapper.h */
~ExpatWrapper()31 ExpatWrapper::~ExpatWrapper()
32 {
33     if (mParser)
34     {
35         ::XML_ParserFree(mParser);
36     }
37 }
38 
39 /** see ExpatWrapper.h */
decode(const char * buf,int len,int isFinal)40 int ExpatWrapper::decode(const char* buf, int len, int isFinal)
41 {
42     return ::XML_Parse(mParser, buf, len, isFinal);
43 }
44 
45 /** see ExpatWrapper.h */
startElementCallback(void * userData,const XML_Char * name,const XML_Char ** atts)46 void ExpatWrapper::startElementCallback(void *userData, const XML_Char *name,
47                                         const XML_Char **atts)
48 {
49     ((ExpatWrapper *)userData)->startElement(name, atts);
50 }
51 
52 /** see ExpatWrapper.h */
endElementCallback(void * userData,const XML_Char * name)53 void ExpatWrapper::endElementCallback(void *userData, const XML_Char *name)
54 {
55     ((ExpatWrapper *)userData)->endElement(name);
56 }
57 
58 /** see ExpatWrapper.h */
dataHandlerCallback(void * userData,const XML_Char * s,int len)59 void ExpatWrapper::dataHandlerCallback(void *userData, const XML_Char *s, int len)
60 {
61     ((ExpatWrapper *)userData)->dataHandler(s, len);
62 }
63 
64 /** see ExpatWrapper.h */
startElement(const XML_Char * name,const XML_Char ** atts)65 void ExpatWrapper::startElement(const XML_Char *name, const XML_Char **atts)
66 {
67 }
68 
69 /** see ExpatWrapper.h */
endElement(const XML_Char * name)70 void ExpatWrapper::endElement(const XML_Char *name)
71 {
72 }
73 
74 /** see ExpatWrapper.h */
dataHandler(const XML_Char * s,int len)75 void ExpatWrapper::dataHandler(const XML_Char *s, int len)
76 {
77 }
78