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 WBXML_ENCODER_H 19 #define WBXML_ENCODER_H 20 21 #include <stdint.h> 22 #include "wbxml_const.h" 23 24 class WbxmlHandler 25 { 26 public: ~WbxmlHandler()27 virtual ~WbxmlHandler() {} 28 virtual void wbxmlData(const char *data, uint32_t len) = 0; 29 }; 30 31 enum EncoderError { 32 NO_ERROR = 0, 33 ERROR_NO_PUBLIC_ID = 1, 34 ERROR_UNSUPPORTED_DOCTYPE, 35 ERROR_UNSUPPORTED_TAG, 36 ERROR_UNSUPPORTED_ATTR, 37 ERROR_INVALID_DATA, 38 ERROR_INVALID_INTEGER_VALUE, 39 ERROR_INVALID_DATETIME_VALUE, 40 ERROR_INVALID_END_ELEMENT, 41 }; 42 43 class WbxmlEncoder 44 { 45 public: ~WbxmlEncoder()46 virtual ~WbxmlEncoder() {} 47 setWbxmlHandler(WbxmlHandler * handler)48 void setWbxmlHandler(WbxmlHandler * handler) 49 { 50 mHandler = handler; 51 } 52 53 virtual EncoderError startElement(const char *name, const char **atts) = 0; 54 virtual EncoderError characters(const char *chars, int len) = 0; 55 virtual EncoderError endElement() = 0; 56 57 /** 58 * Reset the encoder so that it may be used again. The WbxmlHandler is 59 * NOT cleared by reset(). 60 */ 61 virtual void reset() = 0; 62 63 protected: 64 WbxmlHandler * mHandler; 65 }; 66 67 #endif 68 69