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

CEGUIXmlHandlerHelper.cpp

Go to the documentation of this file.
00001 /*************************************************************************
00002     Crazy Eddie's GUI System (http://www.cegui.org.uk)
00003     Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2.1 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 *************************************************************************/
00019 #include <xercesc/sax2/Attributes.hpp>
00020 #include <xercesc/util/XMLString.hpp>
00021 #include <xercesc/util/TransService.hpp>
00022 #include <xercesc/util/PlatformUtils.hpp>
00023 
00024 #include "CEGUIString.h"
00025 #include "CEGUIXmlHandlerHelper.h"
00026 #include "CEGUIExceptions.h"
00027 
00028 using XERCES_CPP_NAMESPACE::XMLString;
00029 using XERCES_CPP_NAMESPACE::XMLTransService;
00030 using XERCES_CPP_NAMESPACE::XMLPlatformUtils;
00031 using XERCES_CPP_NAMESPACE::XMLTranscoder;
00032 using XERCES_CPP_NAMESPACE::XMLRecognizer;
00033 
00034 
00035 namespace CEGUI 
00036 {
00037 
00038 const XMLCh* XmlHandlerHelper::getAttributeValueAsXmlChar(const XERCES_CPP_NAMESPACE::Attributes& attrs, const char* const attributeName)
00039 {
00040         XMLCh* attr_name = XMLString::transcode(attributeName);
00041         const XMLCh* val_str = attrs.getValue(attr_name);
00042         XMLString::release(&attr_name);
00043 
00044         return val_str;
00045 }
00046 
00047 char* XmlHandlerHelper::getAttributeValueAsChar(const XERCES_CPP_NAMESPACE::Attributes& attrs, const char* const attributeName)
00048 {
00049         return XMLString::transcode(getAttributeValueAsXmlChar(attrs, attributeName));
00050 }
00051 
00052 int XmlHandlerHelper::getAttributeValueAsInteger(const XERCES_CPP_NAMESPACE::Attributes& attrs, const char* const attributeName)
00053 {
00054         return XMLString::parseInt(getAttributeValueAsXmlChar(attrs, attributeName));
00055 }
00056 
00057 String XmlHandlerHelper::getAttributeValueAsString(const XERCES_CPP_NAMESPACE::Attributes& attrs, const char* const attributeName)
00058 {
00059         return transcodeXmlCharToString(getAttributeValueAsXmlChar(attrs, attributeName));
00060 }
00061 
00062 String XmlHandlerHelper::transcodeXmlCharToString(const XMLCh* const xmlch_str)
00063 {
00064         XMLTransService::Codes  res;
00065         XMLTranscoder* transcoder = XMLPlatformUtils::fgTransService->makeNewTranscoderFor(XMLRecognizer::UTF_8, res, 4096, XMLPlatformUtils::fgMemoryManager );
00066 
00067         if (res == XMLTransService::Ok)
00068         {
00069                 String out;
00070                 utf8 outBuff[128];
00071                 unsigned int outputLength;
00072                 unsigned int eaten = 0;
00073                 unsigned int offset = 0;
00074                 unsigned int inputLength = XMLString::stringLen(xmlch_str);
00075 
00076                 while (inputLength)
00077                 {
00078                         outputLength = transcoder->transcodeTo(xmlch_str + offset, inputLength, outBuff, 128, eaten, XMLTranscoder::UnRep_RepChar);
00079                         out.append(outBuff, outputLength);
00080                         offset += eaten;
00081                         inputLength -= eaten;
00082                 }
00083 
00084                 delete transcoder;
00085 
00086                 return out;
00087         }
00088         else
00089         {
00090                 throw GenericException((utf8*)"XmlHandlerHelper::transcodeXmlCharToString - Internal Error: Could not create UTF-8 string transcoder.");
00091         }
00092 
00093 }
00094 
00095 }

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