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

valuesstreamer.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  VALUESHANDLER.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 "valuesstreamer.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 //  CLASS ValuesStreamerFactory
00050 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00051 
00052     XMLStreamer* ValuesStreamerFactory::getStreamer(
00053         StreamerParams*         p_pParameters, 
00054         XMLFlowContext* p_pStreamContext, 
00055         XMLStreamConsumer*      p_pStreamConsumer) const
00056     {
00057         //---------------------------------------------------------------------
00058         SAXValuesHandler*   l_pSaxRawHandler;
00059         //---------------------------------------------------------------------
00060 
00061         l_pSaxRawHandler = new SAXValuesHandler( p_pParameters, p_pStreamContext);
00062         return (XMLStreamer*) new SaxStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer, l_pSaxRawHandler, true);
00063     }
00064 
00065 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00066 //=============================================================================
00067 
00068 //=============================================================================
00069 //  CLASS _ValuesStreamerFactory
00070 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00071 
00072     XMLStreamer* _ValuesStreamerFactory::getStreamer(
00073         StreamerParams*         p_pParameters, 
00074         XMLFlowContext* p_pStreamContext, 
00075         XMLStreamConsumer*      p_pStreamConsumer) const
00076     {
00077         //---------------------------------------------------------------------
00078         SAXValuesHandler*   l_pSaxRawHandler;
00079         //---------------------------------------------------------------------
00080 
00081         l_pSaxRawHandler = new SAXValuesHandler( p_pParameters, (XMLFlowContext*) p_pStreamContext->getParent());
00082         return (XMLStreamer*) new SaxStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer, l_pSaxRawHandler, true);
00083     }
00084 
00085 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00086 //=============================================================================
00087 
00088 
00089 
00090 //=============================================================================
00091 //  CLASS SAXVALUESHANDLER
00092 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00093 
00094 
00095     //_________________________________________________________________________
00096     //  SAXVALUESHANDLER
00097     //-------------------------------------------------------------------------
00098     SAXValuesHandler::SAXValuesHandler( StreamerParams* p_pParameters,XMLFlowContext*   p_pContext)
00099     {   
00100         //---------------------------------------------------------------------
00101         const char*     l_pszFilter;
00102         //---------------------------------------------------------------------
00103 
00104         // init properties
00105         m_fValues=false;
00106         if ( strcmp( XMLStreamer::getParamValue( p_pParameters, VALUESSTREAMER_VALUES, VALUESSTREAMER_VALUES_DEF ) , REQ_TRUE ) == 0 ) m_fValues=true;
00107         m_fCount=false;
00108         if ( strcmp( XMLStreamer::getParamValue( p_pParameters, VALUESSTREAMER_COUNT, VALUESSTREAMER_COUNT_DEF) , REQ_TRUE ) == 0 ) m_fCount=true;
00109         m_fList=false;
00110         if ( strcmp( XMLStreamer::getParamValue( p_pParameters, VALUESSTREAMER_LIST, VALUESSTREAMER_LIST_DEF) , REQ_TRUE ) == 0 ) m_fList=true;
00111         
00112         m_pszSep = importCharBuffer(0, XMLStreamer::getParamValue( p_pParameters,VALUESSTREAMER_SEP,VALUESSTREAMER_SEP_DEF));
00113 
00114         m_pszFilter = 0;
00115         l_pszFilter = XMLStreamer::getParamValue( p_pParameters,VALUESSTREAMER_FILTER,VALUESSTREAMER_FILTER_DEF);
00116         if ( strlen( l_pszFilter) > 0)
00117         {
00118             m_pszFilter = concatCharBuffer( 0, VALUESSTREAMER_FILTERSEP);
00119             m_pszFilter = concatCharBuffer( m_pszFilter, l_pszFilter);
00120             m_pszFilter = concatCharBuffer( m_pszFilter, VALUESSTREAMER_FILTERSEP);
00121         }
00122 
00123         m_pContext = p_pContext;
00124 
00125         DEBUG_CREATE(SAXValuesHandler)
00126     }
00127 
00128     //_________________________________________________________________________
00129     //  ~SAXVALUESHANDLER
00130     //-------------------------------------------------------------------------
00131     SAXValuesHandler::~SAXValuesHandler()
00132     {
00133         //---------------------------------------------------------------------
00134         char* l_pszBuffer = 0;
00135         //---------------------------------------------------------------------
00136 
00137         DEBUG_DEL(SAXValuesHandler)
00138 
00139         m_pszFilter = releaseCharBuffer( m_pszFilter);
00140         m_pszSep = releaseCharBuffer( m_pszSep);
00141         while(!m_vaValues.empty()) releaseCharBuffer( m_vaValues.pop());
00142     }
00143 
00144 
00145     //  CONTENTHANDLER  
00146 
00147     //_________________________________________________________________________
00148     //  CHARACTERS
00149     //-------------------------------------------------------------------------
00150     void SAXValuesHandler::characters(const XMLCh* const chars ,const unsigned int length)
00151     {
00152         //---------------------------------------------------------------------
00153         char*   l_pszChars = 0;
00154         char*   l_pszTrimmedChars = 0;
00155         char*   l_pszValue = 0;
00156         char*   l_pszName;
00157         //---------------------------------------------------------------------
00158 
00159         DEBUG_IN(SAXValuesHandler::characters)
00160 
00161         l_pszChars = XSTR( m_pContext->getTranscoder(), chars, length);
00162         l_pszTrimmedChars = trimCharBuffer(l_pszChars);
00163         releaseCharBuffer( l_pszChars);
00164          
00165         if(( strlen( l_pszTrimmedChars) > 0 ) && (! m_vaValues.empty() )) 
00166         {
00167             l_pszName = copyCharBuffer( m_vaValues.getKey( m_vaValues.size() -1));
00168             l_pszValue = m_vaValues.top();
00169             m_vaValues.pop();
00170             
00171             l_pszValue = concatCharBuffer( l_pszValue, l_pszTrimmedChars);          
00172             m_vaValues.add(l_pszValue, l_pszName);
00173             l_pszName = releaseCharBuffer( l_pszName);
00174         }
00175 
00176         l_pszTrimmedChars = releaseCharBuffer( l_pszTrimmedChars);
00177 
00178         DEBUG_OUT(SAXValuesHandler::characters)
00179     }
00180 
00181     //_________________________________________________________________________
00182     //  STARTELEMENT
00183     //-------------------------------------------------------------------------
00184     void SAXValuesHandler::startElement(  const XMLCh* const uri,    const XMLCh* const localname,   const XMLCh* const qname, const Attributes& attrs)
00185     {
00186         char*   l_pszValName = 0;
00187         char    l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE];
00188 
00189         DEBUG_IN(SAXValuesHandler::startElement)
00190 
00191         XSTR(m_pContext->getTranscoder(), localname, (char*) &l_szTagName);
00192 
00193         l_pszValName = 0;
00194         if(! m_vaValues.empty())
00195         {
00196             l_pszValName = copyCharBuffer( m_vaValues.getKey( m_vaValues.size() -1));
00197             l_pszValName = concatCharBuffer( l_pszValName, VALUESSTREAMER_VALSEP);
00198         }
00199 
00200         l_pszValName = concatCharBuffer( l_pszValName, (char*) &l_szTagName);
00201 
00202         m_vaValues.add( copyCharBuffer(""), l_pszValName);
00203         releaseCharBuffer( l_pszValName);
00204 
00205         DEBUG_OUT(SAXValuesHandler::startElement)
00206     }
00207 
00208     //_________________________________________________________________________
00209     //  ENDELEMENT
00210     //-------------------------------------------------------------------------
00211     void SAXValuesHandler::endElement(  const XMLCh* const uri,  const XMLCh* const localname,   const XMLCh* const qname)
00212     {
00213         //---------------------------------------------------------------------
00214         char*           l_pszName = 0;
00215         char*           l_pszEnclosedName = 0;
00216         char*           l_pszValue = 0;
00217         char*           l_pszListParam = 0;
00218         char*           l_pszNameCount = 0;
00219         const char*     l_pszParam = 0;
00220         char            l_cCount[50];
00221         unsigned int    l_uiCount = 0;
00222         //---------------------------------------------------------------------
00223 
00224         DEBUG_IN(SAXValuesHandler::endElement)
00225 
00226         if( !m_vaValues.empty()) 
00227         {   
00228             l_pszName = copyCharBuffer(m_vaValues.getKey( m_vaValues.size() -1));
00229             l_pszValue = m_vaValues.pop();  
00230 
00231             if(strlen(l_pszValue)>0)
00232             {
00233                 // Enclose name with filter seps
00234                 l_pszEnclosedName = copyCharBuffer( VALUESSTREAMER_FILTERSEP);
00235                 l_pszEnclosedName = concatCharBuffer( l_pszEnclosedName, l_pszName);
00236                 l_pszEnclosedName = concatCharBuffer( l_pszEnclosedName, VALUESSTREAMER_FILTERSEP);
00237                 
00238                 // test filter
00239                 if( ( ! m_pszFilter ) || ( strstr( m_pszFilter, l_pszEnclosedName) ) )
00240                 { 
00241                     if(m_fValues)
00242                     {                   
00243                         if(m_fList)
00244                         {
00245                             l_pszParam = m_pContext->getParameter(l_pszName);
00246                             if( strlen( l_pszParam) == 0 )
00247                             {
00248                                 m_pContext->addParameter(l_pszName, l_pszValue);
00249                             }
00250                             else
00251                             {
00252                                 l_pszListParam = copyCharBuffer( l_pszParam);
00253                                 l_pszListParam = concatCharBuffer( l_pszListParam, m_pszSep);
00254                                 l_pszListParam = concatCharBuffer( l_pszListParam, l_pszValue);
00255                                 m_pContext->addParameter( l_pszName, l_pszListParam);
00256                             }
00257                         }
00258                         else
00259                         {
00260                             m_pContext->addParameter( l_pszName, l_pszValue);
00261                         }
00262                     }
00263                     if(m_fCount)
00264                     {                   
00265                         l_pszNameCount = copyCharBuffer( l_pszName);
00266                         l_pszNameCount = concatCharBuffer( l_pszNameCount, VALUESSTREAMER_COUNT_SUFFIX);
00267 
00268                         l_pszParam = m_pContext->getParameter( l_pszNameCount);
00269                         if( strlen( l_pszParam) == 0 ) l_pszParam = "0";
00270 
00271                         l_uiCount=atoi( l_pszParam);
00272                         l_uiCount++;
00273                         sprintf((char*) &l_cCount,"%d", l_uiCount);
00274                         m_pContext->addParameter( l_pszNameCount, l_cCount);                
00275                     }
00276                 }
00277                 
00278                 l_pszEnclosedName = releaseCharBuffer( l_pszEnclosedName);          
00279                 l_pszListParam = releaseCharBuffer( l_pszListParam);
00280                 l_pszNameCount = releaseCharBuffer( l_pszNameCount);
00281             }
00282 
00283             l_pszValue = releaseCharBuffer( l_pszValue);
00284             l_pszName = releaseCharBuffer( l_pszName);
00285         }
00286 
00287         DEBUG_OUT(SAXValuesHandler::endElement)
00288     }
00289 
00290 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00291 //=============================================================================
00292 
00293 
00294 END_XDFLENGINE_NS
00295 
00296 
00297 

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