ome-common  5.5.0
Node.h
1 /*
2  * #%L
3  * OME-XERCES C++ library for working with Xerces C++.
4  * %%
5  * Copyright © 2006 - 2015 Open Microscopy Environment:
6  * - Massachusetts Institute of Technology
7  * - National Institutes of Health
8  * - University of Dundee
9  * - Board of Regents of the University of Wisconsin-Madison
10  * - Glencoe Software, Inc.
11  * %%
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright notice,
16  * this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright notice,
18  * this list of conditions and the following disclaimer in the documentation
19  * and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * The views and conclusions contained in the software and documentation are
34  * those of the authors and should not be interpreted as representing official
35  * policies, either expressed or implied, of any organization.
36  * #L%
37  */
38 
39 #ifndef OME_COMMON_XML_DOM_NODE_H
40 #define OME_COMMON_XML_DOM_NODE_H
41 
42 #include <functional>
43 
44 #include <ome/common/config.h>
45 
46 #include <ome/common/xml/String.h>
47 #include <ome/common/xml/dom/Base.h>
48 #include <ome/common/xml/dom/NodeList.h>
49 #include <ome/common/xml/dom/NamedNodeMap.h>
50 #include <ome/common/xml/dom/Wrapper.h>
51 
52 #include <xercesc/dom/DOMNode.hpp>
53 
54 namespace ome
55 {
56  namespace common
57  {
58  namespace xml
59  {
60  namespace dom
61  {
62 
70  class Node : public Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>
71  {
72  public:
74  typedef xercesc::DOMNode::NodeType node_type;
75 
79  Node ():
80  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>()
81  {
82  }
83 
89  Node (const Node& node):
90  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>(node)
91  {
92  }
93 
100  Node (xercesc::DOMNode *node,
101  bool managed):
102  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>(managed ?
103  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>(node, std::mem_fun(&base_element_type::release)) :
104  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode>>(node, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
105  {
106  }
107 
109  ~Node ()
110  {
111  }
112 
119  Node
121  {
122  // TODO: Catch and rethrow xerces exceptions with the xerces
123  // errors converted to sane descriptions. And additionally
124  // for all other xerces methods which throw.
125  return Node((*this)->appendChild(node.get()), false);
126  }
127 
133  node_type
135  {
136  return (*this)->getNodeType();
137  }
138 
144  NodeList
146  {
147  return NodeList((*this)->getChildNodes());
148  }
149 
157  {
158  return NamedNodeMap((*this)->getAttributes());
159  }
160 
166  std::string
168  {
169  return String((*this)->getNodeValue());
170  }
171 
177  std::string
179  {
180  return String((*this)->getTextContent());
181  }
182  };
183 
184  }
185  }
186  }
187 }
188 
189 #endif // OME_COMMON_XML_DOM_NODE_H
190 
191 /*
192  * Local Variables:
193  * mode:C++
194  * End:
195  */
NamedNodeMap getAttributes()
Get node attributes.
Definition: Node.h:156
Xerces DOM class wrapper.
Definition: Wrapper.h:72
Node appendChild(Node &node)
Append a child Node.
Definition: Node.h:120
DOM Node wrapper.
Definition: Node.h:70
STL namespace.
xercesc::DOMNode::NodeType node_type
The derived object type of a node.
Definition: Node.h:74
Node(const Node &node)
Copy construct a Node.
Definition: Node.h:89
Node()
Construct a NULL Node.
Definition: Node.h:79
~Node()
Destructor.
Definition: Node.h:109
std::string getNodeValue()
Get node value.
Definition: Node.h:167
NodeList getChildNodes()
Get child nodes.
Definition: Node.h:145
Open Microscopy Environment C++.
Definition: base64.h:48
DOM NamedNodeMap wrapper.
Definition: NamedNodeMap.h:69
node_type getNodeType()
Get the object type of this node.
Definition: Node.h:134
Base of the DOM wrapper hierarchy.
Definition: Base.h:76
xercesc::DOMNode base_element_type
Base element type (root type of the wrapped type).
Definition: Base.h:82
Xerces string wrapper.
Definition: String.h:74
DOM NodeList wrapper.
Definition: NodeList.h:69
Node(xercesc::DOMNode *node, bool managed)
Construct a Node from a xercesc::DOMNode *.
Definition: Node.h:100
std::string getTextContent()
Get node text content.
Definition: Node.h:178
element_type * get()
Get wrapped element_type *.
Definition: Wrapper.h:155