2004-05-20 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 20 May 2004 08:41:12 +0000 (08:41 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 20 May 2004 08:41:12 +0000 (08:41 -0000)
* Compiler.cs :
  - CompilePattern() now throws XsltCompileException for invalid
    pattern, and add error location support.
  - In Compiler.TryGetFunction(), compare namespace URI, not prefix.
    Now it returns MSXslNodeSet instance (for msxsl:node-set).
* Debug.cs : don't throw System.Exception.
* XslFunctions.cs : Added MSXslNodeSet class.
* XslTemplate.cs : reflected CompilePattern() change.
* XslTransformProcessor.cs : don't throw System.Exception.
* XsltCompiledContext.cs : don't throw System.Exception.

svn path=/trunk/mcs/; revision=27724

mcs/class/System.XML/Mono.Xml.Xsl/ChangeLog
mcs/class/System.XML/Mono.Xml.Xsl/Compiler.cs
mcs/class/System.XML/Mono.Xml.Xsl/Debug.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslFunctions.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslTemplate.cs
mcs/class/System.XML/Mono.Xml.Xsl/XslTransformProcessor.cs
mcs/class/System.XML/Mono.Xml.Xsl/XsltCompiledContext.cs

index f4a5c23223027e4c665f43598dc728060449eba1..8ca4d86d1727d3b8cc9cdea472da2842a6c21c54 100644 (file)
@@ -1,3 +1,16 @@
+2004-05-20  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Compiler.cs :
+         - CompilePattern() now throws XsltCompileException for invalid
+           pattern, and add error location support.
+         - In Compiler.TryGetFunction(), compare namespace URI, not prefix.
+           Now it returns MSXslNodeSet instance (for msxsl:node-set).
+       * Debug.cs : don't throw System.Exception.
+       * XslFunctions.cs : Added MSXslNodeSet class.
+       * XslTemplate.cs : reflected CompilePattern() change.
+       * XslTransformProcessor.cs : don't throw System.Exception.
+       * XsltCompiledContext.cs : don't throw System.Exception.
+
 2004-05-12  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlOutputter.cs,
index 3f57ed984128c40ec20dc497380f4d3a62e2c98b..bc2721a9525a6a7b82a614c21c741a485de16013 100644 (file)
@@ -302,11 +302,12 @@ namespace Mono.Xml.Xsl
                
 #endregion
 #region Compile
-               public Pattern CompilePattern (string pattern)
+               public Pattern CompilePattern (string pattern, XPathNavigator loc)
                {
                        if (pattern == null || pattern == "") return null;
                        Pattern p = Pattern.Compile (pattern, this);
-                       
+                       if (p == null)
+                               throw new XsltCompileException (String.Format ("Invalid pattern '{0}'.", pattern), null, loc);
                        exprStore.AddPattern (p, this);
                        
                        return p;
@@ -495,9 +496,13 @@ namespace Mono.Xml.Xsl
                
                Expression IStaticXsltContext.TryGetFunction (QName name, FunctionArguments args)
                {
-                       if (name.Namespace != null && name.Namespace != "")
-                               return null;
+                       string ns = GetNsm ().LookupNamespace (name.Namespace);
+                       if (ns == XslStylesheet.MSXsltNamespace && name.Name == "node-set")
+                               return new MSXslNodeSet (args);
                        
+                       if (ns != "")
+                               return null;
+
                        switch (name.Name) {
                                case "current": return new XsltCurrent (args);
                                case "unparsed-entity-uri": return new XsltUnparsedEntityUri (args);
index b0a98ae31a46df9c16dce25855e2e50209ac5562..cdd4f5919943903a77faf8516044f295ff78850d 100644 (file)
@@ -43,7 +43,7 @@ namespace Mono.Xml.Xsl {
                internal static void Assert (bool condition, string message)
                {
                        if (!condition)
-                               throw new Exception (message);
+                               throw new XsltException (message, null);
                }
 
                [System.Diagnostics.Conditional("_DEBUG")]
index 8c7c6f7f7f516d84e795a2dbf66d2b767365da36..2654015c811b2fcb6dc6973447e9a12e3bdae267 100755 (executable)
@@ -602,4 +602,39 @@ namespace Mono.Xml.Xsl
                                return ent.BaseURI;
                }
        }
+
+       class MSXslNodeSet : XPathFunction
+       {
+               Expression arg0;
+
+               public MSXslNodeSet (FunctionArguments args) : base (args)
+               {
+                       if (args == null || args.Tail != null)
+                               throw new XPathException ("element-available takes 1 arg");
+                       
+                       arg0 = args.Arg;
+               }
+\r
+               public override XPathResultType ReturnType {\r
+                       get {\r
+                               return XPathResultType.NodeSet;\r
+                       }\r
+               }\r
+
+               public override object Evaluate (BaseIterator iter)\r
+               {\r
+                       XsltCompiledContext ctx = iter.NamespaceManager as XsltCompiledContext;\r
+                       XPathNavigator loc = iter.Current != null ? iter.Current.Clone () : null;\r
+                       XPathNavigator nav = arg0.EvaluateAs (iter, XPathResultType.Navigator) as XPathNavigator;\r
+                       if (nav == null) {\r
+                               if (loc != null)\r
+                                       return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null, loc);\r
+                               else\r
+                                       return new XsltException ("Cannot convert the XPath argument to a result tree fragment.", null);\r
+                       }\r
+                       ArrayList al = new ArrayList ();\r
+                       al.Add (nav);\r
+                       return new ListIterator (al, ctx, false);\r
+               }
+       }
 }
index 7601b49597e808b0ca1b565ca9b9a598495fcd50..af45e1cfa359e965e85d5c57e531e99b0ecab1a9 100644 (file)
@@ -241,7 +241,7 @@ namespace Mono.Xml.Xsl {
                                this.mode = QName.Empty;
                        } else {
                                this.name = c.ParseQNameAttribute ("name");
-                               this.match = c.CompilePattern (c.GetAttribute ("match"));
+                               this.match = c.CompilePattern (c.GetAttribute ("match"), c.Input);
                                this.mode = c.ParseQNameAttribute ("mode");
                                
                                string pri = c.GetAttribute ("priority");
index 9316165607b991bd1b22ee0e58d8a1356a2ebcc2..0b25bdc4a49ce5cd6c22f9cec201c38cebf6a12c 100644 (file)
@@ -156,7 +156,7 @@ namespace Mono.Xml.Xsl {
                {
                        #if DEBUG
                                if (avtSBlock)
-                                       throw new Exception ("String Builder was locked");
+                                       throw new XsltException ("String Builder was locked", null);
                                avtSBlock = true;
                        #endif
                        
@@ -170,7 +170,7 @@ namespace Mono.Xml.Xsl {
                {
                        #if DEBUG
                                if (!avtSBlock)
-                                       throw new Exception ("you never locked the string builder");
+                                       throw new XsltException ("you never locked the string builder", null);
                                avtSBlock = false;
                        #endif
                        
index 49dcb88485aa44d623dc98bb839d162c7fdb0945..85815d3ebfeec4091c017ff3ed514163605fdbbe 100644 (file)
@@ -42,7 +42,7 @@ namespace Mono.Xml.Xsl
 
                public override string LookupNamespace (string prefix)
                {
-                       throw new Exception ("we should never get here");
+                       throw new InvalidOperationException ("we should never get here");
                }
                
                internal override IXsltContextFunction ResolveFunction (XmlQualifiedName name, XPathResultType [] argTypes)
@@ -134,12 +134,12 @@ namespace Mono.Xml.Xsl
                        
                public override IXsltContextVariable ResolveVariable (string prefix, string name)
                {
-                       throw new Exception ("shouldn't get here");
+                       throw new InvalidOperationException ("shouldn't get here");
                }
                
                public override IXsltContextFunction ResolveFunction (string prefix, string name, XPathResultType [] ArgTypes)
                {
-                       throw new Exception ("shouldn't get here");
+                       throw new InvalidOperationException ("XsltCompiledContext exception: shouldn't get here.");
                }
                
                internal override System.Xml.Xsl.IXsltContextVariable ResolveVariable(QName q)