GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: InMemMsgLoader.cpp 570552 2007-08-28 19:57:36Z amassari $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/util/BitOps.hpp> 00027 #include <xercesc/util/PlatformUtils.hpp> 00028 #include <xercesc/util/XMLMsgLoader.hpp> 00029 #include <xercesc/util/XMLString.hpp> 00030 #include <xercesc/util/XMLUni.hpp> 00031 #include "InMemMsgLoader.hpp" 00032 #include "XercesMessages_en_US.hpp" 00033 00034 XERCES_CPP_NAMESPACE_BEGIN 00035 00036 // --------------------------------------------------------------------------- 00037 // Public Constructors and Destructor 00038 // --------------------------------------------------------------------------- 00039 InMemMsgLoader::InMemMsgLoader(const XMLCh* const msgDomain) 00040 :fMsgDomain(0) 00041 { 00042 if (!XMLString::equals(msgDomain, XMLUni::fgXMLErrDomain) 00043 && !XMLString::equals(msgDomain, XMLUni::fgExceptDomain) 00044 && !XMLString::equals(msgDomain, XMLUni::fgXMLDOMMsgDomain) 00045 && !XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) 00046 { 00047 XMLPlatformUtils::panic(PanicHandler::Panic_UnknownMsgDomain); 00048 } 00049 00050 fMsgDomain = XMLString::replicate(msgDomain, XMLPlatformUtils::fgMemoryManager); 00051 } 00052 00053 InMemMsgLoader::~InMemMsgLoader() 00054 { 00055 XMLPlatformUtils::fgMemoryManager->deallocate(fMsgDomain);//delete [] fMsgDomain; 00056 } 00057 00058 00059 // --------------------------------------------------------------------------- 00060 // Implementation of the virtual message loader API 00061 // --------------------------------------------------------------------------- 00062 bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad 00063 , XMLCh* const toFill 00064 , const XMLSize_t maxChars) 00065 { 00066 // 00067 // Just use the id to map into the correct array of messages. Then 00068 // copy that to the caller's buffer. 00069 // 00070 // NOTE: The source text is in little endian form. So, if we are a 00071 // big endian machine, flip them in the process. 00072 // 00073 XMLCh* endPtr = toFill + maxChars; 00074 XMLCh* outPtr = toFill; 00075 const XMLCh* srcPtr = 0; 00076 00077 if (XMLString::equals(fMsgDomain, XMLUni::fgXMLErrDomain)) 00078 { 00079 if ( msgToLoad > gXMLErrArraySize) 00080 return false; 00081 else 00082 srcPtr = gXMLErrArray[msgToLoad - 1]; 00083 } 00084 else if (XMLString::equals(fMsgDomain, XMLUni::fgExceptDomain)) 00085 { 00086 if ( msgToLoad > gXMLExceptArraySize) 00087 return false; 00088 else 00089 srcPtr = gXMLExceptArray[msgToLoad - 1]; 00090 } 00091 else if (XMLString::equals(fMsgDomain, XMLUni::fgValidityDomain)) 00092 { 00093 if ( msgToLoad > gXMLValidityArraySize) 00094 return false; 00095 else 00096 srcPtr = gXMLValidityArray[msgToLoad - 1]; 00097 } 00098 else if (XMLString::equals(fMsgDomain, XMLUni::fgXMLDOMMsgDomain)) 00099 { 00100 if ( msgToLoad > gXMLDOMMsgArraySize) 00101 return false; 00102 else 00103 srcPtr = gXMLDOMMsgArray[msgToLoad - 1]; 00104 } 00105 00106 while (*srcPtr && (outPtr < endPtr)) 00107 { 00108 *outPtr++ = *srcPtr++; 00109 } 00110 *outPtr = 0; 00111 00112 return true; 00113 } 00114 00115 00116 bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad 00117 , XMLCh* const toFill 00118 , const XMLSize_t maxChars 00119 , const XMLCh* const repText1 00120 , const XMLCh* const repText2 00121 , const XMLCh* const repText3 00122 , const XMLCh* const repText4 00123 , MemoryManager* const manager) 00124 { 00125 // Call the other version to load up the message 00126 if (!loadMsg(msgToLoad, toFill, maxChars)) 00127 return false; 00128 00129 // And do the token replacement 00130 XMLString::replaceTokens(toFill, maxChars, repText1, repText2, repText3, repText4, manager); 00131 return true; 00132 } 00133 00134 00135 bool InMemMsgLoader::loadMsg(const XMLMsgLoader::XMLMsgId msgToLoad 00136 , XMLCh* const toFill 00137 , const XMLSize_t maxChars 00138 , const char* const repText1 00139 , const char* const repText2 00140 , const char* const repText3 00141 , const char* const repText4 00142 , MemoryManager * const manager) 00143 { 00144 // 00145 // Transcode the provided parameters and call the other version, 00146 // which will do the replacement work. 00147 // 00148 XMLCh* tmp1 = 0; 00149 XMLCh* tmp2 = 0; 00150 XMLCh* tmp3 = 0; 00151 XMLCh* tmp4 = 0; 00152 00153 bool bRet = false; 00154 if (repText1) 00155 tmp1 = XMLString::transcode(repText1, manager); 00156 if (repText2) 00157 tmp2 = XMLString::transcode(repText2, manager); 00158 if (repText3) 00159 tmp3 = XMLString::transcode(repText3, manager); 00160 if (repText4) 00161 tmp4 = XMLString::transcode(repText4, manager); 00162 00163 bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4, manager); 00164 00165 if (tmp1) 00166 manager->deallocate(tmp1);//delete [] tmp1; 00167 if (tmp2) 00168 manager->deallocate(tmp2);//delete [] tmp2; 00169 if (tmp3) 00170 manager->deallocate(tmp3);//delete [] tmp3; 00171 if (tmp4) 00172 manager->deallocate(tmp4);//delete [] tmp4; 00173 00174 return bRet; 00175 } 00176 00177 XERCES_CPP_NAMESPACE_END