OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
OtherXMLParser.h
Go to the documentation of this file.
1 // This file is part of the "NcML Module" project, a BES module designed
3 // to allow NcML files to be used to be used as a wrapper to add
4 // AIS to existing datasets of any format.
5 //
6 // Copyright (c) 2009 OPeNDAP, Inc.
7 // Author: Michael Johnson <m.johnson@opendap.org>
8 //
9 // For more information, please also see the main website: http://opendap.org/
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public
22 // License along with this library; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 // Please see the files COPYING and COPYRIGHT for more information on the GLPL.
26 //
27 // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
29 #ifndef __NCML_MODULE__OTHER_XML_PARSER_H__
30 #define __NCML_MODULE__OTHER_XML_PARSER_H__
31 
32 #include "SaxParser.h" // super
33 
34 namespace ncml_module
35 {
36  class NCMLParser;
37 }
38 
39 namespace ncml_module
40 {
41 
49  class OtherXMLParser : public SaxParser
50  {
51  private: // Disallow copy and assign
52  explicit OtherXMLParser(const OtherXMLParser& proto);
53  OtherXMLParser& operator=(const OtherXMLParser& rhs);
54 
55  public:
56  explicit OtherXMLParser(NCMLParser& p);
57  virtual ~OtherXMLParser();
58 
63  int getParseDepth() const;
64 
68  const std::string& getString() const;
69 
71  void reset();
72 
73  // These two calls are invalid for this class since it for parsing subtree
74  // They just throw exception.
75  virtual void onStartDocument();
76  virtual void onEndDocument();
77 
78  // This is the main calls, they just keep consing up a string with all the XML in it.
79  virtual void onStartElement(const std::string& name, const XMLAttributeMap& attrs);
80  virtual void onEndElement(const std::string& name);
81  virtual void onCharacters(const std::string& content);
82 
83  virtual void onStartElementWithNamespace(
84  const std::string& localname ,
85  const std::string& prefix,
86  const std::string& uri,
87  const XMLAttributeMap& attributes,
88  const XMLNamespaceMap& namespaces);
89 
90  virtual void onEndElementWithNamespace(
91  const std::string& localname,
92  const std::string& prefix,
93  const std::string& uri);
94 
95  // Implemented to add explanation that the error occured
96  // within the OtherXML parse and not the NCMLParser.
97  virtual void onParseWarning(std::string msg);
98  virtual void onParseError(std::string msg);
99 
100  private: // helpers
101 
102  // Add "<prefix:localname " or "<localname " to _otherXML
103  void appendOpenStartElementTag(const std::string& localname, const std::string& prefix);
104 
105  // For each attribute in attributes, append it to _otherXML
106  void appendAttributes(const XMLAttributeMap& attributes);
107 
108  // For each namespace in XMLNamespaceMap, append it to _otherXML
109  void appendNamespaces(const XMLNamespaceMap& namespaces);
110 
111  // Append ">" since we don't handle self-closing via sax
112  void appendCloseStartElementTag();
113 
114  // Append a </qname> to _otherXML
115  void appendEndElementTag(const string& qname);
116 
117  // Increase the depth
118  void pushDepth();
119 
120  // Decrease the depth checking for underflow and throw internal exception if so.
121  void popDepth();
122 
123  private: // Data rep
124  NCMLParser& _rParser; // ref to the enclosing parser so we can get to its state if need be.
125  int _depth; // how many opened elements not closed yet, used to see if the subtree parse is complete
126  std::string _otherXML; // The current string with all the parsed elements and content appended into it
127  };
128 }
129 
130 #endif /* __NCML_MODULE__OTHER_XML_PARSER_H__ */
int getParseDepth() const
Get the current parse depth (how many elements we've opened with onStartElement and not closed yet) I...
virtual void onParseWarning(std::string msg)
A recoverable parse error occured.
An abstract superclass for NCMLArray that handles the non-parameterized functionality and allows u...
virtual void onEndElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri)
SAX2 End element with namespace information.
virtual void onStartElement(const std::string &name, const XMLAttributeMap &attrs)
const std::string & getString() const
Get the parsed data as big string that we've been parsing in.
virtual void onCharacters(const std::string &content)
Called when characters are encountered within an element.
Class used to handle parsing in an attribute of type=="OtherXML" which basically just has to keep app...
void reset()
Reset the string and depth so we can start parsing from scratch again.
virtual void onStartElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri, const XMLAttributeMap &attributes, const XMLNamespaceMap &namespaces)
SAX2 start element call with gets namespace information.
virtual void onEndElement(const std::string &name)
Interface class for the wrapper between libxml C SAX parser and our NCMLParser.
Definition: SaxParser.h:49
virtual void onParseError(std::string msg)
An unrecoverable parse error occurred.