Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

CEGUIScheme_xmlHandler.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 filename:       CEGUIScheme_xmlHandler.cpp
00003 created:        21/2/2004
00004 author:         Paul D Turner
00005 
00006 purpose:        Implements GUI Scheme class
00007 *************************************************************************/
00008 /*************************************************************************
00009 Crazy Eddie's GUI System (http://www.cegui.org.uk)
00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00011 
00012 This library is free software; you can redistribute it and/or
00013 modify it under the terms of the GNU Lesser General Public
00014 License as published by the Free Software Foundation; either
00015 version 2.1 of the License, or (at your option) any later version.
00016 
00017 This library is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 Lesser General Public License for more details.
00021 
00022 You should have received a copy of the GNU Lesser General Public
00023 License along with this library; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 *************************************************************************/
00026 #include "CEGUIScheme_xmlHandler.h"
00027 
00028 #include "CEGUIExceptions.h"
00029 #include "CEGUIImageset.h"
00030 #include "CEGUILogger.h"
00031 #include "CEGUIXmlHandlerHelper.h"
00032 
00033 #include "xercesc/sax2/SAX2XMLReader.hpp"
00034 #include "xercesc/sax2/XMLReaderFactory.hpp"
00035 
00036 // Start of CEGUI namespace section
00037 namespace CEGUI
00038 {
00039 
00040 /*************************************************************************
00041 Static Data definitions
00042 *************************************************************************/
00043 
00044 // xml file elements and attributes
00045 const String Scheme_xmlHandler::GUISchemeElement( (utf8*)"GUIScheme" );
00046 const String Scheme_xmlHandler::ImagesetElement( (utf8*)"Imageset" );
00047 const String Scheme_xmlHandler::FontElement( (utf8*)"Font" );
00048 const String Scheme_xmlHandler::WindowSetElement( (utf8*)"WindowSet" );
00049 const String Scheme_xmlHandler::WindowFactoryElement( (utf8*)"WindowFactory" );
00050 const String Scheme_xmlHandler::WindowAliasElement( (utf8*)"WindowAlias" );
00051 const char      Scheme_xmlHandler::NameAttribute[]                              = "Name";
00052 const char      Scheme_xmlHandler::FilenameAttribute[]                  = "Filename";
00053 const char      Scheme_xmlHandler::AliasAttribute[]                             = "Alias";
00054 const char      Scheme_xmlHandler::TargetAttribute[]                    = "Target";
00055 const char      Scheme_xmlHandler::ResourceGroupAttribute[]     = "ResourceGroup";
00056 
00057 /*************************************************************************
00058 SAX2 Handler methods
00059 *************************************************************************/
00060 void Scheme_xmlHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const XERCES_CPP_NAMESPACE::Attributes& attrs)
00061 {
00062         XERCES_CPP_NAMESPACE_USE
00063         String element(XmlHandlerHelper::transcodeXmlCharToString(localname));
00064 
00065         // handle alias element
00066         if (element == WindowAliasElement)
00067         {
00068                 Scheme::AliasMapping    alias;
00069 
00070                 alias.aliasName  = XmlHandlerHelper::getAttributeValueAsString(attrs, AliasAttribute);
00071                 alias.targetName = XmlHandlerHelper::getAttributeValueAsString(attrs, TargetAttribute);
00072                 d_scheme->d_aliasMappings.push_back(alias);
00073         }
00074         // handle an Imageset element
00075         else if (element == ImagesetElement)
00076         {
00077                 Scheme::LoadableUIElement       imageset;
00078 
00079                 imageset.name = XmlHandlerHelper::getAttributeValueAsString(attrs, NameAttribute);
00080                 imageset.filename = XmlHandlerHelper::getAttributeValueAsString(attrs, FilenameAttribute);
00081         imageset.resourceGroup = XmlHandlerHelper::getAttributeValueAsString(attrs, ResourceGroupAttribute);
00082 
00083                 d_scheme->d_imagesets.push_back(imageset);
00084         }
00085         // handle a font element
00086         else if (element == FontElement)
00087         {
00088                 Scheme::LoadableUIElement       font;
00089 
00090                 font.name = XmlHandlerHelper::getAttributeValueAsString(attrs, NameAttribute);
00091                 font.filename = XmlHandlerHelper::getAttributeValueAsString(attrs, FilenameAttribute);
00092         font.resourceGroup = XmlHandlerHelper::getAttributeValueAsString(attrs, ResourceGroupAttribute);
00093 
00094                 d_scheme->d_fonts.push_back(font);
00095         }
00096         // handle a WindowSet element
00097         else if (element == WindowSetElement)
00098         {
00099                 Scheme::UIModule        module;
00100                 module.name             = XmlHandlerHelper::getAttributeValueAsString(attrs, FilenameAttribute);
00101                 module.module   = NULL;
00102 
00103                 module.factories.clear();
00104                 d_scheme->d_widgetModules.push_back(module);
00105         }
00106         // handle a WindowFactory element
00107         else if (element == WindowFactoryElement)
00108         {
00109                 Scheme::UIElementFactory factory;
00110 
00111                 factory.name = XmlHandlerHelper::getAttributeValueAsString(attrs, NameAttribute);
00112 
00113                 d_scheme->d_widgetModules[d_scheme->d_widgetModules.size() - 1].factories.push_back(factory);
00114         }
00115         // handle root Scheme element
00116         else if (element == GUISchemeElement)
00117         {
00118                 // get name of scheme we are creating
00119                 d_scheme->d_name = XmlHandlerHelper::getAttributeValueAsString(attrs, NameAttribute);
00120 
00121                 Logger::getSingleton().logEvent("Started creation of Scheme '" + d_scheme->d_name + "' via XML file.", Informative);
00122 
00123                 if (SchemeManager::getSingleton().isSchemePresent(d_scheme->d_name))
00124                 {
00125                         throw   AlreadyExistsException((utf8*)"A GUI Scheme named '" + d_scheme->d_name + "' is already present in the system.");
00126                 }
00127 
00128         }
00129         // anything else is an error which *should* have already been caught by XML validation
00130         else
00131         {
00132                 throw FileIOException("Scheme::xmlHandler::startElement - Unexpected data was found while parsing the Scheme file: '" + element + "' is unknown.");
00133         }
00134 
00135 }
00136 
00137 void Scheme_xmlHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname)
00138 {
00139         XERCES_CPP_NAMESPACE_USE
00140         String element(XmlHandlerHelper::transcodeXmlCharToString(localname));
00141 
00142         if (element == GUISchemeElement)
00143         {
00144                 Logger::getSingleton().logEvent("Finished creation of Scheme '" + d_scheme->d_name + "' via XML file.", Informative);
00145         }
00146 
00147 }
00148 
00149 
00150 void Scheme_xmlHandler::warning(const XERCES_CPP_NAMESPACE::SAXParseException &exc)
00151 {
00152         throw(exc);
00153 }
00154 
00155 void Scheme_xmlHandler::error(const XERCES_CPP_NAMESPACE::SAXParseException &exc)
00156 {
00157         throw(exc);
00158 }
00159 
00160 void Scheme_xmlHandler::fatalError(const XERCES_CPP_NAMESPACE::SAXParseException &exc)
00161 {
00162         throw(exc);
00163 }
00164 
00165 } // End of  CEGUI namespace section

Generated on Wed Feb 16 12:41:07 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1