BESXMLGetDataDDXCommand.cc

Go to the documentation of this file.
00001 // BESXMLGetDataDDXCommand.cc
00002 
00003 // This file is part of bes, A C++ back-end server implementation framework
00004 // for the OPeNDAP Data Access Protocol.
00005 
00006 // Copyright (c) 2004,2005 University Corporation for Atmospheric Research
00007 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
00008 //
00009 // This library is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU Lesser General Public
00011 // License as published by the Free Software Foundation; either
00012 // version 2.1 of the License, or (at your option) any later version.
00013 // 
00014 // This library is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 // 
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // You can contact University Corporation for Atmospheric Research at
00024 // 3080 Center Green Drive, Boulder, CO 80301
00025  
00026 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
00027 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
00028 //
00029 // Authors:
00030 //      pwest       Patrick West <pwest@ucar.edu>
00031 //      jgarcia     Jose Garcia <jgarcia@ucar.edu>
00032 
00033 #include "BESXMLGetDataDDXCommand.h"
00034 #include "BESDefinitionStorageList.h"
00035 #include "BESDefinitionStorage.h"
00036 #include "BESDefine.h"
00037 #include "BESDapNames.h"
00038 #include "BESResponseNames.h"
00039 #include "BESXMLUtils.h"
00040 #include "BESUtil.h"
00041 #include "BESSyntaxUserError.h"
00042 #include "BESDebug.h"
00043 
00044 BESXMLGetDataDDXCommand::BESXMLGetDataDDXCommand( const BESDataHandlerInterface &base_dhi )
00045     : BESXMLGetCommand( base_dhi )
00046 {
00047 }
00048 
00055 void
00056 BESXMLGetDataDDXCommand::parse_request( xmlNode *node )
00057 {
00058     string name ;
00059     string value ;
00060     map<string, string> props ;
00061     BESXMLUtils::GetNodeInfo( node, name, value, props ) ;
00062 
00063     if( name != GET_RESPONSE )
00064     {
00065         string err = "The specified command " + name
00066                      + " is not a get command" ;
00067         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00068     }
00069 
00070     string type = props["type"] ;
00071     if( type.empty() || type != DATADDX_SERVICE )
00072     {
00073         string err = name + " command: data product must be "
00074                           + DATADDX_SERVICE ;
00075         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00076     }
00077 
00078     parse_basic_get( node, name, type, value, props ) ;
00079 
00080     // Get the elements for contentStartId and mimeBoundary
00081     map<string,string> cprops ;
00082     string cname ;
00083     string cval ;
00084     int elems = 0 ;
00085     xmlNode *cnode = BESXMLUtils::GetFirstChild( node, cname, cval, cprops ) ;
00086     while( cnode && (elems < 2) )
00087     {
00088         if( cname == "contentStartId" )
00089         {
00090             if( !_contentStartId.empty() )
00091             {
00092                 string err = name
00093                              + " command: contentStartId has multiple values" ;
00094                 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00095             }
00096             _contentStartId = cval ;
00097             _str_cmd += " contentStartId " + _contentStartId ;
00098             elems++ ;
00099         }
00100         if( cname == "mimeBoundary" )
00101         {
00102             if( !_mimeBoundary.empty() )
00103             {
00104                 string err = name
00105                              + " command: mimeBoundary has multiple values" ;
00106                 throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00107             }
00108             _mimeBoundary = cval ;
00109             _str_cmd += " mimeBoundary " + _mimeBoundary ;
00110             elems++ ;
00111         }
00112         cprops.clear() ;
00113         cnode = BESXMLUtils::GetNextChild( cnode, cname, cval, cprops ) ;
00114     }
00115     if( _contentStartId.empty() )
00116     {
00117         string err = name + " command: contentStartId not specified" ;
00118         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00119     }
00120     if( _mimeBoundary.empty() )
00121     {
00122         string err = name + " command: mimeBoundary not specified" ;
00123         throw BESSyntaxUserError( err, __FILE__, __LINE__ ) ;
00124     }
00125     _str_cmd += ";" ;
00126 
00127     // now that we've set the action, go get the response handler for the
00128     // action
00129     BESXMLCommand::set_response() ;
00130 }
00131 
00137 void
00138 BESXMLGetDataDDXCommand::prep_request()
00139 {
00140     BESXMLGetCommand::prep_request() ;
00141     _dhi.data[DATADDX_STARTID] = _contentStartId ;
00142     _dhi.data[DATADDX_BOUNDARY] = _mimeBoundary ;
00143 }
00144 
00151 void
00152 BESXMLGetDataDDXCommand::dump( ostream &strm ) const
00153 {
00154     strm << BESIndent::LMarg << "BESXMLGetDataDDXCommand::dump - ("
00155                              << (void *)this << ")" << endl ;
00156     BESIndent::Indent() ;
00157     BESXMLCommand::dump( strm ) ;
00158     BESIndent::UnIndent() ;
00159 }
00160 
00161 BESXMLCommand *
00162 BESXMLGetDataDDXCommand::CommandBuilder( const BESDataHandlerInterface &base_dhi )
00163 {
00164     return new BESXMLGetDataDDXCommand( base_dhi ) ;
00165 }
00166