2012-07-20 01:04:35 +06:00
|
|
|
using System;
|
2012-07-30 22:52:59 +06:00
|
|
|
using Umbraco.Core.Logging;
|
2012-08-10 13:08:47 +06:00
|
|
|
using Umbraco.Core.Models;
|
2012-10-28 11:58:48 -01:00
|
|
|
using Umbraco.Core;
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Routing
|
|
|
|
|
{
|
2012-07-27 04:39:43 -02:00
|
|
|
/// <summary>
|
2013-01-18 13:20:08 -01:00
|
|
|
/// Provides an implementation of <see cref="IContentFinder"/> that handles page identifiers.
|
2012-07-27 04:39:43 -02:00
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// <para>Handles <c>/1234</c> where <c>1234</c> is the identified of a document.</para>
|
|
|
|
|
/// </remarks>
|
2013-01-24 08:51:27 -01:00
|
|
|
public class ContentFinderByIdPath : IContentFinder
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-07-27 04:39:43 -02:00
|
|
|
/// <summary>
|
2012-10-02 01:40:19 +05:00
|
|
|
/// Tries to find and assign an Umbraco document to a <c>PublishedContentRequest</c>.
|
2012-07-27 04:39:43 -02:00
|
|
|
/// </summary>
|
2012-10-02 01:40:19 +05:00
|
|
|
/// <param name="docRequest">The <c>PublishedContentRequest</c>.</param>
|
2012-07-27 04:39:43 -02:00
|
|
|
/// <returns>A value indicating whether an Umbraco document was found and assigned.</returns>
|
2013-03-20 16:01:49 -01:00
|
|
|
public bool TryFindContent(PublishedContentRequest docRequest)
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-10-02 01:35:39 +05:00
|
|
|
IPublishedContent node = null;
|
2012-10-28 11:58:48 -01:00
|
|
|
var path = docRequest.Uri.GetAbsolutePathDecoded();
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2013-02-19 06:37:25 -01:00
|
|
|
var nodeId = -1;
|
2012-10-28 11:58:48 -01:00
|
|
|
if (path != "/") // no id if "/"
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2013-02-19 06:37:25 -01:00
|
|
|
var noSlashPath = path.Substring(1);
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
if (!Int32.TryParse(noSlashPath, out nodeId))
|
|
|
|
|
nodeId = -1;
|
|
|
|
|
|
|
|
|
|
if (nodeId > 0)
|
|
|
|
|
{
|
2013-01-18 13:20:08 -01:00
|
|
|
LogHelper.Debug<ContentFinderByIdPath>("Id={0}", () => nodeId);
|
2013-03-19 17:51:55 -01:00
|
|
|
node = docRequest.RoutingContext.UmbracoContext.ContentCache.GetById(nodeId);
|
2012-08-10 13:38:02 +06:00
|
|
|
|
2012-07-20 01:04:35 +06:00
|
|
|
if (node != null)
|
|
|
|
|
{
|
2012-10-02 01:35:39 +05:00
|
|
|
docRequest.PublishedContent = node;
|
2013-01-23 14:08:17 -01:00
|
|
|
LogHelper.Debug<ContentFinderByIdPath>("Found node with id={0}", () => docRequest.PublishedContent.Id);
|
2012-07-20 01:04:35 +06:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nodeId = -1; // trigger message below
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nodeId == -1)
|
2013-01-18 13:20:08 -01:00
|
|
|
LogHelper.Debug<ContentFinderByIdPath>("Not a node id");
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
return node != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|