bes  Updated for version 3.20.6
OtherXMLParser.h
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 class NCMLParser;
36 }
37 
38 namespace ncml_module {
39 
47 class OtherXMLParser: public SaxParser {
48 private:
49  // Disallow copy and assign
50  explicit OtherXMLParser(const OtherXMLParser& proto);
51  OtherXMLParser& operator=(const OtherXMLParser& rhs);
52 
53 public:
54  explicit OtherXMLParser(NCMLParser& p);
55  virtual ~OtherXMLParser();
56 
61  int getParseDepth() const;
62 
66  const std::string& getString() const;
67 
69  void reset();
70 
71  // These two calls are invalid for this class since it for parsing subtree
72  // They just throw exception.
73  virtual void onStartDocument();
74  virtual void onEndDocument();
75 
76  // This is the main calls, they just keep consing up a string with all the XML in it.
77  virtual void onStartElement(const std::string& name, const XMLAttributeMap& attrs);
78  virtual void onEndElement(const std::string& name);
79  virtual void onCharacters(const std::string& content);
80 
81  virtual void onStartElementWithNamespace(const std::string& localname, const std::string& prefix,
82  const std::string& uri, const XMLAttributeMap& attributes, const XMLNamespaceMap& namespaces);
83 
84  virtual void onEndElementWithNamespace(const std::string& localname, const std::string& prefix,
85  const std::string& uri);
86 
87  // Implemented to add explanation that the error occured
88  // within the OtherXML parse and not the NCMLParser.
89  virtual void onParseWarning(std::string msg);
90  virtual void onParseError(std::string msg);
91 
92 private:
93  // helpers
94 
95  // Add "<prefix:localname " or "<localname " to _otherXML
96  void appendOpenStartElementTag(const std::string& localname, const std::string& prefix);
97 
98  // For each attribute in attributes, append it to _otherXML
99  void appendAttributes(const XMLAttributeMap& attributes);
100 
101  // For each namespace in XMLNamespaceMap, append it to _otherXML
102  void appendNamespaces(const XMLNamespaceMap& namespaces);
103 
104  // Append ">" since we don't handle self-closing via sax
105  void appendCloseStartElementTag();
106 
107  // Append a </qname> to _otherXML
108  void appendEndElementTag(const string& qname);
109 
110  // Increase the depth
111  void pushDepth();
112 
113  // Decrease the depth checking for underflow and throw internal exception if so.
114  void popDepth();
115 
116 private:
117  // Data rep
118  NCMLParser& _rParser; // ref to the enclosing parser so we can get to its state if need be.
119  int _depth; // how many opened elements not closed yet, used to see if the subtree parse is complete
120  std::string _otherXML; // The current string with all the parsed elements and content appended into it
121 };
122 }
123 
124 #endif /* __NCML_MODULE__OTHER_XML_PARSER_H__ */
ncml_module::OtherXMLParser::getParseDepth
int getParseDepth() const
Definition: OtherXMLParser.cc:46
ncml_module::OtherXMLParser::onParseWarning
virtual void onParseWarning(std::string msg)
Definition: OtherXMLParser.cc:131
ncml_module::OtherXMLParser::getString
const std::string & getString() const
Definition: OtherXMLParser.cc:52
ncml_module::OtherXMLParser::reset
void reset()
Definition: OtherXMLParser.cc:57
ncml_module::OtherXMLParser::onEndElementWithNamespace
virtual void onEndElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri)
Definition: OtherXMLParser.cc:118
ncml_module::NCMLParser
Definition: NCMLParser.h:158
ncml_module::XMLAttributeMap
Definition: XMLHelpers.h:93
ncml_module::OtherXMLParser
Definition: OtherXMLParser.h:47
ncml_module::OtherXMLParser::onParseError
virtual void onParseError(std::string msg)
Definition: OtherXMLParser.cc:137
ncml_module
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...
Definition: AggregationElement.cc:72
ncml_module::OtherXMLParser::onStartElementWithNamespace
virtual void onStartElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri, const XMLAttributeMap &attributes, const XMLNamespaceMap &namespaces)
Definition: OtherXMLParser.cc:89
ncml_module::XMLNamespaceMap
Definition: XMLHelpers.h:150
ncml_module::SaxParser
Interface class for the wrapper between libxml C SAX parser and our NCMLParser.
Definition: SaxParser.h:48
ncml_module::OtherXMLParser::onStartElement
virtual void onStartElement(const std::string &name, const XMLAttributeMap &attrs)
Definition: OtherXMLParser.cc:73
ncml_module::OtherXMLParser::onCharacters
virtual void onCharacters(const std::string &content)
Definition: OtherXMLParser.cc:125
ncml_module::OtherXMLParser::onEndElement
virtual void onEndElement(const std::string &name)
Definition: OtherXMLParser.cc:83