Go to the documentation of this file.00001 using System.Web;
00002 using System.Web.Routing;
00003 using N2.Engine;
00004 using System.Web.Mvc;
00005
00006 namespace N2.Web.Mvc
00007 {
00012 public class ContentRoute<T> : ContentRoute, IRouteWithArea where T : ContentItem
00013 {
00014 IEngine engine;
00015
00016 public ContentRoute(IEngine engine)
00017 : base(engine)
00018 {
00019 this.engine = engine;
00020 }
00021
00022 public ContentRoute(IEngine engine, IRouteHandler routeHandler, IControllerMapper controllerMapper, Route innerRoute)
00023 : base(engine, routeHandler, controllerMapper, innerRoute)
00024 {
00025 this.engine = engine;
00026 if (innerRoute.DataTokens.ContainsKey("area"))
00027 this.Area = innerRoute.DataTokens["area"] as string;
00028 }
00029
00030 public override RouteValueDictionary GetRouteValues(ContentItem item, RouteValueDictionary routeValues)
00031 {
00032 if(item is T)
00033 return base.GetRouteValues(item, routeValues);
00034 return null;
00035 }
00036
00037 public override RouteData GetRouteData(HttpContextBase httpContext)
00038 {
00039 var rd = base.GetRouteData(httpContext);
00040
00041 if(rd != null && rd.CurrentItem() is T)
00042
00043 return rd;
00044
00045 return null;
00046 }
00047
00048 public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
00049 {
00050
00051 var item = values.CurrentItem<T>(ContentItemKey, engine.Persister)
00052 ?? requestContext.CurrentItem<T>();
00053
00054
00055 if (!(item is T))
00056 return null;
00057
00058 values = new RouteValueDictionary(values);
00059 values[AreaKey] = Area;
00060 var vpd = base.GetVirtualPath(requestContext, values);
00061
00062 if (vpd != null && Area != null)
00063 vpd.DataTokens[AreaKey] = Area;
00064
00065 return vpd;
00066 }
00067
00068 #region IRouteWithArea Members
00069
00070 string area;
00071 public string Area
00072 {
00073 get { return area; }
00074 protected set { area = value; }
00075 }
00076
00077 #endregion
00078 }
00079 }