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