Crazy Eddies GUI System  0.7.0
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 #include "CEGUIXercesParserProperties.h"
33 
34 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
35 # ifdef CEGUIXERCESPARSER_EXPORTS
36 # define CEGUIXERCESPARSER_API __declspec(dllexport)
37 # else
38 # define CEGUIXERCESPARSER_API __declspec(dllimport)
39 # endif
40 #else
41 # define CEGUIXERCESPARSER_API
42 #endif
43 
44 
45 // Xerces-C includes
46 #include <xercesc/framework/MemBufInputSource.hpp>
47 #include <xercesc/util/PlatformUtils.hpp>
48 #include <xercesc/util/TransService.hpp>
49 #include <xercesc/util/XMLString.hpp>
50 #include <xercesc/sax2/Attributes.hpp>
51 #include <xercesc/sax2/DefaultHandler.hpp>
52 #include <xercesc/sax2/SAX2XMLReader.hpp>
53 #include <xercesc/sax2/XMLReaderFactory.hpp>
54 
55 // Start of CEGUI namespace section
56 namespace CEGUI
57 {
58  class XercesHandler : public XERCES_CPP_NAMESPACE::DefaultHandler
59  {
60  public:
61  XercesHandler(XMLHandler& handler);
62  ~XercesHandler(void);
63 
64  // Implementation of methods in Xerces DefaultHandler.
65  void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
66  void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
67 #if _XERCES_VERSION >= 30000
68  void characters(const XMLCh* const chars, const XMLSize_t length);
69 #else /* _XERCES_VERSION >= 30000 */
70  void characters (const XMLCh *const chars, const unsigned int length);
71 #endif /* _XERCES_VERSION >= 30000 */
72  void warning (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
73  void error (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
74  void fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
75 
76  protected:
78  };
79 
84  class CEGUIXERCESPARSER_API XercesParser : public XMLParser
85  {
86  public:
87  XercesParser(void);
88  ~XercesParser(void);
89 
90  // Implementation of public abstract interface
91  void parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup);
92 
93  // Internal methods
98  static void populateAttributesBlock(const XERCES_CPP_NAMESPACE::Attributes& src, XMLAttributes& dest);
99 
111  static String transcodeXmlCharToString(const XMLCh* const xmlch_str, unsigned int length);
112 
123  static void setSchemaDefaultResourceGroup(const String& resourceGroup)
124  { d_defaultSchemaResourceGroup = resourceGroup; }
125 
133  static const String& getSchemaDefaultResourceGroup()
134  { return d_defaultSchemaResourceGroup; }
135 
136  protected:
137  static void initialiseSchema(XERCES_CPP_NAMESPACE::SAX2XMLReader* reader, const String& schemaName, const String& xmlFilename, const String& resourceGroup);
138  static XERCES_CPP_NAMESPACE::SAX2XMLReader* createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler);
139  static void doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const String& xmlFilename, const String& resourceGroup);
140 
141  // Implementation of abstract interface.
142  bool initialiseImpl(void);
143  void cleanupImpl(void);
144 
150  };
151 
152 } // End of CEGUI namespace section
153 
154 
155 #endif // end of guard _CEGUIXercesParser_h_