2003-10-19 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 using System;
11 using System.IO;
12
13 namespace System.Web.Compilation
14 {
15         internal class ParseException : HtmlizedException
16         {
17                 ILocation location;
18                 string fileText;
19
20                 public ParseException (ILocation location, string message)
21                         : this (location, message, null)
22                 {
23                         location = new Location (location);
24                 }
25
26
27                 public ParseException (ILocation location, string message, Exception inner)
28                         : base (message, inner)
29                 {
30                         this.location = location;
31                 }
32
33                 public override string Title {
34                         get { return "Parser Error"; }
35                 }
36
37                 public override string Description {
38                         get {
39                                 return "Error parsing a resource required to service this request. " +
40                                        "Review your source file and modify it to fix this error.";
41                         }
42                 }
43
44                 public override string ErrorMessage {
45                         get { return Message; }
46                 }
47
48                 public override string SourceFile {
49                         get { return FileName; }
50                 }
51                 
52                 public override string FileName {
53                         get {
54                                 if (location == null)
55                                         return null;
56
57                                 return location.Filename;
58                         }
59                 }
60
61                 public override string FileText {
62                         get {
63                                 if (fileText != null)
64                                         return fileText;
65
66                                 if (FileName == null)
67                                         return null;
68
69                                 //FIXME: encoding
70                                 TextReader reader = new StreamReader (FileName);
71                                 fileText = reader.ReadToEnd ();                         
72                                 return fileText;
73                         }
74                 }
75
76                 public override int [] ErrorLines {
77                         get {
78                                 if (location == null)
79                                         return null;
80
81                                 return new int [] {location.BeginLine, location.EndLine};
82                         }
83                 }
84
85                 public override bool ErrorLinesPaired {
86                         get { return true; }
87                 }
88         }
89 }
90