bioformats  5.1.1
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/DOMDocument.hpp>
50 #include <xercesc/parsers/XercesDOMParser.hpp>
51 
52 #include <ome/common/filesystem.h>
53 
54 #include <ome/compat/memory.h>
55 
56 #include <ome/common/xml/dom/Element.h>
57 #include <ome/common/xml/dom/NodeList.h>
58 #include <ome/common/xml/dom/Wrapper.h>
59 #include <ome/common/xml/String.h>
60 
61 namespace ome
62 {
63  namespace common
64  {
65  namespace xml
66  {
70  namespace dom
71  {
72 
80  class Document : public Wrapper<xercesc::DOMDocument, Node>
81  {
82  public:
87  Wrapper<xercesc::DOMDocument, Node>()
88  {
89  }
90 
96  Document (const Document& document):
97  Wrapper<xercesc::DOMDocument, Node>(document)
98  {
99  }
100 
107  Wrapper<xercesc::DOMDocument, Node>(base)
108  {
109  }
110 
118  bool managed):
119  Wrapper<xercesc::DOMDocument, Node>(managed ?
120  Wrapper<xercesc::DOMDocument, Node>(document, std::mem_fun(&base_element_type::release)) :
121  Wrapper<xercesc::DOMDocument, Node>(document, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
122  {
123  }
124 
132  bool managed):
133  Wrapper<xercesc::DOMDocument, Node>(managed ?
134  Wrapper<xercesc::DOMDocument, Node>(base, std::mem_fun(&base_element_type::release)) :
135  Wrapper<xercesc::DOMDocument, Node>(base, &ome::common::xml::dom::detail::unmanaged<base_element_type>))
136  {
137  }
138 
141  {
142  }
143 
150  Document&
152  {
154  return *this;
155  }
156 
164  Element
165  createElementNS(const std::string& ns,
166  const std::string& name)
167  {
168  common::xml::String xns(ns);
169  common::xml::String xname(name);
170 
171  return Element((*this)->createElementNS(xns, xname), false);
172  }
173 
180  Element
181  createElement(const std::string& name)
182  {
183  common::xml::String xname(name);
184 
185  return Element((*this)->createElement(xname), false);
186  }
187 
193  Element
195  {
196  return Element((*this)->getDocumentElement(), false);
197  }
198 
205  NodeList
206  getElementsByTagName(const std::string& name)
207  {
208  return (*this)->getElementsByTagName(String(name));
209  }
210  };
211 
228  {
230  xercesc::XercesDOMParser::ValSchemes validationScheme;
234  bool doSchema;
241 
244  validationScheme(xercesc::XercesDOMParser::Val_Auto),
245  doNamespaces(true),
246  doSchema(true),
247  handleMultipleImports(true),
248  validationSchemaFullChecking(true),
249  createEntityReferenceNodes(true)
250  {
251  }
252  };
253 
260  Document
261  createEmptyDocument(const std::string& qualifiedName);
262 
271  Document
272  createEmptyDocument(const std::string& namespaceURI,
273  const std::string& qualifiedName);
274 
282  Document
283  createDocument(const boost::filesystem::path& file,
284  const ParseParameters& params = ParseParameters());
285 
294  Document
295  createDocument(const std::string& text,
296  const ParseParameters& params = ParseParameters(),
297  const std::string& id = "membuf");
298 
307  Document
308  createDocument(std::istream& stream,
309  const ParseParameters& params = ParseParameters(),
310  const std::string& id = "streambuf");
311 
328  {
334  bool comments;
340  bool entities;
352  bool validate;
357 
360  canonicalForm(false),
361  CDATASections(true),
362  comments(true),
363  datatypeNormalization(false),
364  discardDefaultContent(true),
365  entities(false),
366  namespaces(true),
367  namespaceDeclarations(true),
368  normalizeCharacters(false),
369  prettyPrint(false),
370  splitCDATASections(true),
371  validate(true),
372  whitespace(false),
373  xmlDeclaration(true)
374  {
375  }
376  };
377 
385  void
386  writeNode(xercesc::DOMNode& node,
387  const boost::filesystem::path& file,
388  const WriteParameters& params = WriteParameters());
389 
397  void
398  writeNode(xercesc::DOMNode& node,
399  std::ostream& stream,
400  const WriteParameters& params = WriteParameters());
401 
409  void
410  writeNode(xercesc::DOMNode& node,
411  std::string& text,
412  const WriteParameters& params = WriteParameters());
413 
421  void
422  writeNode(Node& node,
423  const boost::filesystem::path& file,
424  const WriteParameters& params = WriteParameters());
425 
433  void
434  writeNode(Node& node,
435  std::ostream& stream,
436  const WriteParameters& params = WriteParameters());
437 
445  void
446  writeNode(Node& node,
447  std::string& text,
448  const WriteParameters& params = WriteParameters());
449 
457  void
458  writeDocument(Document& document,
459  const boost::filesystem::path& file,
460  const WriteParameters& params = WriteParameters());
461 
469  void
470  writeDocument(Document& document,
471  std::ostream& stream,
472  const WriteParameters& params = WriteParameters());
473 
481  void
482  writeDocument(Document& document,
483  std::string& text,
484  const WriteParameters& params = WriteParameters());
485 
486  }
487  }
488  }
489 }
490 
491 #endif // OME_COMMON_XML_DOM_DOCUMENT_H
492 
493 /*
494  * Local Variables:
495  * mode:C++
496  * End:
497  */
bool discardDefaultContent
Discard defaults (discard-default-content).
Definition: Document.h:338
bool comments
Retain comments (comments).
Definition: Document.h:334
bool doSchema
Use schemas?
Definition: Document.h:234
element_type * wrapped
The wrapped type.
Definition: Wrapper.h:264
Memory type substitution.
bool CDATASections
Retain CDATA (cdata-sections).
Definition: Document.h:332
Xerces DOM class wrapper.
Definition: Wrapper.h:72
bool whitespace
Retain whitespace (element-content-whitespace).
Definition: Document.h:354
DOM Node wrapper.
Definition: Node.h:68
bool doNamespaces
Use namespaces?
Definition: Document.h:232
DOM Document wrapper.
Definition: Document.h:80
STL namespace.
DOM Element wrapper.
Definition: Element.h:66
bool validate
Validate if schema available (validate-if-schema).
Definition: Document.h:352
bool canonicalForm
Canonicalize document (canonical-form).
Definition: Document.h:330
bool datatypeNormalization
Datatype normalization (datatype-normalization).
Definition: Document.h:336
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:340
WriteParameters()
Constructor.
Definition: Document.h:359
Element createElement(const std::string &name)
Create Element without namespace.
Definition: Document.h:181
Document(Wrapper< xercesc::DOMDocument, Node >::base_element_type *base, bool managed)
Construct a Document from a xercesc::DOMNode *.
Definition: Document.h:131
bool namespaces
Namespace processing (namespaces).
Definition: Document.h:342
~Document()
Destructor.
Definition: Document.h:140
bool handleMultipleImports
Handle multiple imports?
Definition: Document.h:236
bool createEntityReferenceNodes
Create entity reference nodes?
Definition: Document.h:240
Boost.Filesystem compatibility.
Document(const Wrapper< xercesc::DOMDocument, Node >::base_type &base)
Copy construct a Document.
Definition: Document.h:106
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
Document(const Document &document)
Copy construct a Document.
Definition: Document.h:96
Document(Wrapper< xercesc::DOMDocument, Node >::element_type *document, bool managed)
Construct a Document from a xercesc::DOMDocument *.
Definition: Document.h:117
bool prettyPrint
Pretty-print (format-pretty-print).
Definition: Document.h:348
Element getDocumentElement()
Get the root element of this document.
Definition: Document.h:194
Document & operator=(const Document &wrapped)
Assign a Document.
Definition: Document.h:151
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:86
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:206
Xerces string wrapper.
Definition: String.h:74
ParseParameters()
Constructor.
Definition: Document.h:243
bool xmlDeclaration
Require XML declaration (xml-declaration).
Definition: Document.h:356
bool normalizeCharacters
Normalize characters.
Definition: Document.h:346
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:238
Element createElementNS(const std::string &ns, const std::string &name)
Create Element with namespace.
Definition: Document.h:165
Parameters controlling DOM writing.
Definition: Document.h:227
bool splitCDATASections
Split CDATA sections (split-cdata-sections).
Definition: Document.h:350
Parameters controlling DOM writing.
Definition: Document.h:327
xercesc::XercesDOMParser::ValSchemes validationScheme
Validation scheme.
Definition: Document.h:230
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:344
Xerces-C modern C++ wrapper.
Definition: Base.h:53