2004-09-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web.Compilation / ParseException.cs
1 //
2 // System.Web.Compilation.ParseException
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System;
32 using System.IO;
33
34 namespace System.Web.Compilation
35 {
36         internal class ParseException : HtmlizedException
37         {
38                 ILocation location;
39                 string fileText;
40
41                 public ParseException (ILocation location, string message)
42                         : this (location, message, null)
43                 {
44                         location = new Location (location);
45                 }
46
47
48                 public ParseException (ILocation location, string message, Exception inner)
49                         : base (message, inner)
50                 {
51                         this.location = location;
52                 }
53
54                 public override string Title {
55                         get { return "Parser Error"; }
56                 }
57
58                 public override string Description {
59                         get {
60                                 return "Error parsing a resource required to service this request. " +
61                                        "Review your source file and modify it to fix this error.";
62                         }
63                 }
64
65                 public override string ErrorMessage {
66                         get { return Message; }
67                 }
68
69                 public override string SourceFile {
70                         get { return FileName; }
71                 }
72                 
73                 public override string FileName {
74                         get {
75                                 if (location == null)
76                                         return null;
77
78                                 return location.Filename;
79                         }
80                 }
81
82                 public override string FileText {
83                         get {
84                                 if (fileText != null)
85                                         return fileText;
86
87                                 if (FileName == null)
88                                         return null;
89
90                                 //FIXME: encoding
91                                 TextReader reader = new StreamReader (FileName);
92                                 fileText = reader.ReadToEnd ();                         
93                                 return fileText;
94                         }
95                 }
96
97                 public override int [] ErrorLines {
98                         get {
99                                 if (location == null)
100                                         return null;
101
102                                 return new int [] {location.BeginLine, location.EndLine};
103                         }
104                 }
105
106                 public override bool ErrorLinesPaired {
107                         get { return true; }
108                 }
109         }
110 }
111