From 58b91fe6a040fe9ba321855dc27b082e76f4d9b1 Mon Sep 17 00:00:00 2001 From: Stephan Date: Wed, 23 Jan 2013 14:08:14 -0100 Subject: [PATCH] Web.Routing - reorganize finders for better backward compat. with pre-4.10 --- .../Routing/ContentFinderByLegacy404.cs | 2 +- ....cs => ContentFinderByNotFoundHandlers.cs} | 41 +++++++------------ .../Routing/PublishedContentRequestEngine.cs | 9 ++-- src/Umbraco.Web/Umbraco.Web.csproj | 2 +- src/Umbraco.Web/WebBootManager.cs | 5 ++- 5 files changed, 26 insertions(+), 33 deletions(-) rename src/Umbraco.Web/Routing/{ContentLastChanceFinder.cs => ContentFinderByNotFoundHandlers.cs} (71%) diff --git a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs index 52bb68d6ec..c092668ea3 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByLegacy404.cs @@ -34,7 +34,7 @@ namespace Umbraco.Web.Routing if (id > 0) { - LogHelper.Debug("Got id={1}.", () => id); + LogHelper.Debug("Got id={0}.", () => id); content = pcr.RoutingContext.PublishedContentStore.GetDocumentById( pcr.RoutingContext.UmbracoContext, diff --git a/src/Umbraco.Web/Routing/ContentLastChanceFinder.cs b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs similarity index 71% rename from src/Umbraco.Web/Routing/ContentLastChanceFinder.cs rename to src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs index e8d5d90b15..f46f393135 100644 --- a/src/Umbraco.Web/Routing/ContentLastChanceFinder.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNotFoundHandlers.cs @@ -12,25 +12,18 @@ using umbraco.interfaces; namespace Umbraco.Web.Routing { /// - /// Provides an implementation of to be used as a last chance finder, - /// that handles backward compatilibty with legacy INotFoundHandler. + /// Provides an implementation of that runs legacy INotFoundHandler. /// - internal class ContentLastChanceFinder : IContentFinder + internal class ContentFinderByNotFoundHandlers : IContentFinder { // notes // // at the moment we load the legacy INotFoundHandler - // excluding those that have been replaced by proper lookups, + // excluding those that have been replaced by proper finders, // and run them. // - // when we finaly obsolete INotFoundHandler, we'll have to move - // over here code from legacy requestHandler.hande404, which - // basically uses umbraco.library.GetCurrentNotFoundPageId(); - // which also would need to be refactored / migrated here. - // - // the best way to do this would be to create a DefaultLastChanceLookup2 - // that would do everything by itself, and let ppl use it if they - // want, then make it the default one, then remove this one. + // code from requestHandler.handle404 has been moved over to + // the new ContentFinderByLegacy404 finder. /// /// Tries to find and assign an Umbraco document to a PublishedContentRequest. @@ -49,7 +42,7 @@ namespace Umbraco.Web.Routing IPublishedContent HandlePageNotFound(PublishedContentRequest docRequest) { - LogHelper.Debug("Running for url='{0}'.", () => docRequest.Uri.AbsolutePath); + LogHelper.Debug("Running for url='{0}'.", () => docRequest.Uri.AbsolutePath); //XmlNode currentPage = null; IPublishedContent currentPage = null; @@ -66,7 +59,7 @@ namespace Umbraco.Web.Routing // FIXME - could it be null? - LogHelper.Debug("Handler '{0}' found node with id={1}.", () => handler.GetType().FullName, () => handler.redirectID); + LogHelper.Debug("Handler '{0}' found node with id={1}.", () => handler.GetType().FullName, () => handler.redirectID); //// check for caching //if (handler.CacheUrl) @@ -97,7 +90,7 @@ namespace Umbraco.Web.Routing // initialize handlers // create the definition cache - LogHelper.Debug("Registering custom handlers."); + LogHelper.Debug("Registering custom handlers."); var customHandlerTypes = new List(); @@ -108,21 +101,17 @@ namespace Umbraco.Web.Routing { var assemblyName = n.Attributes.GetNamedItem("assembly").Value; + // skip those that are in umbraco.dll because we have replaced them with finders + if (assemblyName == "umbraco") + continue; + var typeName = n.Attributes.GetNamedItem("type").Value; string ns = assemblyName; var nsAttr = n.Attributes.GetNamedItem("namespace"); if (nsAttr != null && !string.IsNullOrWhiteSpace(nsAttr.Value)) ns = nsAttr.Value; - if (assemblyName == "umbraco" && (ns + "." + typeName) != "umbraco.handle404") - { - // skip those that are in umbraco.dll because we have replaced them with IContentFinder - // but do not skip "handle404" as that's the built-in legacy final handler, and for the time - // being people will have it in their config. - continue; - } - - LogHelper.Debug("Registering '{0}.{1},{2}'.", () => ns, () => typeName, () => assemblyName); + LogHelper.Debug("Registering '{0}.{1},{2}'.", () => ns, () => typeName, () => assemblyName); Type type = null; try @@ -135,7 +124,7 @@ namespace Umbraco.Web.Routing } catch (Exception e) { - LogHelper.Error("Error registering handler, ignoring.", e); + LogHelper.Error("Error registering handler, ignoring.", e); } if (type != null) @@ -168,7 +157,7 @@ namespace Umbraco.Web.Routing } catch (Exception e) { - LogHelper.Error(string.Format("Error instanciating handler {0}, ignoring.", type.FullName), e); + LogHelper.Error(string.Format("Error instanciating handler {0}, ignoring.", type.FullName), e); } } diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs index 86ed01278d..49a0a4643e 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs @@ -524,7 +524,7 @@ namespace Umbraco.Web.Routing } /// - /// Finds a template for the current node. + /// Finds a template for the current node, if any. /// private void FindTemplate() { @@ -534,8 +534,11 @@ namespace Umbraco.Web.Routing const string tracePrefix = "FindTemplate: "; - if (_pcr.PublishedContent == null) - throw new InvalidOperationException("There is no PublishedContent."); + if (_pcr.PublishedContent == null) + { + _pcr.Template = null; + return; + } // 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 diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 6ef4b120ba..496050690d 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -329,6 +329,7 @@ + @@ -429,7 +430,6 @@ - diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 422bef2dbc..cb52a8dc5e 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -193,7 +193,7 @@ namespace Umbraco.Web typeof (RenderControllerFactory) }); - IContentLastChanceFinderResolver.Current = new IContentLastChanceFinderResolver(new ContentLastChanceFinder()); + IContentLastChanceFinderResolver.Current = new IContentLastChanceFinderResolver(new ContentFinderByLegacy404()); IContentFinderResolver.Current = new IContentFinderResolver( //add all known resolvers in the correct order, devs can then modify this list on application startup either by binding to events @@ -205,7 +205,8 @@ namespace Umbraco.Web typeof (ContentFinderByIdPath), typeof (ContentFinderByNiceUrlAndTemplate), typeof (ContentFinderByProfile), - typeof (ContentFinderByUrlAlias) + typeof (ContentFinderByUrlAlias), + typeof (ContentFinderByNotFoundHandlers) }); RoutesCacheResolver.Current = new RoutesCacheResolver(new DefaultRoutesCache(_isForTesting == false));