diff --git a/src/Umbraco.Tests/Routing/FinderByAliasTests.cs b/src/Umbraco.Tests/Routing/FinderByAliasTests.cs index 8108577439..0a9822cfda 100644 --- a/src/Umbraco.Tests/Routing/FinderByAliasTests.cs +++ b/src/Umbraco.Tests/Routing/FinderByAliasTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Routing var result = lookup.TryFindDocument(docRequest); Assert.IsTrue(result); - Assert.AreEqual(docRequest.DocumentId, nodeMatch); + Assert.AreEqual(docRequest.PublishedContentId, nodeMatch); } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Routing/FinderByIdTests.cs b/src/Umbraco.Tests/Routing/FinderByIdTests.cs index 3826e8da1c..94925599a8 100644 --- a/src/Umbraco.Tests/Routing/FinderByIdTests.cs +++ b/src/Umbraco.Tests/Routing/FinderByIdTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Routing var result = lookup.TryFindDocument(docRequest); Assert.IsTrue(result); - Assert.AreEqual(docRequest.DocumentId, nodeMatch); + Assert.AreEqual(docRequest.PublishedContentId, nodeMatch); } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Routing/FinderByNiceUrlTests.cs b/src/Umbraco.Tests/Routing/FinderByNiceUrlTests.cs index cd6ccbdbed..638d8a2de7 100644 --- a/src/Umbraco.Tests/Routing/FinderByNiceUrlTests.cs +++ b/src/Umbraco.Tests/Routing/FinderByNiceUrlTests.cs @@ -48,7 +48,7 @@ namespace Umbraco.Tests.Routing if (expectedId > 0) { Assert.IsTrue(result); - Assert.AreEqual(expectedId, docreq.DocumentId); + Assert.AreEqual(expectedId, docreq.PublishedContentId); } else { @@ -72,7 +72,7 @@ namespace Umbraco.Tests.Routing var result = lookup.TryFindDocument(docreq); Assert.IsTrue(result); - Assert.AreEqual(expectedId, docreq.DocumentId); + Assert.AreEqual(expectedId, docreq.PublishedContentId); } } diff --git a/src/Umbraco.Tests/Routing/FinderByNiceUrlWithDomainsTests.cs b/src/Umbraco.Tests/Routing/FinderByNiceUrlWithDomainsTests.cs index 67b6efbdf8..ea20439455 100644 --- a/src/Umbraco.Tests/Routing/FinderByNiceUrlWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/FinderByNiceUrlWithDomainsTests.cs @@ -167,7 +167,7 @@ namespace Umbraco.Tests.Routing var lookup = new FinderByNiceUrl(); var result = lookup.TryFindDocument(docreq); Assert.IsTrue(result); - Assert.AreEqual(expectedId, docreq.DocumentId); + Assert.AreEqual(expectedId, docreq.PublishedContentId); } [TestCase("http://domain1.com/", 1001, "en-US")] @@ -207,7 +207,7 @@ namespace Umbraco.Tests.Routing var lookup = new FinderByNiceUrl(); var result = lookup.TryFindDocument(docreq); Assert.IsTrue(result); - Assert.AreEqual(expectedId, docreq.DocumentId); + Assert.AreEqual(expectedId, docreq.PublishedContentId); } } } diff --git a/src/Umbraco.Tests/Routing/FinderByPageIdQueryTests.cs b/src/Umbraco.Tests/Routing/FinderByPageIdQueryTests.cs index 6c814b22be..f7820ef2f1 100644 --- a/src/Umbraco.Tests/Routing/FinderByPageIdQueryTests.cs +++ b/src/Umbraco.Tests/Routing/FinderByPageIdQueryTests.cs @@ -37,7 +37,7 @@ namespace Umbraco.Tests.Routing var result = lookup.TryFindDocument(docRequest); Assert.IsTrue(result); - Assert.AreEqual(docRequest.DocumentId, nodeMatch); + Assert.AreEqual(docRequest.PublishedContentId, nodeMatch); } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 6b25e34e63..f8131ec656 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -52,7 +52,7 @@ namespace Umbraco.Tests.Routing var lookup = new FinderByNiceUrl(); var result = lookup.TryFindDocument(docreq); Assert.IsTrue(result); - Assert.AreEqual(100111, docreq.DocumentId); + Assert.AreEqual(100111, docreq.PublishedContentId); // has the cache been polluted? cachedRoutes = ((DefaultRoutesCache)routingContext.UmbracoContext.RoutesCache).GetCachedRoutes(); diff --git a/src/Umbraco.Web/Routing/DefaultLastChanceFinder.cs b/src/Umbraco.Web/Routing/DefaultLastChanceFinder.cs index 8bad8fd7b7..aabe0968ee 100644 --- a/src/Umbraco.Web/Routing/DefaultLastChanceFinder.cs +++ b/src/Umbraco.Web/Routing/DefaultLastChanceFinder.cs @@ -40,7 +40,7 @@ namespace Umbraco.Web.Routing public bool TryFindDocument(PublishedContentRequest docRequest) { docRequest.PublishedContent = HandlePageNotFound(docRequest); - return docRequest.HasNode; + return docRequest.HasPublishedContent; } #region Copied over from presentation.requestHandler diff --git a/src/Umbraco.Web/Routing/FinderByAlias.cs b/src/Umbraco.Web/Routing/FinderByAlias.cs index 9eaf343d8a..6dcc507835 100644 --- a/src/Umbraco.Web/Routing/FinderByAlias.cs +++ b/src/Umbraco.Web/Routing/FinderByAlias.cs @@ -36,7 +36,7 @@ namespace Umbraco.Web.Routing if (node != null) { docRequest.PublishedContent = node; - LogHelper.Debug("Path \"{0}\" is an alias for id={1}", () => docRequest.Uri.AbsolutePath, () => docRequest.DocumentId); + LogHelper.Debug("Path \"{0}\" is an alias for id={1}", () => docRequest.Uri.AbsolutePath, () => docRequest.PublishedContentId); } } diff --git a/src/Umbraco.Web/Routing/FinderByIdPath.cs b/src/Umbraco.Web/Routing/FinderByIdPath.cs index 3a6529c02b..f3d88b35cb 100644 --- a/src/Umbraco.Web/Routing/FinderByIdPath.cs +++ b/src/Umbraco.Web/Routing/FinderByIdPath.cs @@ -44,7 +44,7 @@ namespace Umbraco.Web.Routing if (node != null) { docRequest.PublishedContent = node; - LogHelper.Debug("Found node with id={0}", () => docRequest.DocumentId); + LogHelper.Debug("Found node with id={0}", () => docRequest.PublishedContentId); } else { diff --git a/src/Umbraco.Web/Routing/FinderByNiceUrl.cs b/src/Umbraco.Web/Routing/FinderByNiceUrl.cs index cba181b32c..e084171716 100644 --- a/src/Umbraco.Web/Routing/FinderByNiceUrl.cs +++ b/src/Umbraco.Web/Routing/FinderByNiceUrl.cs @@ -79,7 +79,7 @@ namespace Umbraco.Web.Routing if (node != null) { docreq.PublishedContent = node; - LogHelper.Debug("Query matches, id={0}", () => docreq.DocumentId); + LogHelper.Debug("Query matches, id={0}", () => docreq.PublishedContentId); var iscanon = !DomainHelper.ExistsDomainInPath(docreq.Domain, node.Path); if (!iscanon) @@ -87,7 +87,7 @@ namespace Umbraco.Web.Routing // do not store if previewing or if non-canonical if (!docreq.RoutingContext.UmbracoContext.InPreviewMode && iscanon) - docreq.RoutingContext.UmbracoContext.RoutesCache.Store(docreq.DocumentId, route); + docreq.RoutingContext.UmbracoContext.RoutesCache.Store(docreq.PublishedContentId, route); } else diff --git a/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs b/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs index 282f118899..83db913b44 100644 --- a/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs +++ b/src/Umbraco.Web/Routing/PublishedContentNotFoundHandler.cs @@ -30,7 +30,7 @@ namespace Umbraco.Web.Routing var docreq = UmbracoContext.Current.PublishedContentRequest; var reason = "Cannot render the page at url '{0}'."; - if (!docreq.HasNode) + if (!docreq.HasPublishedContent) reason = "No umbraco document matches the url '{0}'."; else if (!docreq.HasTemplate) reason = "No template exists to render the document at url '{0}'."; diff --git a/src/Umbraco.Web/Routing/PublishedContentRequest.cs b/src/Umbraco.Web/Routing/PublishedContentRequest.cs index 2f15e6e107..8f6795a8d5 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequest.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequest.cs @@ -23,8 +23,8 @@ using Template = umbraco.cms.businesslogic.template.Template; namespace Umbraco.Web.Routing { /// - /// represents a request for one specified Umbraco document to be rendered - /// by one specified template, using one particular culture. + /// Represents a request for one specified Umbraco IPublishedContent to be rendered + /// by one specified Template, using one specified Culture and RenderingEngine. /// internal class PublishedContentRequest { @@ -79,7 +79,7 @@ namespace Umbraco.Web.Routing { httpContext.Response.StatusCode = 404; - if (!this.HasNode) + if (!this.HasPublishedContent) { httpContext.RemapHandler(new PublishedContentNotFoundHandler()); return; @@ -90,7 +90,7 @@ namespace Umbraco.Web.Routing } // just be safe - should never ever happen - if (!this.HasNode) + if (!this.HasPublishedContent) throw new Exception("No document to render."); // trigger PublishedContentRequest.Rendering event? @@ -105,7 +105,7 @@ namespace Umbraco.Web.Routing this.UmbracoPage = new page(this); // these two are used by many legacy objects - httpContext.Items["pageID"] = this.DocumentId; + httpContext.Items["pageID"] = this.PublishedContentId; httpContext.Items["pageElements"] = this.UmbracoPage.Elements; if (onSuccess != null) @@ -137,7 +137,7 @@ namespace Umbraco.Web.Routing // here .Is404 _has_ to be true httpContext.Response.StatusCode = 404; - if (!this.HasNode) + if (!this.HasPublishedContent) { // means the builder could not find a proper document to handle 404 // restore the saved content so we know it exists @@ -162,7 +162,7 @@ namespace Umbraco.Web.Routing this.UmbracoPage = new page(this); // these two are used by many legacy objects - httpContext.Items["pageID"] = this.DocumentId; + httpContext.Items["pageID"] = this.PublishedContentId; httpContext.Items["pageElements"] = this.UmbracoPage.Elements; switch (this.RenderingEngine) @@ -192,86 +192,27 @@ namespace Umbraco.Web.Routing _builder = new PublishedContentRequestBuilder(this); - // set default + // default is Mvc this.RenderingEngine = RenderingEngine.Mvc; } - #region Properties - - /// - /// The identifier of the requested node, if any, else zero. - /// - int _nodeId = 0; - - /// - /// The requested node, if any, else null. - /// - private IPublishedContent _publishedContent = null; - - /// - /// The "umbraco page" object. - /// - private page _umbracoPage; - - /// - /// Gets or sets the current RoutingContext. - /// - public RoutingContext RoutingContext { get; private set; } - /// /// Gets or sets the cleaned up Uri used for routing. /// + /// The cleaned up Uri has no virtual directory, no trailing slash, no .aspx extension, etc. public Uri Uri { get; private set; } - /// - /// Gets or sets the content request's domain. - /// - public Domain Domain { get; internal set; } + #region PublishedContent /// - /// Gets or sets the content request's domain Uri. + /// The identifier of the requested IPublishedContent, if any, else zero. /// - /// The Domain may contain "example.com" whereas the Uri will be fully qualified eg "http://example.com/". - public Uri DomainUri { get; internal set; } + private int _publishedContentId = 0; /// - /// Gets or sets whether the rendering engine is MVC or WebForms. + /// The requested IPublishedContent, if any, else null. /// - public RenderingEngine RenderingEngine { get; internal set; } - - /// - /// Gets a value indicating whether the content request has a domain. - /// - public bool HasDomain - { - get { return this.Domain != null; } - } - - /// - /// Gets or sets the content request's culture. - /// - public CultureInfo Culture { get; set; } - - /// - /// Gets or sets the "umbraco page" object. - /// - /// - /// This value is only used for legacy/webforms code. - /// - internal page UmbracoPage - { - get - { - if (_umbracoPage == null) - throw new InvalidOperationException("The umbraco page object is only available once Finalize()"); - - return _umbracoPage; - } - set { _umbracoPage = value; } - } - - // TODO: fixme - do we want to have an ordered list of alternate cultures, - // to allow for fallbacks when doing dictionnary lookup and such? + private IPublishedContent _publishedContent = null; /// /// Gets or sets the requested content. @@ -285,11 +226,37 @@ namespace Umbraco.Web.Routing _publishedContent = value; this.Template = null; this.AlternateTemplateAlias = null; - _nodeId = _publishedContent != null ? _publishedContent.Id : 0; + _publishedContentId = _publishedContent != null ? _publishedContent.Id : 0; } } /// + /// Gets the identifier of the requested content. + /// + /// Thrown when the content request has no content. + public int PublishedContentId + { + get + { + if (this.PublishedContent == null) + throw new InvalidOperationException("PublishedContentRequest has no document."); + return _publishedContentId; + } + } + + /// + /// Gets a value indicating whether the content request has a content. + /// + public bool HasPublishedContent + { + get { return this.PublishedContent != null; } + } + + #endregion + + #region Template + + /// /// Gets or sets the template to use to display the requested content. /// public Template Template { get; set; } @@ -312,29 +279,79 @@ namespace Umbraco.Web.Routing /// public string AlternateTemplateAlias { get; set; } - /// - /// Gets the identifier of the requested content. - /// - /// Thrown when the content request has no content. - public int DocumentId - { - get - { - if (this.PublishedContent == null) - throw new InvalidOperationException("PublishedContentRequest has no document."); - return _nodeId; - } - } + #endregion - /// - /// Gets a value indicating whether the content request has a content. - /// - public bool HasNode - { - get { return this.PublishedContent != null; } - } + #region Domain and Culture - /// + /// + /// Gets or sets the content request's domain. + /// + public Domain Domain { get; internal set; } + + /// + /// Gets or sets the content request's domain Uri. + /// + /// The Domain may contain "example.com" whereas the Uri will be fully qualified eg "http://example.com/". + public Uri DomainUri { get; internal set; } + + /// + /// Gets a value indicating whether the content request has a domain. + /// + public bool HasDomain + { + get { return this.Domain != null; } + } + + /// + /// Gets or sets the content request's culture. + /// + 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? + + #endregion + + #region Rendering + + /// + /// Gets or sets whether the rendering engine is MVC or WebForms. + /// + public RenderingEngine RenderingEngine { get; internal set; } + + #endregion + + /// + /// Gets or sets the current RoutingContext. + /// + public RoutingContext RoutingContext { get; private set; } + + /// + /// The "umbraco page" object. + /// + private page _umbracoPage; + + /// + /// Gets or sets the "umbraco page" object. + /// + /// + /// This value is only used for legacy/webforms code. + /// + internal page UmbracoPage + { + get + { + if (_umbracoPage == null) + throw new InvalidOperationException("The umbraco page object is only available once Finalize()"); + + return _umbracoPage; + } + set { _umbracoPage = value; } + } + + #region Status + + /// /// Gets or sets a value indicating whether the requested content could not be found. /// /// This is set in the PublishedContentRequestBuilder. diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs b/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs index 221c9dadaa..63490a11ee 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestBuilder.cs @@ -162,7 +162,7 @@ namespace Umbraco.Web.Routing // handle wildcard domains HandleWildcardDomains(); - bool resolved = _publishedContentRequest.HasNode && _publishedContentRequest.HasTemplate; + bool resolved = _publishedContentRequest.HasPublishedContent && _publishedContentRequest.HasTemplate; return resolved; } @@ -180,7 +180,7 @@ namespace Umbraco.Web.Routing using (DisposableTimer.DebugDuration( () => string.Format("{0}Begin resolvers", tracePrefix), - () => string.Format("{0}End resolvers, {1}", tracePrefix, (_publishedContentRequest.HasNode ? "a document was found" : "no document was found")))) + () => string.Format("{0}End resolvers, {1}", tracePrefix, (_publishedContentRequest.HasPublishedContent ? "a document was found" : "no document was found")))) { _routingContext.PublishedContentFinders.Any(lookup => lookup.TryFindDocument(_publishedContentRequest)); } @@ -214,7 +214,7 @@ namespace Umbraco.Web.Routing LogHelper.Debug("{0}{1}", () => tracePrefix, () => (i == 0 ? "Begin" : "Loop")); // handle not found - if (!_publishedContentRequest.HasNode) + if (!_publishedContentRequest.HasPublishedContent) { _publishedContentRequest.Is404 = true; LogHelper.Debug("{0}No document, try last chance lookup", () => tracePrefix); @@ -237,14 +237,14 @@ namespace Umbraco.Web.Routing break; // ensure access - if (_publishedContentRequest.HasNode) + if (_publishedContentRequest.HasPublishedContent) EnsureNodeAccess(); // loop while we don't have page, ie the redirect or access // got us to nowhere and now we need to run the notFoundLookup again // as long as it's not running out of control ie infinite loop of some sort - } while (!_publishedContentRequest.HasNode && i++ < maxLoop); + } while (!_publishedContentRequest.HasPublishedContent && i++ < maxLoop); if (i == maxLoop || j == maxLoop) { @@ -255,7 +255,7 @@ namespace Umbraco.Web.Routing // resolve template - will do nothing if a template is already set // moved out of the loop because LookupTemplate does set .PublishedContent to null anymore // (see node in LookupTemplate) - if (_publishedContentRequest.HasNode) + if (_publishedContentRequest.HasPublishedContent) LookupTemplate(); LogHelper.Debug("{0}End", () => tracePrefix); @@ -293,7 +293,7 @@ namespace Umbraco.Web.Routing //_publishedContentRequest.Document = null; // no! that would be to force a 404 LogHelper.Debug("{0}Failed to redirect to id={1}: invalid value", () => tracePrefix, () => internalRedirect); } - else if (internalRedirectId == _publishedContentRequest.DocumentId) + else if (internalRedirectId == _publishedContentRequest.PublishedContentId) { // redirect to self LogHelper.Debug("{0}Redirecting to self, ignore", () => tracePrefix); @@ -334,7 +334,7 @@ namespace Umbraco.Web.Routing var path = _publishedContentRequest.PublishedContent.Path; - if (Access.IsProtected(_publishedContentRequest.DocumentId, path)) + if (Access.IsProtected(_publishedContentRequest.PublishedContentId, path)) { LogHelper.Debug("{0}Page is protected, check for access", () => tracePrefix); @@ -352,16 +352,16 @@ namespace Umbraco.Web.Routing { LogHelper.Debug("{0}Not logged in, redirect to login page", () => tracePrefix); var loginPageId = Access.GetLoginPage(path); - if (loginPageId != _publishedContentRequest.DocumentId) + if (loginPageId != _publishedContentRequest.PublishedContentId) _publishedContentRequest.PublishedContent = _routingContext.PublishedContentStore.GetDocumentById( _umbracoContext, loginPageId); } - else if (!Access.HasAccces(_publishedContentRequest.DocumentId, user.ProviderUserKey)) + else if (!Access.HasAccces(_publishedContentRequest.PublishedContentId, user.ProviderUserKey)) { LogHelper.Debug("{0}Current member has not access, redirect to error page", () => tracePrefix); var errorPageId = Access.GetErrorPage(path); - if (errorPageId != _publishedContentRequest.DocumentId) + if (errorPageId != _publishedContentRequest.PublishedContentId) _publishedContentRequest.PublishedContent = _routingContext.PublishedContentStore.GetDocumentById( _umbracoContext, errorPageId); @@ -471,7 +471,7 @@ namespace Umbraco.Web.Routing /// As per legacy, if the redirect does not work, we just ignore it. private void FollowRedirect() { - if (_publishedContentRequest.HasNode) + if (_publishedContentRequest.HasPublishedContent) { var redirectId = _publishedContentRequest.PublishedContent.GetPropertyValue("umbracoRedirect", -1); @@ -490,7 +490,7 @@ namespace Umbraco.Web.Routing { const string tracePrefix = "HandleWildcardDomains: "; - if (!_publishedContentRequest.HasNode) + if (!_publishedContentRequest.HasPublishedContent) return; var nodePath = _publishedContentRequest.PublishedContent.Path; diff --git a/src/Umbraco.Web/Templates/TemplateRenderer.cs b/src/Umbraco.Web/Templates/TemplateRenderer.cs index 0967f0c360..4f8180fbc7 100644 --- a/src/Umbraco.Web/Templates/TemplateRenderer.cs +++ b/src/Umbraco.Web/Templates/TemplateRenderer.cs @@ -169,7 +169,7 @@ namespace Umbraco.Web.Templates // handlers like default.aspx will want it and most macros currently need it contentRequest.UmbracoPage = new page(contentRequest); //now, set the new ones for this page execution - _umbracoContext.HttpContext.Items["pageID"] = contentRequest.DocumentId; + _umbracoContext.HttpContext.Items["pageID"] = contentRequest.PublishedContentId; _umbracoContext.HttpContext.Items["pageElements"] = contentRequest.UmbracoPage.Elements; _umbracoContext.HttpContext.Items["altTemplate"] = null; _umbracoContext.PublishedContentRequest = contentRequest; diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs index e98efd8e5e..959951f564 100644 --- a/src/Umbraco.Web/umbraco.presentation/page.cs +++ b/src/Umbraco.Web/umbraco.presentation/page.cs @@ -98,7 +98,7 @@ namespace umbraco internal page(PublishedContentRequest docreq) { - if (!docreq.HasNode) + if (!docreq.HasPublishedContent) throw new ArgumentException("Document request has no node.", "docreq"); populatePageData(docreq.PublishedContent.Id, diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs index b28bcadd89..6139abefd3 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/uQuery/uQuery-Nodes.cs @@ -213,7 +213,7 @@ namespace umbraco var builder = new Umbraco.Web.Routing.PublishedContentRequestBuilder(docreq); builder.LookupDomain(); builder.LookupDocument1(); // will _not_ follow redirects, handle 404, nothing - just run lookups - return docreq.HasNode ? docreq.DocumentId : uQuery.RootNodeId; + return docreq.HasPublishedContent ? docreq.PublishedContentId : uQuery.RootNodeId; } ///