ome-common 5.3.2

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