Merge pull request #3626 from lateralusX/jlorenss/win-api-family-support-eglib
[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.Reflection;
36 using System.Runtime.InteropServices;
37 using System.Security;
38 using System.Security.Policy;
39 using System.Xml.XPath;
40 using System.Xml.XmlConfiguration;
41
42 namespace System.Xml.Xsl
43 {
44         public sealed class XslCompiledTransform
45         {
46                 readonly bool enable_debug;
47                 object debugger;
48                 XmlWriterSettings output_settings = new XmlWriterSettings ();
49                 XslTransform impl = new XslTransform ();
50                 
51                 public XslCompiledTransform ()
52                         : this (false)
53                 {
54                 }
55
56                 public XslCompiledTransform (bool enableDebug)
57                 {
58                         enable_debug = enableDebug;
59                         if (enable_debug)
60                                 debugger = new NoOperationDebugger ();
61                         output_settings.ConformanceLevel = ConformanceLevel.Fragment;
62                 }
63
64                 [MonoTODO]
65                 public XmlWriterSettings OutputSettings {
66                         get { return output_settings; }
67                 }
68
69                 #region Transform
70
71                 public void Transform (string inputUri, string resultsFile)
72                 {
73                         using (Stream outStream = File.Create (resultsFile)) {
74                                 Transform (new XPathDocument (inputUri, XmlSpace.Preserve), null, outStream);
75                         }
76                 }
77
78                 public void Transform (string inputUri, XmlWriter results)
79                 {
80                         Transform (inputUri, null, results);
81                 }
82
83                 public void Transform (string inputUri, XsltArgumentList arguments, Stream results)
84                 {
85                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
86                 }
87
88                 public void Transform (string inputUri, XsltArgumentList arguments, TextWriter results)
89                 {
90                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
91                 }
92
93                 public void Transform (string inputUri, XsltArgumentList arguments, XmlWriter results)
94                 {
95                         Transform (new XPathDocument (inputUri, XmlSpace.Preserve), arguments, results);
96                 }
97
98                 public void Transform (XmlReader input, XmlWriter results)
99                 {
100                         Transform (input, null, results);
101                 }
102
103                 public void Transform (XmlReader input, XsltArgumentList arguments, Stream results)
104                 {
105                         Transform (new XPathDocument (input, XmlSpace.Preserve), arguments, results);
106                 }
107
108                 public void Transform (XmlReader input, XsltArgumentList arguments, TextWriter results)
109                 {
110                         Transform (new XPathDocument (input, XmlSpace.Preserve), arguments, results);
111                 }
112
113                 public void Transform (XmlReader input, XsltArgumentList arguments, XmlWriter results)
114                 {
115                         Transform (input, arguments, results, null);
116                 }
117
118                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, TextWriter results)
119                 {
120                         Transform (input.CreateNavigator (), arguments, results);
121                 }
122
123                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, Stream results)
124                 {
125                         using (var sw = new StreamWriter (results)) {
126                                 Transform (input.CreateNavigator (), arguments, sw);
127                         }
128                 }
129
130                 public void Transform (IXPathNavigable input, XmlWriter results)
131                 {
132                         Transform (input, null, results);
133                 }
134
135                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, XmlWriter results)
136                 {
137                         Transform (input.CreateNavigator (), arguments, results, null);
138                 }
139
140                 public void Transform (IXPathNavigable input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
141                 {
142                         Transform (input.CreateNavigator (), arguments, results, documentResolver);
143                 }
144
145                 public void Transform (XmlReader input, XsltArgumentList arguments, XmlWriter results, XmlResolver documentResolver)
146                 {
147                         Transform (new XPathDocument (input, XmlSpace.Preserve).CreateNavigator (), arguments, results, documentResolver);
148                 }
149
150                 void Transform (XPathNavigator input, XsltArgumentList args, XmlWriter output, XmlResolver resolver)
151                 {
152                         impl.Transform (input, args, output, resolver);
153                 }
154
155                 void Transform (XPathNavigator input, XsltArgumentList args, TextWriter output)
156                 {
157                         impl.Transform (input, args, output);
158                 }
159
160                 #endregion
161
162                 #region Load
163
164                 private XmlReader GetXmlReader (string url)
165                 {
166                         XmlResolver res = new XmlUrlResolver ();
167                         Uri uri = res.ResolveUri (null, url);
168                         Stream s = res.GetEntity (uri, null, typeof (Stream)) as Stream;
169                         XmlTextReader xtr = new XmlTextReader (uri.ToString (), s);
170                         xtr.XmlResolver = res;
171                         XmlValidatingReader xvr = new XmlValidatingReader (xtr);
172                         xvr.XmlResolver = res;
173                         xvr.ValidationType = ValidationType.None;
174                         return xvr;
175                 }
176
177                 public void Load (string stylesheetUri)
178                 {
179                         using (XmlReader r = GetXmlReader (stylesheetUri))
180                                 Load (r);
181                 }
182
183                 public void Load (XmlReader stylesheet)
184                 {
185                         Load (stylesheet, XsltSettings.Default, XsltConfigSection.CreateDefaultResolver());
186                 }
187
188                 public void Load (IXPathNavigable stylesheet)
189                 {
190                         Load (stylesheet.CreateNavigator(), XsltSettings.Default, XsltConfigSection.CreateDefaultResolver());
191                 }
192
193                 public void Load (IXPathNavigable stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
194                 {
195 //                      if (!settings.EnableDocumentFunction)
196 //                              throw new NotSupportedException ("'document' function cannot be disabled on this framework because it just runs XslTransform which does not support XsltSettings");
197                         if (settings.EnableScript)
198                                 throw new NotSupportedException ("'msxsl:script' element is not supported on this framework because it does not support run-time code generation");
199                         impl.Load (stylesheet, stylesheetResolver);
200                 }
201
202                 public void Load (XmlReader stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
203                 {
204                         Load (new XPathDocument (stylesheet, XmlSpace.Preserve), settings, stylesheetResolver);
205                 }
206
207                 public void Load (string stylesheetUri, XsltSettings settings, XmlResolver stylesheetResolver)
208                 {
209                         Load (new XPathDocument (stylesheetUri, XmlSpace.Preserve).CreateNavigator (), settings, stylesheetResolver);
210                 }
211
212                 public void Load (MethodInfo executeMethod, byte[] queryData, Type[] earlyBoundTypes)
213                 {
214                         throw new NotImplementedException ();
215                 }
216
217                 public void Load (Type compiledStylesheet)
218                 {
219                         throw new NotImplementedException ();
220                 }
221                 #endregion
222         }
223
224                 class NoOperationDebugger
225                 {
226                         protected void OnCompile (XPathNavigator input)
227                         {
228                         }
229
230                         protected void OnExecute (XPathNodeIterator currentNodeset, XPathNavigator style, XsltContext context)
231                         {
232                                 //ShowLocationInTrace (style);
233                         }
234 /*
235                         string ShowLocationInTrace (XPathNavigator style)
236                         {
237                                 IXmlLineInfo li = style as IXmlLineInfo;
238                                 return li != null ? String.Format ("at {0} ({1},{2})", style.BaseURI, li.LineNumber, li.LinePosition) : "(no debug info available)";
239                         }
240 */
241                 }
242 }