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