1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is TransforMiiX XSLT processor code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2001
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Peter Van der Beken <peterv@propagandism.org>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "txOutputFormat.h"
40 : #include "txXMLUtils.h"
41 :
42 0 : txOutputFormat::txOutputFormat() : mMethod(eMethodNotSet),
43 : mOmitXMLDeclaration(eNotSet),
44 : mStandalone(eNotSet),
45 0 : mIndent(eNotSet)
46 : {
47 0 : }
48 :
49 0 : txOutputFormat::~txOutputFormat()
50 : {
51 0 : txListIterator iter(&mCDATASectionElements);
52 0 : while (iter.hasNext())
53 0 : delete (txExpandedName*)iter.next();
54 0 : }
55 :
56 0 : void txOutputFormat::reset()
57 : {
58 0 : mMethod = eMethodNotSet;
59 0 : mVersion.Truncate();
60 0 : if (mEncoding.IsEmpty())
61 0 : mOmitXMLDeclaration = eNotSet;
62 0 : mStandalone = eNotSet;
63 0 : mPublicId.Truncate();
64 0 : mSystemId.Truncate();
65 0 : txListIterator iter(&mCDATASectionElements);
66 0 : while (iter.hasNext())
67 0 : delete (txExpandedName*)iter.next();
68 0 : mIndent = eNotSet;
69 0 : mMediaType.Truncate();
70 0 : }
71 :
72 0 : void txOutputFormat::merge(txOutputFormat& aOutputFormat)
73 : {
74 0 : if (mMethod == eMethodNotSet)
75 0 : mMethod = aOutputFormat.mMethod;
76 :
77 0 : if (mVersion.IsEmpty())
78 0 : mVersion = aOutputFormat.mVersion;
79 :
80 0 : if (mEncoding.IsEmpty())
81 0 : mEncoding = aOutputFormat.mEncoding;
82 :
83 0 : if (mOmitXMLDeclaration == eNotSet)
84 0 : mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration;
85 :
86 0 : if (mStandalone == eNotSet)
87 0 : mStandalone = aOutputFormat.mStandalone;
88 :
89 0 : if (mPublicId.IsEmpty())
90 0 : mPublicId = aOutputFormat.mPublicId;
91 :
92 0 : if (mSystemId.IsEmpty())
93 0 : mSystemId = aOutputFormat.mSystemId;
94 :
95 0 : txListIterator iter(&aOutputFormat.mCDATASectionElements);
96 : txExpandedName* qName;
97 0 : while ((qName = (txExpandedName*)iter.next())) {
98 0 : mCDATASectionElements.add(qName);
99 : // XXX We need txList.clear()
100 0 : iter.remove();
101 : }
102 :
103 0 : if (mIndent == eNotSet)
104 0 : mIndent = aOutputFormat.mIndent;
105 :
106 0 : if (mMediaType.IsEmpty())
107 0 : mMediaType = aOutputFormat.mMediaType;
108 0 : }
109 :
110 0 : void txOutputFormat::setFromDefaults()
111 : {
112 0 : switch (mMethod) {
113 : case eMethodNotSet:
114 : {
115 0 : mMethod = eXMLOutput;
116 : // Fall through
117 : }
118 : case eXMLOutput:
119 : {
120 0 : if (mVersion.IsEmpty())
121 0 : mVersion.AppendLiteral("1.0");
122 :
123 0 : if (mEncoding.IsEmpty())
124 0 : mEncoding.AppendLiteral("UTF-8");
125 :
126 0 : if (mOmitXMLDeclaration == eNotSet)
127 0 : mOmitXMLDeclaration = eFalse;
128 :
129 0 : if (mIndent == eNotSet)
130 0 : mIndent = eFalse;
131 :
132 0 : if (mMediaType.IsEmpty())
133 0 : mMediaType.AppendLiteral("text/xml");
134 :
135 0 : break;
136 : }
137 : case eHTMLOutput:
138 : {
139 0 : if (mVersion.IsEmpty())
140 0 : mVersion.AppendLiteral("4.0");
141 :
142 0 : if (mEncoding.IsEmpty())
143 0 : mEncoding.AppendLiteral("UTF-8");
144 :
145 0 : if (mIndent == eNotSet)
146 0 : mIndent = eTrue;
147 :
148 0 : if (mMediaType.IsEmpty())
149 0 : mMediaType.AppendLiteral("text/html");
150 :
151 0 : break;
152 : }
153 : case eTextOutput:
154 : {
155 0 : if (mEncoding.IsEmpty())
156 0 : mEncoding.AppendLiteral("UTF-8");
157 :
158 0 : if (mMediaType.IsEmpty())
159 0 : mMediaType.AppendLiteral("text/plain");
160 :
161 0 : break;
162 : }
163 : }
164 0 : }
|