[sgen] Untag the vtable during concurrent mark
[mono.git] / mcs / class / System.XML / System.Xml.Xsl / XslCompiledTransform_Mobile.cs
1 // XslCompiledTransform_Mobile.cs
2 //
3 // Author:
4 //      Atsushi Enomoto  <atsushi@xamarin.com>
5 //
6 // Copyright (C) 2015 Xamarin Inc. http://www.xamarin.com
7 //
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.CodeDom.Compiler;
32 using System.Collections;
33 using System.IO;
34 using System.Text;
35 using System.Runtime.InteropServices;
36 using System.Security;
37 using System.Security.Policy;
38 using System.Xml.XPath;
39 using System.Xml.XmlConfiguration;
40
41 namespace System.Xml.Xsl
42 {
43         public sealed class XslCompiledTransform
44         {
45                 readonly bool enable_debug;
46                 object debugger;
47                 XmlWriterSettings output_settings = new XmlWriterSettings ();
48                 XslTransform impl = new XslTransform ();
49                 
50                 public XslCompiledTransform ()
51                         : this (false)
52                 {
53                 }
54
55                 public XslCompiledTransform (bool enableDebug)
56                 {
57                         enable_debug = enableDebug;
58                         if (enable_debug)
59                                 debugger = new NoOperationDebugger ();
60                         output_settings.ConformanceLevel = ConformanceLevel.Fragment;
61                 }
62
63                 [MonoTODO]
64                 public XmlWriterSettings OutputSettings {
65                         get { return output_settings; }
66                 }
67
68                 #region Transform
69
70                 public void Transform (string inputUri, string resultsFile)
71                 {
72                         using (Stream outStream = File.Create (resultsFile)) {
73                                 Transform (new XPathDocument (inputUri, XmlSpace.Preserve), null, outStream);
74                         }
75                 }
76
77                 public void Transform (string inputUri, XmlWriter results)
78                 {
79                         Transform (inputUri, null, results);
80                 }
81
82                 public void Transform (string inputUri, XsltArgumentList arguments, Stream results)
83                 {
84                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
85                 }
86
87                 public void Transform (string inputUri, XsltArgumentList arguments, TextWriter results)
88                 {
89                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
90                 }
91
92                 public void Transform (string inputUri, XsltArgumentList arguments, XmlWriter results)
93                 {
94                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
95                 }
96
97                 public void Transform (XmlReader input, XmlWriter results)
98                 {
99                         Transform (input, null, results);
100                 }
101
102                 public void Transform (XmlReader input, XsltArgumentList arguments, Stream results)
103                 {
104                         Transform (new XPathDocument (input, XmlSpace.Preserve), arguments, results);
105                 }
106
107                 public void Transform (XmlReader input, XsltArgumentList arguments, TextWriter results)
108                 {
109                         Transform (new XPathDocument (input, XmlSpace.Preserve), arguments, results);
110                 }
111
112                 public void Transform (XmlReader input, XsltArgumentList arguments, XmlWriter results)
113                 {
114                         Transform (input, arguments, results, null);
115                 }
116
117                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
118                 {
119                         Transform (input.CreateNavigator (), arguments, results);
120                 }
121
122                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, Stream results)
123                 {
124                         using (var sw = new StreamWriter (results)) {
125                                 Transform (input.CreateNavigator (), arguments, sw);
126                         }
127                 }
128
129                 public void Transform (IXPathNavigable input, XmlWriter results)
130                 {
131                         Transform (input, null, results);
132                 }
133
134                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, XmlWriter results)
135                 {
136                         Transform (input.CreateNavigator (), arguments, results, null);
137                 }
138
139                 public void Transform (XmlReader input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
140                 {
141                         Transform (new XPathDocument (input, XmlSpace.Preserve).CreateNavigator (), arguments, results, documentResolver);
142                 }
143
144                 void Transform (XPathNavigator input, XsltArgumentList args, XmlWriter output, XmlResolver resolver)
145                 {
146                         impl.Transform (input, args, output, resolver);
147                 }
148
149                 void Transform (XPathNavigator input, XsltArgumentList args, TextWriter output)
150                 {
151                         impl.Transform (input, args, output);
152                 }
153
154                 #endregion
155
156                 #region Load
157
158                 private XmlReader GetXmlReader (string url)
159                 {
160                         XmlResolver res = new XmlUrlResolver ();
161                         Uri uri = res.ResolveUri (null, url);
162                         Stream s = res.GetEntity (uri, null, typeof (Stream)) as Stream;
163                         XmlTextReader xtr = new XmlTextReader (uri.ToString (), s);
164                         xtr.XmlResolver = res;
165                         XmlValidatingReader xvr = new XmlValidatingReader (xtr);
166                         xvr.XmlResolver = res;
167                         xvr.ValidationType = ValidationType.None;
168                         return xvr;
169                 }
170
171                 public void Load (string stylesheetUri)
172                 {
173                         using (XmlReader r = GetXmlReader (stylesheetUri))
174                                 Load (r);
175                 }
176
177                 public void Load (XmlReader stylesheet)
178                 {
179                         Load (stylesheet, XsltSettings.Default, XsltConfigSection.CreateDefaultResolver());
180                 }
181
182                 public void Load (IXPathNavigable stylesheet)
183                 {
184                         Load (stylesheet.CreateNavigator(), XsltSettings.Default, XsltConfigSection.CreateDefaultResolver());
185                 }
186
187                 public void Load (IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
188                 {
189 //                      if (!settings.EnableDocumentFunction)
190 //                              throw new NotSupportedException ("'document' function cannot be disabled on this framework because it just runs XslTransform which does not support XsltSettings");
191                         if (settings.EnableScript)
192                                 throw new NotSupportedException ("'msxsl:script' element is not supported on this framework because it does not support run-time code generation");
193                         impl.Load (stylesheet, stylesheetResolver);
194                 }
195
196                 public void Load (XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
197                 {
198                         Load (new XPathDocument (stylesheet, XmlSpace.Preserve), settings, stylesheetResolver);
199                 }
200
201                 public void Load (string stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)
202                 {
203                         Load (new XPathDocument (stylesheetUri, XmlSpace.Preserve).CreateNavigator (), settings, stylesheetResolver);
204                 }
205
206                 #endregion
207         }
208
209                 class NoOperationDebugger
210                 {
211                         protected void OnCompile (XPathNavigator input)
212                         {
213                         }
214
215                         protected void OnExecute (XPathNodeIterator currentNodeset, XPathNavigator style, XsltContext context)
216                         {
217                                 //ShowLocationInTrace (style);
218                         }
219 /*
220                         string ShowLocationInTrace (XPathNavigator style)
221                         {
222                                 IXmlLineInfo li = style as IXmlLineInfo;
223                                 return li != null ? String.Format ("at {0} ({1},{2})", style.BaseURI, li.LineNumber, li.LinePosition) : "(no debug info available)";
224                         }
225 */
226                 }
227 }