Files
Umbraco-CMS/src/Umbraco.Web/Routing/PublishedContentRequest.cs
Shannon Deminick 827d4dd6c0 After talks with morten and stephane, this renames
DocumentRequestBuilder -> PublishedContentRequestBuilder
2012-10-02 01:41:54 +05:00

167 lines
4.7 KiB
C#

using System;
using System.Linq;
using System.Text;
using System.Xml;
using System.Globalization;
using System.Diagnostics;
// legacy
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using umbraco;
using umbraco.BusinessLogic;
using umbraco.NodeFactory;
using umbraco.cms.businesslogic.web;
using umbraco.cms.businesslogic.template;
using umbraco.cms.businesslogic.member;
using umbraco.interfaces;
namespace Umbraco.Web.Routing
{
/// <summary>
/// represents a request for one specified Umbraco document to be rendered
/// by one specified template, using one particular culture.
/// </summary>
internal class PublishedContentRequest
{
public PublishedContentRequest(Uri uri, RoutingContext routingContext)
{
this.Uri = uri;
RoutingContext = routingContext;
RenderingEngine = RenderingEngine.Mvc;
}
/// <summary>
/// the id of the requested node, if any, else zero.
/// </summary>
int _nodeId = 0;
private IPublishedContent _publishedContent = null;
#region Properties
/// <summary>
/// Returns the current RoutingContext
/// </summary>
public RoutingContext RoutingContext { get; private set; }
/// <summary>
/// The cleaned up Uri used for routing
/// </summary>
public Uri Uri { get; private set; }
/// <summary>
/// Gets or sets the document request's domain.
/// </summary>
public Domain Domain { get; internal set; }
public Uri DomainUri { get; internal set; }
/// <summary>
/// Gets or sets whether the rendering engine is MVC or WebForms
/// </summary>
public RenderingEngine RenderingEngine { get; internal set; }
/// <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>
public CultureInfo Culture { get; set; }
private page _umbracoPage;
/// <summary>
/// Returns the Umbraco page object
/// </summary>
/// <remarks>
/// This value is only used for legacy/webforms code.
/// </remarks>
internal page UmbracoPage
{
get
{
if (_umbracoPage == null)
{
throw new InvalidOperationException("The umbraco page object is only available once Finalize()");
}
return _umbracoPage;
}
set { _umbracoPage = value; }
}
// TODO: fixme - do we want to have an ordered list of alternate cultures,
// to allow for fallbacks when doing dictionnary lookup and such?
public IPublishedContent PublishedContent
{
get { return _publishedContent; }
set
{
_publishedContent = value;
this.Template = null;
_nodeId = _publishedContent != null ? _publishedContent.Id : 0;
}
}
/// <summary>
/// Gets or sets the document request's template lookup
/// </summary>
public Template Template { get; set; }
/// <summary>
/// Gets a value indicating whether the document request has a template.
/// </summary>
public bool HasTemplate
{
get { return this.Template != null ; }
}
/// <summary>
/// Gets the id of the document.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when the document request has no document.</exception>
public int DocumentId
{
get
{
if (this.PublishedContent == null)
throw new InvalidOperationException("PublishedContentRequest has no document.");
return _nodeId;
}
}
/// <summary>
/// Gets a value indicating whether the document request has a document.
/// </summary>
public bool HasNode
{
get { return this.PublishedContent != null; }
}
/// <summary>
/// Gets or sets a value indicating whether the requested document could not be found. This is set in the PublishedContentRequestBuilder.
/// </summary>
internal bool Is404 { get; set; }
/// <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
}
}