libdap++ Updated for version 3.8.2
|
00001 00002 // -*- mode: c++; c-basic-offset:4 -*- 00003 00004 // This file is part of libdap, A C++ implementation of the OPeNDAP Data 00005 // Access Protocol. 00006 00007 // Copyright (c) 2003 OPeNDAP, Inc. 00008 // Author: James Gallagher <jgallagher@opendap.org> 00009 // 00010 // This library is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU Lesser General Public 00012 // License as published by the Free Software Foundation; either 00013 // version 2.1 of the License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 // 00024 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112. 00025 00026 #ifndef ddx_parser_h 00027 #define ddx_parser_h 00028 00029 #include <string> 00030 #include <map> 00031 #include <stack> 00032 00033 #include <libxml/parserInternals.h> 00034 00035 #ifndef ddx_exceptions_h 00036 #include "DDXExceptions.h" 00037 #endif 00038 00039 #ifndef _dds_h 00040 #include "DDS.h" 00041 #endif 00042 00043 #ifndef _basetype_h 00044 #include "BaseType.h" 00045 #endif 00046 00047 #ifndef base_type_factory_h 00048 #include "BaseTypeFactory.h" 00049 #endif 00050 00051 namespace libdap 00052 { 00053 00079 class DDXParser 00080 { 00081 private: 00084 enum ParseState { 00085 parser_start, 00086 00087 inside_dataset, 00088 00089 inside_attribute_container, 00090 inside_attribute, 00091 inside_attribute_value, 00092 00093 inside_alias, 00094 00095 // This covers Byte, ..., Url. 00096 inside_simple_type, 00097 00098 inside_array, 00099 inside_dimension, 00100 00101 inside_grid, 00102 inside_map, 00103 00104 inside_structure, 00105 inside_sequence, 00106 00107 inside_blob_href, 00108 00109 parser_unknown, 00110 parser_error 00111 }; 00112 00113 BaseTypeFactory *d_factory; 00114 00115 // These stacks hold the state of the parse as it progresses. 00116 stack<ParseState> s; // Current parse state 00117 stack<BaseType*> bt_stack; // current variable(s) 00118 stack<AttrTable*> at_stack; // current attribute table 00119 00120 // These are used for processing errors. 00121 string error_msg; // Error message(s), if any. 00122 xmlParserCtxtPtr ctxt; // used for error msg line numbers 00123 00124 // The results of the parse operation are stored in these fields. 00125 DDS *dds; // dump DDX here 00126 string *blob_href; // put href to blob here 00127 00128 // These hold temporary values read during the parse. 00129 string dods_attr_name; // DAP2 attributes, not XML attributes 00130 string dods_attr_type; // ... not XML ... 00131 string char_data; // char data in value elements; null after use 00132 map<string, string> attributes; // dump XML attributes here 00133 00134 // These are kind of silly... 00135 void set_state(DDXParser::ParseState state); 00136 DDXParser::ParseState get_state() const; 00137 void pop_state(); 00138 00139 // Glue for the BaseTypeFactory class. 00140 BaseType *factory(Type t, const string &name); 00141 00142 // Common cleanup code for intern() and intern_stream() 00143 void cleanup_parse(xmlParserCtxtPtr &context) const; 00144 00151 void transfer_attrs(const char **attrs); 00152 bool check_required_attribute(const string &attr); 00153 bool check_attribute(const string & attr); 00154 00155 void process_attribute_element(const char **attrs); 00156 void process_attribute_alias(const char **attrs); 00157 00158 void process_variable(Type t, ParseState s, const char **attrs); 00159 00160 void process_dimension(const char **attrs); 00161 void process_blob(const char **attrs); 00162 00163 bool is_attribute_or_alias(const char *name, const char **attrs); 00164 bool is_variable(const char *name, const char **attrs); 00165 00166 void finish_variable(const char *tag, Type t, const char *expected); 00168 00170 DDXParser() 00171 {} 00172 00173 public: 00174 DDXParser(BaseTypeFactory *factory) : d_factory(factory) 00175 {} 00176 00177 void intern(const string &document, DDS *dest_dds); 00178 void intern_stream(FILE *in, DDS *dds); 00179 00180 static void ddx_start_document(DDXParser *parser); 00181 static void ddx_end_document(DDXParser *parser); 00182 static void ddx_start_element(DDXParser *parser, const char *name, 00183 const char **attrs); 00184 static void ddx_end_element(DDXParser *parser, const char *name); 00185 static void characters(DDXParser *parser, const xmlChar *ch, int len); 00186 static xmlEntityPtr ddx_get_entity(DDXParser *parser, 00187 const xmlChar *name); 00188 static void ddx_fatal_error(DDXParser *parser, const char *msg, ...); 00189 }; 00190 00191 } // namespace libdap 00192 00193 #endif // ddx_parser_h