using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.XPath;
using Umbraco.Core.Models;
using Umbraco.Core.Xml;
namespace Umbraco.Web.PublishedCache
{
///
/// Provides access to cached contents in a specified context.
///
/// The type of the underlying published cache.
/// The type differenciates between the content cache and the media cache,
/// ie it will be either IPublishedContentCache or IPublishedMediaCache.
public abstract class ContextualPublishedCache : ContextualPublishedCache
where T : IPublishedCache
{
private readonly T _cache;
///
/// Initializes a new instance of the with a context and a published cache.
///
/// The context.
/// The cache.
protected ContextualPublishedCache(UmbracoContext umbracoContext, T cache)
: base(umbracoContext)
{
_cache = cache;
}
///
/// Gets the underlying published cache.
///
public T InnerCache { get { return _cache; } }
///
/// Gets a content identified by its unique identifier.
///
/// A value indicating whether to consider unpublished content.
/// The content unique identifier.
/// The content, or null.
public override IPublishedContent GetById(bool preview, int contentId)
{
return _cache.GetById(UmbracoContext, preview, contentId);
}
///
/// Gets content at root.
///
/// A value indicating whether to consider unpublished content.
/// The contents.
public override IEnumerable GetAtRoot(bool preview)
{
return _cache.GetAtRoot(UmbracoContext, preview);
}
///
/// Gets a content resulting from an XPath query.
///
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
/// The content, or null.
///
/// 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 override IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars)
{
return _cache.GetSingleByXPath(UmbracoContext, preview, xpath, vars);
}
///
/// Gets a content resulting from an XPath query.
///
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
/// The content, or null.
///
/// 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 override IPublishedContent GetSingleByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars)
{
return _cache.GetSingleByXPath(UmbracoContext, preview, xpath, vars);
}
///
/// Gets content resulting from an XPath query.
///
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
/// The contents.
///
/// 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 override IEnumerable GetByXPath(bool preview, string xpath, params XPathVariable[] vars)
{
return _cache.GetByXPath(UmbracoContext, preview, xpath, vars);
}
///
/// Gets content resulting from an XPath query.
///
/// A value indicating whether to consider unpublished content.
/// The XPath query.
/// Optional XPath variables.
/// The contents.
///
/// 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 override IEnumerable GetByXPath(bool preview, XPathExpression xpath, params XPathVariable[] vars)
{
return _cache.GetByXPath(UmbracoContext, preview, xpath, vars);
}
///
/// Gets an XPath navigator that can be used to navigate content.
///
/// A value indicating whether to consider unpublished content.
/// The XPath navigator.
public override XPathNavigator GetXPathNavigator(bool preview)
{
return _cache.GetXPathNavigator(UmbracoContext, preview);
}
///
/// Gets a value indicating whether GetXPathNavigator returns an XPathNavigator
/// and that navigator is a NavigableNavigator.
///
public override bool XPathNavigatorIsNavigable { get { return _cache.XPathNavigatorIsNavigable; } }
///
/// 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.
public override bool HasContent(bool preview)
{
return _cache.HasContent(UmbracoContext, preview);
}
}
}