diff --git a/src/Umbraco.Web/Routing/PublishedContentRequest.cs b/src/Umbraco.Web/Routing/PublishedContentRequest.cs index fd50e48b5e..f526dd715f 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequest.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequest.cs @@ -1,22 +1,9 @@ using System; -using System.Linq; -using System.Text; -using System.Threading; -using System.Web; -using System.Xml; using System.Globalization; -using System.Diagnostics; - -// legacy using Umbraco.Core; -using Umbraco.Core.Logging; using Umbraco.Core.Models; using umbraco; -using umbraco.BusinessLogic; -using umbraco.NodeFactory; using umbraco.cms.businesslogic.web; -using umbraco.cms.businesslogic.member; -using umbraco.interfaces; namespace Umbraco.Web.Routing { @@ -37,7 +24,7 @@ namespace Umbraco.Web.Routing // the engine that does all the processing // because in order to keep things clean and separated, // the content request is just a data holder - private PublishedContentRequestEngine _engine; + private readonly PublishedContentRequestEngine _engine; /// /// Initializes a new instance of the class with a specific Uri and routing context. @@ -49,12 +36,12 @@ namespace Umbraco.Web.Routing if (uri == null) throw new ArgumentNullException("uri"); if (routingContext == null) throw new ArgumentNullException("routingContext"); - this.Uri = uri; - this.RoutingContext = routingContext; + Uri = uri; + RoutingContext = routingContext; _engine = new PublishedContentRequestEngine(this); - this.RenderingEngine = RenderingEngine.Unknown; + RenderingEngine = RenderingEngine.Unknown; } /// @@ -95,22 +82,17 @@ namespace Umbraco.Web.Routing #region PublishedContent - /// - /// The identifier of the requested IPublishedContent, if any, else zero. - /// - private int _publishedContentId = 0; - /// /// The requested IPublishedContent, if any, else null. /// - private IPublishedContent _publishedContent = null; + private IPublishedContent _publishedContent; /// /// The initial requested IPublishedContent, if any, else null. /// /// The initial requested content is the content that was found by the finders, /// before anything such as 404, redirect... took place. - private IPublishedContent _initialPublishedContent = null; + private IPublishedContent _initialPublishedContent; /// /// Gets or sets the requested content. @@ -122,8 +104,7 @@ namespace Umbraco.Web.Routing set { _publishedContent = value; - this.TemplateModel = null; - _publishedContentId = _publishedContent != null ? _publishedContent.Id : 0; + TemplateModel = null; } } @@ -135,20 +116,31 @@ namespace Umbraco.Web.Routing public IPublishedContent InitialPublishedContent { get { return _initialPublishedContent; } } /// - /// Gets or sets a value indicating whether the current published content is the initial one. + /// Gets value indicating whether the current published content is the initial one. /// public bool IsInitialPublishedContent { - get { return _initialPublishedContent != null && _initialPublishedContent == _publishedContent; } - set { _initialPublishedContent = _publishedContent; } + get + { + return _initialPublishedContent != null && _initialPublishedContent == _publishedContent; + } } + /// + /// Indicates that the current PublishedContent is the initial one. + /// + public void SetIsInitialPublishedContent() + { + // note: it can very well be null if the initial content was not found + _initialPublishedContent = _publishedContent; + } + /// /// Gets a value indicating whether the content request has a content. /// public bool HasPublishedContent { - get { return this.PublishedContent != null; } + get { return PublishedContent != null; } } #endregion @@ -173,10 +165,10 @@ namespace Umbraco.Web.Routing set { _template = value; - this.RenderingEngine = RenderingEngine.Unknown; // reset + RenderingEngine = RenderingEngine.Unknown; // reset if (_template != null) - this.RenderingEngine = _engine.FindTemplateRenderingEngine(_template.Alias); + RenderingEngine = _engine.FindTemplateRenderingEngine(_template.Alias); } } @@ -204,25 +196,19 @@ namespace Umbraco.Web.Routing { if (string.IsNullOrWhiteSpace(alias)) { - this.TemplateModel = null; + TemplateModel = null; return true; } - else - { - // NOTE - can we stil get it with whitespaces in it due to old legacy bugs? - alias = alias.Replace(" ", ""); - var model = ApplicationContext.Current.Services.FileService.GetTemplate(alias); - if (model == null) - { - return false; - } - else - { - this.TemplateModel = model; - return true; - } - } + // NOTE - can we stil get it with whitespaces in it due to old legacy bugs? + alias = alias.Replace(" ", ""); + + var model = ApplicationContext.Current.Services.FileService.GetTemplate(alias); + if (model == null) + return false; + + TemplateModel = model; + return true; } /// @@ -253,7 +239,7 @@ namespace Umbraco.Web.Routing /// public bool HasDomain { - get { return this.Domain != null; } + get { return Domain != null; } } /// @@ -261,8 +247,8 @@ namespace Umbraco.Web.Routing /// public CultureInfo Culture { get; set; } - // TODO: fixme - do we want to have an ordered list of alternate cultures, - // to allow for fallbacks when doing dictionnary lookup and such? + // note: do we want to have an ordered list of alternate cultures, + // to allow for fallbacks when doing dictionnary lookup and such? #endregion @@ -318,13 +304,13 @@ namespace Umbraco.Web.Routing /// where we want to allow developers to indicate a request is 404 but not to cancel it. public void SetIs404() { - this.Is404 = true; + Is404 = true; } /// /// Gets a value indicating whether the content request triggers a redirect (permanent or not). /// - public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(this.RedirectUrl); } } + public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(RedirectUrl); } } /// /// Gets or sets a value indicating whether the redirect is permanent. diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs index 2557b21c4c..af7336b578 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using System.Threading; using System.Globalization; using System.IO; @@ -13,15 +11,14 @@ using Umbraco.Core.Logging; using umbraco; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.language; -using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.member; namespace Umbraco.Web.Routing { internal class PublishedContentRequestEngine { - private PublishedContentRequest _pcr; - private RoutingContext _routingContext; + private readonly PublishedContentRequest _pcr; + private readonly RoutingContext _routingContext; /// /// Initializes a new instance of the class with a content request. @@ -342,7 +339,7 @@ namespace Umbraco.Web.Routing // indicate that the published content (if any) we have at the moment is the // one that was found by the standard finders before anything else took place. - _pcr.IsInitialPublishedContent = true; + _pcr.SetIsInitialPublishedContent(); } /// @@ -382,8 +379,9 @@ namespace Umbraco.Web.Routing // follow internal redirects as long as it's not running out of control ie infinite loop of some sort j = 0; - while (FollowInternalRedirects() && j++ < maxLoop) ; - if (j == maxLoop) // we're running out of control + while (FollowInternalRedirects() && j++ < maxLoop) + { } + if (j == maxLoop) // we're running out of control break; // ensure access @@ -447,8 +445,8 @@ namespace Umbraco.Web.Routing // redirect to another page var node = _routingContext.PublishedContentStore.GetDocumentById(_routingContext.UmbracoContext, internalRedirectId); - _pcr.PublishedContent = node; - if (node != null) + _pcr.PublishedContent = node; + if (node != null) { redirect = true; LogHelper.Debug("{0}Redirecting to id={1}", () => tracePrefix, () => internalRedirectId); @@ -535,8 +533,8 @@ namespace Umbraco.Web.Routing // read the alternate template alias, from querystring, form, cookie or server vars, // only if the published content is the initial once, else the alternate template // does not apply - string altTemplate = _pcr.IsInitialPublishedContent - ? _routingContext.UmbracoContext.HttpContext.Request["altTemplate"] + string altTemplate = _pcr.IsInitialPublishedContent + ? _routingContext.UmbracoContext.HttpContext.Request["altTemplate"] : null; if (string.IsNullOrWhiteSpace(altTemplate))