2012-07-20 01:04:35 +06:00
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
|
|
// legacy
|
2012-07-30 22:52:59 +06:00
|
|
|
using Umbraco.Core;
|
|
|
|
|
using Umbraco.Core.Logging;
|
2012-08-10 13:08:47 +06:00
|
|
|
using Umbraco.Core.Models;
|
2012-07-21 00:20:50 +06:00
|
|
|
using umbraco.BusinessLogic;
|
2012-08-08 23:10:34 +06:00
|
|
|
using umbraco.NodeFactory;
|
2012-07-20 01:04:35 +06:00
|
|
|
using umbraco.cms.businesslogic.web;
|
|
|
|
|
using umbraco.cms.businesslogic.template;
|
|
|
|
|
using umbraco.cms.businesslogic.member;
|
2012-08-08 23:10:34 +06:00
|
|
|
using umbraco.interfaces;
|
|
|
|
|
|
2012-07-20 01:04:35 +06:00
|
|
|
namespace Umbraco.Web.Routing
|
|
|
|
|
{
|
2012-08-29 08:54:29 +07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a found template that is resolved by the ILookups.
|
|
|
|
|
/// The TemplateObject is the business logic object that represents a template, this will be different for
|
|
|
|
|
/// web forms and MVC.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// NOTE: This is not the prettiest thing in the world and we cannot use generics but we need to avoid looking up
|
|
|
|
|
/// template objects more than once which would occur if we were only storing the alias.
|
|
|
|
|
/// Once we take templates out of the db this becomes even more interesting because the templateId on the XML
|
|
|
|
|
/// will probably not be an integer Id anymore but more like an alias so the reprecussions will be big.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
internal class TemplateLookup
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Static method to return an empty template lookup
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
internal static TemplateLookup NoTemplate()
|
|
|
|
|
{
|
|
|
|
|
return new TemplateLookup();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private TemplateLookup()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal TemplateLookup(string alias, object templateObject)
|
|
|
|
|
{
|
|
|
|
|
TemplateAlias = alias;
|
|
|
|
|
TemplateObject = templateObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal bool FoundTemplate
|
|
|
|
|
{
|
|
|
|
|
get { return TemplateObject != null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The alias of the template found
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal string TemplateAlias { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The business logic template object that has been found, null if not found
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal object TemplateObject { get; private set; }
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-06 22:40:06 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// represents a request for one specified Umbraco document to be rendered
|
|
|
|
|
/// by one specified template, using one particular culture.
|
|
|
|
|
/// </summary>
|
2012-08-07 02:33:08 +06:00
|
|
|
internal class DocumentRequest
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-08-09 04:15:35 +06:00
|
|
|
public DocumentRequest(Uri uri, RoutingContext routingContext)
|
2012-07-20 01:04:35 +06:00
|
|
|
{
|
2012-07-20 18:54:59 -02:00
|
|
|
this.Uri = uri;
|
2012-08-09 04:15:35 +06:00
|
|
|
RoutingContext = routingContext;
|
2012-07-20 01:04:35 +06:00
|
|
|
}
|
|
|
|
|
|
2012-07-20 23:10:43 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// the id of the requested node, if any, else zero.
|
|
|
|
|
/// </summary>
|
|
|
|
|
int _nodeId = 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// the requested node, if any, else null.
|
|
|
|
|
/// </summary>
|
2012-08-08 23:10:34 +06:00
|
|
|
XmlNode _xmlNode = null;
|
|
|
|
|
|
2012-08-10 13:08:47 +06:00
|
|
|
private IDocument _node = null;
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2012-07-20 23:10:43 +06:00
|
|
|
#region Properties
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2012-07-20 23:10:43 +06:00
|
|
|
/// <summary>
|
2012-07-21 00:20:50 +06:00
|
|
|
/// Returns the current RoutingContext
|
2012-07-20 23:10:43 +06:00
|
|
|
/// </summary>
|
2012-07-21 00:20:50 +06:00
|
|
|
public RoutingContext RoutingContext { get; private set; }
|
2012-08-09 04:15:35 +06:00
|
|
|
|
2012-08-08 23:55:55 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// The cleaned up Uri used for routing
|
|
|
|
|
/// </summary>
|
2012-07-20 18:54:59 -02:00
|
|
|
public Uri Uri { get; private set; }
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the document request's domain.
|
|
|
|
|
/// </summary>
|
2012-08-09 04:15:35 +06:00
|
|
|
public Domain Domain { get; internal set; }
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2012-08-09 04:15:35 +06:00
|
|
|
public Uri DomainUri { get; internal set; }
|
2012-07-20 18:54:59 -02:00
|
|
|
|
2012-08-29 08:54:29 +07:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether the rendering engine is MVC or WebForms
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsMvc { get; internal set; }
|
|
|
|
|
|
2012-07-20 01:04:35 +06:00
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the document request has a domain.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasDomain
|
|
|
|
|
{
|
|
|
|
|
get { return this.Domain != null; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the document request's culture
|
|
|
|
|
/// </summary>
|
2012-08-08 23:10:34 +06:00
|
|
|
public CultureInfo Culture { get; set; }
|
2012-07-20 01:04:35 +06:00
|
|
|
|
2012-08-08 23:10:34 +06:00
|
|
|
// TODO: fixme - do we want to have an ordered list of alternate cultures,
|
2012-07-20 01:04:35 +06:00
|
|
|
// to allow for fallbacks when doing dictionnary lookup and such?
|
|
|
|
|
|
2012-08-10 13:08:47 +06:00
|
|
|
public IDocument Node
|
2012-08-14 23:35:34 +06:00
|
|
|
{
|
2012-08-10 13:08:47 +06:00
|
|
|
get { return _node; }
|
|
|
|
|
set
|
2012-08-08 23:10:34 +06:00
|
|
|
{
|
2012-08-10 13:08:47 +06:00
|
|
|
_node = value;
|
2012-08-29 08:54:29 +07:00
|
|
|
this.TemplateLookup = null;
|
2012-08-10 13:08:47 +06:00
|
|
|
_nodeId = _node != null ? _node.Id : 0;
|
2012-08-08 23:10:34 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-20 01:04:35 +06:00
|
|
|
/// <summary>
|
2012-08-29 08:54:29 +07:00
|
|
|
/// Gets or sets the document request's template lookup
|
2012-07-20 01:04:35 +06:00
|
|
|
/// </summary>
|
2012-08-29 08:54:29 +07:00
|
|
|
public TemplateLookup TemplateLookup { get; set; }
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the document request has a template.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasTemplate
|
|
|
|
|
{
|
2012-08-29 08:54:29 +07:00
|
|
|
get { return this.TemplateLookup != null && TemplateLookup.FoundTemplate; }
|
2012-07-20 01:04:35 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the id of the document.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <exception cref="InvalidOperationException">Thrown when the document request has no document.</exception>
|
|
|
|
|
public int NodeId
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2012-08-10 13:08:47 +06:00
|
|
|
if (this.Node == null)
|
2012-07-20 01:04:35 +06:00
|
|
|
throw new InvalidOperationException("DocumentRequest has no document.");
|
|
|
|
|
return _nodeId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the document request has a document.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool HasNode
|
|
|
|
|
{
|
2012-08-10 13:08:47 +06:00
|
|
|
get { return this.Node != null; }
|
2012-07-20 01:04:35 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets a value indicating whether the requested document could not be found.
|
|
|
|
|
/// </summary>
|
2012-08-09 04:15:35 +06:00
|
|
|
public bool Is404 { get; internal set; }
|
2012-07-20 01:04:35 +06:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a value indicating whether the document request triggers a redirect.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(this.RedirectUrl); } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the url to redirect to, when the document request triggers a redirect.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string RedirectUrl { get; set; }
|
|
|
|
|
|
|
|
|
|
#endregion
|
2012-08-09 04:15:35 +06:00
|
|
|
|
2012-07-20 01:04:35 +06:00
|
|
|
}
|
|
|
|
|
}
|