3 // Marek Habersack <grendel@twistedcode.net>
5 // (C) 2011 Novell, Inc (http://novell.com/)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections.Generic;
35 abstract class ExceptionPageTemplate
37 public const string Template_PageTopName = "PageTop";
38 public const string Template_PageBottomName = "PageBottom";
39 public const string Template_PageStandardName = "PageStandard";
40 public const string Template_PageCustomErrorDefaultName = "PageCustomErrorDefault";
41 public const string Template_PageHtmlizedExceptionName = "PageHtmlizedException";
42 public const string Template_PageTitleName = "Title";
43 public const string Template_ExceptionTypeName = "ExceptionType";
44 public const string Template_ExceptionMessageName = "ExceptionMessage";
45 public const string Template_DescriptionName = "Description";
46 public const string Template_DetailsName = "Details";
47 public const string Template_RuntimeVersionInformationName = "RuntimeVersionInformation";
48 public const string Template_AspNetVersionInformationName = "AspNetVersionInformation";
49 public const string Template_StackTraceName = "StackTrace";
50 public const string Template_FullStackTraceName = "FullStackTrace";
51 public const string Template_HtmlizedExceptionOriginName = "HtmlizedExceptionOrigin";
52 public const string Template_HtmlizedExceptionShortSourceName = "HtmlizedExceptionShortSource";
53 public const string Template_HtmlizedExceptionLongSourceName = "HtmlizedExceptionLongSource";
54 public const string Template_HtmlizedExceptionSourceFileName = "HtmlizedExceptionSourceFile";
55 public const string Template_HtmlizedExceptionErrorLinesName = "HtmlizedExceptionErrorLines";
56 public const string Template_HtmlizedExceptionCompilerOutputName = "HtmlizedExceptionCompilerOutput";
58 List <ExceptionPageTemplateFragment> fragments;
60 public List <ExceptionPageTemplateFragment> Fragments {
62 if (fragments == null)
63 fragments = new List <ExceptionPageTemplateFragment> ();
68 public abstract void Init ();
70 void InitFragments (ExceptionPageTemplateValues values)
72 foreach (ExceptionPageTemplateFragment fragment in fragments) {
76 fragment.Init (values);
80 public string Render (ExceptionPageTemplateValues values, ExceptionPageTemplateType pageType)
83 throw new ArgumentNullException ("values");
84 var sb = new StringBuilder ();
86 Render (values, pageType, (string text) => {
90 return sb.ToString ();
93 public void Render (HttpResponse response, ExceptionPageTemplateValues values, ExceptionPageTemplateType pageType)
99 throw new ArgumentNullException ("values");
101 Render (values, pageType, (string text) => {
102 response.Write (text);
106 void Render (ExceptionPageTemplateValues values, ExceptionPageTemplateType pageType, Action <string> writer)
108 if (fragments == null || fragments.Count == 0 || values.Count == 0)
111 InitFragments (values);
113 foreach (ExceptionPageTemplateFragment fragment in fragments) {
114 if (fragment == null || (fragment.ValidForPageType & pageType) == 0)
117 value = values.Get (fragment.Name);
118 if (value == null || !fragment.Visible (values))
121 writer (fragment.ReplaceMacros (value, values));