OPeNDAP Hyrax Back End Server (BES) Updated for version 3.8.3
|
00001 // BESXMLUtils.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-2009 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 "BESXMLUtils.h" 00034 #include "BESUtil.h" 00035 00046 void 00047 BESXMLUtils::XMLErrorFunc( void *context, const char *msg, ... ) 00048 { 00049 va_list args ; 00050 va_start( args, msg ) ; 00051 char mymsg[1024] ; 00052 vsprintf( mymsg, msg, args ) ; 00053 vector<string> *myerrors = (vector<string> *)context ; 00054 myerrors->push_back( mymsg ) ; 00055 } 00056 00065 void 00066 BESXMLUtils::GetProps( xmlNode *node, map< string, string> &props ) 00067 { 00068 if( !node ) 00069 { 00070 return ; 00071 } 00072 00073 if( node->properties == NULL ) 00074 { 00075 return ; 00076 } 00077 00078 xmlAttr *curr_prop = node->properties ; 00079 while( curr_prop ) 00080 { 00081 string prop_name = (char *)curr_prop->name ; 00082 BESUtil::removeLeadingAndTrailingBlanks( prop_name ) ; 00083 string prop_val ; 00084 xmlNode *curr_val = curr_prop->children ; 00085 if( curr_val && curr_val->content ) 00086 { 00087 prop_val = BESUtil::xml2id( (char *)curr_val->content ) ; 00088 BESUtil::removeLeadingAndTrailingBlanks( prop_val ) ; 00089 } 00090 props[prop_name] = prop_val ; 00091 00092 curr_prop = curr_prop->next ; 00093 } 00094 } 00095 00104 void 00105 BESXMLUtils::GetNodeInfo( xmlNode *node, 00106 string &name, 00107 string &value, 00108 map<string, string> &props ) 00109 { 00110 if( node ) 00111 { 00112 name = (char *)node->name ; 00113 BESUtil::removeLeadingAndTrailingBlanks( name ) ; 00114 BESXMLUtils::GetProps( node, props ) ; 00115 xmlNode *child_node = node->children ; 00116 bool done = false ; 00117 while( child_node && !done ) 00118 { 00119 if( child_node->type == XML_TEXT_NODE ) 00120 { 00121 if( child_node->content ) 00122 { 00123 value = BESUtil::xml2id( (char *)child_node->content ) ; 00124 BESUtil::removeLeadingAndTrailingBlanks( value ) ; 00125 } 00126 else 00127 { 00128 value = "" ; 00129 } 00130 done = true ; 00131 } 00132 child_node = child_node->next ; 00133 } 00134 } 00135 } 00136 00144 xmlNode * 00145 BESXMLUtils::GetFirstChild( xmlNode *node, 00146 string &child_name, 00147 string &child_value, 00148 map<string, string> &child_props ) 00149 { 00150 xmlNode *child_node = NULL ; 00151 if( node ) 00152 { 00153 child_node = node->children ; 00154 bool done = false ; 00155 while( child_node && !done ) 00156 { 00157 if( child_node->type == XML_ELEMENT_NODE ) 00158 { 00159 done = true ; 00160 BESXMLUtils::GetNodeInfo( child_node, child_name, 00161 child_value, child_props ) ; 00162 } 00163 else 00164 { 00165 child_node = child_node->next ; 00166 } 00167 } 00168 } 00169 return child_node ; 00170 } 00171 00179 xmlNode * 00180 BESXMLUtils::GetNextChild( xmlNode *child_node, 00181 string &next_name, 00182 string &next_value, 00183 map<string, string> &next_props ) 00184 { 00185 if( child_node ) 00186 { 00187 child_node = child_node->next ; 00188 bool done = false ; 00189 while( child_node && !done ) 00190 { 00191 if( child_node->type == XML_ELEMENT_NODE ) 00192 { 00193 done = true ; 00194 BESXMLUtils::GetNodeInfo( child_node, next_name, 00195 next_value, next_props ) ; 00196 } 00197 else 00198 { 00199 child_node = child_node->next ; 00200 } 00201 } 00202 } 00203 return child_node ; 00204 } 00205 00213 xmlNode * 00214 BESXMLUtils::GetChild( xmlNode *node, 00215 const string &child_name, 00216 string &child_value, 00217 map<string, string> &child_props ) 00218 { 00219 xmlNode *child_node = NULL ; 00220 if( node ) 00221 { 00222 child_node = node->children ; 00223 bool done = false ; 00224 while( child_node && !done ) 00225 { 00226 if( child_node->type == XML_ELEMENT_NODE ) 00227 { 00228 string name = (char *)child_node->name ; 00229 BESUtil::removeLeadingAndTrailingBlanks( name ) ; 00230 if( name == child_name ) 00231 { 00232 done = true ; 00233 BESXMLUtils::GetNodeInfo( child_node, name, 00234 child_value, child_props ) ; 00235 } 00236 else 00237 { 00238 child_node = child_node->next ; 00239 } 00240 } 00241 else 00242 { 00243 child_node = child_node->next ; 00244 } 00245 } 00246 } 00247 return child_node ; 00248 } 00249