00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef __GNUG__
00034 #pragma implementation
00035 #endif
00036
00037 #include <sstream>
00038
00039 using std::ostringstream ;
00040
00041 #include "BESXMLInfo.h"
00042
00051 BESXMLInfo::BESXMLInfo( )
00052 : BESInfo( ),
00053 _do_indent( true )
00054 {
00055
00056 }
00057
00058 BESXMLInfo::~BESXMLInfo()
00059 {
00060 }
00061
00069 void
00070 BESXMLInfo::begin_response( const string &response_name )
00071 {
00072 BESInfo::begin_response( response_name ) ;
00073 add_data( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ) ;
00074 _response_name = response_name ;
00075 add_data( (string)"<" + _response_name + ">\n" ) ;
00076 _indent += " " ;
00077 add_data( "<response>\n" ) ;
00078 _indent += " " ;
00079 }
00080
00088 void
00089 BESXMLInfo::end_response()
00090 {
00091 BESInfo::end_response() ;
00092 if( _indent.length() >= 4 )
00093 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00094 add_data( "</response>\n" ) ;
00095 if( _indent.length() >= 4 )
00096 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00097 add_data( (string)"</" + _response_name + ">\n" ) ;
00098 }
00099
00105 void
00106 BESXMLInfo::add_tag( const string &tag_name,
00107 const string &tag_data,
00108 map<string,string> *attrs )
00109 {
00110 add_data( (string)"<" + tag_name ) ;
00111 if( attrs )
00112 {
00113 map<string,string>::const_iterator i = attrs->begin() ;
00114 map<string,string>::const_iterator e = attrs->end() ;
00115 for( ; i != e; i++ )
00116 {
00117 string name = (*i).first ;
00118 string val = (*i).second ;
00119 _do_indent = false ;
00120 if( val != "" )
00121 add_data( " " + name + "=" + val ) ;
00122 else
00123 add_data( " " + name ) ;
00124 }
00125 }
00126 _do_indent = false ;
00127 add_data( ">" + tag_data + "</" + tag_name + ">\n" ) ;
00128 }
00129
00134 void
00135 BESXMLInfo::begin_tag( const string &tag_name,
00136 map<string,string> *attrs )
00137 {
00138 BESInfo::begin_tag( tag_name ) ;
00139 add_data( (string)"<" + tag_name ) ;
00140 if( attrs )
00141 {
00142 map<string,string>::const_iterator i = attrs->begin() ;
00143 map<string,string>::const_iterator e = attrs->end() ;
00144 for( ; i != e; i++ )
00145 {
00146 string name = (*i).first ;
00147 string val = (*i).second ;
00148 _do_indent = false ;
00149 if( val != "" )
00150 add_data( " " + name + "=" + val ) ;
00151 else
00152 add_data( " " + name ) ;
00153 }
00154 }
00155 _do_indent = false ;
00156 add_data( ">\n" ) ;
00157 _indent += " " ;
00158 }
00159
00166 void
00167 BESXMLInfo::end_tag( const string &tag_name )
00168 {
00169 BESInfo::end_tag( tag_name ) ;
00170 if( _indent.length() >= 4 )
00171 _indent = _indent.substr( 0, _indent.length()-4 ) ;
00172 add_data( (string)"</" + tag_name + ">\n" ) ;
00173 }
00174
00179 void
00180 BESXMLInfo::add_space( unsigned long num_spaces )
00181 {
00182 string to_add ;
00183 for( unsigned long i = 0; i < num_spaces; i++ )
00184 {
00185 to_add += " " ;
00186 }
00187 _do_indent = false ;
00188 add_data( to_add ) ;
00189 }
00190
00195 void
00196 BESXMLInfo::add_break( unsigned long num_breaks )
00197 {
00198 string to_add ;
00199 for( unsigned long i = 0; i < num_breaks; i++ )
00200 {
00201 to_add += "\n" ;
00202 }
00203 _do_indent = false ;
00204 add_data( to_add ) ;
00205 }
00206
00207 void
00208 BESXMLInfo::add_data( const string &s )
00209 {
00210 if( _do_indent )
00211 BESInfo::add_data( _indent + s ) ;
00212 else
00213 BESInfo::add_data( s ) ;
00214 _do_indent = true ;
00215 }
00216
00225 void
00226 BESXMLInfo::add_data_from_file( const string &key, const string &name )
00227 {
00228 string newkey = key + ".XML" ;
00229 BESInfo::add_data_from_file( newkey, name ) ;
00230 }
00231
00240 void
00241 BESXMLInfo::transmit( BESTransmitter *transmitter,
00242 BESDataHandlerInterface &dhi )
00243 {
00244 transmitter->send_text( *this, dhi ) ;
00245 }
00246
00252 void
00253 BESXMLInfo::print( ostream &strm )
00254 {
00255 BESInfo::print( strm ) ;
00256 }
00257
00265 void
00266 BESXMLInfo::dump( ostream &strm ) const
00267 {
00268 strm << BESIndent::LMarg << "BESXMLInfo::dump - ("
00269 << (void *)this << ")" << endl ;
00270 BESIndent::Indent() ;
00271 strm << BESIndent::LMarg << "indentation \"" << _indent << "\"" << endl ;
00272 strm << BESIndent::LMarg << "do indent? " << _do_indent << endl ;
00273 BESInfo::dump( strm ) ;
00274 BESIndent::UnIndent() ;
00275 }
00276
00277 BESInfo *
00278 BESXMLInfo::BuildXMLInfo( const string &info_type )
00279 {
00280 return new BESXMLInfo( ) ;
00281 }
00282