libxspf  1.2.0
XspfXmlFormatter.h
Go to the documentation of this file.
00001 /*
00002  * libxspf - XSPF playlist handling library
00003  *
00004  * Copyright (C) 2006-2008, Sebastian Pipping / Xiph.Org Foundation
00005  * All rights reserved.
00006  *
00007  * Redistribution  and use in source and binary forms, with or without
00008  * modification,  are permitted provided that the following conditions
00009  * are met:
00010  *
00011  *     * Redistributions   of  source  code  must  retain  the   above
00012  *       copyright  notice, this list of conditions and the  following
00013  *       disclaimer.
00014  *
00015  *     * Redistributions  in  binary  form must  reproduce  the  above
00016  *       copyright  notice, this list of conditions and the  following
00017  *       disclaimer   in  the  documentation  and/or  other  materials
00018  *       provided with the distribution.
00019  *
00020  *     * Neither  the name of the Xiph.Org Foundation nor the names of
00021  *       its  contributors may be used to endorse or promote  products
00022  *       derived  from  this software without specific  prior  written
00023  *       permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026  * "AS  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT  NOT
00027  * LIMITED  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS
00028  * FOR  A  PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT  SHALL  THE
00029  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00030  * INCIDENTAL,    SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL   DAMAGES
00031  * (INCLUDING,  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00032  * SERVICES;  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00033  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00034  * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
00035  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00036  * OF THE POSSIBILITY OF SUCH DAMAGE.
00037  *
00038  * Sebastian Pipping, sping@xiph.org
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; // allow access to registerNamespace
00266 
00267 };
00268 
00269 
00270 } // namespace Xspf
00271 
00272 #endif // XSPF_XML_FORMATTER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines