00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00037 namespace CEGUI
00038 {
00039
00040
00041
00042
00043
00044
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
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
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
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
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
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
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
00116 else if (element == GUISchemeElement)
00117 {
00118
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
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 }