00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef _XML2_B_WRITER_H
00014 #define _XML2_B_WRITER_H
00015
00016 #include <support/Vector.h>
00017 #include <support/IByteStream.h>
00018 #include <xml/XMLOStr.h>
00019
00020 #if _SUPPORTS_NAMESPACE
00021 namespace palmos {
00022 namespace xml {
00023 using namespace support;
00024 #endif
00025
00026
00027
00028 enum {
00029 stfLeaf = 0x00000001,
00030 stfCanAddWS = 0x00000002
00031 };
00032
00033
00034
00035 class BOutputStream : public CXMLOStr {
00036 public:
00037 BOutputStream(const sptr<IByteOutput>& stream, bool writeHeader=false);
00038 virtual ~BOutputStream();
00039
00040 virtual status_t StartTag(SString &name, SValue &attributes);
00041 virtual status_t EndTag(SString &name);
00042 virtual status_t TextData(const char * data, int32_t size);
00043 virtual status_t Comment(const char *data, int32_t size);
00044
00045 private:
00046 void Indent();
00047
00048 sptr<IByteOutput> m_stream;
00049 int32_t m_depth;
00050 int32_t m_lastPrettyDepth;
00051 bool m_isLeaf:1;
00052 bool m_openStartTag:1;
00053 uint8_t m_reserved:6;
00054 };
00055
00056
00057
00058
00059 class BWriter
00060 {
00061 public:
00062 BWriter(const sptr<IByteOutput>& data, uint32_t formattingStyle);
00063 virtual ~BWriter();
00064
00065
00066
00067
00068
00069
00070
00071
00072 virtual status_t StartTag(const SString &name, const SValue &attributes, uint32_t formattingHints=0);
00073 virtual status_t EndTag();
00074 virtual status_t TextData(const char * data, int32_t size);
00075 virtual status_t CData(const char * data, int32_t size);
00076 virtual status_t WriteEscaped(const char * data, int32_t size);
00077
00078
00079 virtual status_t Comment(const char *data, int32_t size);
00080 virtual status_t ProcessingInstruction(const SString & target, const SString & data);
00081
00082
00083 enum
00084 {
00085 BALANCE_WHITESPACE = 0x00000001,
00086 SKIP_DOCTYPE_OPENER = 0x00000002
00087 };
00088
00089
00090 enum
00091 {
00092 NO_EXTRA_WHITESPACE = 0x80000002
00093 };
00094
00095 private:
00096 status_t open_doctype();
00097 status_t indent();
00098
00099 sptr<IByteOutput> m_stream;
00100 SVector<SString> m_elementStack;
00101 uint32_t m_formattingStyle;
00102 bool m_openStartTag;
00103 bool m_doneDOCTYPE;
00104 bool m_startedInternalDTD;
00105 int32_t m_depth;
00106 int32_t m_lastPrettyDepth;
00107 };
00108
00109 #if _SUPPORTS_NAMESPACE
00110 };
00111 };
00112 #endif
00113
00114 #endif // _XML2_B_WRITER_H