Welcome to mirror list, hosted at ThFree Co, Russian Federation.

XsltOutput.cs « XsltOld « Xsl « Xml « System « System.Data.SqlXml « referencesource « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0df2f0ab5d186a18c277d8c59b6916f22da346bf (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
//------------------------------------------------------------------------------
// <copyright file="XsltOutput.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <owner current="true" primary="true">Microsoft</owner>
//------------------------------------------------------------------------------

namespace System.Xml.Xsl.XsltOld {
    using Res = System.Xml.Utils.Res;
    using System;
    using System.Diagnostics;
    using System.IO;
    using System.Xml;
    using System.Text;
    using System.Collections;

    internal class XsltOutput : CompiledAction {

        internal enum OutputMethod {
            Xml,
            Html,
            Text,
            Other,
            Unknown,
        }

        private OutputMethod        method             = OutputMethod.Unknown;
        private int                 methodSId          = int.MaxValue;
        private Encoding            encoding           = System.Text.Encoding.UTF8;
        private int                 encodingSId        = int.MaxValue;
        private string              version;
        private int                 versionSId         = int.MaxValue;
        private bool                omitXmlDecl;
        private int                 omitXmlDeclSId     = int.MaxValue;
        private bool                standalone;
        private int                 standaloneSId      = int.MaxValue;
        private string              doctypePublic;
        private int                 doctypePublicSId   = int.MaxValue;
        private string              doctypeSystem;
        private int                 doctypeSystemSId   = int.MaxValue;
        private bool                indent;
        private int                 indentSId          = int.MaxValue;
        private string              mediaType          = "text/html";
        private int                 mediaTypeSId       = int.MaxValue;
        private Hashtable           cdataElements;

        internal OutputMethod Method {
            get { return this.method; }
        }

        internal bool OmitXmlDeclaration {
            get { return this.omitXmlDecl; }
        }

        internal bool HasStandalone {
            get { return this.standaloneSId != int.MaxValue; }
        }

        internal bool Standalone {
            get { return this.standalone; }
        }

        internal string DoctypePublic {
            get { return this.doctypePublic; }
        }

        internal string DoctypeSystem {
            get { return this.doctypeSystem; }
        }

        internal Hashtable CDataElements {
            get { return this.cdataElements; }
        }

        internal bool Indent {
            get { return this.indent; }
        }

        internal Encoding Encoding {
            get { return this.encoding; }
        }

        internal string MediaType {
            get { return this.mediaType; }
        }

        internal XsltOutput CreateDerivedOutput(OutputMethod method) {
            XsltOutput output = (XsltOutput) MemberwiseClone();
            output.method = method;
            if (method == OutputMethod.Html && this.indentSId == int.MaxValue) { // HTML output and Ident wasn't specified
                output.indent = true;
            }
            return output;
        }

        internal override void Compile(Compiler compiler) {
            CompileAttributes(compiler);
            CheckEmpty(compiler);
        }

        internal override bool CompileAttribute(Compiler compiler) {
            string name   = compiler.Input.LocalName;
            string value  = compiler.Input.Value;

            if (Ref.Equal(name, compiler.Atoms.Method)) {
                if (compiler.Stylesheetid <= this.methodSId) {
                    this.method    = ParseOutputMethod(value, compiler);
                    this.methodSId = compiler.Stylesheetid;
                    if (this.indentSId == int.MaxValue) {
                        this.indent = (this.method == OutputMethod.Html);
                    }
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.Version)) {
                if (compiler.Stylesheetid <= this.versionSId) {
                    this.version    = value;
                    this.versionSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.Encoding)) {
                if (compiler.Stylesheetid <= this.encodingSId) {
                    try {
                        this.encoding    = System.Text.Encoding.GetEncoding(value);
                        this.encodingSId = compiler.Stylesheetid;
                    }
                    catch (System.NotSupportedException) {}
                    catch (System.ArgumentException) {}
                    Debug.Assert(this.encoding != null);
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.OmitXmlDeclaration)) {
                if (compiler.Stylesheetid <= this.omitXmlDeclSId) {
                    this.omitXmlDecl    = compiler.GetYesNo(value);
                    this.omitXmlDeclSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.Standalone)) {
                if (compiler.Stylesheetid <= this.standaloneSId) {
                    this.standalone    = compiler.GetYesNo(value);
                    this.standaloneSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.DocTypePublic)) {
                if (compiler.Stylesheetid <= this.doctypePublicSId) {
                    this.doctypePublic    = value;
                    this.doctypePublicSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.DocTypeSystem)) {
                if (compiler.Stylesheetid <= this.doctypeSystemSId) {
                    this.doctypeSystem    = value;
                    this.doctypeSystemSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.Indent)) {
                if (compiler.Stylesheetid <= this.indentSId) {
                    this.indent    = compiler.GetYesNo(value);
                    this.indentSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.MediaType)) {
                if (compiler.Stylesheetid <= this.mediaTypeSId) {
                    this.mediaType    = value;
                    this.mediaTypeSId = compiler.Stylesheetid;
                }
            }
            else if (Ref.Equal(name, compiler.Atoms.CDataSectionElements)) {
                string[] qnames = XmlConvert.SplitString(value);

                if (this.cdataElements == null) {
                    this.cdataElements = new Hashtable(qnames.Length);
                }

                for (int i = 0; i < qnames.Length; i++) {
                    XmlQualifiedName qname = compiler.CreateXmlQName(qnames[i]);
                    this.cdataElements[qname] = qname;
                }
            }
            else {
                return false;
            }
            return true;
        }

        internal override void Execute(Processor processor, ActionFrame frame) {
            Debug.Assert(false);
        }

        private static OutputMethod ParseOutputMethod(string value, Compiler compiler) {
            XmlQualifiedName method = compiler.CreateXPathQName(value);
            if(method.Namespace.Length != 0) {
                return OutputMethod.Other;
            }
            switch(method.Name) {
            case "xml"  :
                return OutputMethod.Xml ;
            case "html" :
                return OutputMethod.Html;
            case "text" :
                return OutputMethod.Text;
            default :
                if (compiler.ForwardCompatibility) {
                    return OutputMethod.Unknown;
                }
                throw XsltException.Create(Res.Xslt_InvalidAttrValue, "method", value);
            }
        }
    }
}