/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;
namespace Everest.Library.Mvc.View{
public class WebFormThemeViewEngine : EverestWebFormViewEngine
{
public WebFormThemeViewEngine()
{
base.ViewLocationFormats = new string[] {
"{3}Views/{2}/{1}/{0}.aspx",
"{3}Views/{2}/{1}/{0}.ascx",
"{3}Views/{2}/Shared/{0}.aspx",
"{3}Views/{2}/Shared/{0}.ascx"
};
base.MasterLocationFormats = new string[] {
"{3}Views/{2}/{1}/{0}.master",
"{3}Views/{2}/Shared/{0}.master"
};
base.PartialViewLocationFormats = new string[] {
"{3}Views/{2}/{1}/{0}.aspx",
"{3}Views/{2}/{1}/{0}.ascx",
"{3}Views/{2}/Shared/{0}.aspx",
"{3}Views/{2}/Shared/{0}.ascx"
};
}
private string GetThemeToUse(ControllerContext controllerContext)
{
string themeName = controllerContext.HttpContext.Items["themeName"] as string;
if (themeName == null) themeName = "Default";
return themeName;
}
protected override string GetPath(ControllerContext controllerContext, string[] locations, string viewName, string controllerName, out string[] searchedLocations)
{
string path = null;
string themeName = this.GetThemeToUse(controllerContext);
searchedLocations = new string[locations.Length];
EverestContext everestContext = EverestContext.GetContext();
string rootUrl = everestContext.BaseUrl;
for (int i = 0; i < locations.Length; i++)
{
path = string.Format(CultureInfo.InvariantCulture, locations[i], new object[] { viewName, controllerName, themeName, rootUrl });
if (this.VirtualPathProvider.FileExists(path))
{
searchedLocations = new string[0];
return path;
}
searchedLocations[i] = path;
}
return null;
}
}
}
|