Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

xmlflowbuilder.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  XMLFLOWBUILDER.CPP
00007 //----------------------------------------------------------------------------- 
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //============================================================================= 
00039 
00040 #   include "xmlflowbuilder.hpp"
00041 #   include "processor/xmlprocessor.hpp"
00042 
00043 BEGIN_XDFLENGINE_NS
00044 
00045 //============================================================================= 
00046 //  CLASS XMLFlowBuilder
00047 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00048 
00049 
00050 //  CONSTRUCTORS AND DESTRUCTOR  
00051 
00052     //_________________________________________________________________________
00053     //  XMLFlowBuilder
00054     //-------------------------------------------------------------------------
00055     XMLFlowBuilder::XMLFlowBuilder(  const XMLProcessor* p_pXMLProcessor, RootStreamNode* p_pStreamRoot,  const char* p_pszActiveURI)
00056     :SAX2Formatter(p_pXMLProcessor->getContext()->getEncoding(), XMLFormatter::UnRep_CharRef,false, 0)
00057     {   
00058         m_uiErrorNumber = 0;
00059         m_uiCurDepth = 0;
00060         m_fTopStreamerPassive=false;
00061 
00062         m_pXMLProcessor = p_pXMLProcessor;  
00063         m_pszActiveURI = importCharBuffer(0, p_pszActiveURI);
00064 
00065         m_vaStackStreamNodes.push( p_pStreamRoot);
00066 
00067         DEBUG_CREATE(XMLFlowBuilder)
00068     }
00069 
00070     //_________________________________________________________________________
00071     //  ~XMLFlowBuilder
00072     //-------------------------------------------------------------------------
00073     XMLFlowBuilder::~XMLFlowBuilder()
00074     {       
00075         DEBUG_DEL(XMLFlowBuilder)
00076 
00077         m_pszActiveURI = releaseCharBuffer(m_pszActiveURI);
00078         while( ! m_vaStackStreamNodes.empty() ) m_vaStackStreamNodes.pop();     
00079     }
00080 
00081 
00082 // ERROR
00083 
00084     //_____________________________________________________________________
00085     //  GETERROR
00086     //--------------------------------------------------------------------- 
00087     unsigned int XMLFlowBuilder::getError()
00088     {
00089         DEBUG_FUNC(XMLFlowBuilder::getError)
00090         return m_uiErrorNumber;
00091     }
00092 
00093 
00094 //  CONTENTHANDLER  
00095 
00096     //_________________________________________________________________________
00097     // STARTELEMENT
00098     //-------------------------------------------------------------------------
00099     void XMLFlowBuilder::startElement(  const XMLCh* const uri, 
00100                                             const XMLCh* const localname, 
00101                                             const XMLCh* const qname, 
00102                                             const Attributes& attrs)
00103     {
00104         //---------------------------------------------------------------------
00105         StreamerParams*  l_pParameters;
00106 
00107         char*           l_pszFullName=0;
00108         char*           l_pszTagName=0;
00109         char*           l_pszURI=0;
00110         char*           l_pszAttr=0;
00111         char*           l_pszValue=0;
00112         char*           l_pszTmp=0;
00113 
00114         unsigned int    l_uiAttrsCount;
00115         unsigned int    i;
00116         unsigned int    j;
00117 
00118         ActiveStreamNode*   l_pParentStreamNode = 0;
00119         ActiveStreamNode*   l_pActiveStreamNode = 0;
00120         PassiveStreamNode*  l_pPassiveStreamNode = 0;
00121 
00122         XMLStreamerFactory* l_pStreamerFactory = 0;
00123         //---------------------------------------------------------------------
00124 
00125         DEBUG_IN(XMLFlowBuilder::startElement)
00126 
00127         PREP_CATCH_XML_FLOW_ERROR;
00128 
00129         m_uiCurDepth++;
00130 
00131         l_pszTagName = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), localname);
00132         l_pszFullName = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), qname);
00133         l_pszURI = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), uri);       
00134 
00135         DEBUG_ECHO <<  l_pszTagName << " " << m_uiCurDepth << "(+)\n";
00136 
00137 
00138         // Choose what to do depending on the tag's name
00139         if( strcmp( l_pszURI, m_pszActiveURI) == 0 ) 
00140         {
00141             if(m_fTopStreamerPassive) m_vaStackStreamNodes.pop();
00142             m_fTopStreamerPassive=false;
00143 
00144             l_pParentStreamNode = (ActiveStreamNode*)m_vaStackStreamNodes.top();
00145 
00146             logout << "\t";
00147             for(j=1; j<m_vaStackStreamNodes.size(); j++) logout<< "  ";
00148             logout << l_pszTagName << "\n";
00149 
00150             // make params collection               
00151             l_pParameters = new StreamerParams;
00152             l_uiAttrsCount = attrs.getLength();
00153             for (i=0 ; i< l_uiAttrsCount ; i++)
00154             {
00155                 l_pszAttr = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), attrs.getLocalName( i));
00156                 l_pszValue = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), attrs.getValue( i));                  
00157 
00158                 logout<< "\t";
00159                 for(j=1; j<m_vaStackStreamNodes.size(); j++) logout<< "  ";
00160                 logout << "   | ";
00161                 logout << l_pszAttr << " : " << l_pszValue << "\n";
00162                 
00163                 l_pParameters->add( l_pszValue, l_pszAttr);
00164                 
00165                 //l_pszValue = releaseCharBuffer( l_pszValue);  
00166                 l_pszAttr  = releaseCharBuffer( l_pszAttr);
00167             }
00168             logout << "\n";
00169 
00170             // create new active streamer node
00171             l_pStreamerFactory = m_pXMLProcessor->getStreamerFactory( l_pszTagName);
00172             if(! l_pStreamerFactory)
00173             {
00174                 MAKE_XMLFLOW_EXCEPTION ( ERRCODE_LOC_FLOWBUILDER + ERRCODE_CAUSE_MISSINGREF , "Unknown StreamerFactory Tag." , l_pszTagName, "XMLFlowBuilder::startElement", "", false );
00175                 goto RELEASE_AND_RETURN;
00176             }
00177 
00178 
00179             l_pActiveStreamNode =  new ActiveStreamNode( l_pStreamerFactory,l_pParameters);
00180             l_pParentStreamNode->appendChild( l_pActiveStreamNode);
00181             m_vaStackStreamNodes.push( l_pActiveStreamNode);
00182             DEBUG_ECHO << "active node compiled.\n";
00183         }
00184         else
00185         {
00186             l_pParentStreamNode = (ActiveStreamNode*)m_vaStackStreamNodes.top();
00187 
00188             if(! m_fTopStreamerPassive)
00189             { 
00190                 l_pPassiveStreamNode = new PassiveStreamNode();
00191                 l_pParentStreamNode->appendChild( l_pPassiveStreamNode);
00192                 m_vaStackStreamNodes.push( l_pPassiveStreamNode);
00193                 m_fTopStreamerPassive=true;
00194             }
00195             
00196             SAX2Formatter::startElement(uri,localname,qname,attrs);
00197         }
00198         
00199         RELEASE_AND_RETURN:
00200 
00201         // Release
00202         l_pszURI = releaseCharBuffer( l_pszURI);
00203         l_pszFullName = releaseCharBuffer( l_pszFullName);
00204         l_pszTagName = releaseCharBuffer( l_pszTagName);
00205 
00206         ON_XML_FLOW_ERROR_DO
00207         {
00208             while(! l_pParameters->empty()) releaseCharBuffer( l_pParameters->pop());
00209             delete l_pParameters;
00210         }
00211 
00212         DEBUG_OUT(XMLFlowBuilder::startElement)
00213 
00214         ON_XML_FLOW_ERROR_THROW;
00215     }
00216 
00217     //_________________________________________________________________________
00218     // CHARACTERS
00219     //-------------------------------------------------------------------------
00220     void XMLFlowBuilder::characters(    const XMLCh* const chars , 
00221                                         const unsigned int length)
00222     {
00223         //---------------------------------------------------------------------
00224         char* l_pszChars=0;
00225         char* l_pszTrimmedChars=0;
00226 
00227         ActiveStreamNode*   l_pParentStreamNode;
00228         PassiveStreamNode* l_pPassiveStreamNode=0;
00229         //---------------------------------------------------------------------
00230 
00231         DEBUG_IN(XMLFlowBuilder::characters)
00232 
00233         if(! m_fTopStreamerPassive)
00234         {
00235             l_pParentStreamNode = (ActiveStreamNode*)m_vaStackStreamNodes.top();
00236             l_pPassiveStreamNode = new PassiveStreamNode();
00237             l_pParentStreamNode->appendChild( l_pPassiveStreamNode);
00238             m_vaStackStreamNodes.push( l_pPassiveStreamNode);
00239             m_fTopStreamerPassive=true;
00240         }           
00241 
00242         SAX2Formatter::characters( chars , length);
00243         
00244         DEBUG_OUT(XMLFlowBuilder::characters)           
00245     }
00246 
00247     //_________________________________________________________________________
00248     // ENDELEMENT
00249     //-------------------------------------------------------------------------
00250     void XMLFlowBuilder::endElement(    const XMLCh* const uri,
00251                                         const XMLCh* const localname,
00252                                         const XMLCh* const qname)
00253     {
00254         //---------------------------------------------------------------------
00255         char* l_pszFullName=0;
00256         char* l_pszURI=0;
00257         ActiveStreamNode*       l_pParentStreamNode;
00258         PassiveStreamNode* l_pPassiveStreamNode=0;
00259         ActiveStreamNode*   l_pActiveStreamNode=0;
00260         //---------------------------------------------------------------------
00261         
00262         DEBUG_IN(XMLFlowBuilder::endElement)
00263         
00264         l_pszFullName = XSTR(m_pXMLProcessor->getContext()->getTranscoder(), qname);
00265         l_pszURI =      XSTR(m_pXMLProcessor->getContext()->getTranscoder(), uri);
00266 
00267         DEBUG_ECHO <<  l_pszFullName << " " << m_uiCurDepth << "(-)\n";   
00268         
00269 
00270         // Active node ?
00271         if ( strcmp( l_pszURI, m_pszActiveURI) == 0 )
00272         {
00273             if(m_fTopStreamerPassive) m_vaStackStreamNodes.pop();
00274             m_fTopStreamerPassive=false;
00275 
00276             l_pActiveStreamNode = (ActiveStreamNode*)m_vaStackStreamNodes.pop();
00277         }
00278         else
00279         {
00280             if(! m_fTopStreamerPassive)
00281             {
00282                 l_pParentStreamNode = (ActiveStreamNode*)m_vaStackStreamNodes.top();
00283                 l_pPassiveStreamNode = new PassiveStreamNode();
00284                 l_pParentStreamNode->appendChild( l_pPassiveStreamNode);
00285                 m_vaStackStreamNodes.push( l_pPassiveStreamNode);
00286                 m_fTopStreamerPassive=true;
00287             }
00288 
00289             SAX2Formatter::endElement(uri,localname,qname);
00290         }
00291 
00292         
00293         m_uiCurDepth--;
00294 
00295         l_pszURI = releaseCharBuffer( l_pszURI);
00296         l_pszFullName = releaseCharBuffer( l_pszFullName);
00297 
00298         DEBUG_OUT(XMLFlowBuilder::endElement)
00299     }
00300 
00301 
00302     //_________________________________________________________________________
00303     // WRITECHARS
00304     //-------------------------------------------------------------------------
00305     void XMLFlowBuilder::writeChars(const XMLByte* const toWrite,const unsigned int count,XMLFormatter* const formatter)
00306     {
00307         if(m_fTopStreamerPassive)
00308         {
00309             setConsumer( (PassiveStreamNode*)m_vaStackStreamNodes.top());
00310             SAX2Formatter::writeChars(toWrite,count, formatter);
00311         }
00312     }
00313 
00314 
00315 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00316 //=============================================================================
00317 
00318 END_XDFLENGINE_NS
00319 

Generated on Sat Oct 4 13:20:03 2003 for XDFLengine by doxygen1.3-rc2