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

xmlflow.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //----------------------------------------------------------------------------- 
00006 //  XMLFLOW.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 "xmlflow.hpp"
00041 #include "processor/xmlstreamer.hpp"
00042 #include "processor/xmlflowcontext.hpp"
00043 #include "flow/consumers/nullconsumer.hpp"
00044 
00045 BEGIN_XDFLENGINE_NS
00046 
00047 
00048 //============================================================================= 
00049 //  CLASS PassiveStreamNode
00050 //----------------------------------------------------------------------------- 
00051 
00052     //_____________________________________________________________________
00053     //  PassiveStreamNode
00054     //---------------------------------------------------------------------
00055     PassiveStreamNode::PassiveStreamNode()
00056     {
00057         DEBUG_CREATE(PassiveStreamNode)
00058     }
00059 
00060     //_____________________________________________________________________
00061     //  ~PassiveStreamNode
00062     //---------------------------------------------------------------------
00063     PassiveStreamNode::~PassiveStreamNode()
00064     {
00065         DEBUG_DEL(PassiveStreamNode)
00066     }
00067 
00068     //_____________________________________________________________________
00069     //  streamXML
00070     //---------------------------------------------------------------------
00071     void PassiveStreamNode::streamXML(XMLStreamConsumer* p_pStreamConsumer, XMLFlowContext* p_pStreamContext) const
00072     {
00073         //-----------------------------------------------------------------
00074         char*   l_pszValuatedChunk=0;
00075         //-----------------------------------------------------------------
00076 
00077         DEBUG_FUNC(PassiveStreamNode::streamXML)
00078 
00079         PREP_CATCH_XML_FLOW_ERROR;
00080 
00081         // !! calcul des valeurs parsées
00082         if(MemBuffer::length()>0)
00083         {
00084             WATCH_XML_FLOW_ERROR
00085             {
00086                 l_pszValuatedChunk=p_pStreamContext->calculateValue( MemBuffer::data());
00087                 (*p_pStreamConsumer) << l_pszValuatedChunk;
00088             } 
00089             CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN         
00090         }
00091 
00092     RELEASE_AND_RETURN:
00093         l_pszValuatedChunk = releaseCharBuffer( l_pszValuatedChunk);
00094         ON_XML_FLOW_ERROR_THROW;
00095     }
00096 
00097 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00098 //=============================================================================
00099 
00100 
00101 
00102 
00103 
00104 //============================================================================= 
00105 //  CLASS ActiveStreamNode
00106 //----------------------------------------------------------------------------- 
00107 
00108     
00109     //_____________________________________________________________________
00110     //  ActiveStreamNode
00111     //--------------------------------------------------------------------- 
00112     ActiveStreamNode::ActiveStreamNode(XMLStreamerFactory* p_pStreamerFactory, StreamerParams*  p_pStreamerParams)
00113     {
00114         DEBUG_CREATE(ActiveStreamNode)
00115         m_pStreamerFactory = p_pStreamerFactory;
00116         m_pStreamerParams = p_pStreamerParams;
00117     }
00118 
00119     //_____________________________________________________________________
00120     //  ~ActiveStreamNode
00121     //---------------------------------------------------------------------
00122     ActiveStreamNode::~ActiveStreamNode()
00123     {
00124         DEBUG_DEL(ActiveStreamNode)
00125         if(m_pStreamerParams)
00126         {
00127             while( ! m_pStreamerParams->empty())releaseCharBuffer(m_pStreamerParams->pop()); 
00128             delete m_pStreamerParams;
00129         }
00130         while( ! m_vaChildStreamNodes.empty()) delete m_vaChildStreamNodes.pop();
00131     }
00132 
00133     //_____________________________________________________________________
00134     //  getParams
00135     //---------------------------------------------------------------------
00136     StreamerParams* ActiveStreamNode::getParams()
00137     {
00138         return m_pStreamerParams;
00139     }
00140 
00141     //_____________________________________________________________________
00142     //  appendChild
00143     //---------------------------------------------------------------------
00144     void ActiveStreamNode::appendChild(XMLFlowNode* p_pChildStreamNode)
00145     {
00146         DEBUG_FUNC(ActiveStreamNode::appendChild)
00147         m_vaChildStreamNodes.push( p_pChildStreamNode);
00148     }
00149 
00150     //_____________________________________________________________________
00151     //  streamXML
00152     //---------------------------------------------------------------------
00153     void ActiveStreamNode::streamXML(XMLStreamConsumer* p_pStreamConsumer, XMLFlowContext* p_pStreamContext) const
00154     {
00155         //-----------------------------------------------------------------
00156         XMLFlowNode*        l_pStreamNode;
00157         XMLStreamer*        l_pXMLStreamer=0;
00158         XMLStreamConsumer*  l_pXMLConsumer=0;
00159         XMLStreamConsumer*  l_pErrorOutput=0;
00160         NullConsumer*       l_pNullConsumer=0;
00161         unsigned int        i;
00162         const char*         l_pszEnclose;
00163         const char*         l_pszOutput;
00164         const char*         l_pszComment;
00165         StreamerParams*     l_pszValuatedParams=0;
00166         bool                l_fErrorFatal;
00167         bool                l_fStreamerInitOK;
00168         bool                l_fEncloseCDATA;
00169         //-----------------------------------------------------------------
00170 
00171         PREP_CATCH_XML_FLOW_ERROR;
00172 
00173         DEBUG_FUNC(ActiveStreamNode::streamXML)
00174 
00175         // get general streamer parameters
00176 
00177         // valuate parameters collection
00178         l_pszValuatedParams = valuateParameters( p_pStreamContext, m_pStreamerParams);
00179 
00180         // ? error fatal
00181         l_fErrorFatal = true;
00182         if( strcmp( XMLStreamer::getParamValue(l_pszValuatedParams, REQ_ERRFATAL, REQ_ERRFATAL_DEF), REQ_FALSE) == 0 ) l_fErrorFatal = false;
00183 
00184         // errors output
00185         l_pErrorOutput = 0;
00186         l_pszOutput = XMLStreamer::getParamValue( l_pszValuatedParams, REQ_OUTPUTERROR, REQ_OUTPUTERROR_DEF);
00187         if( strcmp( l_pszOutput, REQ_PARENTOUTPUT) == 0) l_pErrorOutput = p_pStreamConsumer;
00188         if( strcmp( l_pszOutput, REQ_NOOUTPUT) == 0)
00189         {
00190             if(!l_pNullConsumer) l_pNullConsumer =  new NullConsumer;
00191             l_pErrorOutput = l_pNullConsumer;
00192         }
00193         if( !l_pErrorOutput )l_pErrorOutput = p_pStreamContext->getNamedBuffer( l_pszOutput);
00194         if( !l_pErrorOutput ) 
00195         {
00196             MAKE_XMLFLOW_EXCEPTION ( ERRCODE_LOC_FLOWBUILDER + ERRCODE_CAUSE_MISSINGREF , "No error buffer was found with that name." , l_pszOutput, "ActiveStreamNode::streamXML", "", false );
00197             goto RELEASE_AND_RETURN;
00198         }
00199 
00200         // comment ...
00201         l_pszComment = XMLStreamer::getParamValue(l_pszValuatedParams, REQ_COMMENT, "");
00202         if (strlen( l_pszComment)>0) logout << "\n" << l_pszComment << "\n\n";
00203 
00204         // enclose tag
00205         l_pszEnclose = XMLStreamer::getParamValue( l_pszValuatedParams, REQ_ENCLOSE, REQ_ENCLOSE_DEF);
00206         if(strlen(l_pszEnclose)==0) l_pszEnclose = 0;
00207 
00208         // enclose CDATA
00209         l_fEncloseCDATA = false;
00210         if( strcmp( XMLStreamer::getParamValue(l_pszValuatedParams, REQ_ENCLOSECDATA, REQ_ENCLOSECDATA_DEF), REQ_TRUE) == 0 ) l_fEncloseCDATA = true;
00211     
00212         // output 
00213         l_pXMLConsumer = 0;
00214         l_pszOutput = XMLStreamer::getParamValue(l_pszValuatedParams, REQ_OUTPUT, REQ_OUTPUT_DEF);
00215         if( strcmp( l_pszOutput, REQ_PARENTOUTPUT) == 0) l_pXMLConsumer = p_pStreamConsumer;
00216         if( strcmp( l_pszOutput, REQ_NOOUTPUT) == 0)
00217         {
00218             if(!l_pNullConsumer) l_pNullConsumer =  new NullConsumer;
00219             l_pXMLConsumer = l_pNullConsumer;
00220         }
00221         if( !l_pXMLConsumer ) l_pXMLConsumer = p_pStreamContext->getNamedBuffer( l_pszOutput);
00222         if( !l_pXMLConsumer )
00223         {
00224             MAKE_XMLFLOW_EXCEPTION ( ERRCODE_LOC_FLOWBUILDER + ERRCODE_CAUSE_MISSINGREF , "No output buffer was found with that name." , l_pszOutput, "ActiveStreamNode::streamXML", "", false );
00225             goto RELEASE_AND_RETURN;
00226         }
00227         
00228         // create streamer object
00229         l_pXMLStreamer = m_pStreamerFactory->getStreamer( l_pszValuatedParams, p_pStreamContext,  l_pXMLConsumer);
00230         
00231         if(l_pszEnclose)  (*p_pStreamConsumer) << "<" << l_pszEnclose << ">\n";
00232         if(l_fEncloseCDATA) (*p_pStreamConsumer) << "<![CDATA[";
00233 
00234         // process all children into current streamer
00235         WATCH_XML_FLOW_ERROR
00236         {
00237             l_fStreamerInitOK = l_pXMLStreamer->initStream();
00238             if ( l_fStreamerInitOK ) // init ...
00239             {
00240                 for(i=0; i < m_vaChildStreamNodes.size(); i++) 
00241                 {
00242                     l_pStreamNode = m_vaChildStreamNodes.get(i);                    
00243                     l_pStreamNode->streamXML( l_pXMLStreamer, p_pStreamContext);
00244                 }
00245                 l_pXMLStreamer->commitStream(true);
00246                 // .. and commit
00247             }
00248 
00249         } 
00250         CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN
00251 
00252         if(l_fEncloseCDATA) (*p_pStreamConsumer) << "]]>";
00253         if(l_pszEnclose)  (*p_pStreamConsumer) << "</" << l_pszEnclose << ">\n";
00254 
00255     RELEASE_AND_RETURN:
00256 
00257         ON_XML_FLOW_ERROR_DO
00258         {
00259             if(l_pErrorOutput) (*l_pXMLFlowException) >> (*l_pErrorOutput);
00260         }
00261 
00262         if(l_pNullConsumer) delete l_pNullConsumer;
00263         if(l_pszValuatedParams) 
00264         {
00265             while( !l_pszValuatedParams->empty() ) releaseCharBuffer( l_pszValuatedParams->pop());
00266             delete l_pszValuatedParams;
00267         }
00268         delete l_pXMLStreamer;
00269 
00270         ON_XML_FLOW_ERROR_DO
00271         {
00272             if( l_fErrorFatal) throw l_pXMLFlowException;
00273             else delete l_pXMLFlowException;                
00274         }
00275     }
00276 
00277     //_____________________________________________________________________
00278     //  valuateParameters
00279     //---------------------------------------------------------------------
00280     StreamerParams* ActiveStreamNode::valuateParameters(XMLFlowContext* p_pStreamContext,const StreamerParams* p_pStreamerParams) const
00281     {
00282         //-----------------------------------------------------------------
00283         unsigned int    l_uiSize;
00284         unsigned int    i;
00285         char*           l_pszValue;
00286         char*           l_pszCalculatedValue;
00287         const char*     l_pszKey;
00288         StreamerParams* l_pszValuatedParams;
00289         //-----------------------------------------------------------------
00290 
00291 
00292         l_pszValuatedParams = new StreamerParams;
00293         l_uiSize=p_pStreamerParams->size();
00294         for(i=0 ; i< l_uiSize; i++)
00295         {
00296             l_pszKey = p_pStreamerParams->getKey(i);
00297             l_pszValue = p_pStreamerParams->get(i);
00298             l_pszCalculatedValue = p_pStreamContext->calculateValue( l_pszValue);
00299             l_pszValuatedParams->add( l_pszCalculatedValue, l_pszKey);
00300         }
00301 
00302         return l_pszValuatedParams;
00303 
00304     }
00305 
00306 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00307 //=============================================================================
00308 
00309 //============================================================================= 
00310 //  CLASS RootStreamNode
00311 //----------------------------------------------------------------------------- 
00312 
00313 
00314     //_____________________________________________________________________
00315     //  RootStreamNode
00316     //---------------------------------------------------------------------
00317     RootStreamNode::RootStreamNode():ActiveStreamNode(0,0)
00318     {
00319         DEBUG_CREATE(RootStreamNode)
00320     }
00321 
00322     //_____________________________________________________________________
00323     //  RootStreamNode
00324     //---------------------------------------------------------------------
00325     RootStreamNode::~RootStreamNode()
00326     {
00327         DEBUG_DEL(RootStreamNode)
00328     }
00329 
00330 
00331     //_____________________________________________________________________
00332     //  streamXML
00333     //---------------------------------------------------------------------
00334     void RootStreamNode::streamXML( XMLStreamConsumer* p_pStreamConsumer, XMLFlowContext* p_pStreamContext) const
00335     {
00336         //-----------------------------------------------------------------
00337         XMLFlowNode* l_pStreamNode;
00338         unsigned int        i;
00339         //-----------------------------------------------------------------
00340 
00341         PREP_CATCH_XML_FLOW_ERROR;
00342 
00343         DEBUG_FUNC(RootStreamNode::streamXML)
00344 
00345         WATCH_XML_FLOW_ERROR
00346         { 
00347             for(i=0; i < m_vaChildStreamNodes.size(); i++)
00348             {
00349                 l_pStreamNode = m_vaChildStreamNodes.get(i);
00350                 l_pStreamNode->streamXML( p_pStreamConsumer, p_pStreamContext);
00351             }
00352 
00353         } 
00354         CATCH_XML_FLOW_ERROR_RELEASE_AND_RETURN
00355 
00356     RELEASE_AND_RETURN:
00357 
00358         ON_XML_FLOW_ERROR_THROW;
00359     }
00360 
00361 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00362 //=============================================================================
00363 
00364 END_XDFLENGINE_NS
00365 
00366 
00367 

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