diff --git a/src/Umbraco.Tests/LibraryTests.cs b/src/Umbraco.Tests/LibraryTests.cs index 4880d3e2cd..77fe2afe96 100644 --- a/src/Umbraco.Tests/LibraryTests.cs +++ b/src/Umbraco.Tests/LibraryTests.cs @@ -95,7 +95,7 @@ namespace Umbraco.Tests { var cache = UmbracoContext.Current.ContentCache.InnerCache as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); - var umbracoXML = cache.GetXml(UmbracoContext.Current); + var umbracoXML = cache.GetXml(UmbracoContext.Current, UmbracoContext.Current.InPreviewMode); string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}"; if (umbracoXML.GetElementById(nodeId.ToString()) != null) diff --git a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs index 054d21b244..011ed05d0a 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs @@ -90,7 +90,7 @@ namespace Umbraco.Tests.PublishedContent var node = new DynamicNode( new DynamicBackingItem( - new Node(cache.GetXml(ctx).SelectSingleNode("//*[@id='" + id + "' and @isDoc]")))); + new Node(cache.GetXml(ctx, ctx.InPreviewMode).SelectSingleNode("//*[@id='" + id + "' and @isDoc]")))); Assert.IsNotNull(node); return (dynamic)node; } diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs index b965f09c16..6436384ffa 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCache.cs @@ -29,13 +29,36 @@ namespace Umbraco.Web.PublishedCache /// /// The content unique identifier. /// The content, or null. - public abstract IPublishedContent GetById(int contentId); + /// Considers published or unpublished content depending on context. + public IPublishedContent GetById(int 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. + public abstract IPublishedContent GetById(bool preview, int contentId); + + /// + /// Gets content at root. + /// + /// The contents. + /// Considers published or unpublished content depending on context. + public IEnumerable GetAtRoot() + { + return GetAtRoot(UmbracoContext.InPreviewMode); + } /// /// Gets contents at root. /// + /// A value indicating whether to consider unpublished content. /// The contents. - public abstract IEnumerable GetAtRoot(); + public abstract IEnumerable GetAtRoot(bool preview); /// /// Gets a content resulting from an XPath query. @@ -47,11 +70,29 @@ namespace Umbraco.Web.PublishedCache /// 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. /// - public abstract IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars); + public IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars) + { + return GetSingleByXPath(UmbracoContext.InPreviewMode, xpath, vars); + } /// - /// Gets contents resulting from an XPath query. + /// 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 abstract IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars); + + /// + /// Gets content resulting from an XPath query. /// /// The XPath query. /// Optional XPath variables. @@ -60,19 +101,59 @@ namespace Umbraco.Web.PublishedCache /// 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. /// - public abstract IEnumerable GetByXPath(string xpath, params XPathVariable[] vars); + public IEnumerable GetByXPath(string xpath, params XPathVariable[] vars) + { + return GetByXPath(UmbracoContext.InPreviewMode, xpath, vars); + } /// - /// Gets an XPath navigator that can be used to navigate contents. + /// 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 abstract IEnumerable GetByXPath(bool preview, string xpath, params XPathVariable[] vars); + + /// + /// Gets an XPath navigator that can be used to navigate content. /// /// The XPath navigator. - public abstract XPathNavigator GetXPathNavigator(); + /// Considers published or unpublished content depending on context. + public XPathNavigator GetXPathNavigator() + { + return GetXPathNavigator(UmbracoContext.InPreviewMode); + } /// - /// Gets a value indicating whether the underlying non-contextual cache contains published content. + /// Gets an XPath navigator that can be used to navigate content. /// - /// A value indicating whether the underlying non-contextual cache contains published content. - public abstract bool HasContent(); + /// A value indicating whether to consider unpublished content. + /// The XPath navigator. + public abstract XPathNavigator GetXPathNavigator(bool preview); + + /// + /// 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. + public bool HasContent() + { + return HasContent(UmbracoContext.InPreviewMode); + } + + /// + /// 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 abstract bool HasContent(bool preview); } } diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs index 00ad44860d..a279026e86 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedCacheOfT.cs @@ -36,25 +36,28 @@ namespace Umbraco.Web.PublishedCache /// /// 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(int contentId) + public override IPublishedContent GetById(bool preview, int contentId) { - return _cache.GetById(UmbracoContext, contentId); + return _cache.GetById(UmbracoContext, preview, contentId); } /// - /// Gets contents at root. + /// Gets content at root. /// + /// A value indicating whether to consider unpublished content. /// The contents. - public override IEnumerable GetAtRoot() + public override IEnumerable GetAtRoot(bool preview) { - return _cache.GetAtRoot(UmbracoContext); + 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. @@ -63,14 +66,15 @@ namespace Umbraco.Web.PublishedCache /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// - public override IPublishedContent GetSingleByXPath(string xpath, params XPathVariable[] vars) + public override IPublishedContent GetSingleByXPath(bool preview, string xpath, params XPathVariable[] vars) { - return _cache.GetSingleByXPath(UmbracoContext, xpath, vars); + return _cache.GetSingleByXPath(UmbracoContext, preview, xpath, vars); } /// - /// Gets contents resulting from an XPath query. + /// Gets content resulting from an XPath query. /// + /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The contents. @@ -79,27 +83,29 @@ namespace Umbraco.Web.PublishedCache /// value which itself is null, then variables are ignored. /// The XPath expression should reference variables as $var. /// - public override IEnumerable GetByXPath(string xpath, params XPathVariable[] vars) + public override IEnumerable GetByXPath(bool preview, string xpath, params XPathVariable[] vars) { - return _cache.GetByXPath(UmbracoContext, xpath, vars); + return _cache.GetByXPath(UmbracoContext, preview, xpath, vars); } /// - /// Gets an XPath navigator that can be used to navigate contents. + /// 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() + public override XPathNavigator GetXPathNavigator(bool preview) { - return _cache.GetXPathNavigator(UmbracoContext); + return _cache.GetXPathNavigator(UmbracoContext, preview); } /// - /// Gets a value indicating whether the underlying non-contextual cache contains published content. + /// Gets a value indicating whether the underlying non-contextual cache contains content. /// - /// A value indicating whether the underlying non-contextual cache contains published content. - public override bool HasContent() + /// 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); + return _cache.HasContent(UmbracoContext, preview); } } } diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs index 728f114cce..41e540afe5 100644 --- a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs @@ -26,10 +26,26 @@ namespace Umbraco.Web.PublishedCache /// The route /// A value forcing the HideTopLevelNode setting. /// The content, or null. - /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. + /// + /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. + /// Considers published or unpublished content depending on context. + /// public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null) { - return InnerCache.GetByRoute(UmbracoContext, route, hideTopLevelNode); + return GetByRoute(UmbracoContext.InPreviewMode, route, hideTopLevelNode); + } + + /// + /// Gets content identified by a route. + /// + /// A value indicating whether to consider unpublished content. + /// The route + /// A value forcing the HideTopLevelNode setting. + /// The content, or null. + /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. + public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null) + { + return InnerCache.GetByRoute(UmbracoContext, preview, route, hideTopLevelNode); } /// @@ -37,9 +53,22 @@ namespace Umbraco.Web.PublishedCache /// /// The content unique identifier. /// The route. + /// Considers published or unpublished content depending on context. public string GetRouteById(int contentId) { - return InnerCache.GetRouteById(UmbracoContext, contentId); + return GetRouteById(UmbracoContext.InPreviewMode, contentId); + } + + /// + /// Gets the route for a content identified by its unique identifier. + /// + /// A value indicating whether to consider unpublished content. + /// The content unique identifier. + /// The route. + /// Considers published or unpublished content depending on context. + public string GetRouteById(bool preview, int contentId) + { + return InnerCache.GetRouteById(UmbracoContext, preview, contentId); } } } diff --git a/src/Umbraco.Web/PublishedCache/IPublishedCache.cs b/src/Umbraco.Web/PublishedCache/IPublishedCache.cs index 4e48e192eb..fb9d7e71b9 100644 --- a/src/Umbraco.Web/PublishedCache/IPublishedCache.cs +++ b/src/Umbraco.Web/PublishedCache/IPublishedCache.cs @@ -20,49 +20,62 @@ namespace Umbraco.Web.PublishedCache /// Gets a content identified by its unique identifier. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The content unique identifier. /// The content, or null. - IPublishedContent GetById(UmbracoContext umbracoContext, int contentId); + /// The value of overrides the context. + IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int contentId); /// /// Gets contents at root. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The contents. - IEnumerable GetAtRoot(UmbracoContext umbracoContext); + /// The value of overrides the context. + IEnumerable GetAtRoot(UmbracoContext umbracoContext, bool preview); /// /// Gets a content resulting from an XPath query. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The content, or null. - IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, string xpath, XPathVariable[] vars); + /// The value of overrides the context. + IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars); /// /// Gets contents resulting from an XPath query. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The XPath query. /// Optional XPath variables. /// The contents. - IEnumerable GetByXPath(UmbracoContext umbracoContext, string xpath, XPathVariable[] vars); + /// The value of overrides the context. + IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars); /// /// Gets an XPath navigator that can be used to navigate contents. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The XPath navigator. - XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext); + /// The value of overrides the context. + XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview); /// /// Gets a value indicating whether the cache contains published content. /// + /// The context. + /// A value indicating whether to consider unpublished content. /// A value indicating whether the cache contains published content. - bool HasContent(); - - //TODO: SD: We should make this happen! This will allow us to natively do a GetByDocumentType query + /// The value of overrides the context. + bool HasContent(UmbracoContext umbracoContext, bool preview); + + //TODO: SD: We should make this happen! This will allow us to natively do a GetByDocumentType query // on the UmbracoHelper (or an internal DataContext that it uses, etc...) // One issue is that we need to make media work as fast as we can and need to create a ConvertFromMediaObject // method in the DefaultPublishedMediaStore, there's already a TODO noting this but in order to do that we'll diff --git a/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs index 3745271e43..c892af507b 100644 --- a/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs @@ -13,21 +13,25 @@ namespace Umbraco.Web.PublishedCache /// Gets content identified by a route. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The route /// A value forcing the HideTopLevelNode setting. /// The content, or null. /// /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. /// If is null then the settings value is used. + /// The value of overrides the context. /// - IPublishedContent GetByRoute(UmbracoContext umbracoContext, string route, bool? hideTopLevelNode = null); + IPublishedContent GetByRoute(UmbracoContext umbracoContext, bool preview, string route, bool? hideTopLevelNode = null); /// /// Gets the route for a content identified by its unique identifier. /// /// The context. + /// A value indicating whether to consider unpublished content. /// The content unique identifier. /// The route. - string GetRouteById(UmbracoContext umbracoContext, int contentId); + /// The value of overrides the context. + string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId); } } diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs index 915c4fb55f..10bedb99cb 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs @@ -27,40 +27,29 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // for INTERNAL, UNIT TESTS use ONLY internal static bool UnitTesting = false; - /// - /// Gets content identified by a route. - /// - /// The context. - /// The route - /// A value forcing the HideTopLevelNode setting. - /// The content, or null. - /// - /// A valid route is either a simple path eg /foo/bar/nil or a root node id and a path, eg 123/foo/bar/nil. - /// If is null then the settings value is used. - /// - public virtual IPublishedContent GetByRoute(UmbracoContext umbracoContext, string route, bool? hideTopLevelNode = null) + public virtual IPublishedContent GetByRoute(UmbracoContext umbracoContext, bool preview, string route, bool? hideTopLevelNode = null) { if (route == null) throw new ArgumentNullException("route"); // try to get from cache if not previewing - var contentId = umbracoContext.InPreviewMode ? 0 : _routesCache.GetNodeId(route); + var contentId = preview ? 0 : _routesCache.GetNodeId(route); // if found id in cache then get corresponding content // and clear cache if not found - for whatever reason IPublishedContent content = null; if (contentId > 0) { - content = GetById(umbracoContext, contentId); + content = GetById(umbracoContext, preview, contentId); if (content == null) _routesCache.ClearNode(contentId); } // still have nothing? actually determine the id hideTopLevelNode = hideTopLevelNode ?? GlobalSettings.HideTopLevelNodeFromPath; // default = settings - content = content ?? DetermineIdByRoute(umbracoContext, route, hideTopLevelNode.Value); + content = content ?? DetermineIdByRoute(umbracoContext, preview, route, hideTopLevelNode.Value); // cache if we have a content and not previewing - if (content != null && !umbracoContext.InPreviewMode) + if (content != null && !preview) { var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/'))); var iscanon = !UnitTesting && !DomainHelper.ExistsDomainInPath(DomainHelper.GetAllDomains(false), content.Path, domainRootNodeId); @@ -72,32 +61,26 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache return content; } - /// - /// Gets the route for a content identified by its unique identifier. - /// - /// The context. - /// The content unique identifier. - /// The route. - public virtual string GetRouteById(UmbracoContext umbracoContext, int contentId) + public virtual string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId) { // try to get from cache if not previewing - var route = umbracoContext.InPreviewMode ? null : _routesCache.GetRoute(contentId); + var route = preview ? null : _routesCache.GetRoute(contentId); // if found in cache then return if (route != null) return route; // else actually determine the route - route = DetermineRouteById(umbracoContext, contentId); + route = DetermineRouteById(umbracoContext, preview, contentId); // cache if we have a route and not previewing - if (route != null && !umbracoContext.InPreviewMode) + if (route != null && !preview) _routesCache.Store(contentId, route); return route; } - IPublishedContent DetermineIdByRoute(UmbracoContext umbracoContext, string route, bool hideTopLevelNode) + IPublishedContent DetermineIdByRoute(UmbracoContext umbracoContext, bool preview, string route, bool hideTopLevelNode) { if (route == null) throw new ArgumentNullException("route"); @@ -112,7 +95,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache var xpath = CreateXpathQuery(startNodeId, path, hideTopLevelNode, out vars); //check if we can find the node in our xml cache - var content = GetSingleByXPath(umbracoContext, xpath, vars == null ? null : vars.ToArray()); + var content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray()); // if hideTopLevelNodePath is true then for url /foo we looked for /*/foo // but maybe that was the url of a non-default top-level node, so we also @@ -120,15 +103,15 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (content == null && hideTopLevelNode && path.Length > 1 && path.IndexOf('/', 1) < 0) { xpath = CreateXpathQuery(startNodeId, path, false, out vars); - content = GetSingleByXPath(umbracoContext, xpath, vars == null ? null : vars.ToArray()); + content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray()); } return content; } - string DetermineRouteById(UmbracoContext umbracoContext, int contentId) + string DetermineRouteById(UmbracoContext umbracoContext, bool preview, int contentId) { - var node = GetById(umbracoContext, contentId); + var node = GetById(umbracoContext, preview, contentId); if (node == null) return null; @@ -264,52 +247,52 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache #region Getters - public virtual IPublishedContent GetById(UmbracoContext umbracoContext, int nodeId) + public virtual IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int nodeId) { - return ConvertToDocument(GetXml(umbracoContext).GetElementById(nodeId.ToString())); + return ConvertToDocument(GetXml(umbracoContext, preview).GetElementById(nodeId.ToString(CultureInfo.InvariantCulture))); } - public virtual IEnumerable GetAtRoot(UmbracoContext umbracoContext) - { - return (from XmlNode x in GetXml(umbracoContext).SelectNodes(XPathStrings.RootDocuments) select ConvertToDocument(x)).ToList(); + public virtual IEnumerable GetAtRoot(UmbracoContext umbracoContext, bool preview) + { + return ConvertToDocuments(GetXml(umbracoContext, preview).SelectNodes(XPathStrings.RootDocuments)); } - public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, string xpath, params XPathVariable[] vars) + public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, params XPathVariable[] vars) { if (xpath == null) throw new ArgumentNullException("xpath"); if (string.IsNullOrWhiteSpace(xpath)) return null; - var xml = GetXml(umbracoContext); + var xml = GetXml(umbracoContext, preview); var node = vars == null ? xml.SelectSingleNode(xpath) : xml.SelectSingleNode(xpath, vars); return ConvertToDocument(node); } - public virtual IEnumerable GetByXPath(UmbracoContext umbracoContext, string xpath, params XPathVariable[] vars) + public virtual IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, params XPathVariable[] vars) { if (xpath == null) throw new ArgumentNullException("xpath"); if (string.IsNullOrWhiteSpace(xpath)) return Enumerable.Empty(); - var xml = GetXml(umbracoContext); + var xml = GetXml(umbracoContext, preview); var nodes = vars == null ? xml.SelectNodes(xpath) : xml.SelectNodes(xpath, vars); return ConvertToDocuments(nodes); } - public virtual bool HasContent() + public virtual bool HasContent(UmbracoContext umbracoContext, bool preview) { - var xml = GetXml(); + var xml = GetXml(umbracoContext, preview); if (xml == null) return false; var node = xml.SelectSingleNode(XPathStrings.RootDocuments); return node != null; } - public virtual XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext) + public virtual XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview) { - var xml = GetXml(umbracoContext); + var xml = GetXml(umbracoContext, preview); return xml.CreateNavigator(); } @@ -355,14 +338,9 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache } } - internal XmlDocument GetXml(UmbracoContext umbracoContext) + internal XmlDocument GetXml(UmbracoContext umbracoContext, bool preview) { - return GetXmlDelegate(umbracoContext.UmbracoUser, umbracoContext.InPreviewMode); - } - - private XmlDocument GetXml() - { - return GetXmlDelegate(null, false); + return GetXmlDelegate(umbracoContext.UmbracoUser, preview); } #endregion diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index 08e0f65a2f..debb1f8a22 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -47,12 +47,12 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private readonly BaseSearchProvider _searchProvider; private readonly BaseIndexProvider _indexProvider; - public virtual IPublishedContent GetById(UmbracoContext umbracoContext, int nodeId) + public virtual IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int nodeId) { return GetUmbracoMedia(nodeId); } - public IEnumerable GetAtRoot(UmbracoContext umbracoContext) + public virtual IEnumerable GetAtRoot(UmbracoContext umbracoContext, bool preview) { var rootMedia = global::umbraco.cms.businesslogic.media.Media.GetRootMedias(); var result = new List(); @@ -67,22 +67,22 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache return result; } - public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, string xpath, XPathVariable[] vars) + public virtual IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars) { throw new NotImplementedException("PublishedMediaCache does not support XPath."); } - public IEnumerable GetByXPath(UmbracoContext umbracoContext, string xpath, XPathVariable[] vars) + public virtual IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, XPathVariable[] vars) { throw new NotImplementedException("PublishedMediaCache does not support XPath."); } - public virtual XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext) + public virtual XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview) { throw new NotImplementedException("PublishedMediaCache does not support XPath."); } - public bool HasContent() { throw new NotImplementedException(); } + public virtual bool HasContent(UmbracoContext context, bool preview) { throw new NotImplementedException(); } private ExamineManager GetExamineManagerSafe() { diff --git a/src/Umbraco.Web/umbraco.presentation/UmbracoContext.cs b/src/Umbraco.Web/umbraco.presentation/UmbracoContext.cs index dd355562a8..b065c6829c 100644 --- a/src/Umbraco.Web/umbraco.presentation/UmbracoContext.cs +++ b/src/Umbraco.Web/umbraco.presentation/UmbracoContext.cs @@ -88,7 +88,7 @@ namespace umbraco.presentation if (cache == null) throw new InvalidOperationException("Unsupported IPublishedContentCache, only the Xml one is supported."); - return cache.GetXml(umbracoContext); + return cache.GetXml(umbracoContext, umbracoContext.InPreviewMode); } /// diff --git a/src/Umbraco.Web/umbraco.presentation/macro.cs b/src/Umbraco.Web/umbraco.presentation/macro.cs index ea31d49e87..dc0fc04f8b 100644 --- a/src/Umbraco.Web/umbraco.presentation/macro.cs +++ b/src/Umbraco.Web/umbraco.presentation/macro.cs @@ -771,7 +771,7 @@ namespace umbraco // get master xml document var cache = UmbracoContext.Current.ContentCache.InnerCache as Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); - XmlDocument umbracoXml = cache.GetXml(UmbracoContext.Current); + XmlDocument umbracoXml = cache.GetXml(UmbracoContext.Current, UmbracoContext.Current.InPreviewMode); macroXml = new XmlDocument(); macroXml.LoadXml(""); foreach (var prop in macro.Model.Properties) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs index e3303d2823..0116b2f781 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/templateControls/ItemRenderer.cs @@ -106,7 +106,7 @@ namespace umbraco.presentation.templateControls //moved the following from the catch block up as this will allow fallback options alt text etc to work var cache = Umbraco.Web.UmbracoContext.Current.ContentCache.InnerCache as PublishedContentCache; if (cache == null) throw new InvalidOperationException("Unsupported IPublishedContentCache, only the Xml one is supported."); - var xml = cache.GetXml(Umbraco.Web.UmbracoContext.Current); + var xml = cache.GetXml(Umbraco.Web.UmbracoContext.Current, Umbraco.Web.UmbracoContext.Current.InPreviewMode); var itemPage = new page(xml.GetElementById(tempNodeId.ToString())); tempElementContent = new item(itemPage.Elements, item.LegacyAttributes).FieldContent; }