ome-common  5.5.0
Element.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_ELEMENT_H
40 #define OME_COMMON_XML_DOM_ELEMENT_H
41 
42 #include <functional>
43 #include <string>
44 
45 #include <xercesc/dom/DOMElement.hpp>
46 
47 #include <ome/common/xml/String.h>
48 #include <ome/common/xml/dom/Node.h>
49 #include <ome/common/xml/dom/Wrapper.h>
50 
51 namespace ome
52 {
53  namespace common
54  {
55  namespace xml
56  {
57  namespace dom
58  {
59 
67  class Element : public Wrapper<xercesc::DOMElement, Node>
68  {
69  public:
73  Element ():
74  Wrapper<xercesc::DOMElement, Node>()
75  {
76  }
77 
83  Element (const Element& element):
84  Wrapper<xercesc::DOMElement, Node>(element)
85  {
86  }
87 
94  Wrapper<xercesc::DOMElement, Node>(base)
95  {
96  }
97 
104  Element (xercesc::DOMElement *element,
105  bool managed):
106  Wrapper<xercesc::DOMElement, Node>(managed ?
107  Wrapper<xercesc::DOMElement, Node>(element, std::mem_fun(&base_element_type::release)) :
108  Wrapper<xercesc::DOMElement, Node>(element, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
109  {
110  }
111 
119  bool managed):
120  Wrapper<xercesc::DOMElement, Node>(managed ?
121  Wrapper<xercesc::DOMElement, Node>(base, std::mem_fun(&base_element_type::release)) :
122  Wrapper<xercesc::DOMElement, Node>(base, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
123  {
124  }
125 
128  {
129  }
130 
136  String
137  getTagName () const
138  {
139  return (*this)->getTagName();
140  }
141 
148  NodeList
149  getElementsByTagName(const std::string& name)
150  {
151  return (*this)->getElementsByTagName(String(name));
152  }
153 
161  bool
162  hasAttribute (const std::string& attr) const
163  {
164  return (*this)->hasAttribute(common::xml::String(attr));
165  }
166 
173  String
174  getAttribute (const std::string& attr) const
175  {
176  return (*this)->getAttribute(common::xml::String(attr));
177  }
178 
185  void
186  setAttribute (const std::string& attr,
187  const std::string& val)
188  {
189  return (*this)->setAttribute(common::xml::String(attr),
190  common::xml::String(val));
191  }
192 
198  String
199  getTextContent () const
200  {
201  return (*this)->getTextContent();
202  }
203 
209  void
210  setTextContent (const std::string& val)
211  {
212  return (*this)->setTextContent(common::xml::String(val));
213  }
214  };
215 
216  }
217  }
218  }
219 }
220 
221 #endif // OME_COMMON_XML_DOM_ELEMENT_H
222 
223 /*
224  * Local Variables:
225  * mode:C++
226  * End:
227  */
String getTagName() const
Get Element tag name.
Definition: Element.h:137
bool hasAttribute(const std::string &attr) const
Check if the Element has the specified attribute.
Definition: Element.h:162
std::shared_ptr< base_element_type > base
Wrapped reference.
Definition: Base.h:253
Xerces DOM class wrapper.
Definition: Wrapper.h:72
Element(const Wrapper< xercesc::DOMElement, Node >::base_type &base)
Copy construct an Element.
Definition: Element.h:93
DOM Node wrapper.
Definition: Node.h:70
void setTextContent(const std::string &val)
Set Element text content.
Definition: Element.h:210
void setAttribute(const std::string &attr, const std::string &val)
Set the specified attribute value.
Definition: Element.h:186
STL namespace.
DOM Element wrapper.
Definition: Element.h:67
Element(Wrapper< xercesc::DOMElement, Node >::base_element_type *base, bool managed)
Construct an Element from a xercesc::DOMNode *.
Definition: Element.h:118
NodeList getElementsByTagName(const std::string &name)
Get child elements with a given tag name.
Definition: Element.h:149
Open Microscopy Environment C++.
Definition: base64.h:48
~Element()
Destructor.
Definition: Element.h:127
Element(const Element &element)
Copy construct an Element.
Definition: Element.h:83
String getAttribute(const std::string &attr) const
Get the specified attribute value.
Definition: Element.h:174
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
String getTextContent() const
Get Element text content.
Definition: Element.h:199
DOM NodeList wrapper.
Definition: NodeList.h:69
Element()
Construct a NULL Element.
Definition: Element.h:73
Element(xercesc::DOMElement *element, bool managed)
Construct an Element from a xercesc::DOMElement *.
Definition: Element.h:104