From 0225047a521ca470fda432273680d428b61ae875 Mon Sep 17 00:00:00 2001 From: Casey Neehouse Date: Fri, 21 Sep 2012 01:53:43 +0400 Subject: [PATCH] Removes .ChildNode calls for .SelectNodes() with correct element selection. Allows comments in configuration. Also updates some Macro Properties to work with new schema. --- .../Routing/DefaultLastChanceLookup.cs | 2 +- .../umbraco.presentation/library.cs | 2 +- src/Umbraco.Web/umbraco.presentation/macro.cs | 6 ++--- .../umbraco.presentation/requestHandler.cs | 23 +++++++++---------- .../umbraco/helpRedirect.aspx.cs | 3 +-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web/Routing/DefaultLastChanceLookup.cs b/src/Umbraco.Web/Routing/DefaultLastChanceLookup.cs index b20da16226..038233f4e6 100644 --- a/src/Umbraco.Web/Routing/DefaultLastChanceLookup.cs +++ b/src/Umbraco.Web/Routing/DefaultLastChanceLookup.cs @@ -94,7 +94,7 @@ namespace Umbraco.Web.Routing var customHandlers = new XmlDocument(); customHandlers.Load(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemFiles.NotFoundhandlersConfig)); - foreach (XmlNode n in customHandlers.DocumentElement.ChildNodes) + foreach (XmlNode n in customHandlers.DocumentElement.SelectNodes("notFound")) { var assemblyName = n.Attributes.GetNamedItem("assembly").Value; diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index bf7e415dcd..fb4ebc887b 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -2113,7 +2113,7 @@ namespace umbraco { string error404 = ""; XmlNode error404Node = UmbracoSettings.GetKeyAsNode("/settings/content/errors/error404"); - if (error404Node.ChildNodes.Count > 0 && error404Node.ChildNodes[0].HasChildNodes) + if (error404Node.SelectNodes("errorPage").Count > 0 && error404Node.SelectNodes("errorPage")[0].HasChildNodes) { // try to get the 404 based on current culture (via domain) XmlNode cultureErrorNode; diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index 17668fb9c6..75bdf4e7f2 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -958,7 +958,7 @@ namespace umbraco currentNode = macroXML.ImportNode(umbracoXML.GetElementById(currentID.ToString()), true); // remove all sub content nodes - foreach (XmlNode n in currentNode.SelectNodes("./node")) + foreach (XmlNode n in currentNode.SelectNodes("node|*[@isDoc]")) currentNode.RemoveChild(n); macroXmlNode.AppendChild(currentNode); @@ -979,7 +979,7 @@ namespace umbraco XmlNode source = umbracoXML.GetElementById(macroPropertyValue); if (source != null) { - XmlNodeList sourceList = source.SelectNodes("node"); + XmlNodeList sourceList = source.SelectNodes("node|*[@isDoc]"); if (sourceList.Count > 0) { int rndNumber; @@ -990,7 +990,7 @@ namespace umbraco } XmlNode node = macroXML.ImportNode(sourceList[rndNumber], true); // remove all sub content nodes - foreach (XmlNode n in node.SelectNodes("./node")) + foreach (XmlNode n in node.SelectNodes("node|*[@isDoc]")) node.RemoveChild(n); macroXmlNode.AppendChild(node); diff --git a/src/Umbraco.Web/umbraco.presentation/requestHandler.cs b/src/Umbraco.Web/umbraco.presentation/requestHandler.cs index e069f1ca70..b330f5d8ed 100644 --- a/src/Umbraco.Web/umbraco.presentation/requestHandler.cs +++ b/src/Umbraco.Web/umbraco.presentation/requestHandler.cs @@ -286,21 +286,21 @@ namespace umbraco { IOHelper.MapPath( SystemFiles.NotFoundhandlersConfig ) ); } - for (int i = 0; i < _customHandlers.DocumentElement.ChildNodes.Count; i++) { + foreach (XmlNode notFoundHandler in _customHandlers.DocumentElement.SelectNodes("notFound")) + { + // Load handler - string _chAssembly = - _customHandlers.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("assembly").Value; - string _chType = _customHandlers.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("type").Value; + string _chAssembly = notFoundHandler.Attributes.GetNamedItem("assembly").Value; + string _chType = notFoundHandler.Attributes.GetNamedItem("type").Value; // check for namespace string _chNameSpace = _chAssembly; - if (_customHandlers.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("namespace") != null) - _chNameSpace = - _customHandlers.DocumentElement.ChildNodes[i].Attributes.GetNamedItem("namespace").Value; + if (notFoundHandler.Attributes.GetNamedItem("namespace") != null) + _chNameSpace = notFoundHandler.Attributes.GetNamedItem("namespace").Value; + try { // Reflect to execute and check whether the type is umbraco.main.IFormhandler HttpContext.Current.Trace.Write("notFoundHandler", - string.Format("Trying NotFoundHandler '{0}.{1}'...", _chAssembly, - _chType)); + string.Format("Trying NotFoundHandler '{0}.{1}'...", _chAssembly, _chType)); Assembly assembly = Assembly.LoadFrom( IOHelper.MapPath( SystemDirectories.Bin + "/" + _chAssembly + ".dll")); @@ -313,9 +313,8 @@ namespace umbraco { int redirectID = typeInstance.redirectID; currentPage = umbracoContent.GetElementById(redirectID.ToString()); HttpContext.Current.Trace.Write("notFoundHandler", - string.Format( - "NotFoundHandler '{0}.{1} found node matching {2} with id: {3}", - _chAssembly, _chType, url, redirectID)); + string.Format("NotFoundHandler '{0}.{1} found node matching {2} with id: {3}", + _chAssembly, _chType, url, redirectID)); // check for caching if (typeInstance.CacheUrl) { diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/helpRedirect.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/helpRedirect.aspx.cs index a4fb3420b3..2bd8d675ca 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/helpRedirect.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/helpRedirect.aspx.cs @@ -19,9 +19,8 @@ namespace umbraco.presentation.umbraco HelpConfigPages = new List(); - foreach (XmlNode linkNode in helpConfigNode.ChildNodes) + foreach (XmlNode linkNode in helpConfigNode.SelectNodes("link")) { - if (linkNode.NodeType != XmlNodeType.Element) continue; HelpConfigPages.Add(new HelpConfigPage {