diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
index 429e2a2f9e..15a931957c 100644
--- a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
+++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Xml.XPath;
+using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Xml;
@@ -13,14 +12,10 @@ namespace Umbraco.Web.PublishedCache
///
public abstract class ContextualPublishedCache
{
- //TODO: We need to add:
- //* GetById(Guid contentId)
- //* GetById(UDI contentId)
-
protected readonly UmbracoContext UmbracoContext;
///
- /// Initializes a new instance of the with a context.
+ /// Initializes a new instance of the with a context.
///
/// The context.
protected ContextualPublishedCache(UmbracoContext umbracoContext)
@@ -32,8 +27,12 @@ namespace Umbraco.Web.PublishedCache
/// Gets a content identified by its unique identifier.
///
/// The content unique identifier.
- /// The content, or null.
- /// Considers published or unpublished content depending on context.
+ ///
+ /// The content, or null.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
public IPublishedContent GetById(int contentId)
{
return GetById(UmbracoContext.InPreviewMode, contentId);
@@ -43,35 +42,84 @@ namespace Umbraco.Web.PublishedCache
/// Gets a content identified by its unique identifier.
///
/// The content unique identifier.
- /// The content, or null.
- /// Considers published or unpublished content depending on context.
+ ///
+ /// The content, or null.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
public IPublishedContent GetById(Guid contentId)
{
return GetById(UmbracoContext.InPreviewMode, contentId);
}
+ ///
+ /// Gets a content identified by its unique identifier.
+ ///
+ /// The content unique identifier.
+ ///
+ /// The content, or null.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
+ public IPublishedContent GetById(Udi contentId)
+ {
+ return GetById(UmbracoContext.InPreviewMode, contentId);
+ }
+
///
/// Gets a content identified by its unique identifier.
///
/// A value indicating whether to consider unpublished content.
/// The content unique identifier.
- /// The content, or null.
+ ///
+ /// The content, or null.
+ ///
public abstract IPublishedContent GetById(bool preview, int contentId);
- // same with Guid
- // cannot make this public nor abstract without breaking backward compatibility
+ ///
+ /// Gets a content identified by its unique identifier.
+ ///
+ /// A value indicating whether to consider unpublished content.
+ /// The content key.
+ ///
+ /// The content, or null.
+ ///
public virtual IPublishedContent GetById(bool preview, Guid contentKey)
{
- // original implementation - override in concrete classes
- var intId = UmbracoContext.Application.Services.EntityService.GetIdForKey(contentKey, UmbracoObjectTypes.Document);
- return GetById(intId.Success ? intId.Result : -1);
+ var contentIdAttempt = UmbracoContext.Application.Services.EntityService.GetIdForKey(contentKey, UmbracoObjectTypes.Document);
+
+ return GetById(preview, contentIdAttempt.Success ? contentIdAttempt.Result : -1);
+ }
+
+ ///
+ /// Gets a content identified by its unique identifier.
+ ///
+ /// A value indicating whether to consider unpublished content.
+ /// The content identifier.
+ ///
+ /// The content, or null.
+ ///
+ /// UDIs for content items must be
+ public virtual IPublishedContent GetById(bool preview, Udi contentId)
+ {
+ var guidUdi = contentId as GuidUdi;
+ if (guidUdi == null)
+ throw new InvalidOperationException("UDIs for content items must be " + typeof(GuidUdi));
+
+ return GetById(preview, guidUdi.Guid);
}
///
/// Gets content at root.
///
- /// The contents.
- /// Considers published or unpublished content depending on context.
+ ///
+ /// The contents.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
public IEnumerable GetAtRoot()
{
return GetAtRoot(UmbracoContext.InPreviewMode);
@@ -81,7 +129,9 @@ namespace Umbraco.Web.PublishedCache
/// Gets contents at root.
///
/// A value indicating whether to consider unpublished content.
- /// The contents.
+ ///
+ /// The contents.
+ ///
public abstract IEnumerable GetAtRoot(bool preview);
///
@@ -89,10 +139,11 @@ namespace Umbraco.Web.PublishedCache
///
/// The XPath query.
/// Optional XPath variables.
- /// The content, or null.
+ ///
+ /// The content, or null.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
/// Considers published or unpublished content depending on context.
///
@@ -106,10 +157,11 @@ namespace Umbraco.Web.PublishedCache
///
/// The XPath query.
/// Optional XPath variables.
- /// The content, or null.
+ ///
+ /// The content, or null.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
/// Considers published or unpublished content depending on context.
///
@@ -124,10 +176,11 @@ namespace Umbraco.Web.PublishedCache
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
- /// The content, or null.
+ ///
+ /// The content, or null.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
///
public abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars);
@@ -138,10 +191,11 @@ namespace Umbraco.Web.PublishedCache
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
- /// The content, or null.
+ ///
+ /// The content, or null.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
///
public abstract IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
@@ -151,7 +205,9 @@ namespace Umbraco.Web.PublishedCache
///
/// The XPath query.
/// Optional XPath variables.
- /// The contents.
+ ///
+ /// The contents.
+ ///
///
/// If is null, or is empty, or contains only one single
/// value which itself is null, then variables are ignored.
@@ -186,10 +242,11 @@ namespace Umbraco.Web.PublishedCache
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
- /// The contents.
+ ///
+ /// The contents.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
///
public abstract IEnumerable GetByXPath(bool preview, string xpath, params XPathVariable[] vars);
@@ -200,10 +257,11 @@ namespace Umbraco.Web.PublishedCache
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
- /// The contents.
+ ///
+ /// The contents.
+ ///
///
- /// If is null, or is empty, or contains only one single
- /// value which itself is null, then variables are ignored.
+ /// If is null, or is empty, or contains only one single value which itself is null, then variables are ignored.
/// The XPath expression should reference variables as $var.
///
public abstract IEnumerable GetByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars);
@@ -211,8 +269,12 @@ namespace Umbraco.Web.PublishedCache
///
/// Gets an XPath navigator that can be used to navigate content.
///
- /// The XPath navigator.
- /// Considers published or unpublished content depending on context.
+ ///
+ /// The XPath navigator.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
public XPathNavigator GetXPathNavigator()
{
return GetXPathNavigator(UmbracoContext.InPreviewMode);
@@ -222,20 +284,28 @@ namespace Umbraco.Web.PublishedCache
/// Gets an XPath navigator that can be used to navigate content.
///
/// A value indicating whether to consider unpublished content.
- /// The XPath navigator.
+ ///
+ /// The XPath navigator.
+ ///
public abstract XPathNavigator GetXPathNavigator(bool preview);
///
- /// Gets a value indicating whether GetXPathNavigator returns an XPathNavigator
- /// and that navigator is a NavigableNavigator.
+ /// Gets a value indicating whether GetXPathNavigator returns an XPathNavigator and that navigator is a NavigableNavigator.
///
+ ///
+ /// true if the XPathNavigator is navigable; otherwise, false.
+ ///
public abstract bool XPathNavigatorIsNavigable { get; }
///
/// Gets a value indicating whether the underlying non-contextual cache contains content.
///
- /// A value indicating whether the underlying non-contextual cache contains content.
- /// Considers published or unpublished content depending on context.
+ ///
+ /// A value indicating whether the underlying non-contextual cache contains content.
+ ///
+ ///
+ /// Considers published or unpublished content depending on context.
+ ///
public bool HasContent()
{
return HasContent(UmbracoContext.InPreviewMode);
@@ -245,7 +315,9 @@ namespace Umbraco.Web.PublishedCache
/// Gets a value indicating whether the underlying non-contextual cache contains content.
///
/// A value indicating whether to consider unpublished content.
- /// A value indicating whether the underlying non-contextual cache contains content.
+ ///
+ /// A value indicating whether the underlying non-contextual cache contains content.
+ ///
public abstract bool HasContent(bool preview);
}
}