00001 //============================================================================= 00002 // 00003 // XDFLengine library 00004 // 00005 //----------------------------------------------------------------------------- 00006 // SystemStreamer.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 "flow/consumers/streamsax2parser.hpp" 00041 # include "processor/xmlflowcontext.hpp" 00042 # include "streamers/generic/saxstreamer.hpp" 00043 # include "systemstreamer.hpp" 00044 00045 00046 BEGIN_XDFLENGINE_NS 00047 00048 00049 00050 00051 //============================================================================= 00052 // CLASS SystemStreamerFactory 00053 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00054 00055 XMLStreamer* SystemStreamerFactory::getStreamer( 00056 StreamerParams* p_pParameters, 00057 XMLFlowContext* p_pStreamContext, 00058 XMLStreamConsumer* p_pStreamConsumer) const 00059 { 00060 SAXSystemHandler* l_pSaxSystemHandler; 00061 00062 l_pSaxSystemHandler = new SAXSystemHandler(p_pStreamContext, p_pStreamConsumer); 00063 return (XMLStreamer*) new SaxStreamer( this, p_pParameters, p_pStreamContext, p_pStreamConsumer, l_pSaxSystemHandler, false); 00064 } 00065 00066 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00067 //============================================================================= 00068 00069 00070 //============================================================================= 00071 // CLASS SAXSystemHandler 00072 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00073 00074 //_________________________________________________________________________ 00075 // SAXSystemHANDLER 00076 //------------------------------------------------------------------------- 00077 SAXSystemHandler::SAXSystemHandler(XMLFlowContext* p_pContext, XMLStreamConsumer* p_pStreamConsumer) 00078 { 00079 m_pStreamConsumer = p_pStreamConsumer; 00080 m_pContext = p_pContext; 00081 DEBUG_CREATE(SAXSystemHandler) 00082 } 00083 00084 //_________________________________________________________________________ 00085 // ~SAXSystemHANDLER 00086 //------------------------------------------------------------------------- 00087 SAXSystemHandler::~SAXSystemHandler() 00088 { 00089 DEBUG_DEL(SAXSystemHandler) 00090 } 00091 00092 00093 // CONTENTHANDLER 00094 00095 //____________________________________________________________________ 00096 // STARTELEMENT 00097 //-------------------------------------------------------------------- 00098 void SAXSystemHandler::startElement( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) 00099 { 00100 //--------------------------------------------------------------------- 00101 char l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE]; 00102 //--------------------------------------------------------------------- 00103 00104 XSTR( m_pContext->getTranscoder(), localname, (char*) &l_szTagName); 00105 (*m_pStreamConsumer) << "<" << (char*) &l_szTagName << ">" ; 00106 } 00107 00108 //_________________________________________________________________________ 00109 // CHARACTERS 00110 //------------------------------------------------------------------------- 00111 void SAXSystemHandler::characters(const XMLCh* const chars ,const unsigned int length) 00112 { 00113 //--------------------------------------------------------------------- 00114 int l_iReturnValue; 00115 char* l_pszChars; 00116 char* l_pszTrimmedChars; 00117 //--------------------------------------------------------------------- 00118 00119 DEBUG_FUNC(SAXSystemHandler::characters) 00120 00121 l_pszChars=XSTR( m_pContext->getTranscoder(), chars, length); 00122 l_pszTrimmedChars = trimCharBuffer( l_pszChars); 00123 l_pszChars = releaseCharBuffer( l_pszChars); 00124 00125 if( strlen(l_pszTrimmedChars)>0 ) 00126 { 00127 logout << "\t\t" << l_pszTrimmedChars << "->"; 00128 l_iReturnValue=system(l_pszTrimmedChars); 00129 (*m_pStreamConsumer) << (long) l_iReturnValue ; 00130 } 00131 00132 l_pszTrimmedChars = releaseCharBuffer( l_pszTrimmedChars); 00133 } 00134 00135 //____________________________________________________________________ 00136 // ENDELEMENT 00137 //-------------------------------------------------------------------- 00138 void SAXSystemHandler::endElement ( const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) 00139 { 00140 //--------------------------------------------------------------------- 00141 char l_szTagName[XMLPROCESSOR_MAX_TAG_SIZE]; 00142 //--------------------------------------------------------------------- 00143 00144 XSTR(m_pContext->getTranscoder(), localname, (char*) &l_szTagName); 00145 (*m_pStreamConsumer) << "</" << (char*) &l_szTagName << ">\n"; 00146 } 00147 00148 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00149 //============================================================================= 00150 00151 END_XDFLENGINE_NS