diff --git a/src/Umbraco.Core/DocumentExtensions.cs b/src/Umbraco.Core/DocumentExtensions.cs
new file mode 100644
index 0000000000..70ee818524
--- /dev/null
+++ b/src/Umbraco.Core/DocumentExtensions.cs
@@ -0,0 +1,43 @@
+using System.Linq;
+using Umbraco.Core.Models;
+
+namespace Umbraco.Core
+{
+ internal static class DocumentExtensions
+ {
+ ///
+ /// Returns the property as the specified type, if the property is not found or does not convert
+ /// then the default value of type T is returned.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static T GetPropertyValue(this IDocument prop, string alias)
+ {
+ return prop.GetPropertyValue(alias, default(T));
+ }
+
+ public static T GetPropertyValue(this IDocument prop, string alias, T ifCannotConvert)
+ {
+ var p = prop.GetProperty(alias);
+ if (p == null)
+ return default(T);
+ var converted = p.TryConvertTo();
+ if (converted.Success)
+ return converted.Result;
+ return ifCannotConvert;
+ }
+
+ ///
+ /// Returns the property based on the case insensitive match of the alias
+ ///
+ ///
+ ///
+ ///
+ public static IDocumentProperty GetProperty(this IDocument d, string alias)
+ {
+ return d.Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Core/DocumentPropertyExtensions.cs b/src/Umbraco.Core/DocumentPropertyExtensions.cs
deleted file mode 100644
index f7fef5e56e..0000000000
--- a/src/Umbraco.Core/DocumentPropertyExtensions.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Umbraco.Core.Models;
-
-namespace Umbraco.Core
-{
- internal static class DocumentPropertyExtensions
- {
- ///
- /// Returns the property as the specified type, if the property is not found or does not convert
- /// then the default value of type T is returned.
- ///
- ///
- ///
- ///
- ///
- public static T GetProperty(this IDocument prop, string alias)
- {
- var p = prop.GetProperty(alias);
- if (p == null)
- return default(T);
- var converted = p.TryConvertTo();
- if (converted.Success)
- return converted.Result;
- return default(T);
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Models/DocumentExtensions.cs b/src/Umbraco.Core/Models/DocumentExtensions.cs
deleted file mode 100644
index 84be18b9ae..0000000000
--- a/src/Umbraco.Core/Models/DocumentExtensions.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System.Linq;
-
-namespace Umbraco.Core.Models
-{
- ///
- /// Extension methods for IDocument
- ///
- public static class DocumentExtensions
- {
- ///
- /// Returns the property based on the case insensitive match of the alias
- ///
- ///
- ///
- ///
- public static IDocumentProperty GetProperty(this IDocument d, string alias)
- {
- return d.Properties.FirstOrDefault(p => p.Alias.InvariantEquals(alias));
- }
- }
-}
\ No newline at end of file
diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj
index 5fdeed9fec..189ec6d3d1 100644
--- a/src/Umbraco.Core/Umbraco.Core.csproj
+++ b/src/Umbraco.Core/Umbraco.Core.csproj
@@ -59,7 +59,7 @@
-
+
@@ -90,7 +90,6 @@
-
diff --git a/src/Umbraco.Web.UI/Web.config b/src/Umbraco.Web.UI/Web.config
index aa7e19c746..a30b9080dc 100644
--- a/src/Umbraco.Web.UI/Web.config
+++ b/src/Umbraco.Web.UI/Web.config
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Umbraco.Web/DefaultPublishedContentStore.cs b/src/Umbraco.Web/DefaultPublishedContentStore.cs
index 2e41db2819..04da429b7a 100644
--- a/src/Umbraco.Web/DefaultPublishedContentStore.cs
+++ b/src/Umbraco.Web/DefaultPublishedContentStore.cs
@@ -13,7 +13,7 @@ namespace Umbraco.Web
///
/// An IPublishedContentStore which uses the Xml cache system to return data
///
- internal class DefaultPublishedContentStore : DefaultPublishedMediaStore, IPublishedContentStore
+ internal class DefaultPublishedContentStore : IPublishedContentStore
{
private IDocument ConvertToDocument(XmlNode xmlNode)
@@ -24,7 +24,7 @@ namespace Umbraco.Web
return new Models.XmlDocument(xmlNode);
}
- public override IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId)
+ public virtual IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId)
{
if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
diff --git a/src/Umbraco.Web/DefaultPublishedMediaStore.cs b/src/Umbraco.Web/DefaultPublishedMediaStore.cs
index ec8ad95dc5..831c65f06b 100644
--- a/src/Umbraco.Web/DefaultPublishedMediaStore.cs
+++ b/src/Umbraco.Web/DefaultPublishedMediaStore.cs
@@ -21,32 +21,6 @@ namespace Umbraco.Web
return GetUmbracoMedia(nodeId);
}
- public virtual string GetDocumentProperty(UmbracoContext umbracoContext, IDocument node, string propertyAlias)
- {
- if (umbracoContext == null) throw new ArgumentNullException("umbracoContext");
- if (node == null) throw new ArgumentNullException("node");
- if (propertyAlias == null) throw new ArgumentNullException("propertyAlias");
-
- if (propertyAlias.StartsWith("@"))
- {
- //if it starts with an @ then its a property of the object, not a user defined property
- var propName = propertyAlias.TrimStart('@');
- var prop = TypeHelper.GetProperty(typeof(IDocument), propName, true, false, false, false);
- if (prop == null)
- throw new ArgumentException("The property name " + propertyAlias + " was not found on type " + typeof(IDocument));
- var val = prop.GetValue(node, null);
- var valAsString = val == null ? "" : val.ToString();
- return valAsString;
- }
- else
- {
- var prop = node.GetProperty(propertyAlias);
- return prop == null ? null : Convert.ToString(prop.Value);
- //var propertyNode = node.SelectSingleNode("./" + propertyAlias);
- //return propertyNode == null ? null : propertyNode.InnerText;
- }
- }
-
private IDocument GetUmbracoMedia(int id)
{
diff --git a/src/Umbraco.Web/IPublishedContentStore.cs b/src/Umbraco.Web/IPublishedContentStore.cs
index 22ee23ba7a..9195e8bc7d 100644
--- a/src/Umbraco.Web/IPublishedContentStore.cs
+++ b/src/Umbraco.Web/IPublishedContentStore.cs
@@ -5,7 +5,7 @@ namespace Umbraco.Web
///
/// Defines the methods to access published content
///
- internal interface IPublishedContentStore : IPublishedMediaStore
+ internal interface IPublishedContentStore : IPublishedStore
{
IDocument GetDocumentByRoute(UmbracoContext umbracoContext, string route, bool? hideTopLevelNode = null);
IDocument GetDocumentByUrlAlias(UmbracoContext umbracoContext, int rootNodeId, string alias);
diff --git a/src/Umbraco.Web/IPublishedMediaStore.cs b/src/Umbraco.Web/IPublishedMediaStore.cs
index 78efe3488f..82f8b8e15b 100644
--- a/src/Umbraco.Web/IPublishedMediaStore.cs
+++ b/src/Umbraco.Web/IPublishedMediaStore.cs
@@ -1,13 +1,9 @@
-using Umbraco.Core.Models;
-
namespace Umbraco.Web
{
///
/// Defines the methods to access published media
///
- internal interface IPublishedMediaStore
+ internal interface IPublishedMediaStore : IPublishedStore
{
- IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId);
- string GetDocumentProperty(UmbracoContext umbracoContext, IDocument node, string propertyAlias);
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/IPublishedStore.cs b/src/Umbraco.Web/IPublishedStore.cs
new file mode 100644
index 0000000000..807730550a
--- /dev/null
+++ b/src/Umbraco.Web/IPublishedStore.cs
@@ -0,0 +1,12 @@
+using Umbraco.Core.Models;
+
+namespace Umbraco.Web
+{
+ ///
+ /// Defines the methods for published documents
+ ///
+ internal interface IPublishedStore
+ {
+ IDocument GetDocumentById(UmbracoContext umbracoContext, int nodeId);
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Routing/DocumentRequestBuilder.cs b/src/Umbraco.Web/Routing/DocumentRequestBuilder.cs
index 31cbff2a39..92215614b1 100644
--- a/src/Umbraco.Web/Routing/DocumentRequestBuilder.cs
+++ b/src/Umbraco.Web/Routing/DocumentRequestBuilder.cs
@@ -238,8 +238,8 @@ namespace Umbraco.Web.Routing
throw new InvalidOperationException("There is no node.");
bool redirect = false;
- string internalRedirect = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "umbracoInternalRedirectId");
-
+ var internalRedirect = _documentRequest.Document.GetPropertyValue("umbracoInternalRedirectId");
+
if (!string.IsNullOrWhiteSpace(internalRedirect))
{
LogHelper.Debug("{0}Found umbracoInternalRedirectId={1}", () => tracePrefix, () => internalRedirect);
@@ -293,7 +293,7 @@ namespace Umbraco.Web.Routing
if (_documentRequest.Document == null)
throw new InvalidOperationException("There is no node.");
- var path = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "@path");
+ var path = _documentRequest.Document.Path;
if (Access.IsProtected(_documentRequest.DocumentId, path))
{
@@ -352,12 +352,9 @@ namespace Umbraco.Web.Routing
// associated with it.
//TODO: When we remove the need for a database for templates, then this id should be irrelavent, not sure how were going to do this nicely.
- var templateIdAsString = _routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "@TemplateId");
- LogHelper.Debug("{0}Look for template id={1}", () => tracePrefix, () => templateIdAsString);
- int templateId;
- if (!int.TryParse(templateIdAsString, out templateId))
- templateId = 0;
-
+ var templateId = _documentRequest.Document.TemplateId;
+ LogHelper.Debug("{0}Look for template id={1}", () => tracePrefix, () => templateId);
+
if (templateId > 0)
{
//NOTE: This will throw an exception if the template id doesn't exist, but that is ok to inform the front end.
@@ -381,9 +378,8 @@ namespace Umbraco.Web.Routing
{
if (_documentRequest.HasNode)
{
- int redirectId;
- if (!int.TryParse(_routingContext.PublishedContentStore.GetDocumentProperty(_umbracoContext, _documentRequest.Document, "umbracoRedirect"), out redirectId))
- redirectId = -1;
+ var redirectId = _documentRequest.Document.GetPropertyValue("umbracoRedirect", -1);
+
string redirectUrl = "#";
if (redirectId > 0)
redirectUrl = _routingContext.NiceUrlProvider.GetNiceUrl(redirectId);
diff --git a/src/Umbraco.Web/Routing/NiceUrlProvider.cs b/src/Umbraco.Web/Routing/NiceUrlProvider.cs
index bbf8dffaee..9b486209a6 100644
--- a/src/Umbraco.Web/Routing/NiceUrlProvider.cs
+++ b/src/Umbraco.Web/Routing/NiceUrlProvider.cs
@@ -79,7 +79,8 @@ namespace Umbraco.Web.Routing
domainUri = DomainUriAtNode(id, current);
while (domainUri == null && id > 0)
{
- pathParts.Add(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, UrlNameProperty));
+ var urlName = node.GetPropertyValue(UrlNameProperty);
+ pathParts.Add(urlName);
node = node.Parent; // set to parent node
if (node == null)
{
@@ -87,7 +88,7 @@ namespace Umbraco.Web.Routing
}
else
{
- id = int.Parse(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, "@id")); // will be -1 or 1234
+ id = node.Id;
}
domainUri = id > 0 ? DomainUriAtNode(id, current) : null;
}
@@ -145,9 +146,10 @@ namespace Umbraco.Web.Routing
domainUris = DomainUrisAtNode(id, current);
while (!domainUris.Any() && id > 0)
{
- pathParts.Add(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, UrlNameProperty));
+ var urlName = node.GetPropertyValue(UrlNameProperty);
+ pathParts.Add(urlName);
node = node.Parent; //set to parent node
- id = int.Parse(_publishedContentStore.GetDocumentProperty(_umbracoContext, node, "@id")); // will be -1 or 1234
+ id = node.Id;
domainUris = id > 0 ? DomainUrisAtNode(id, current) : new Uri[] { };
}
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 9a23411e87..d4c57a793f 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -250,6 +250,7 @@
+