2 // MSXslScriptManager.cs
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Atsushi Enomoto (ginga@kit.hi-ho.ne.jp)
8 // (C)2003 Atsushi Enomoto
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Diagnostics
;
33 using System
.Collections
;
34 using System
.Globalization
;
36 using System
.Reflection
;
37 using System
.Security
;
38 using System
.Security
.Cryptography
;
39 using System
.Security
.Policy
;
42 using System
.Xml
.Schema
;
43 using System
.Xml
.XPath
;
46 namespace Mono
.Xml
.Xsl
{
48 // FIXME: Correct evidence handling; test other than simple string case
49 internal class MSXslScriptManager
{
50 Hashtable scripts
= new Hashtable ();
52 public MSXslScriptManager () {}
54 public void AddScript (Compiler c
)
56 MSXslScript s
= new MSXslScript (c
.Input
, c
.Evidence
);
57 string ns
= c
.Input
.GetNamespace (s
.ImplementsPrefix
);
59 throw new XsltCompileException ("Specified prefix for msxsl:script was not found: " + s
.ImplementsPrefix
, null, c
.Input
);
60 scripts
.Add (ns
, s
.Compile (c
.Input
));
63 enum ScriptingLanguage
{
69 public object GetExtensionObject (string ns
)
71 if (!scripts
.ContainsKey (ns
))
73 return Activator
.CreateInstance ((Type
) scripts
[ns
]);
77 ScriptingLanguage language
= ScriptingLanguage
.JScript
; // default = JScript.
78 string implementsPrefix
= null;
82 public MSXslScript (XPathNavigator nav
, Evidence evidence
)
84 this.evidence
= evidence
;
86 if (nav
.MoveToFirstAttribute ()) {
88 switch (nav
.LocalName
) {
90 switch (nav
.Value
.ToLower (CultureInfo
.InvariantCulture
)) {
93 language
= ScriptingLanguage
.JScript
; break;
96 language
= ScriptingLanguage
.VisualBasic
;
100 language
= ScriptingLanguage
.CSharp
;
103 throw new XsltException ("Invalid scripting language!", null);
106 case "implements-prefix":
107 implementsPrefix
= nav
.Value
;
110 } while (nav
.MoveToNextAttribute ());
114 if (implementsPrefix
== null)
115 throw new XsltException ("need implements-prefix attr", null);
118 public ScriptingLanguage Language
{
119 get { return language; }
122 public string ImplementsPrefix
{
123 get { return implementsPrefix; }
130 public object Compile (XPathNavigator node
)
132 #if TARGET_JVM || MONOTOUCH
133 throw new NotImplementedException ();
136 foreach (byte b
in MD5
.Create ().ComputeHash (Encoding
.Unicode
.GetBytes (code
))) {
137 suffix
+= b
.ToString ("x2");
139 switch (this.language
) {
140 case ScriptingLanguage
.CSharp
:
141 return new CSharpCompilerInfo ().GetScriptClass (Code
, suffix
, node
, evidence
);
142 case ScriptingLanguage
.JScript
:
143 return new JScriptCompilerInfo ().GetScriptClass (Code
, suffix
, node
, evidence
);
144 case ScriptingLanguage
.VisualBasic
:
145 return new VBCompilerInfo ().GetScriptClass (Code
, suffix
, node
, evidence
);