Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
XMLParserModules/Xerces/XMLParser.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 "../../XMLParser.h"
32 #include "CEGUI/XMLParserModules/Xerces/XMLParserProperties.h"
33 
34 #if defined(_MSC_VER)
35 # pragma warning(push)
36 # pragma warning(disable : 4251)
37 #endif
38 
39 #if (defined( __WIN32__ ) || defined( _WIN32 )) && !defined(CEGUI_STATIC)
40 # ifdef CEGUIXERCESPARSER_EXPORTS
41 # define CEGUIXERCESPARSER_API __declspec(dllexport)
42 # else
43 # define CEGUIXERCESPARSER_API __declspec(dllimport)
44 # endif
45 #else
46 # define CEGUIXERCESPARSER_API
47 #endif
48 
49 
50 // Xerces-C includes
51 #include <xercesc/framework/MemBufInputSource.hpp>
52 #include <xercesc/util/PlatformUtils.hpp>
53 #include <xercesc/util/TransService.hpp>
54 #include <xercesc/util/XMLString.hpp>
55 #include <xercesc/sax2/Attributes.hpp>
56 #include <xercesc/sax2/DefaultHandler.hpp>
57 #include <xercesc/sax2/SAX2XMLReader.hpp>
58 #include <xercesc/sax2/XMLReaderFactory.hpp>
59 
60 // Start of CEGUI namespace section
61 namespace CEGUI
62 {
63  class XercesHandler : public XERCES_CPP_NAMESPACE::DefaultHandler
64  {
65  public:
66  XercesHandler(XMLHandler& handler);
67  ~XercesHandler(void);
68 
69  // Implementation of methods in Xerces DefaultHandler.
70  void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs);
71  void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
72 #if _XERCES_VERSION >= 30000
73  void characters(const XMLCh* const chars, const XMLSize_t length);
74 #else /* _XERCES_VERSION >= 30000 */
75  void characters (const XMLCh *const chars, const unsigned int length);
76 #endif /* _XERCES_VERSION >= 30000 */
77  void warning (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
78  void error (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
79  void fatalError (const XERCES_CPP_NAMESPACE::SAXParseException &exc);
80 
81  protected:
83  };
84 
89  class CEGUIXERCESPARSER_API XercesParser : public XMLParser
90  {
91  public:
92  XercesParser(void);
93  ~XercesParser(void);
94 
95  // Implementation of public abstract interface
96  void parseXML(XMLHandler& handler, const RawDataContainer& source, const String& schemaName);
97 
98  // Internal methods
103  static void populateAttributesBlock(const XERCES_CPP_NAMESPACE::Attributes& src, XMLAttributes& dest);
104 
116  static String transcodeXmlCharToString(const XMLCh* const xmlch_str, unsigned int length);
117 
128  static void setSchemaDefaultResourceGroup(const String& resourceGroup)
129  { d_defaultSchemaResourceGroup = resourceGroup; }
130 
138  static const String& getSchemaDefaultResourceGroup()
139  { return d_defaultSchemaResourceGroup; }
140 
141  protected:
142  static void initialiseSchema(XERCES_CPP_NAMESPACE::SAX2XMLReader* reader, const String& schemaName);
143  static XERCES_CPP_NAMESPACE::SAX2XMLReader* createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler);
144  static void doParse(XERCES_CPP_NAMESPACE::SAX2XMLReader* parser, const RawDataContainer& source);
145 
146  // Implementation of abstract interface.
147  bool initialiseImpl(void);
148  void cleanupImpl(void);
149 
155  };
156 
157 } // End of CEGUI namespace section
158 
159 #if defined(_MSC_VER)
160 # pragma warning(pop)
161 #endif
162 
163 #endif // end of guard _CEGUIXercesParser_h_