blob: fe4d068f6e44d804fa8c179ca6850265db4d9484 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "txOutputFormat.h"
#include "txXMLUtils.h"
#include "txExpandedName.h"
txOutputFormat::txOutputFormat()
: mMethod(eMethodNotSet),
mOmitXMLDeclaration(eNotSet),
mStandalone(eNotSet),
mIndent(eNotSet) {}
txOutputFormat::~txOutputFormat() {
txListIterator iter(&mCDATASectionElements);
while (iter.hasNext()) delete (txExpandedName*)iter.next();
}
void txOutputFormat::reset() {
mMethod = eMethodNotSet;
mVersion.Truncate();
if (mEncoding.IsEmpty()) mOmitXMLDeclaration = eNotSet;
mStandalone = eNotSet;
mPublicId.Truncate();
mSystemId.Truncate();
txListIterator iter(&mCDATASectionElements);
while (iter.hasNext()) delete (txExpandedName*)iter.next();
mIndent = eNotSet;
mMediaType.Truncate();
}
void txOutputFormat::merge(txOutputFormat& aOutputFormat) {
if (mMethod == eMethodNotSet) mMethod = aOutputFormat.mMethod;
if (mVersion.IsEmpty()) mVersion = aOutputFormat.mVersion;
if (mEncoding.IsEmpty()) mEncoding = aOutputFormat.mEncoding;
if (mOmitXMLDeclaration == eNotSet)
mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration;
if (mStandalone == eNotSet) mStandalone = aOutputFormat.mStandalone;
if (mPublicId.IsEmpty()) mPublicId = aOutputFormat.mPublicId;
if (mSystemId.IsEmpty()) mSystemId = aOutputFormat.mSystemId;
txListIterator iter(&aOutputFormat.mCDATASectionElements);
txExpandedName* qName;
while ((qName = (txExpandedName*)iter.next())) {
mCDATASectionElements.add(qName);
// XXX We need txList.clear()
iter.remove();
}
if (mIndent == eNotSet) mIndent = aOutputFormat.mIndent;
if (mMediaType.IsEmpty()) mMediaType = aOutputFormat.mMediaType;
}
void txOutputFormat::setFromDefaults() {
switch (mMethod) {
case eMethodNotSet: {
mMethod = eXMLOutput;
[[fallthrough]];
}
case eXMLOutput: {
if (mVersion.IsEmpty()) mVersion.AppendLiteral("1.0");
if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
if (mOmitXMLDeclaration == eNotSet) mOmitXMLDeclaration = eFalse;
if (mIndent == eNotSet) mIndent = eFalse;
if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/xml");
break;
}
case eHTMLOutput: {
if (mVersion.IsEmpty()) mVersion.AppendLiteral("4.0");
if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
if (mIndent == eNotSet) mIndent = eTrue;
if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/html");
break;
}
case eTextOutput: {
if (mEncoding.IsEmpty()) mEncoding.AppendLiteral("UTF-8");
if (mMediaType.IsEmpty()) mMediaType.AppendLiteral("text/plain");
break;
}
}
}
|