Changed the Template prop of documentrequest to be a new TemplateLookup object since we are going
to need to support MVC and the old Template object is for webforms. I've added a lot of TODO's here because we'll need to enable the lookups properly in each ILookup and also set the rendering engine (IsMvc) in the ILookups too. This hasn't been enabled, yet, just a bunch of TODO's written.
This commit is contained in:
@@ -26,8 +26,8 @@ namespace Umbraco.Tests.DocumentLookups
|
||||
|
||||
Assert.IsTrue(result);
|
||||
Assert.IsNotNull(docRequest.Node);
|
||||
Assert.IsNotNull(docRequest.Template);
|
||||
Assert.AreEqual("blah".ToUpperInvariant(), docRequest.Template.Alias.ToUpperInvariant());
|
||||
Assert.IsNotNull(docRequest.TemplateLookup);
|
||||
Assert.AreEqual("blah".ToUpperInvariant(), docRequest.TemplateLookup.TemplateAlias.ToUpperInvariant());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace Umbraco.Tests.DocumentLookups
|
||||
var docRequest = new DocumentRequest(routingContext.UmbracoContext.UmbracoUrl, routingContext)
|
||||
{
|
||||
Node = routingContext.PublishedContentStore.GetDocumentById(routingContext.UmbracoContext, 1174),
|
||||
Template = template
|
||||
TemplateLookup = new TemplateLookup(template.Alias, template)
|
||||
};
|
||||
|
||||
var handler = new RenderRouteHandler(new TestControllerFactory());
|
||||
@@ -68,7 +68,7 @@ namespace Umbraco.Tests.DocumentLookups
|
||||
var docRequest = new DocumentRequest(routingContext.UmbracoContext.UmbracoUrl, routingContext)
|
||||
{
|
||||
Node = routingContext.PublishedContentStore.GetDocumentById(routingContext.UmbracoContext, 1172),
|
||||
Template = template
|
||||
TemplateLookup = new TemplateLookup(template.Alias, template)
|
||||
};
|
||||
|
||||
var handler = new RenderRouteHandler(new TestControllerFactory());
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Umbraco.Web.Mvc
|
||||
|
||||
//check if the custom controller has an action with the same name as the template name (we convert ToUmbracoAlias since the template name might have invalid chars).
|
||||
//NOTE: This also means that all custom actions MUST be PascalCase.. but that should be standard.
|
||||
var templateName = documentRequest.Template.Alias.Split('.')[0].ToUmbracoAlias(StringAliasCaseType.PascalCase);
|
||||
var templateName = documentRequest.TemplateLookup.TemplateAlias.Split('.')[0].ToUmbracoAlias(StringAliasCaseType.PascalCase);
|
||||
def.ActionName = templateName;
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,56 @@ using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
|
||||
/// <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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// represents a request for one specified Umbraco document to be rendered
|
||||
/// by one specified template, using one particular culture.
|
||||
@@ -61,6 +111,11 @@ namespace Umbraco.Web.Routing
|
||||
|
||||
public Uri DomainUri { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the rendering engine is MVC or WebForms
|
||||
/// </summary>
|
||||
public bool IsMvc { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the document request has a domain.
|
||||
/// </summary>
|
||||
@@ -83,22 +138,22 @@ namespace Umbraco.Web.Routing
|
||||
set
|
||||
{
|
||||
_node = value;
|
||||
this.Template = null;
|
||||
this.TemplateLookup = null;
|
||||
_nodeId = _node != null ? _node.Id : 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the document request's template.
|
||||
/// Gets or sets the document request's template lookup
|
||||
/// </summary>
|
||||
public Template Template { get; set; }
|
||||
public TemplateLookup TemplateLookup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the document request has a template.
|
||||
/// </summary>
|
||||
public bool HasTemplate
|
||||
{
|
||||
get { return this.Template != null; }
|
||||
get { return this.TemplateLookup != null && TemplateLookup.FoundTemplate; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -297,12 +297,27 @@ namespace Umbraco.Web.Routing
|
||||
int templateId;
|
||||
if (!int.TryParse(templateAlias, out templateId))
|
||||
templateId = 0;
|
||||
_documentRequest.Template = templateId > 0 ? new Template(templateId) : null;
|
||||
|
||||
if (templateId > 0)
|
||||
{
|
||||
//TODO: Need to figure out if this is web forms or MVC based on template name somehow!!
|
||||
var webFormsTemplate = new Template(templateId);
|
||||
_documentRequest.TemplateLookup = new TemplateLookup(webFormsTemplate.Alias, webFormsTemplate);
|
||||
}
|
||||
else
|
||||
{
|
||||
_documentRequest.TemplateLookup = TemplateLookup.NoTemplate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO: Is this required??? I thought that was the purpose of the other LookupByNiceUrlAndTemplate?
|
||||
LogHelper.Debug<DocumentRequest>("{0}Look for template alias=\"{1}\" (altTemplate)", () => tracePrefix, () => templateAlias);
|
||||
_documentRequest.Template = Template.GetByAlias(templateAlias);
|
||||
//TODO: Need to figure out if this is web forms or MVC based on template name somehow!!
|
||||
var webFormsTemplate = Template.GetByAlias(templateAlias);
|
||||
_documentRequest.TemplateLookup = webFormsTemplate != null
|
||||
? new TemplateLookup(webFormsTemplate.Alias, webFormsTemplate)
|
||||
: TemplateLookup.NoTemplate();
|
||||
}
|
||||
|
||||
if (!_documentRequest.HasTemplate)
|
||||
|
||||
@@ -35,6 +35,10 @@ namespace Umbraco.Web.Routing
|
||||
var templateAlias = docRequest.Uri.AbsolutePath.Substring(pos + 1);
|
||||
path = path.Substring(0, pos);
|
||||
|
||||
//TODO: We need to check if the altTemplate is for MVC or not, though I'm not exactly sure how the best
|
||||
// way to do that would be since the template is just an alias and if we are not having a flag on the
|
||||
// doc type for rendering engine and basing it only on template name, then how would we handle this?
|
||||
|
||||
var template = Template.GetByAlias(templateAlias);
|
||||
if (template != null)
|
||||
{
|
||||
@@ -44,7 +48,7 @@ namespace Umbraco.Web.Routing
|
||||
node = LookupDocumentNode(docRequest, route);
|
||||
|
||||
if (node != null)
|
||||
docRequest.Template = template;
|
||||
docRequest.TemplateLookup = new TemplateLookup(template.Alias, template);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -126,8 +126,8 @@ namespace Umbraco.Web
|
||||
}
|
||||
|
||||
//TODO: Detect MVC vs WebForms
|
||||
|
||||
var isMvc = true;
|
||||
docreq.IsMvc = true; //TODO: This needs to be set in the ILookups based on the template
|
||||
var isMvc = docreq.IsMvc;
|
||||
RewriteToUmbracoHandler(HttpContext.Current, uri.Query, isMvc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace umbraco
|
||||
{
|
||||
_upage = new page(_docRequest);
|
||||
UmbracoContext.Current.HttpContext.Items["pageID"] = _docRequest.NodeId; // legacy - fixme
|
||||
var templatePath = SystemDirectories.Masterpages + "/" + _docRequest.Template.Alias.Replace(" ", "") + ".master"; // fixme - should be in .Template!
|
||||
var templatePath = SystemDirectories.Masterpages + "/" + _docRequest.TemplateLookup.TemplateAlias.Replace(" ", "") + ".master"; // fixme - should be in .Template!
|
||||
this.MasterPageFile = templatePath; // set the template
|
||||
}
|
||||
else
|
||||
|
||||
@@ -5,9 +5,11 @@ using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Xml;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
using umbraco.cms.businesslogic.property;
|
||||
using umbraco.cms.businesslogic.template;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.interfaces;
|
||||
|
||||
@@ -98,8 +100,22 @@ namespace umbraco
|
||||
|
||||
if (docreq.HasTemplate)
|
||||
{
|
||||
this.template = docreq.Template.Id;
|
||||
elements["template"] = this.template.ToString();
|
||||
//TODO: The template property which returns just an int will be obsoleted once we remove the need for templates
|
||||
// in the database but I suspect this will take a bit of work!
|
||||
// Because the docrequest doesn't know about what template object we have (since the webforms template object is legacy)
|
||||
// we need to check here to see if we can cast it. This should always work with webforms and the Template property of this
|
||||
// object only gets used in very few places, the worrying part is that it is used in library.RenderMacroContent and library.RenderTemplate so not sure
|
||||
// what would happen if someone tried to execute this inside of MVC... perhaps we can do a check in those methods and throw an exception if
|
||||
// they are executed in MVC for now?
|
||||
if (TypeHelper.IsTypeAssignableFrom<Template>(docreq.TemplateLookup.TemplateObject))
|
||||
{
|
||||
this.template = ((Template)docreq.TemplateLookup.TemplateObject).Id;
|
||||
elements["template"] = this.template.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// we can't get the ID because it doesn't exist for MVC, throw exception?
|
||||
}
|
||||
}
|
||||
|
||||
PopulateElementData(docreq.Node);
|
||||
|
||||
Reference in New Issue
Block a user