2 // System.Xml.Xsl.XsltException.cs
\r
5 // Tim Coleman (tim@timcoleman.com)
\r
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
\r
8 // (C) Copyright 2002 Tim Coleman
\r
9 // (C) 2003 Andreas Nahr
\r
10 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
\r
12 // Permission is hereby granted, free of charge, to any person obtaining
\r
13 // a copy of this software and associated documentation files (the
\r
14 // "Software"), to deal in the Software without restriction, including
\r
15 // without limitation the rights to use, copy, modify, merge, publish,
\r
16 // distribute, sublicense, and/or sell copies of the Software, and to
\r
17 // permit persons to whom the Software is furnished to do so, subject to
\r
18 // the following conditions:
\r
20 // The above copyright notice and this permission notice shall be
\r
21 // included in all copies or substantial portions of the Software.
\r
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
32 using System.Globalization;
\r
33 using System.Runtime.Serialization;
\r
34 using System.Xml.XPath;
\r
35 using System.Security.Permissions;
\r
37 namespace System.Xml.Xsl
\r
40 public class XsltException : SystemException
\r
42 static string CreateMessage (string message, XPathNavigator nav)
\r
44 IXmlLineInfo li = nav as IXmlLineInfo;
\r
45 int lineNumber = li != null ? li.LineNumber : 0;
\r
46 int linePosition = li != null ? li.LinePosition : 0;
\r
47 string sourceUri = nav != null ? nav.BaseURI : string.Empty;
\r
49 if (lineNumber != 0) {
\r
50 return CreateMessage ("{0} at {1}({2},{3}).", message, lineNumber, linePosition, sourceUri);
\r
52 return CreateMessage ("{0}.", message, lineNumber, linePosition, sourceUri);
\r
55 static string CreateMessage (string msgFormat, string message, int lineNumber, int linePosition, string sourceUri)
\r
57 return string.Format (CultureInfo.InvariantCulture, msgFormat,
\r
58 message, sourceUri, lineNumber.ToString (CultureInfo.InvariantCulture),
\r
59 linePosition.ToString (CultureInfo.InvariantCulture));
\r
70 #region Constructors
\r
73 public XsltException ()
\r
74 : this (string.Empty, (Exception) null)
\r
78 public XsltException (string message)
\r
79 : this (message, (Exception) null)
\r
84 public XsltException (string message, Exception innerException)
\r
85 : this ("{0}", message, innerException, 0, 0, (string) null)
\r
89 protected XsltException (SerializationInfo info, StreamingContext context)
\r
91 lineNumber = info.GetInt32 ("lineNumber");
\r
92 linePosition = info.GetInt32 ("linePosition");
\r
93 sourceUri = info.GetString ("sourceUri");
\r
96 internal XsltException (string msgFormat, string message, Exception innerException, int lineNumber, int linePosition, string sourceUri)
\r
97 : base (CreateMessage (msgFormat, message, lineNumber, linePosition, sourceUri), innerException)
\r
99 this.lineNumber = lineNumber;
\r
100 this.linePosition = linePosition;
\r
101 this.sourceUri = sourceUri;
\r
104 internal XsltException (string message, Exception innerException, XPathNavigator nav)
\r
105 : base (CreateMessage (message, nav), innerException)
\r
107 IXmlLineInfo li = nav as IXmlLineInfo;
\r
108 this.lineNumber = li != null ? li.LineNumber : 0;
\r
109 this.linePosition = li != null ? li.LinePosition : 0;
\r
110 this.sourceUri = nav != null ? nav.BaseURI : string.Empty;
\r
118 public virtual int LineNumber {
\r
120 public int LineNumber {
\r
122 get { return lineNumber; }
\r
126 public virtual int LinePosition {
\r
128 public int LinePosition {
\r
130 get { return linePosition; }
\r
133 public override string Message {
\r
135 return base.Message;
\r
140 public virtual string SourceUri {
\r
142 public string SourceUri {
\r
144 get { return sourceUri; }
\r
151 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
\r
152 public override void GetObjectData (SerializationInfo info, StreamingContext context)
\r
154 base.GetObjectData (info, context);
\r
155 info.AddValue ("lineNumber", lineNumber);
\r
156 info.AddValue ("linePosition", linePosition);
\r
157 info.AddValue ("sourceUri", sourceUri);
\r