ome-common 5.2.0-m2

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Document.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_DOCUMENT_H
40 #define OME_COMMON_XML_DOM_DOCUMENT_H
41
42 #include <ome/common/config.h>
43
44 #include <cassert>
45 #include <istream>
46 #include <string>
47 #include <ostream>
48
49 #include <xercesc/dom/DOMComment.hpp>
50 #include <xercesc/dom/DOMDocument.hpp>
51 #include <xercesc/dom/DOMNode.hpp>
52 #include <xercesc/parsers/XercesDOMParser.hpp>
53
54 #include <ome/common/filesystem.h>
55
56 #include <ome/compat/memory.h>
57
58 #include <ome/common/xml/dom/Element.h>
59 #include <ome/common/xml/dom/NodeList.h>
60 #include <ome/common/xml/dom/Wrapper.h>
61 #include <ome/common/xml/EntityResolver.h>
62 #include <ome/common/xml/String.h>
63
64 namespace ome
65 {
66 namespace common
67 {
68 namespace xml
69 {
73 namespace dom
74 {
75
83 class Document : public Wrapper<xercesc::DOMDocument, Node>
84 {
85 public:
89 Document ():
90 Wrapper<xercesc::DOMDocument, Node>()
91 {
92 }
93
99 Document (const Document& document):
100 Wrapper<xercesc::DOMDocument, Node>(document)
101 {
102 }
103
109 Document (const Wrapper<xercesc::DOMDocument, Node>::base_type& base):
110 Wrapper<xercesc::DOMDocument, Node>(base)
111 {
112 }
113
120 Document (Wrapper<xercesc::DOMDocument, Node>::element_type *document,
121 bool managed):
122 Wrapper<xercesc::DOMDocument, Node>(managed ?
123 Wrapper<xercesc::DOMDocument, Node>(document, std::mem_fun(&base_element_type::release)) :
124 Wrapper<xercesc::DOMDocument, Node>(document, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
125 {
126 }
127
134 Document (Wrapper<xercesc::DOMDocument, Node>::base_element_type *base,
135 bool managed):
136 Wrapper<xercesc::DOMDocument, Node>(managed ?
137 Wrapper<xercesc::DOMDocument, Node>(base, std::mem_fun(&base_element_type::release)) :
138 Wrapper<xercesc::DOMDocument, Node>(base, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
139 {
140 }
141
143 ~Document ()
144 {
145 }
146
153 Document&
154 operator= (const Document& wrapped)
155 {
156 Wrapper<xercesc::DOMDocument, Node>::operator=(wrapped);
157 return *this;
158 }
159
167 Element
168 createElementNS(const std::string& ns,
169 const std::string& name)
170 {
171 common::xml::String xns(ns);
172 common::xml::String xname(name);
173
174 return Element((*this)->createElementNS(xns, xname), false);
175 }
176
183 Node
184 createComment(const std::string& comment)
185 {
186 common::xml::String text(comment);
187
188 xercesc::DOMNode *node = dynamic_cast<xercesc::DOMNode *>((*this)->createComment(text));
189 return Node(node, false);
190 }
191
198 Element
199 createElement(const std::string& name)
200 {
201 common::xml::String xname(name);
202
203 return Element((*this)->createElement(xname), false);
204 }
205
211 Element
212 getDocumentElement()
213 {
214 return Element((*this)->getDocumentElement(), false);
215 }
216
223 NodeList
224 getElementsByTagName(const std::string& name)
225 {
226 return (*this)->getElementsByTagName(String(name));
227 }
228 };
229
245 struct ParseParameters
246 {
248 xercesc::XercesDOMParser::ValSchemes validationScheme;
250 bool doNamespaces;
252 bool doSchema;
254 bool handleMultipleImports;
256 bool validationSchemaFullChecking;
258 bool createEntityReferenceNodes;
259
261 ParseParameters():
262 validationScheme(xercesc::XercesDOMParser::Val_Auto),
263 doNamespaces(true),
264 doSchema(true),
265 handleMultipleImports(true),
266 validationSchemaFullChecking(true),
267 createEntityReferenceNodes(true)
268 {
269 }
270 };
271
278 Document
279 createEmptyDocument(const std::string& qualifiedName);
280
289 Document
290 createEmptyDocument(const std::string& namespaceURI,
291 const std::string& qualifiedName);
292
301 Document
302 createDocument(const boost::filesystem::path& file,
303 EntityResolver& resolver,
304 const ParseParameters& params = ParseParameters());
305
315 Document
316 createDocument(const std::string& text,
317 EntityResolver& resolver,
318 const ParseParameters& params = ParseParameters(),
319 const std::string& id = "membuf");
320
330 Document
331 createDocument(std::istream& stream,
332 EntityResolver& resolver,
333 const ParseParameters& params = ParseParameters(),
334 const std::string& id = "streambuf");
335
351 struct WriteParameters
352 {
354 bool canonicalForm;
356 bool CDATASections;
358 bool comments;
360 bool datatypeNormalization;
362 bool discardDefaultContent;
364 bool entities;
366 bool namespaces;
368 bool namespaceDeclarations;
370 bool normalizeCharacters;
372 bool prettyPrint;
374 bool splitCDATASections;
376 bool validate;
378 bool whitespace;
380 bool xmlDeclaration;
381
383 WriteParameters():
384 canonicalForm(false),
385 CDATASections(true),
386 comments(true),
387 datatypeNormalization(false),
388 discardDefaultContent(true),
389 entities(false),
390 namespaces(true),
391 namespaceDeclarations(true),
392 normalizeCharacters(false),
393 prettyPrint(false),
394 splitCDATASections(true),
395 validate(true),
396 whitespace(false),
397 xmlDeclaration(true)
398 {
399 }
400 };
401
409 void
410 writeNode(xercesc::DOMNode& node,
411 const boost::filesystem::path& file,
412 const WriteParameters& params = WriteParameters());
413
421 void
422 writeNode(xercesc::DOMNode& node,
423 std::ostream& stream,
424 const WriteParameters& params = WriteParameters());
425
433 void
434 writeNode(xercesc::DOMNode& node,
435 std::string& text,
436 const WriteParameters& params = WriteParameters());
437
445 void
446 writeNode(Node& node,
447 const boost::filesystem::path& file,
448 const WriteParameters& params = WriteParameters());
449
457 void
458 writeNode(Node& node,
459 std::ostream& stream,
460 const WriteParameters& params = WriteParameters());
461
469 void
470 writeNode(Node& node,
471 std::string& text,
472 const WriteParameters& params = WriteParameters());
473
481 void
482 writeDocument(Document& document,
483 const boost::filesystem::path& file,
484 const WriteParameters& params = WriteParameters());
485
493 void
494 writeDocument(Document& document,
495 std::ostream& stream,
496 const WriteParameters& params = WriteParameters());
497
505 void
506 writeDocument(Document& document,
507 std::string& text,
508 const WriteParameters& params = WriteParameters());
509
510 }
511 }
512 }
513 }
514
515 #endif // OME_COMMON_XML_DOM_DOCUMENT_H
516
517 /*
518 * Local Variables:
519 * mode:C++
520 * End:
521 */
ome::common::xml::dom::WriteParameters::discardDefaultContent
bool discardDefaultContent
Discard defaults (discard-default-content).
Definition: Document.h:362
ome::common::xml::dom::Document::createComment
Node createComment(const std::string &comment)
Create Comment.
Definition: Document.h:184
ome::common::xml::dom::WriteParameters::comments
bool comments
Retain comments (comments).
Definition: Document.h:358
ome::common::xml::dom::ParseParameters::doSchema
bool doSchema
Use schemas?
Definition: Document.h:252
ome::common::xml::dom::Wrapper< xercesc::DOMDocument, Node >::wrapped
element_type * wrapped
The wrapped type.
Definition: Wrapper.h:264
memory.h
Memory type substitution.
ome::common::xml::dom::WriteParameters::CDATASections
bool CDATASections
Retain CDATA (cdata-sections).
Definition: Document.h:356
ome::common::xml::dom::Wrapper
Xerces DOM class wrapper.
Definition: Wrapper.h:72
ome::common::xml::dom::WriteParameters::whitespace
bool whitespace
Retain whitespace (element-content-whitespace).
Definition: Document.h:378
ome::common::xml::dom::Node
DOM Node wrapper.
Definition: Node.h:68
ome::common::xml::dom::ParseParameters::doNamespaces
bool doNamespaces
Use namespaces?
Definition: Document.h:250
ome::common::xml::dom::Document
DOM Document wrapper.
Definition: Document.h:83
std
STL namespace.
ome::common::xml::dom::Element
DOM Element wrapper.
Definition: Element.h:66
ome::common::xml::dom::createDocument
Document createDocument(const boost::filesystem::path &file, EntityResolver &resolver, const ParseParameters &params)
Construct a Document from the content of a file.
Definition: Document.cpp:225
ome::common::xml::dom::WriteParameters::validate
bool validate
Validate if schema available (validate-if-schema).
Definition: Document.h:376
ome::common::xml::dom::WriteParameters::canonicalForm
bool canonicalForm
Canonicalize document (canonical-form).
Definition: Document.h:354
ome::common::xml::dom::WriteParameters::datatypeNormalization
bool datatypeNormalization
Datatype normalization (datatype-normalization).
Definition: Document.h:360
ome::common::xml::dom::Node::Node
Node()
Construct a NULL Node.
Definition: Node.h:77
ome::common::xml::dom::writeDocument
void writeDocument(Document &document, const boost::filesystem::path &file, const WriteParameters &params)
Write a Document to a file.
Definition: Document.cpp:361
ome::common::xml::dom::WriteParameters::entities
bool entities
Retain entities (entities).
Definition: Document.h:364
ome::common::xml::dom::WriteParameters::WriteParameters
WriteParameters()
Constructor.
Definition: Document.h:383
ome::common::xml::dom::Document::createElement
Element createElement(const std::string &name)
Create Element without namespace.
Definition: Document.h:199
ome::common::xml::EntityResolver
Xerces entity resolver.
Definition: EntityResolver.h:66
ome::common::xml::dom::Document::Document
Document(Wrapper< xercesc::DOMDocument, Node >::base_element_type *base, bool managed)
Construct a Document from a xercesc::DOMNode *.
Definition: Document.h:134
ome::common::xml::dom::WriteParameters::namespaces
bool namespaces
Namespace processing (namespaces).
Definition: Document.h:366
ome::common::xml::dom::Document::~Document
~Document()
Destructor.
Definition: Document.h:143
ome::common::xml::dom::ParseParameters::handleMultipleImports
bool handleMultipleImports
Handle multiple imports?
Definition: Document.h:254
ome::common::xml::dom::ParseParameters::createEntityReferenceNodes
bool createEntityReferenceNodes
Create entity reference nodes?
Definition: Document.h:258
filesystem.h
Boost.Filesystem compatibility.
ome::common::xml::dom::Document::Document
Document(const Wrapper< xercesc::DOMDocument, Node >::base_type &base)
Copy construct a Document.
Definition: Document.h:109
ome
Definition: boolean.h:48
ome::common::xml::dom::Document::Document
Document(const Document &document)
Copy construct a Document.
Definition: Document.h:99
ome::common::xml::dom::Document::Document
Document(Wrapper< xercesc::DOMDocument, Node >::element_type *document, bool managed)
Construct a Document from a xercesc::DOMDocument *.
Definition: Document.h:120
ome::common::xml::dom::WriteParameters::prettyPrint
bool prettyPrint
Pretty-print (format-pretty-print).
Definition: Document.h:372
ome::common::xml::dom::Document::getDocumentElement
Element getDocumentElement()
Get the root element of this document.
Definition: Document.h:212
ome::common::xml::dom::Document::operator=
Document & operator=(const Document &wrapped)
Assign a Document.
Definition: Document.h:154
ome::common::xml::dom::writeNode
void writeNode(xercesc::DOMNode &node, const boost::filesystem::path &file, const WriteParameters &params)
Write a Node to a file.
Definition: Document.cpp:293
ome::common::xml::dom::Wrapper::operator=
Wrapper & operator=(const Wrapper &wrapped)
Assign a Wrapper.
Definition: Wrapper.h:208
ome::common::xml::dom::Document::Document
Document()
Construct a NULL Document.
Definition: Document.h:89
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::dom::Document::getElementsByTagName
NodeList getElementsByTagName(const std::string &name)
Get child elements with a given tag name.
Definition: Document.h:224
ome::common::xml::String
Xerces string wrapper.
Definition: String.h:74
ome::common::xml::dom::ParseParameters::ParseParameters
ParseParameters()
Constructor.
Definition: Document.h:261
ome::common::xml::dom::WriteParameters::xmlDeclaration
bool xmlDeclaration
Require XML declaration (xml-declaration).
Definition: Document.h:380
ome::common::xml::dom::WriteParameters::normalizeCharacters
bool normalizeCharacters
Normalize characters.
Definition: Document.h:370
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::ParseParameters::validationSchemaFullChecking
bool validationSchemaFullChecking
Do full checking during validation?
Definition: Document.h:256
ome::common::xml::dom::Document::createElementNS
Element createElementNS(const std::string &ns, const std::string &name)
Create Element with namespace.
Definition: Document.h:168
ome::common::xml::dom::ParseParameters
Parameters controlling DOM writing.
Definition: Document.h:245
ome::common::xml::dom::WriteParameters::splitCDATASections
bool splitCDATASections
Split CDATA sections (split-cdata-sections).
Definition: Document.h:374
ome::common::xml::dom::WriteParameters
Parameters controlling DOM writing.
Definition: Document.h:351
ome::common::xml::dom::ParseParameters::validationScheme
xercesc::XercesDOMParser::ValSchemes validationScheme
Validation scheme.
Definition: Document.h:248
ome::common::xml::dom::createEmptyDocument
Document createEmptyDocument(const std::string &qualifiedName)
Construct an empty Document.
Definition: Document.cpp:200
ome::common::xml::dom::WriteParameters::namespaceDeclarations
bool namespaceDeclarations
Include namespace declaration attributes (namespace-declarations).
Definition: Document.h:368