Crazy Eddies GUI System  0.7.6
CEGUIXercesParser.h
00001 /***********************************************************************
00002     filename:   CEGUIXercesParser.h
00003     created:    Sat Mar 12 2005
00004     author:     Paul D Turner
00005 *************************************************************************/
00006 /***************************************************************************
00007  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00008  *
00009  *   Permission is hereby granted, free of charge, to any person obtaining
00010  *   a copy of this software and associated documentation files (the
00011  *   "Software"), to deal in the Software without restriction, including
00012  *   without limitation the rights to use, copy, modify, merge, publish,
00013  *   distribute, sublicense, and/or sell copies of the Software, and to
00014  *   permit persons to whom the Software is furnished to do so, subject to
00015  *   the following conditions:
00016  *
00017  *   The above copyright notice and this permission notice shall be
00018  *   included in all copies or substantial portions of the Software.
00019  *
00020  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00023  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00024  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00025  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00026  *   OTHER DEALINGS IN THE SOFTWARE.
00027  ***************************************************************************/
00028 #ifndef _CEGUIXercesParser_h_
00029 #define _CEGUIXercesParser_h_
00030 
00031 #include "../../CEGUIXMLParser.h"
00032 #include "CEGUIXercesParserProperties.h"
00033 
00034 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
00035 #   ifdef CEGUIXERCESPARSER_EXPORTS
00036 #       define CEGUIXERCESPARSER_API __declspec(dllexport)
00037 #   else
00038 #       define CEGUIXERCESPARSER_API __declspec(dllimport)
00039 #   endif
00040 #else
00041 #   define CEGUIXERCESPARSER_API
00042 #endif
00043 
00044 
00045 // Xerces-C includes
00046 #include <xercesc/framework/MemBufInputSource.hpp>
00047 #include <xercesc/util/PlatformUtils.hpp>
00048 #include <xercesc/util/TransService.hpp>
00049 #include <xercesc/util/XMLString.hpp>
00050 #include <xercesc/sax2/Attributes.hpp>
00051 #include <xercesc/sax2/DefaultHandler.hpp>
00052 #include <xercesc/sax2/SAX2XMLReader.hpp>
00053 #include <xercesc/sax2/XMLReaderFactory.hpp>
00054 
00055 // Start of CEGUI namespace section
00056 namespace CEGUI
00057 {
00058     class XercesHandler : public XERCES_CPP_NAMESPACE::DefaultHandler
00059     {
00060     public:
00061         XercesHandler(XMLHandler& handler);
00062         ~XercesHandler(void);
00063 
00064         // Implementation of methods in Xerces DefaultHandler.
00065         void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
00066         void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
00067 #if _XERCES_VERSION >= 30000
00068         void characters(const XMLCh* const chars, const XMLSize_t length);
00069 #else /* _XERCES_VERSION >= 30000 */
00070         void characters (const XMLCh *const chars, const unsigned int length);
00071 #endif /* _XERCES_VERSION >= 30000 */
00072         void warning (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
00073         void error (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
00074         void fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
00075 
00076     protected:
00077         XMLHandler& d_handler;      
00078     };
00079 
00084     class CEGUIXERCESPARSER_API XercesParser : public XMLParser
00085     {
00086     public:
00087         XercesParser(void);
00088         ~XercesParser(void);
00089 
00090         // Implementation of public abstract interface
00091         void parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup);
00092 
00093         // Internal methods
00098         static void populateAttributesBlock(const XERCES_CPP_NAMESPACE::Attributes& src, XMLAttributes& dest);
00099 
00111         static String transcodeXmlCharToString(const XMLCh* const xmlch_str, unsigned int length);
00112 
00123         static void setSchemaDefaultResourceGroup(const String& resourceGroup)
00124             { d_defaultSchemaResourceGroup = resourceGroup; }
00125 
00133         static const String& getSchemaDefaultResourceGroup()
00134             { return d_defaultSchemaResourceGroup; }
00135 
00136     protected:
00137         static void initialiseSchema(XERCES_CPP_NAMESPACE::SAX2XMLReader* reader, const String& schemaName, const String& xmlFilename, const String& resourceGroup);
00138         static XERCES_CPP_NAMESPACE::SAX2XMLReader* createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler);
00139         static void doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const String& xmlFilename, const String& resourceGroup);
00140 
00141         // Implementation of abstract interface.
00142         bool initialiseImpl(void);
00143         void cleanupImpl(void);
00144 
00146         static String d_defaultSchemaResourceGroup;
00148         static XercesParserProperties::SchemaDefaultResourceGroup
00149             s_schemaDefaultResourceGroupProperty;
00150     };
00151 
00152 } // End of  CEGUI namespace section
00153 
00154 
00155 #endif  // end of guard _CEGUIXercesParser_h_