1 /* 2 * Copyright (C) 2007 Esmertec AG. 3 * Copyright (C) 2007 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #ifndef XML_TO_WBXML_ENCODER_H 19 #define XML_TO_WBXML_ENCODER_H 20 21 #include <expat.h> 22 #include "wbxml_encoder.h" 23 #include "wbxml_stl.h" 24 #include "expat_parser.h" 25 26 class Xml2WbxmlEncoder: public XmlContentHandler 27 { 28 public: 29 Xml2WbxmlEncoder(); 30 ~Xml2WbxmlEncoder(); 31 32 void setWbxmlHandler(WbxmlHandler * handler); 33 34 int encode(const char * data, uint32_t len, bool end); 35 36 void startElement(const char *name, const char **atts); 37 void endElement(const char *name); 38 void characters(const char *data, int len); 39 void startDoctype(const char *doctypeName, const char *sysid, const char *pubid, 40 int has_internal_subset); 41 void endDoctype(void) {} 42 43 private: 44 WbxmlHandler * mWbxmlHandler; 45 WbxmlEncoder * mEncoder; 46 ExpatParser * mExpatParser; 47 48 int mPublicId; 49 int mDepth; 50 int mErrorCode; 51 52 bool detectPublicId(const char * pubid); 53 bool detectPublicIdByXmlns(const char * xmlnsUri); 54 bool isPublicIdSet(void) const 55 { 56 return mPublicId != -1; 57 } 58 void setPublicId(int id) 59 { 60 mPublicId = id; 61 } 62 int getErrorCode(void) const 63 { 64 return mErrorCode; 65 } 66 void setError(int err) 67 { 68 mErrorCode = err; 69 } 70 }; 71 72 #endif 73 74