00001
00002
00003
00004
00005
00006
00007
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 # include "langloadstreamer.hpp"
00041 # include "flow/consumers/streamsax2parser.hpp"
00042 # include "processor/xmlflowcontext.hpp"
00043 # include "streamers/generic/saxstreamer.hpp"
00044
00045 BEGIN_XDFLENGINE_NS
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 LangLoadStreamerFactory::LangLoadStreamerFactory()
00056 {
00057 m_pCurDictionnary = 0;
00058 m_pCurLangPack = 0;
00059 m_pszCurLangPack = copyCharBuffer("");
00060 m_pszCurDictionnary = copyCharBuffer("");
00061 }
00062
00063
00064
00065
00066 LangLoadStreamerFactory::~LangLoadStreamerFactory()
00067 {
00068 VAlangPack * l_pLangPack = 0;
00069 VAdictionnary * l_pDictionnary = 0;
00070
00071 while(!m_vaLangPacks.empty())
00072 {
00073 l_pLangPack = m_vaLangPacks.pop();
00074 while(! l_pLangPack->empty())
00075 {
00076 l_pDictionnary = l_pLangPack->pop();
00077 while(! l_pDictionnary->empty()) releaseCharBuffer( l_pDictionnary->pop());
00078 delete l_pDictionnary;
00079 }
00080 delete l_pLangPack;
00081 }
00082
00083 m_pszCurLangPack = releaseCharBuffer(m_pszCurLangPack);
00084 m_pszCurDictionnary = releaseCharBuffer(m_pszCurDictionnary);
00085
00086 }
00087
00088
00089
00090
00091
00092 XMLStreamer* LangLoadStreamerFactory::getStreamer(
00093 StreamerParams* p_pParameters,
00094 XMLFlowContext* p_pStreamContext,
00095 XMLStreamConsumer* p_pStreamConsumer) const
00096 {
00097
00098 SAXLangHandler* l_pSaxRawHandler;
00099
00100
00101 l_pSaxRawHandler = new SAXLangHandler( p_pParameters, p_pStreamContext, this);
00102 return (XMLStreamer*) new SaxStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer, l_pSaxRawHandler, true);
00103 }
00104
00105
00106
00107
00108
00109
00110 void LangLoadStreamerFactory::setDictionnaryEntry( const char* p_pszLangCode, const char* p_pszDicName, const char* p_pszKey, char* p_pszWord)
00111 {
00112
00113 if( strcmp( m_pszCurLangPack, p_pszLangCode) != 0 )
00114 {
00115
00116 m_pCurLangPack = m_vaLangPacks.get( p_pszLangCode);
00117
00118 if( !m_pCurLangPack)
00119 {
00120
00121 m_pCurLangPack = new VAlangPack;
00122 m_vaLangPacks.add( m_pCurLangPack, p_pszLangCode);
00123 }
00124
00125 m_pszCurLangPack = importCharBuffer( m_pszCurLangPack,p_pszLangCode);
00126 m_pszCurDictionnary = importCharBuffer( m_pszCurDictionnary,"");
00127 m_pCurDictionnary = 0;
00128
00129 }
00130
00131 if( strcmp( m_pszCurDictionnary, p_pszDicName) != 0 )
00132 {
00133
00134 m_pCurDictionnary = m_pCurLangPack->get( p_pszDicName);
00135
00136 if( !m_pCurDictionnary)
00137 {
00138
00139 m_pCurDictionnary = new VAdictionnary;
00140 m_pCurLangPack->add( m_pCurDictionnary, p_pszDicName);
00141 logout << "\t" << LANGLOADSTREAMER_TAGNAME<< " : " << "Loading "<< m_pszCurLangPack << "." << p_pszDicName << " language dictionnary.\n";
00142 }
00143
00144 m_pszCurDictionnary = importCharBuffer( m_pszCurDictionnary,p_pszDicName);
00145
00146 }
00147
00148 m_pCurDictionnary->add( copyCharBuffer(p_pszWord), p_pszKey);
00149 }
00150
00151
00152
00153
00154 const char* LangLoadStreamerFactory::getDictionnaryEntry( const char* p_pszLangCode, const char* p_pszDicName, const char* p_pszKey) const
00155 {
00156 VAlangPack * l_pLangPack = 0;
00157 VAdictionnary * l_pDictionnary = 0;
00158 const char* l_pszValue = 0;
00159
00160 l_pLangPack = m_vaLangPacks.get( p_pszLangCode);
00161 if( l_pLangPack) l_pDictionnary = l_pLangPack->get( p_pszDicName);
00162 if( l_pDictionnary ) l_pszValue = l_pDictionnary->get( p_pszKey);
00163 if(l_pszValue) return l_pszValue;
00164 else return "";
00165 }
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 SAXLangHandler::SAXLangHandler( StreamerParams* p_pParameters,XMLFlowContext* p_pContext, const LangLoadStreamerFactory* p_pParent)
00183 {
00184
00185 m_pContext = p_pContext;
00186 m_intCurLevel = 0;
00187 m_pParent = (LangLoadStreamerFactory*) p_pParent;
00188 m_pszCurLangPack=0;
00189 m_pszCurDictionnary=0;
00190
00191 DEBUG_CREATE(SAXLangHandler)
00192 }
00193
00194
00195
00196
00197 SAXLangHandler::~SAXLangHandler()
00198 {
00199
00200 DEBUG_DEL(SAXLangHandler)
00201 m_pszCurLangPack=releaseCharBuffer( m_pszCurLangPack);
00202 m_pszCurDictionnary=releaseCharBuffer( m_pszCurDictionnary);
00203 while(!m_vaValues.empty()) releaseCharBuffer( m_vaValues.pop());
00204 }
00205
00206
00207
00208
00209
00210
00211
00212 void SAXLangHandler::characters(const XMLCh* const chars ,const unsigned int length)
00213 {
00214
00215 char* l_pszChars = 0;
00216 char* l_pszTrimmedChars = 0;
00217 char* l_pszValue = 0;
00218 char* l_pszName;
00219
00220
00221 DEBUG_IN(SAXLangHandler::characters)
00222
00223 if(m_intCurLevel>3)
00224 {
00225 l_pszChars = XSTR(m_pContext->getTranscoder(), chars, length);
00226 l_pszTrimmedChars = trimCharBuffer(l_pszChars);
00227 releaseCharBuffer( l_pszChars);
00228
00229 if(( strlen( l_pszTrimmedChars) > 0 ) && (! m_vaValues.empty() ))
00230 {
00231 l_pszName = copyCharBuffer( m_vaValues.getKey( m_vaValues.size() -1));
00232 l_pszValue = m_vaValues.top();
00233 m_vaValues.pop();
00234
00235 l_pszValue = concatCharBuffer( l_pszValue, l_pszTrimmedChars);
00236 m_vaValues.add(l_pszValue, l_pszName);
00237 l_pszName = releaseCharBuffer( l_pszName);
00238 }
00239
00240 l_pszTrimmedChars = releaseCharBuffer( l_pszTrimmedChars);
00241 }
00242
00243 DEBUG_OUT(SAXLangHandler::characters)
00244 }
00245
00246
00247
00248
00249 void SAXLangHandler::startElement( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs)
00250 {
00251 char* l_pszValName = 0;
00252 char l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE];
00253
00254 m_intCurLevel++;
00255
00256 DEBUG_IN(SAXLangHandler::startElement)
00257
00258 XSTR(m_pContext->getTranscoder(), localname, (char*) &l_szTagName);
00259
00260 if(m_intCurLevel==2) m_pszCurLangPack = importCharBuffer(m_pszCurLangPack, l_szTagName);
00261 if(m_intCurLevel==3) m_pszCurDictionnary = importCharBuffer(m_pszCurDictionnary, l_szTagName);
00262 if(m_intCurLevel>3)
00263 {
00264 l_pszValName = 0;
00265 if(! m_vaValues.empty())
00266 {
00267 l_pszValName = copyCharBuffer( m_vaValues.getKey( m_vaValues.size() -1));
00268 l_pszValName = concatCharBuffer( l_pszValName, LANGLOADSTREAMER_VALSEP);
00269 }
00270
00271 l_pszValName = concatCharBuffer( l_pszValName, (char*) &l_szTagName);
00272 m_vaValues.add( copyCharBuffer(""), l_pszValName);
00273 releaseCharBuffer( l_pszValName);
00274 }
00275
00276 DEBUG_OUT(SAXLangHandler::startElement)
00277 }
00278
00279
00280
00281
00282 void SAXLangHandler::endElement( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname)
00283 {
00284
00285 char* l_pszName = 0;
00286 char* l_pszValue = 0;
00287
00288
00289 DEBUG_IN(SAXLangHandler::endElement)
00290
00291 if(m_intCurLevel>3)
00292 {
00293 if( !m_vaValues.empty())
00294 {
00295 l_pszName = copyCharBuffer(m_vaValues.getKey( m_vaValues.size() -1));
00296 l_pszValue = m_vaValues.pop();
00297 if(strlen(l_pszValue)>0)
00298 {
00299 m_pParent->setDictionnaryEntry( m_pszCurLangPack, m_pszCurDictionnary, l_pszName, l_pszValue);
00300 }
00301 l_pszName = releaseCharBuffer( l_pszName);
00302 l_pszValue = releaseCharBuffer( l_pszValue);
00303 }
00304 }
00305
00306 m_intCurLevel--;
00307
00308 DEBUG_OUT(SAXLangHandler::endElement)
00309 }
00310
00311
00312
00313
00314
00315 END_XDFLENGINE_NS
00316
00317
00318