00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00046 #ifndef XSPF_XML_FORMATTER_H
00047 #define XSPF_XML_FORMATTER_H
00048
00049
00050 #include "XspfDefines.h"
00051 #include <sstream>
00052
00053 namespace Xspf {
00054
00055
00056 class XspfWriter;
00057
00058
00060
00064 struct XspfNamespaceRegistrationUndo {
00065 int level;
00066 XML_Char const * uri;
00067
00074 XspfNamespaceRegistrationUndo(int level, XML_Char const * uri)
00075 : level(level), uri(uri) {
00076
00077 }
00078
00079 };
00080
00082
00083
00084 class XspfXmlFormatterPrivate;
00085
00086
00090 class XspfXmlFormatter {
00091
00092 private:
00094 XspfXmlFormatterPrivate * const d;
00095
00096
00097 protected:
00101 XspfXmlFormatter();
00102
00108 XspfXmlFormatter(XspfXmlFormatter const & source);
00109
00115 XspfXmlFormatter & operator=(XspfXmlFormatter const & source);
00116
00121 virtual ~XspfXmlFormatter();
00122
00126 virtual void writeXmlDeclaration();
00127
00128 private:
00136 XML_Char const * getPrefix(XML_Char const * nsUri) const;
00137
00146 XML_Char * makeFullName(XML_Char const * nsUri,
00147 XML_Char const * localName) const;
00148
00153 void cleanupNamespaceRegs();
00154
00162 bool registerNamespace(XML_Char const * uri,
00163 XML_Char const * prefixSuggestion);
00164
00165 public:
00171 void setOutput(std::basic_ostringstream<XML_Char> & output);
00172
00182 void writeStart(XML_Char const * ns, XML_Char const * localName,
00183 XML_Char const * const * atts, XML_Char const * const * nsRegs = NULL);
00184
00192 void writeEnd(XML_Char const * ns, XML_Char const * localName);
00193
00201 void writeHomeStart(XML_Char const * localName,
00202 XML_Char const * const * atts, XML_Char const * const * nsRegs = NULL);
00203
00209 void writeHomeEnd(XML_Char const * localName);
00210
00211 protected:
00221 virtual void writeStart(XML_Char const * name,
00222 XML_Char const * const * atts) = 0;
00223
00229 virtual void writeEnd(XML_Char const * name) = 0;
00230
00231 public:
00237 virtual void writeBody(XML_Char const * text) = 0;
00238
00244 virtual void writeBody(int number) = 0;
00245
00251 void writeCharacterData(XML_Char const * data);
00252
00253 static XML_Char const * const namespaceKey;
00254
00255 protected:
00259 std::basic_ostringstream<XML_Char> * & getOutput();
00260
00262 void virtualHook(int methodId, void * parameters);
00264
00265 friend class XspfWriter;
00266
00267 };
00268
00269
00270 }
00271
00272 #endif // XSPF_XML_FORMATTER_H