bioformats  5.1.2
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/String.h>
62 
63 namespace ome
64 {
65  namespace common
66  {
67  namespace xml
68  {
72  namespace dom
73  {
74 
82  class Document : public Wrapper<xercesc::DOMDocument, Node>
83  {
84  public:
89  Wrapper<xercesc::DOMDocument, Node>()
90  {
91  }
92 
98  Document (const Document& document):
99  Wrapper<xercesc::DOMDocument, Node>(document)
100  {
101  }
102 
109  Wrapper<xercesc::DOMDocument, Node>(base)
110  {
111  }
112 
120  bool managed):
121  Wrapper<xercesc::DOMDocument, Node>(managed ?
122  Wrapper<xercesc::DOMDocument, Node>(document, std::mem_fun(&base_element_type::release)) :
123  Wrapper<xercesc::DOMDocument, Node>(document, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
124  {
125  }
126 
134  bool managed):
135  Wrapper<xercesc::DOMDocument, Node>(managed ?
136  Wrapper<xercesc::DOMDocument, Node>(base, std::mem_fun(&base_element_type::release)) :
137  Wrapper<xercesc::DOMDocument, Node>(base, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
138  {
139  }
140 
143  {
144  }
145 
152  Document&
154  {
156  return *this;
157  }
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
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 
246  {
248  xercesc::XercesDOMParser::ValSchemes validationScheme;
252  bool doSchema;
259 
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 
300  Document
301  createDocument(const boost::filesystem::path& file,
302  const ParseParameters& params = ParseParameters());
303 
312  Document
313  createDocument(const std::string& text,
314  const ParseParameters& params = ParseParameters(),
315  const std::string& id = "membuf");
316 
325  Document
326  createDocument(std::istream& stream,
327  const ParseParameters& params = ParseParameters(),
328  const std::string& id = "streambuf");
329 
346  {
352  bool comments;
358  bool entities;
370  bool validate;
375 
378  canonicalForm(false),
379  CDATASections(true),
380  comments(true),
381  datatypeNormalization(false),
382  discardDefaultContent(true),
383  entities(false),
384  namespaces(true),
385  namespaceDeclarations(true),
386  normalizeCharacters(false),
387  prettyPrint(false),
388  splitCDATASections(true),
389  validate(true),
390  whitespace(false),
391  xmlDeclaration(true)
392  {
393  }
394  };
395 
403  void
404  writeNode(xercesc::DOMNode& node,
405  const boost::filesystem::path& file,
406  const WriteParameters& params = WriteParameters());
407 
415  void
416  writeNode(xercesc::DOMNode& node,
417  std::ostream& stream,
418  const WriteParameters& params = WriteParameters());
419 
427  void
428  writeNode(xercesc::DOMNode& node,
429  std::string& text,
430  const WriteParameters& params = WriteParameters());
431 
439  void
440  writeNode(Node& node,
441  const boost::filesystem::path& file,
442  const WriteParameters& params = WriteParameters());
443 
451  void
452  writeNode(Node& node,
453  std::ostream& stream,
454  const WriteParameters& params = WriteParameters());
455 
463  void
464  writeNode(Node& node,
465  std::string& text,
466  const WriteParameters& params = WriteParameters());
467 
475  void
476  writeDocument(Document& document,
477  const boost::filesystem::path& file,
478  const WriteParameters& params = WriteParameters());
479 
487  void
488  writeDocument(Document& document,
489  std::ostream& stream,
490  const WriteParameters& params = WriteParameters());
491 
499  void
500  writeDocument(Document& document,
501  std::string& text,
502  const WriteParameters& params = WriteParameters());
503 
504  }
505  }
506  }
507 }
508 
509 #endif // OME_COMMON_XML_DOM_DOCUMENT_H
510 
511 /*
512  * Local Variables:
513  * mode:C++
514  * End:
515  */
bool discardDefaultContent
Discard defaults (discard-default-content).
Definition: Document.h:356
Node createComment(const std::string &comment)
Create Comment.
Definition: Document.h:184
bool comments
Retain comments (comments).
Definition: Document.h:352
bool doSchema
Use schemas?
Definition: Document.h:252
element_type * wrapped
The wrapped type.
Definition: Wrapper.h:264
Memory type substitution.
bool CDATASections
Retain CDATA (cdata-sections).
Definition: Document.h:350
Xerces DOM class wrapper.
Definition: Wrapper.h:72
bool whitespace
Retain whitespace (element-content-whitespace).
Definition: Document.h:372
DOM Node wrapper.
Definition: Node.h:68
bool doNamespaces
Use namespaces?
Definition: Document.h:250
DOM Document wrapper.
Definition: Document.h:82
STL namespace.
DOM Element wrapper.
Definition: Element.h:66
bool validate
Validate if schema available (validate-if-schema).
Definition: Document.h:370
bool canonicalForm
Canonicalize document (canonical-form).
Definition: Document.h:348
bool datatypeNormalization
Datatype normalization (datatype-normalization).
Definition: Document.h:354
Node()
Construct a NULL Node.
Definition: Node.h:77
void writeDocument(Document &document, const boost::filesystem::path &file, const WriteParameters &params)
Write a Document to a file.
Definition: Document.cpp:358
bool entities
Retain entities (entities).
Definition: Document.h:358
WriteParameters()
Constructor.
Definition: Document.h:377
Element createElement(const std::string &name)
Create Element without namespace.
Definition: Document.h:199
Document(Wrapper< xercesc::DOMDocument, Node >::base_element_type *base, bool managed)
Construct a Document from a xercesc::DOMNode *.
Definition: Document.h:133
bool namespaces
Namespace processing (namespaces).
Definition: Document.h:360
~Document()
Destructor.
Definition: Document.h:142
bool handleMultipleImports
Handle multiple imports?
Definition: Document.h:254
bool createEntityReferenceNodes
Create entity reference nodes?
Definition: Document.h:258
Boost.Filesystem compatibility.
Document(const Wrapper< xercesc::DOMDocument, Node >::base_type &base)
Copy construct a Document.
Definition: Document.h:108
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
Document(const Document &document)
Copy construct a Document.
Definition: Document.h:98
Document(Wrapper< xercesc::DOMDocument, Node >::element_type *document, bool managed)
Construct a Document from a xercesc::DOMDocument *.
Definition: Document.h:119
bool prettyPrint
Pretty-print (format-pretty-print).
Definition: Document.h:366
Element getDocumentElement()
Get the root element of this document.
Definition: Document.h:212
Document & operator=(const Document &wrapped)
Assign a Document.
Definition: Document.h:153
void writeNode(xercesc::DOMNode &node, const boost::filesystem::path &file, const WriteParameters &params)
Write a Node to a file.
Definition: Document.cpp:290
Wrapper & operator=(const Wrapper &wrapped)
Assign a Wrapper.
Definition: Wrapper.h:208
Document()
Construct a NULL Document.
Definition: Document.h:88
Document createDocument(const boost::filesystem::path &file, const ParseParameters &params)
Construct a Document from the content of a file.
Definition: Document.cpp:225
xercesc::DOMNode base_element_type
Base element type (root type of the wrapped type).
Definition: Base.h:82
NodeList getElementsByTagName(const std::string &name)
Get child elements with a given tag name.
Definition: Document.h:224
Xerces string wrapper.
Definition: String.h:74
ParseParameters()
Constructor.
Definition: Document.h:261
bool xmlDeclaration
Require XML declaration (xml-declaration).
Definition: Document.h:374
bool normalizeCharacters
Normalize characters.
Definition: Document.h:364
ome::compat::shared_ptr< base_element_type > base
Wrapped reference.
Definition: Base.h:231
DOM NodeList wrapper.
Definition: NodeList.h:69
bool validationSchemaFullChecking
Do full checking during validation?
Definition: Document.h:256
Element createElementNS(const std::string &ns, const std::string &name)
Create Element with namespace.
Definition: Document.h:168
Parameters controlling DOM writing.
Definition: Document.h:245
bool splitCDATASections
Split CDATA sections (split-cdata-sections).
Definition: Document.h:368
Parameters controlling DOM writing.
Definition: Document.h:345
xercesc::XercesDOMParser::ValSchemes validationScheme
Validation scheme.
Definition: Document.h:248
Document createEmptyDocument(const std::string &qualifiedName)
Construct an empty Document.
Definition: Document.cpp:200
bool namespaceDeclarations
Include namespace declaration attributes (namespace-declarations).
Definition: Document.h:362
Xerces-C modern C++ wrapper.
Definition: Base.h:53