NCBI C++ ToolKit
xml_init.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  * Copyright (C) 2001-2003 Peter J Jones (pjones@pmade.org)
3  * All Rights Reserved
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name of the Author nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
23  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
29  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 /*
34  * $Id: xml_init.cpp 72932 2016-06-08 18:03:19Z satskyse $
35  * NOTE: This file was modified from its original version 0.6.0
36  * to fit the NCBI C++ Toolkit build framework and
37  * API and functionality requirements.
38  */
39 
40 /** @file
41  * This file contains the implementation of the xml::init class for libxml.
42 **/
43 
44 // defintion include
46 #include "deref_impl.hpp"
47 #include "https_input_impl.hpp"
48 
49 // libxml includes
50 #include <libxml/globals.h>
51 #include <libxml/xmlerror.h>
52 #include <libxml/parser.h>
53 
54 //####################################################################
55 namespace {
56  extern "C" void xml_error (void *, const char*, ...);
57 }
58 //####################################################################
59 int xml::init::ms_counter = 0;
61 //####################################################################
63  if ( ms_counter++ == 0 )
64  init_library();
65 }
66 //####################################################################
68  if ( --ms_counter == 0 )
69  shutdown_library();
70 }
71 //####################################################################
73  // set some libxml global variables
74  indent_output(true);
75  remove_whitespace(false);
76  substitute_entities(true);
77  load_external_subsets(true);
78  validate_xml(false);
79 
80  // keep libxml2 from using stderr
81  xmlSetGenericErrorFunc(0, xml_error);
82 
83  // Register the nodes cleanup function
84  xmlDeregisterNodeDefault(xml::impl::cleanup_node);
85  xmlThrDefDeregisterNodeDefault(xml::impl::cleanup_node);
86 
87  // init the parser (keeps libxml2 thread safe)
88  xmlInitParser();
89 
91 }
92 //####################################################################
94  if ( do_cleanup_at_exit )
95  xmlCleanupParser();
96 }
97 //####################################################################
98 void xml::init::indent_output (bool flag) {
99  xmlIndentTreeOutput = flag ? 1 : 0;
100 }
101 //####################################################################
103  xmlKeepBlanksDefaultValue = flag ? 0 : 1;
104 }
105 //####################################################################
107  return xmlKeepBlanksDefaultValue == 0;
108 }
109 //####################################################################
111  xmlSubstituteEntitiesDefaultValue = flag ? 1 : 0;
112 }
113 //####################################################################
115  xmlLoadExtDtdDefaultValue = flag ? 1 : 0;
116 }
117 //####################################################################
118 void xml::init::validate_xml (bool flag) {
119  xmlDoValidityCheckingDefaultValue = flag ? 1 : 0;
120 }
121 //####################################################################
123  do_cleanup_at_exit = flag;
124 }
125 //####################################################################
126 namespace {
127  extern "C" void xml_error (void*, const char*, ...)
128  { /* don't do anything */ }
129 }
130 //####################################################################
virtual ~init(void)
Definition: xml_init.cpp:67
void shutdown_library()
Definition: xml_init.cpp:93
static void validate_xml(bool flag)
This member function controls whether or not the XML parser should validate every XML document that i...
Definition: xml_init.cpp:118
static void substitute_entities(bool flag)
This member function controls whether or not the XML parser should substitute entities while parsing.
Definition: xml_init.cpp:110
static void library_cleanup_on_exit(bool flag)
This member function controls whether or not the libxml2 library data will be cleaned up at exit.
Definition: xml_init.cpp:122
static bool get_remove_whitespace(void)
This member function provides the current setting of the XML parser which tells whether it should rem...
Definition: xml_init.cpp:106
static void remove_whitespace(bool flag)
This member function controls whether or not the XML parser should remove ignorable whitespace around...
Definition: xml_init.cpp:102
init(void)
Definition: xml_init.cpp:62
void init_library()
Definition: xml_init.cpp:72
static int ms_counter
Definition: xml_init.hpp:179
static bool do_cleanup_at_exit
Definition: xml_init.hpp:180
static void load_external_subsets(bool flag)
This member function controls whether or not the XML parser should load external (DTD) subsets while ...
Definition: xml_init.cpp:114
static void indent_output(bool flag)
This member function controls whether or not the XML parser should add text nodes for indenting when ...
Definition: xml_init.cpp:98
This file contains declarations required for iterators dereferencing support.
void cleanup_node(xmlNodePtr xmlnode)
Definition: deref_impl.cpp:52
void register_https_input(void)
This file contains the definition of the xml::init class.
Modified on Fri Jun 07 13:30:27 2024 by modify_doxy.py rev. 669887