diff --git a/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs
index f221b5a0da..25d627c423 100644
--- a/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs
+++ b/src/Umbraco.Tests/DocumentLookups/LookupByNiceUrlAndTemplateTests.cs
@@ -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());
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Tests/DocumentLookups/RenderRouteHandlerTests.cs b/src/Umbraco.Tests/DocumentLookups/RenderRouteHandlerTests.cs
index 55dad878df..7dd31393f9 100644
--- a/src/Umbraco.Tests/DocumentLookups/RenderRouteHandlerTests.cs
+++ b/src/Umbraco.Tests/DocumentLookups/RenderRouteHandlerTests.cs
@@ -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());
diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
index 4dbd091071..ab637f4449 100644
--- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
+++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs
@@ -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;
}
diff --git a/src/Umbraco.Web/Routing/DocumentRequest.cs b/src/Umbraco.Web/Routing/DocumentRequest.cs
index 8b125b9c2e..c9d5f2dbc4 100644
--- a/src/Umbraco.Web/Routing/DocumentRequest.cs
+++ b/src/Umbraco.Web/Routing/DocumentRequest.cs
@@ -18,6 +18,56 @@ 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.
@@ -61,6 +111,11 @@ namespace Umbraco.Web.Routing
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.
///
@@ -83,22 +138,22 @@ namespace Umbraco.Web.Routing
set
{
_node = value;
- this.Template = null;
+ this.TemplateLookup = null;
_nodeId = _node != null ? _node.Id : 0;
}
}
///
- /// Gets or sets the document request's template.
+ /// Gets or sets the document request's template lookup
///
- public Template Template { get; set; }
+ public TemplateLookup TemplateLookup { get; set; }
///
/// Gets a value indicating whether the document request has a template.
///
public bool HasTemplate
{
- get { return this.Template != null; }
+ get { return this.TemplateLookup != null && TemplateLookup.FoundTemplate; }
}
///
diff --git a/src/Umbraco.Web/Routing/DocumentSearcher.cs b/src/Umbraco.Web/Routing/DocumentSearcher.cs
index 8127e8627f..99b8ec85ae 100644
--- a/src/Umbraco.Web/Routing/DocumentSearcher.cs
+++ b/src/Umbraco.Web/Routing/DocumentSearcher.cs
@@ -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("{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)
diff --git a/src/Umbraco.Web/Routing/LookupByNiceUrlAndTemplate.cs b/src/Umbraco.Web/Routing/LookupByNiceUrlAndTemplate.cs
index b9b6b6755d..78d057f6a1 100644
--- a/src/Umbraco.Web/Routing/LookupByNiceUrlAndTemplate.cs
+++ b/src/Umbraco.Web/Routing/LookupByNiceUrlAndTemplate.cs
@@ -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
{
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index f547f5813a..ebd7ef7670 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -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);
}
}
diff --git a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
index e7dbbd7d28..5808337f42 100644
--- a/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/default.aspx.cs
@@ -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
diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs
index a075b678fb..55cec120d4 100644
--- a/src/Umbraco.Web/umbraco.presentation/page.cs
+++ b/src/Umbraco.Web/umbraco.presentation/page.cs
@@ -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(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);