bioformats  5.1.6
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 <ome/common/config.h>
43 
44 #include <ome/common/xml/String.h>
45 #include <ome/common/xml/dom/Base.h>
46 #include <ome/common/xml/dom/NodeList.h>
47 #include <ome/common/xml/dom/NamedNodeMap.h>
48 #include <ome/common/xml/dom/Wrapper.h>
49 
50 #include <xercesc/dom/DOMNode.hpp>
51 
52 namespace ome
53 {
54  namespace common
55  {
56  namespace xml
57  {
58  namespace dom
59  {
60 
68  class Node : public Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >
69  {
70  public:
72  typedef xercesc::DOMNode::NodeType node_type;
73 
77  Node ():
78  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >()
79  {
80  }
81 
87  Node (const Node& node):
88  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >(node)
89  {
90  }
91 
98  Node (xercesc::DOMNode *node,
99  bool managed):
100  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >(managed ?
101  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >(node, std::mem_fun(&base_element_type::release)) :
102  Wrapper<xercesc::DOMNode, Base<xercesc::DOMNode> >(node, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
103  {
104  }
105 
107  ~Node ()
108  {
109  }
110 
117  Node
119  {
120  // TODO: Catch and rethrow xerces exceptions with the xerces
121  // errors converted to sane descriptions. And additionally
122  // for all other xerces methods which throw.
123  return Node((*this)->appendChild(node.get()), false);
124  }
125 
131  node_type
133  {
134  return (*this)->getNodeType();
135  }
136 
142  NodeList
144  {
145  return NodeList((*this)->getChildNodes());
146  }
147 
155  {
156  return NamedNodeMap((*this)->getAttributes());
157  }
158 
164  std::string
166  {
167  return String((*this)->getNodeValue());
168  }
169 
175  std::string
177  {
178  return String((*this)->getTextContent());
179  }
180  };
181 
182  }
183  }
184  }
185 }
186 
187 #endif // OME_COMMON_XML_DOM_NODE_H
188 
189 /*
190  * Local Variables:
191  * mode:C++
192  * End:
193  */
NamedNodeMap getAttributes()
Get node attributes.
Definition: Node.h:154
Xerces DOM class wrapper.
Definition: Wrapper.h:72
Node appendChild(Node &node)
Append a child Node.
Definition: Node.h:118
DOM Node wrapper.
Definition: Node.h:68
STL namespace.
xercesc::DOMNode::NodeType node_type
The derived object type of a node.
Definition: Node.h:72
Node(const Node &node)
Copy construct a Node.
Definition: Node.h:87
Node()
Construct a NULL Node.
Definition: Node.h:77
~Node()
Destructor.
Definition: Node.h:107
std::string getNodeValue()
Get node value.
Definition: Node.h:165
NodeList getChildNodes()
Get child nodes.
Definition: Node.h:143
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
DOM NamedNodeMap wrapper.
Definition: NamedNodeMap.h:69
node_type getNodeType()
Get the object type of this node.
Definition: Node.h:132
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:98
std::string getTextContent()
Get node text content.
Definition: Node.h:176
element_type * get()
Get wrapped element_type *.
Definition: Wrapper.h:155
Xerces-C modern C++ wrapper.
Definition: Base.h:53