using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Umbraco.Core.Models;
using Umbraco.Core.Xml;
namespace Umbraco.Web.PublishedCache
{
///
/// Provides access to cached contents in a specified context.
///
internal abstract class ContextualPublishedCache
{
protected readonly UmbracoContext UmbracoContext;
private readonly IPublishedCache _cache;
protected ContextualPublishedCache(UmbracoContext umbracoContext, IPublishedCache cache)
{
UmbracoContext = umbracoContext;
_cache = cache;
}
///
/// Gets a content identified by its unique identifier.
///
/// The content unique identifier.
/// The content, or null.
public virtual IPublishedContent GetById(int contentId)
{
return _cache.GetById(UmbracoContext, contentId);
}
///
/// Gets contents at root.
///
/// The contents.
public virtual IEnumerable GetAtRoot()
{
return _cache.GetAtRoot(UmbracoContext);
}
///
/// Gets a content resulting from an XPath query.
///
/// 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 virtual IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars)
{
return _cache.GetSingleByXPath(UmbracoContext, xpath, vars);
}
///
/// Gets contents resulting from an XPath query.
///
/// 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 virtual IEnumerable GetByXPath(string xpath, params XPathVariable[] vars)
{
return _cache.GetByXPath(UmbracoContext, xpath, vars);
}
///
/// Gets a value indicating whether the underlying non-contextual cache contains published content.
///
/// A value indicating whether the underlying non-contextual cache contains published content.
public virtual bool HasContent()
{
return _cache.HasContent();
}
}
}