Crazy Eddies GUI System  0.6.2
CEGUIXercesParser.h
1 /***********************************************************************
2  filename: CEGUIXercesParser.h
3  created: Sat Mar 12 2005
4  author: Paul D Turner
5 *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUIXercesParser_h_
29 #define _CEGUIXercesParser_h_
30 
31 #include "CEGUIXMLParser.h"
32 
33 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
34 # ifdef CEGUIXERCESPARSER_EXPORTS
35 # define CEGUIXERCESPARSER_API __declspec(dllexport)
36 # else
37 # define CEGUIXERCESPARSER_API __declspec(dllimport)
38 # endif
39 #else
40 # define CEGUIXERCESPARSER_API
41 #endif
42 
43 
44 // Xerces-C includes
45 #include <xercesc/framework/MemBufInputSource.hpp>
46 #include <xercesc/util/PlatformUtils.hpp>
47 #include <xercesc/util/TransService.hpp>
48 #include <xercesc/util/XMLString.hpp>
49 #include <xercesc/sax2/Attributes.hpp>
50 #include <xercesc/sax2/DefaultHandler.hpp>
51 #include <xercesc/sax2/SAX2XMLReader.hpp>
52 #include <xercesc/sax2/XMLReaderFactory.hpp>
53 
54 // Start of CEGUI namespace section
55 namespace CEGUI
56 {
57  class XercesHandler : public XERCES_CPP_NAMESPACE::DefaultHandler
58  {
59  public:
60  XercesHandler(XMLHandler& handler);
61  ~XercesHandler(void);
62 
63  // Implementation of methods in Xerces DefaultHandler.
64  void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
65  void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
66  void characters (const XMLCh *const chars, const unsigned int length);
67  void warning (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
68  void error (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
69  void fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
70 
71  protected:
73  };
74 
79  class CEGUIXERCESPARSER_API XercesParser : public XMLParser
80  {
81  public:
82  XercesParser(void);
83  ~XercesParser(void);
84 
85  // Implementation of public abstract interface
86  void parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup);
87 
88  // Internal methods
93  static void populateAttributesBlock(const XERCES_CPP_NAMESPACE::Attributes& src, XMLAttributes& dest);
94 
106  static String transcodeXmlCharToString(const XMLCh* const xmlch_str, unsigned int length);
107 
118  static void setSchemaDefaultResourceGroup(const String& resourceGroup)
119  { d_defaultSchemaResourceGroup = resourceGroup; }
120 
128  static const String& getSchemaDefaultResourceGroup()
129  { return d_defaultSchemaResourceGroup; }
130 
131  protected:
132  static void initialiseSchema(XERCES_CPP_NAMESPACE::SAX2XMLReader* reader, const String& schemaName, const String& xmlFilename, const String& resourceGroup);
133  static XERCES_CPP_NAMESPACE::SAX2XMLReader* createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler);
134  static void doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const String& xmlFilename, const String& resourceGroup);
135 
136  // Implementation of abstract interface.
137  bool initialiseImpl(void);
138  void cleanupImpl(void);
139 
142  };
143 
144 } // End of CEGUI namespace section
145 
146 
147 #endif // end of guard _CEGUIXercesParser_h_