~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/transformiix/source/xslt/txOutputFormat.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 the TransforMiiX XSLT processor.
 
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@netscape.com>
 
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 "XMLUtils.h"
 
41
 
 
42
txOutputFormat::txOutputFormat() : mMethod(eMethodNotSet),
 
43
                                   mOmitXMLDeclaration(eNotSet),
 
44
                                   mStandalone(eNotSet),
 
45
                                   mIndent(eNotSet)
 
46
{
 
47
}
 
48
 
 
49
txOutputFormat::~txOutputFormat()
 
50
{
 
51
    txListIterator iter(&mCDATASectionElements);
 
52
    while (iter.hasNext())
 
53
        delete (txExpandedName*)iter.next();
 
54
}
 
55
 
 
56
void txOutputFormat::reset()
 
57
{
 
58
    mMethod = eMethodNotSet;
 
59
    mVersion.Truncate();
 
60
    if (mEncoding.IsEmpty())
 
61
        mOmitXMLDeclaration = eNotSet;
 
62
    mStandalone = eNotSet;
 
63
    mPublicId.Truncate();
 
64
    mSystemId.Truncate();
 
65
    txListIterator iter(&mCDATASectionElements);
 
66
    while (iter.hasNext())
 
67
        delete (txExpandedName*)iter.next();
 
68
    mIndent = eNotSet;
 
69
    mMediaType.Truncate();
 
70
}
 
71
 
 
72
void txOutputFormat::merge(txOutputFormat& aOutputFormat)
 
73
{
 
74
    if (mMethod == eMethodNotSet)
 
75
        mMethod = aOutputFormat.mMethod;
 
76
 
 
77
    if (mVersion.IsEmpty())
 
78
        mVersion = aOutputFormat.mVersion;
 
79
 
 
80
    if (mEncoding.IsEmpty())
 
81
        mEncoding = aOutputFormat.mEncoding;
 
82
 
 
83
    if (mOmitXMLDeclaration == eNotSet)
 
84
        mOmitXMLDeclaration = aOutputFormat.mOmitXMLDeclaration;
 
85
 
 
86
    if (mStandalone == eNotSet)
 
87
        mStandalone = aOutputFormat.mStandalone;
 
88
 
 
89
    if (mPublicId.IsEmpty())
 
90
        mPublicId = aOutputFormat.mPublicId;
 
91
 
 
92
    if (mSystemId.IsEmpty())
 
93
        mSystemId = aOutputFormat.mSystemId;
 
94
 
 
95
    txListIterator iter(&aOutputFormat.mCDATASectionElements);
 
96
    txExpandedName* qName;
 
97
    while ((qName = (txExpandedName*)iter.next())) {
 
98
        mCDATASectionElements.add(qName);
 
99
        // XXX We need txList.clear()
 
100
        iter.remove();
 
101
    }
 
102
 
 
103
    if (mIndent == eNotSet)
 
104
        mIndent = aOutputFormat.mIndent;
 
105
 
 
106
    if (mMediaType.IsEmpty())
 
107
        mMediaType = aOutputFormat.mMediaType;
 
108
}
 
109
 
 
110
void txOutputFormat::setFromDefaults()
 
111
{
 
112
    switch (mMethod) {
 
113
        case eMethodNotSet:
 
114
        {
 
115
            mMethod = eXMLOutput;
 
116
            // Fall through
 
117
        }
 
118
        case eXMLOutput:
 
119
        {
 
120
            if (mVersion.IsEmpty())
 
121
                mVersion.Append(NS_LITERAL_STRING("1.0"));
 
122
 
 
123
            if (mEncoding.IsEmpty())
 
124
                mEncoding.Append(NS_LITERAL_STRING("UTF-8"));
 
125
 
 
126
            if (mOmitXMLDeclaration == eNotSet)
 
127
                mOmitXMLDeclaration = eFalse;
 
128
 
 
129
            if (mIndent == eNotSet)
 
130
                mIndent = eFalse;
 
131
 
 
132
            if (mMediaType.IsEmpty())
 
133
                mMediaType.Append(NS_LITERAL_STRING("text/xml"));
 
134
 
 
135
            break;
 
136
        }
 
137
        case eHTMLOutput:
 
138
        {
 
139
            if (mVersion.IsEmpty())
 
140
                mVersion.Append(NS_LITERAL_STRING("4.0"));
 
141
 
 
142
            if (mEncoding.IsEmpty())
 
143
                mEncoding.Append(NS_LITERAL_STRING("UTF-8"));
 
144
 
 
145
            if (mIndent == eNotSet)
 
146
                mIndent = eTrue;
 
147
 
 
148
            if (mMediaType.IsEmpty())
 
149
                mMediaType.Append(NS_LITERAL_STRING("text/html"));
 
150
 
 
151
            break;
 
152
        }
 
153
        case eTextOutput:
 
154
        {
 
155
            if (mEncoding.IsEmpty())
 
156
                mEncoding.Append(NS_LITERAL_STRING("UTF-8"));
 
157
 
 
158
            if (mMediaType.IsEmpty())
 
159
                mMediaType.Append(NS_LITERAL_STRING("text/plain"));
 
160
 
 
161
            break;
 
162
        }
 
163
    }
 
164
}