1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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/. */
6 #include "txOutputFormat.h"
7 #include "txXMLUtils.h"
8 #include "txExpandedName.h"
10 txOutputFormat::txOutputFormat()
11 : mMethod(eMethodNotSet
),
12 mOmitXMLDeclaration(eNotSet
),
16 txOutputFormat::~txOutputFormat() {
17 txListIterator
iter(&mCDATASectionElements
);
18 while (iter
.hasNext()) delete (txExpandedName
*)iter
.next();
21 void txOutputFormat::reset() {
22 mMethod
= eMethodNotSet
;
24 if (mEncoding
.IsEmpty()) mOmitXMLDeclaration
= eNotSet
;
25 mStandalone
= eNotSet
;
28 txListIterator
iter(&mCDATASectionElements
);
29 while (iter
.hasNext()) delete (txExpandedName
*)iter
.next();
31 mMediaType
.Truncate();
34 void txOutputFormat::merge(txOutputFormat
& aOutputFormat
) {
35 if (mMethod
== eMethodNotSet
) mMethod
= aOutputFormat
.mMethod
;
37 if (mVersion
.IsEmpty()) mVersion
= aOutputFormat
.mVersion
;
39 if (mEncoding
.IsEmpty()) mEncoding
= aOutputFormat
.mEncoding
;
41 if (mOmitXMLDeclaration
== eNotSet
)
42 mOmitXMLDeclaration
= aOutputFormat
.mOmitXMLDeclaration
;
44 if (mStandalone
== eNotSet
) mStandalone
= aOutputFormat
.mStandalone
;
46 if (mPublicId
.IsEmpty()) mPublicId
= aOutputFormat
.mPublicId
;
48 if (mSystemId
.IsEmpty()) mSystemId
= aOutputFormat
.mSystemId
;
50 txListIterator
iter(&aOutputFormat
.mCDATASectionElements
);
51 txExpandedName
* qName
;
52 while ((qName
= (txExpandedName
*)iter
.next())) {
53 mCDATASectionElements
.add(qName
);
54 // XXX We need txList.clear()
58 if (mIndent
== eNotSet
) mIndent
= aOutputFormat
.mIndent
;
60 if (mMediaType
.IsEmpty()) mMediaType
= aOutputFormat
.mMediaType
;
63 void txOutputFormat::setFromDefaults() {
70 if (mVersion
.IsEmpty()) mVersion
.AppendLiteral("1.0");
72 if (mEncoding
.IsEmpty()) mEncoding
.AppendLiteral("UTF-8");
74 if (mOmitXMLDeclaration
== eNotSet
) mOmitXMLDeclaration
= eFalse
;
76 if (mIndent
== eNotSet
) mIndent
= eFalse
;
78 if (mMediaType
.IsEmpty()) mMediaType
.AppendLiteral("text/xml");
83 if (mVersion
.IsEmpty()) mVersion
.AppendLiteral("4.0");
85 if (mEncoding
.IsEmpty()) mEncoding
.AppendLiteral("UTF-8");
87 if (mIndent
== eNotSet
) mIndent
= eTrue
;
89 if (mMediaType
.IsEmpty()) mMediaType
.AppendLiteral("text/html");
94 if (mEncoding
.IsEmpty()) mEncoding
.AppendLiteral("UTF-8");
96 if (mMediaType
.IsEmpty()) mMediaType
.AppendLiteral("text/plain");