libxspf  1.2.0
XspfXmlFormatter.h
Go to the documentation of this file.
1 /*
2  * libxspf - XSPF playlist handling library
3  *
4  * Copyright (C) 2006-2008, Sebastian Pipping / Xiph.Org Foundation
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials
18  * provided with the distribution.
19  *
20  * * Neither the name of the Xiph.Org Foundation nor the names of
21  * its contributors may be used to endorse or promote products
22  * derived from this software without specific prior written
23  * permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36  * OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Sebastian Pipping, sping@xiph.org
39  */
40 
46 #ifndef XSPF_XML_FORMATTER_H
47 #define XSPF_XML_FORMATTER_H
48 
49 
50 #include "XspfDefines.h"
51 #include <sstream>
52 
53 namespace Xspf {
54 
55 
56 class XspfWriter;
57 
58 
60 
64 struct XspfNamespaceRegistrationUndo {
65  int level;
66  XML_Char const * uri;
67 
74  XspfNamespaceRegistrationUndo(int level, XML_Char const * uri)
75  : level(level), uri(uri) {
76 
77  }
78 
79 };
80 
82 
83 
84 class XspfXmlFormatterPrivate;
85 
86 
91 
92 private:
94  XspfXmlFormatterPrivate * const d;
95 
97 protected:
102 
108  XspfXmlFormatter(XspfXmlFormatter const & source);
109 
115  XspfXmlFormatter & operator=(XspfXmlFormatter const & source);
116 
121  virtual ~XspfXmlFormatter();
122 
126  virtual void writeXmlDeclaration();
127 
128 private:
136  XML_Char const * getPrefix(XML_Char const * nsUri) const;
137 
146  XML_Char * makeFullName(XML_Char const * nsUri,
147  XML_Char const * localName) const;
148 
153  void cleanupNamespaceRegs();
154 
162  bool registerNamespace(XML_Char const * uri,
163  XML_Char const * prefixSuggestion);
164 
165 public:
171  void setOutput(std::basic_ostringstream<XML_Char> & output);
172 
182  void writeStart(XML_Char const * ns, XML_Char const * localName,
183  XML_Char const * const * atts, XML_Char const * const * nsRegs = NULL);
184 
192  void writeEnd(XML_Char const * ns, XML_Char const * localName);
193 
201  void writeHomeStart(XML_Char const * localName,
202  XML_Char const * const * atts, XML_Char const * const * nsRegs = NULL);
203 
209  void writeHomeEnd(XML_Char const * localName);
210 
211 protected:
221  virtual void writeStart(XML_Char const * name,
222  XML_Char const * const * atts) = 0;
223 
229  virtual void writeEnd(XML_Char const * name) = 0;
230 
231 public:
237  virtual void writeBody(XML_Char const * text) = 0;
238 
244  virtual void writeBody(int number) = 0;
245 
251  void writeCharacterData(XML_Char const * data);
252 
253  static XML_Char const * const namespaceKey;
254 
255 protected:
259  std::basic_ostringstream<XML_Char> * & getOutput();
260 
262  void virtualHook(int methodId, void * parameters);
264 
265  friend class XspfWriter; // allow access to registerNamespace
266 
267 };
268 
269 
270 } // namespace Xspf
271 
272 #endif // XSPF_XML_FORMATTER_H
static XML_Char const *const namespaceKey
Namespace key pointer.