bes Updated for version 3.21.1
The Backend Server (BES) is the lower two tiers of the Hyrax data server
OtherXMLParser.h
1
2// 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
34namespace ncml_module {
35class NCMLParser;
36}
37
38namespace ncml_module {
39
47class OtherXMLParser: public SaxParser {
48private:
49 // Disallow copy and assign
50 explicit OtherXMLParser(const OtherXMLParser& proto);
51 OtherXMLParser& operator=(const OtherXMLParser& rhs);
52
53public:
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
92private:
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
116private:
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__ */
virtual void onStartElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri, const XMLAttributeMap &attributes, const XMLNamespaceMap &namespaces)
const std::string & getString() const
virtual void onParseWarning(std::string msg)
virtual void onParseError(std::string msg)
virtual void onEndElement(const std::string &name)
virtual void onStartElement(const std::string &name, const XMLAttributeMap &attrs)
virtual void onCharacters(const std::string &content)
virtual void onEndElementWithNamespace(const std::string &localname, const std::string &prefix, const std::string &uri)
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...