| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Linq; |
| | | 6 | | using System.Web; |
| | | 7 | | using System.Xml.Linq; |
| | | 8 | | |
| | | 9 | | namespace CoreWCF.Dispatcher |
| | | 10 | | { |
| | | 11 | | internal class HelpHtmlBuilder |
| | | 12 | | { |
| | | 13 | | private const string HtmlHtmlElementName = "{http://www.w3.org/1999/xhtml}html"; |
| | | 14 | | private const string HtmlHeadElementName = "{http://www.w3.org/1999/xhtml}head"; |
| | | 15 | | private const string HtmlTitleElementName = "{http://www.w3.org/1999/xhtml}title"; |
| | | 16 | | private const string HtmlBodyElementName = "{http://www.w3.org/1999/xhtml}body"; |
| | | 17 | | private const string HtmlPElementName = "{http://www.w3.org/1999/xhtml}p"; |
| | | 18 | | private const string HtmlDivElementName = "{http://www.w3.org/1999/xhtml}div"; |
| | | 19 | | private const string HtmlClassAttributeName = "class"; |
| | | 20 | | private const string HtmlIdAttributeName = "id"; |
| | | 21 | | private const string HtmlHeading1Class = "heading1"; |
| | | 22 | | private const string HtmlContentClass = "content"; |
| | | 23 | | |
| | | 24 | | public static XDocument CreateServerErrorPage(Uri helpUri, Exception error) |
| | | 25 | | { |
| | 4 | 26 | | XDocument document = CreateBaseDocument(SR.Format(SR.HelpPageRequestErrorTitle)); |
| | | 27 | | |
| | 4 | 28 | | XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass), |
| | 4 | 29 | | new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.Format(SR.H |
| | 4 | 30 | | if (helpUri == null) |
| | | 31 | | { |
| | 4 | 32 | | if (error != null) |
| | | 33 | | { |
| | 3 | 34 | | div.Add(new XElement(HtmlPElementName, SR.Format(SR.HelpServerErrorProcessingRequestWithDetails, err |
| | 3 | 35 | | div.Add(new XElement(HtmlPElementName, error.StackTrace ?? String.Empty)); |
| | | 36 | | } |
| | | 37 | | else |
| | | 38 | | { |
| | 1 | 39 | | div.Add(new XElement(HtmlPElementName, SR.Format(SR.HelpServerErrorProcessingRequest))); |
| | | 40 | | } |
| | | 41 | | } |
| | | 42 | | else |
| | | 43 | | { |
| | 0 | 44 | | string encodedHelpLink = HttpUtility.HtmlEncode(helpUri.AbsoluteUri); |
| | 0 | 45 | | if (error != null) |
| | | 46 | | { |
| | 0 | 47 | | string errorMessage = HttpUtility.HtmlEncode(error.Message); |
| | 0 | 48 | | div.Add(XElement.Parse(SR.Format(SR.HelpServerErrorProcessingRequestWithDetailsAndLink, encodedHelpL |
| | 0 | 49 | | div.Add(new XElement(HtmlPElementName, error.StackTrace ?? string.Empty)); |
| | | 50 | | } |
| | | 51 | | else |
| | | 52 | | { |
| | 0 | 53 | | div.Add(XElement.Parse(SR.Format(SR.HelpServerErrorProcessingRequestWithLink, encodedHelpLink))); |
| | | 54 | | } |
| | | 55 | | |
| | | 56 | | } |
| | | 57 | | |
| | 4 | 58 | | document.Descendants(HtmlBodyElementName).First().Add(div); |
| | 4 | 59 | | return document; |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | public static XDocument CreateTransferRedirectPage(string originalTo, string newLocation) |
| | | 63 | | { |
| | 0 | 64 | | XDocument document = CreateBaseDocument(SR.HelpPageTitleText); |
| | | 65 | | |
| | 0 | 66 | | XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass), |
| | 0 | 67 | | new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit |
| | 0 | 68 | | XElement.Parse(SR.Format(SR.HelpPageRedirect, HttpUtility.HtmlEncode(originalTo), HttpUtility.HtmlEncode |
| | 0 | 69 | | document.Descendants(HtmlBodyElementName).First().Add(div); |
| | 0 | 70 | | return document; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | public static XDocument CreateMethodNotAllowedPage(Uri helpUri) |
| | | 74 | | { |
| | 0 | 75 | | XDocument document = CreateBaseDocument(SR.HelpPageTitleText); |
| | | 76 | | |
| | 0 | 77 | | XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass), |
| | 0 | 78 | | new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit |
| | 0 | 79 | | if (helpUri == null) |
| | | 80 | | { |
| | 0 | 81 | | div.Add(new XElement(HtmlPElementName, SR.HelpPageMethodNotAllowed)); |
| | | 82 | | } |
| | | 83 | | else |
| | | 84 | | { |
| | 0 | 85 | | div.Add(XElement.Parse(SR.Format(SR.HelpPageMethodNotAllowedWithLink, HttpUtility.HtmlEncode(helpUri.Abs |
| | | 86 | | } |
| | 0 | 87 | | document.Descendants(HtmlBodyElementName).First().Add(div); |
| | 0 | 88 | | return document; |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | public static XDocument CreateEndpointNotFound(Uri helpUri) |
| | | 92 | | { |
| | 0 | 93 | | XDocument document = CreateBaseDocument(SR.HelpPageTitleText); |
| | | 94 | | |
| | 0 | 95 | | XElement div = new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass), |
| | 0 | 96 | | new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR.HelpPageTit |
| | 0 | 97 | | if (helpUri == null) |
| | | 98 | | { |
| | 0 | 99 | | div.Add(new XElement(HtmlPElementName, SR.HelpPageEndpointNotFound)); |
| | | 100 | | } |
| | | 101 | | else |
| | | 102 | | { |
| | 0 | 103 | | div.Add(XElement.Parse(SR.Format(SR.HelpPageEndpointNotFoundWithLink, HttpUtility.HtmlEncode(helpUri.Abs |
| | | 104 | | } |
| | 0 | 105 | | document.Descendants(HtmlBodyElementName).First().Add(div); |
| | 0 | 106 | | return document; |
| | | 107 | | } |
| | | 108 | | |
| | | 109 | | private static XDocument CreateBaseDocument(string title) |
| | | 110 | | { |
| | 4 | 111 | | return new XDocument( |
| | 4 | 112 | | new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xht |
| | 4 | 113 | | new XElement(HtmlHtmlElementName, |
| | 4 | 114 | | new XElement(HtmlHeadElementName, |
| | 4 | 115 | | new XElement(HtmlTitleElementName, title), |
| | 4 | 116 | | new XElement("{http://www.w3.org/1999/xhtml}style", SR.Format(SR.HelpPageHtml))), |
| | 4 | 117 | | new XElement(HtmlBodyElementName))); |
| | | 118 | | } |
| | | 119 | | } |
| | | 120 | | } |