/// <summary>
        /// Returns the content id based on the configured IContentErrorPage section
        /// </summary>
        /// <param name="errorPage"></param>
        /// <param name="entityService"></param>
        /// <param name="publishedContentQuery"></param>
        /// <returns></returns>
        internal static int?GetContentIdFromErrorPageConfig(IContentErrorPage errorPage, IEntityService entityService, ITypedPublishedContentQuery publishedContentQuery)
        {
            if (errorPage.HasContentId)
            {
                return(errorPage.ContentId);
            }

            if (errorPage.HasContentKey)
            {
                //need to get the Id for the GUID
                //TODO: When we start storing GUIDs into the IPublishedContent, then we won't have to look this up
                // but until then we need to look it up in the db. For now we've implemented a cached service for
                // converting Int -> Guid and vice versa.
                var found = entityService.GetIdForKey(errorPage.ContentKey, UmbracoObjectTypes.Document);
                if (found)
                {
                    return(found.Result);
                }
                return(null);
            }

            if (errorPage.ContentXPath.IsNullOrWhiteSpace() == false)
            {
                try
                {
                    //we have an xpath statement to execute
                    var xpathResult = UmbracoXPathPathSyntaxParser.ParseXPathQuery(
                        xpathExpression: errorPage.ContentXPath,
                        nodeContextId: null,
                        getPath: nodeid =>
                    {
                        var ent = entityService.Get(nodeid);
                        return(ent.Path.Split(',').Reverse());
                    },
                        publishedContentExists: i => publishedContentQuery.TypedContent(i) != null);

                    //now we'll try to execute the expression
                    var nodeResult = publishedContentQuery.TypedContentSingleAtXPath(xpathResult);
                    if (nodeResult != null)
                    {
                        return(nodeResult.Id);
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.Error <NotFoundHandlerHelper>("Could not parse xpath expression: " + errorPage.ContentXPath, ex);
                    return(null);
                }
            }
            return(null);
        }
예제 #2
0
 public IPublishedContent GetTypedContentSingleAtXPath(string xpath)
 {
     return(_umbracoContentQuery.TypedContentSingleAtXPath(xpath));
 }
 public IPublishedContent TypedContentSingleAtXPath(string xpath, params XPathVariable[] vars)
 {
     return(_typedContentQuery == null
         ? TypedDocumentByXPath(xpath, vars, _contentCache)
         : _typedContentQuery.TypedContentSingleAtXPath(xpath, vars));
 }