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 { internal enum RenderingEngine { Mvc, WebForms } /// /// represents a request for one specified Umbraco document to be rendered /// by one specified template, using one particular culture. /// internal class DocumentRequest { public DocumentRequest(Uri uri, RoutingContext routingContext) { this.Uri = uri; RoutingContext = routingContext; RenderingEngine = RenderingEngine.Mvc; } /// /// the id of the requested node, if any, else zero. /// int _nodeId = 0; private IDocument _document = null; #region Properties /// /// Returns the current RoutingContext /// public RoutingContext RoutingContext { get; private set; } /// /// The cleaned up Uri used for routing /// public Uri Uri { get; private set; } /// /// Gets or sets the document request's domain. /// public Domain Domain { get; internal set; } public Uri DomainUri { get; internal set; } /// /// Gets or sets whether the rendering engine is MVC or WebForms /// public RenderingEngine RenderingEngine { get; internal set; } /// /// Gets a value indicating whether the document request has a domain. /// public bool HasDomain { get { return this.Domain != null; } } /// /// Gets or sets the document request's culture /// public CultureInfo Culture { get; set; } private page _umbracoPage; /// /// Returns the Umbraco page object /// /// /// This value is only used for legacy/webforms code. /// 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 IDocument Document { get { return _document; } set { _document = value; this.Template = null; _nodeId = _document != null ? _document.Id : 0; } } /// /// Gets or sets the document request's template lookup /// public Template Template { get; set; } /// /// Gets a value indicating whether the document request has a template. /// public bool HasTemplate { get { return this.Template != null ; } } /// /// Gets the id of the document. /// /// Thrown when the document request has no document. public int DocumentId { get { if (this.Document == null) throw new InvalidOperationException("DocumentRequest has no document."); return _nodeId; } } /// /// Gets a value indicating whether the document request has a document. /// public bool HasNode { get { return this.Document != null; } } /// /// Gets or sets a value indicating whether the requested document could not be found. /// public bool Is404 { get; internal set; } /// /// Gets a value indicating whether the document request triggers a redirect. /// public bool IsRedirect { get { return !string.IsNullOrWhiteSpace(this.RedirectUrl); } } /// /// Gets the url to redirect to, when the document request triggers a redirect. /// public string RedirectUrl { get; set; } #endregion } }