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.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 { /// /// 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. /// /// /// 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. /// internal class TemplateLookup { /// /// Static method to return an empty template lookup /// /// 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; } } /// /// The alias of the template found /// internal string TemplateAlias { get; private set; } /// /// The business logic template object that has been found, null if not found /// internal object TemplateObject { get; private set; } } /// /// 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; } /// /// the id of the requested node, if any, else zero. /// int _nodeId = 0; /// /// the requested node, if any, else null. /// XmlNode _xmlNode = null; private IDocument _node = 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 bool IsMvc { 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; } // 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 Node { get { return _node; } set { _node = value; this.TemplateLookup = null; _nodeId = _node != null ? _node.Id : 0; } } /// /// Gets or sets the document request's template lookup /// public TemplateLookup TemplateLookup { get; set; } /// /// Gets a value indicating whether the document request has a template. /// public bool HasTemplate { get { return this.TemplateLookup != null && TemplateLookup.FoundTemplate; } } /// /// Gets the id of the document. /// /// Thrown when the document request has no document. public int NodeId { get { if (this.Node == 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.Node != 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 } }