libdap++ Updated for version 3.8.2
|
#include <DDXParserSAX2.h>
Classes | |
class | XMLAttribute |
Public Member Functions | |
DDXParser (BaseTypeFactory *factory) | |
void | intern (const string &document, DDS *dest_dds, string &cid) |
void | intern_stream (FILE *in, DDS *dds, string &cid, const string &boundary="") |
Read the DDX from a stream instead of a file. | |
Static Public Member Functions | |
SAX Parser Callbacks | |
These methods are declared static in the class header. This gives them C linkage which allows them to be used as callbacks by the SAX parser engine. | |
static void | ddx_start_document (void *parser) |
static void | ddx_end_document (void *parser) |
static void | ddx_sax2_start_element (void *parser, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI, int nb_namespaces, const xmlChar **namespaces, int nb_attributes, int nb_defaulted, const xmlChar **attributes) |
static void | ddx_sax2_end_element (void *parser, const xmlChar *localname, const xmlChar *prefix, const xmlChar *URI) |
static void | ddx_get_characters (void *parser, const xmlChar *ch, int len) |
static void | ddx_ignoreable_whitespace (void *parser, const xmlChar *ch, int len) |
static void | ddx_get_cdata (void *parser, const xmlChar *value, int len) |
static xmlEntityPtr | ddx_get_entity (void *parser, const xmlChar *name) |
static void | ddx_fatal_error (void *parser, const char *msg,...) |
Friends | |
class | DDXParserTest |
Parse the XML text which encodes the network/persistent representation of the DDX object. In the current implementation, the DDX is held by an instance of the class DDS which in turn holds variables which include attributes. That is, the binary implementation of a DDX uses the old DDS, BaseType and AttrTable classes, albeit arranged in a slightly new way.
This parser for the DDX document uses the SAX interface of libxml2
. Static methods are used as callbacks for the SAX parser. These static methods are public because making them private complicates compilation. They should not be called by anything other than the intern method. They do not throw exceptions because exceptions from within callbacks are not reliable or portable. To signal errors, the methods record information in the DDXParser object. Once the error handler is called, construction of an DDX/DDS object ends even though the SAX parser still calls the various callback functions. The parser treats warnings, errors and fatal_errors the same way; when any are found parsing stops. The intern method throws an DDXParseFailed exception if an error was found.
Note that this class uses the C++-supplied default definitions for the default and copy constructors as well as the destructor and assignment operator.
Definition at line 79 of file DDXParserSAX2.h.
libdap::DDXParser::DDXParser | ( | BaseTypeFactory * | factory | ) | [inline] |
Definition at line 234 of file DDXParserSAX2.h.
void libdap::DDXParser::ddx_end_document | ( | void * | p | ) | [static] |
Clean up after finishing a parse.
parser | The SAX parser |
Definition at line 540 of file DDXParserSAX2.cc.
References libdap::DDS::add_var(), DBG2, ddx_fatal_error(), libdap::Constructor::var_begin(), and libdap::Constructor::var_end().
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_fatal_error | ( | void * | p, |
const char * | msg, | ||
... | |||
) | [static] |
Process an XML fatal error. Note that SAX provides for warnings, errors and fatal errors. This code treats them all as fatal errors since there's typically no way to tell a user about the error since there's often no user interface for this software.
parser | The SAX parser |
msg | A printf-style format string. |
Definition at line 1056 of file DDXParserSAX2.cc.
References libdap::long_to_string().
Referenced by ddx_end_document(), ddx_get_cdata(), ddx_sax2_end_element(), ddx_sax2_start_element(), intern(), and intern_stream().
void libdap::DDXParser::ddx_get_cdata | ( | void * | p, |
const xmlChar * | value, | ||
int | len | ||
) | [static] |
Get characters in a cdata block. DAP does not use CData, but XML in an OtherXML attribute (the value of that DAP attribute) might use it. This callback also allows CData when the parser is in the 'parser_unknown' state since some future DAP element might use it.
Definition at line 1020 of file DDXParserSAX2.cc.
References ddx_fatal_error().
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_get_characters | ( | void * | p, |
const xmlChar * | ch, | ||
int | len | ||
) | [static] |
Process/accumulate character data. This may be called more than once for one logical clump of data. Only save character data when processing 'value' elements; throw away all other characters.
Definition at line 976 of file DDXParserSAX2.cc.
References DBG2.
Referenced by intern(), and intern_stream().
xmlEntityPtr libdap::DDXParser::ddx_get_entity | ( | void * | parser, |
const xmlChar * | name | ||
) | [static] |
Handle the standard XML entities.
parser | The SAX parser |
name | The XML entity. |
Definition at line 1044 of file DDXParserSAX2.cc.
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_ignoreable_whitespace | ( | void * | p, |
const xmlChar * | ch, | ||
int | len | ||
) | [static] |
Read whitespace that's not really important for content. This is used only for the OtherXML attribute type to preserve formating of the XML. Doing so makes the attribute value far easier to read.
Definition at line 1000 of file DDXParserSAX2.cc.
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_sax2_end_element | ( | void * | parser, |
const xmlChar * | localname, | ||
const xmlChar * | prefix, | ||
const xmlChar * | URI | ||
) | [static] |
Definition at line 798 of file DDXParserSAX2.cc.
References libdap::BaseType::add_var(), libdap::AttrTable::append_attr(), DBG2, DBGN, ddx_fatal_error(), libdap::dods_array_c, libdap::dods_grid_c, libdap::dods_null_c, libdap::dods_sequence_c, libdap::dods_structure_c, libdap::BaseType::is_constructor_type(), and libdap::BaseType::is_vector_type().
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_sax2_start_element | ( | void * | parser, |
const xmlChar * | localname, | ||
const xmlChar * | prefix, | ||
const xmlChar * | URI, | ||
int | nb_namespaces, | ||
const xmlChar ** | namespaces, | ||
int | nb_attributes, | ||
int | nb_defaulted, | ||
const xmlChar ** | attributes | ||
) | [static] |
Definition at line 569 of file DDXParserSAX2.cc.
References DBG2, DBGN, ddx_fatal_error(), libdap::dods_array_c, libdap::DDS::set_dap_version(), and libdap::DDS::set_dataset_name().
Referenced by intern(), and intern_stream().
void libdap::DDXParser::ddx_start_document | ( | void * | p | ) | [static] |
Initialize the SAX parser state object. This object is passed to each callback as a void pointer. The initial state is parser_start.
parser | The SAX parser |
Definition at line 519 of file DDXParserSAX2.cc.
References DBG2, and libdap::DDS::get_attr_table().
Referenced by intern(), and intern_stream().
void libdap::DDXParser::intern | ( | const string & | document, |
DDS * | dest_dds, | ||
string & | cid | ||
) |
Parse a DDX document stored in a file. The XML in the document is parsed and a binary DDX is built. This implementation stores the result in a DDS object where each instance of BaseType can hold an AttrTable object.
document | Read the DDX from this file. |
dest_dds | Value/result parameter; dumps the information to this DDS instance. |
cid | Value/result parameter; puts the href which references the CID . |
DDXParseFailed | Thrown if the XML document could not be read or parsed. |
Definition at line 1172 of file DDXParserSAX2.cc.
References ddx_end_document(), ddx_fatal_error(), ddx_get_cdata(), ddx_get_characters(), ddx_get_entity(), ddx_ignoreable_whitespace(), ddx_sax2_end_element(), ddx_sax2_start_element(), and ddx_start_document().
void libdap::DDXParser::intern_stream | ( | FILE * | in, |
DDS * | dest_dds, | ||
string & | cid, | ||
const string & | boundary = "" |
||
) |
Definition at line 1107 of file DDXParserSAX2.cc.
References DBG, ddx_end_document(), ddx_fatal_error(), ddx_get_cdata(), ddx_get_characters(), ddx_get_entity(), ddx_ignoreable_whitespace(), ddx_sax2_end_element(), ddx_sax2_start_element(), ddx_start_document(), and libdap::is_boundary().
Referenced by libdap::Connect::request_ddx(), and libdap::Connect::request_ddx_url().
friend class DDXParserTest [friend] |
Definition at line 231 of file DDXParserSAX2.h.