2012-07-20 01:04:35 +06:00
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Xml;
|
2012-07-26 07:52:13 -02:00
|
|
|
using Umbraco.Core.Resolving;
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Routing
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// handles /1234 where 1234 is the id of a document
|
|
|
|
|
//
|
2012-07-26 07:52:13 -02:00
|
|
|
[ResolutionWeight(20)]
|
2012-07-22 14:01:18 -02:00
|
|
|
internal class ResolveById : IRequestDocumentResolver
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-07-22 14:01:18 -02:00
|
|
|
static readonly TraceSource Trace = new TraceSource("ResolveById");
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2012-07-22 14:01:18 -02:00
|
|
|
public bool TrySetDocument(DocumentRequest docreq)
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
|
|
|
|
XmlNode node = null;
|
|
|
|
|
|
|
|
|
|
int nodeId = -1;
|
2012-07-20 18:54:59 -02:00
|
|
|
if (docreq.Uri.AbsolutePath != "/") // no id if "/"
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-07-20 18:54:59 -02:00
|
|
|
string noSlashPath = docreq.Uri.AbsolutePath.Substring(1);
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
if (!Int32.TryParse(noSlashPath, out nodeId))
|
|
|
|
|
nodeId = -1;
|
|
|
|
|
|
|
|
|
|
if (nodeId > 0)
|
|
|
|
|
{
|
|
|
|
|
Trace.TraceInformation("Id={0}", nodeId);
|
2012-07-21 00:20:50 +06:00
|
|
|
node = docreq.RoutingContext.ContentStore.GetNodeById(nodeId);
|
2012-07-20 01:04:35 +06:00
|
|
|
if (node != null)
|
|
|
|
|
{
|
|
|
|
|
docreq.Node = node;
|
|
|
|
|
Trace.TraceInformation("Found node with id={0}", docreq.NodeId);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nodeId = -1; // trigger message below
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nodeId == -1)
|
|
|
|
|
Trace.TraceInformation("Not a node id");
|
|
|
|
|
|
|
|
|
|
return node != null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|