Imported Upstream version 2.81
[platform/upstream/libbullet.git] / UnitTests / cppunit / src / cppunit / XmlDocument.cpp
1 #include <cppunit/config/SourcePrefix.h>
2 #include <cppunit/tools/XmlDocument.h>
3 #include <cppunit/tools/XmlElement.h>
4
5
6 CPPUNIT_NS_BEGIN
7
8
9 XmlDocument::XmlDocument( const std::string &encoding,
10                           const std::string &styleSheet )
11   : m_styleSheet( styleSheet )
12   , m_rootElement( new XmlElement( "DummyRoot" ) )
13   , m_standalone( true )
14 {
15   setEncoding( encoding );
16 }
17
18
19 XmlDocument::~XmlDocument()
20 {
21   delete m_rootElement;
22 }
23
24
25
26 std::string 
27 XmlDocument::encoding() const
28 {
29   return m_encoding;
30 }
31
32
33 void 
34 XmlDocument::setEncoding( const std::string &encoding )
35 {
36   m_encoding = encoding.empty() ? std::string("ISO-8859-1") : encoding;
37 }
38
39
40 std::string 
41 XmlDocument::styleSheet() const
42 {
43   return m_styleSheet;
44 }
45
46
47 void 
48 XmlDocument::setStyleSheet( const std::string &styleSheet )
49 {
50   m_styleSheet = styleSheet;
51 }
52
53
54 bool
55 XmlDocument::standalone() const
56 {
57   return m_standalone;
58 }
59
60
61 void
62 XmlDocument::setStandalone( bool standalone )
63 {
64   m_standalone = standalone;
65 }
66
67
68 void 
69 XmlDocument::setRootElement( XmlElement *rootElement )
70 {
71   if ( rootElement == m_rootElement )
72     return;
73
74   delete m_rootElement;
75   m_rootElement = rootElement;
76 }
77
78
79 XmlElement &
80 XmlDocument::rootElement() const
81 {
82   return *m_rootElement;
83 }
84
85
86 std::string 
87 XmlDocument::toString() const
88 {
89   std::string asString = "<?xml version=\"1.0\" "
90                          "encoding='" + m_encoding + "'";
91   if ( m_standalone )
92       asString += " standalone='yes'";
93
94   asString += " ?>\n"; 
95
96   if ( !m_styleSheet.empty() )
97     asString += "<?xml-stylesheet type=\"text/xsl\" href=\"" + m_styleSheet + "\"?>\n";
98
99   asString += m_rootElement->toString();
100
101   return asString;
102 }
103
104
105 CPPUNIT_NS_END
106