Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv8601/src/Spring/Spring.Web/Web/Support
Modified Files:
AbstractHandlerFactory.cs PageHandlerFactory.cs
Log Message:
fixed SPRNET-762
Index: PageHandlerFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/PageHandlerFactory.cs,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** PageHandlerFactory.cs 27 Jan 2008 23:29:55 -0000 1.34
--- PageHandlerFactory.cs 19 Mar 2008 18:05:08 -0000 1.35
***************
*** 110,158 ****
}
! // strip application path from url
! string appPath = context.Request.ApplicationPath.TrimEnd('/');
! string appRelativeVirtualPath = url;
! if (appRelativeVirtualPath.ToLower().StartsWith(appPath.ToLower()))
! {
! appRelativeVirtualPath = appRelativeVirtualPath.Substring(appPath.Length);
! }
!
! string pageId = appRelativeVirtualPath;
! // lookup definition using app-relative url
! if (isDebug) Log.Debug(string.Format("GetHandler():looking up definition for app-relative url '{0}'", appRelativeVirtualPath));
! IObjectDefinition pageDefinition = (appContext != null) ? appContext.ObjectFactory.GetObjectDefinition(appRelativeVirtualPath, true) : null;
! if (pageDefinition == null)
! {
! // try using pagename only
! // only looks in the specified context -- it will *not* search parent contexts
! string pageName = WebUtils.GetPageName(appRelativeVirtualPath);
! pageDefinition = (appContext != null) ? appContext.ObjectFactory.GetObjectDefinition(pageName, false) : null;
! if (pageDefinition != null)
! {
! pageId = pageName;
! if (isDebug)
! Log.Debug(string.Format("GetHandler():found definition for page-name '{0}'", pageName));
! }
! else
! {
! if (isDebug)
! Log.Debug(string.Format("GetHandler():no definition found for page-name '{0}'", pageName));
! }
! }
! else
! {
! if (isDebug) Log.Debug(string.Format("GetHandler():found definition for page-url '{0}'", appRelativeVirtualPath));
! }
! if (pageDefinition != null)
{
! Type pageType = pageDefinition.ObjectType;
if (typeof(IRequiresSessionState).IsAssignableFrom(pageType))
{
! handler = new SessionAwarePageHandler(appContext, pageId, url, null);
}
else
{
! handler = new PageHandler(appContext, pageId, url, null);
}
}
--- 110,126 ----
}
! string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url);
! NamedObjectDefinition namedPageDefinition = FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory);
! if (namedPageDefinition != null)
{
! Type pageType = namedPageDefinition.ObjectDefinition.ObjectType;
if (typeof(IRequiresSessionState).IsAssignableFrom(pageType))
{
! handler = new SessionAwarePageHandler(appContext, namedPageDefinition.Name, url, null);
}
else
{
! handler = new PageHandler(appContext, namedPageDefinition.Name, url, null);
}
}
***************
*** 164,172 ****
if (typeof(IRequiresSessionState).IsAssignableFrom(pageType))
{
! handler = new SessionAwarePageHandler(appContext, pageId, url, physicalPath);
}
else
{
! handler = new PageHandler(appContext, pageId, url, physicalPath);
}
}
--- 132,140 ----
if (typeof(IRequiresSessionState).IsAssignableFrom(pageType))
{
! handler = new SessionAwarePageHandler(appContext, appRelativeVirtualPath, url, physicalPath);
}
else
{
! handler = new PageHandler(appContext, appRelativeVirtualPath, url, physicalPath);
}
}
Index: AbstractHandlerFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Web/Web/Support/AbstractHandlerFactory.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AbstractHandlerFactory.cs 18 May 2006 21:37:52 -0000 1.4
--- AbstractHandlerFactory.cs 19 Mar 2008 18:05:08 -0000 1.5
***************
*** 21,25 ****
--- 21,29 ----
#region Imports
+ using System.IO;
using System.Web;
+ using Common.Logging;
+ using Spring.Objects.Factory.Config;
+ using Spring.Util;
#endregion
***************
*** 83,86 ****
--- 87,183 ----
public virtual void ReleaseHandler(IHttpHandler handler)
{}
+
+ /// <summary>
+ /// DO NOT USE - this is subject to change!
+ /// </summary>
+ /// <param name="appRelativeVirtualPath"></param>
+ /// <param name="objectFactory"></param>
+ /// <returns>
+ /// This method requires registrars to follow the convention of registering web object definitions using their
+ /// application relative urls (~/mypath/mypage.aspx).
+ /// </returns>
+ /// <remarks>
+ /// Resolve an object definition by url.
+ /// </remarks>
+ protected internal static NamedObjectDefinition FindWebObjectDefinition(string appRelativeVirtualPath, IConfigurableListableObjectFactory objectFactory)
+ {
+ ILog Log = LogManager.GetLogger(typeof(AbstractHandlerFactory));
+ bool isDebug = Log.IsDebugEnabled;
+
+ // lookup definition using app-relative url
+ if (isDebug) Log.Debug(string.Format("GetHandler():looking up definition for app-relative url '{0}'", appRelativeVirtualPath));
+ string objectDefinitionName = appRelativeVirtualPath;
+ IObjectDefinition pageDefinition = objectFactory.GetObjectDefinition(appRelativeVirtualPath, true);
+
+ if (pageDefinition == null)
+ {
+ // try using pagename+extension and pagename only
+ string pageExtension = Path.GetExtension(appRelativeVirtualPath);
+ string pageName = WebUtils.GetPageName(appRelativeVirtualPath);
+ // only looks in the specified object factory -- it will *not* search parent contexts
+ pageDefinition = objectFactory.GetObjectDefinition(pageName + pageExtension, false);
+ if (pageDefinition == null)
+ {
+ pageDefinition = objectFactory.GetObjectDefinition(pageName, false);
+ if (pageDefinition != null) objectDefinitionName = pageName;
+ }
+ else
+ {
+ objectDefinitionName = pageName + pageExtension;
+ }
+
+ if (pageDefinition != null)
+ {
+ if (isDebug)
+ Log.Debug(string.Format("GetHandler():found definition for page-name '{0}'", objectDefinitionName));
+ }
+ else
+ {
+ if (isDebug)
+ Log.Debug(string.Format("GetHandler():no definition found for page-name '{0}'", pageName));
+ }
+ }
+ else
+ {
+ if (isDebug) Log.Debug(string.Format("GetHandler():found definition for page-url '{0}'", appRelativeVirtualPath));
+ }
+
+ return (pageDefinition == null) ? (NamedObjectDefinition)null : new NamedObjectDefinition(objectDefinitionName, pageDefinition);
+ }
+
+ /// <summary>
+ /// DO NOT USE - this is subject to change!
+ /// </summary>
+ protected internal class NamedObjectDefinition
+ {
+ private readonly string _name;
+ private readonly IObjectDefinition _objectDefinition;
+
+ /// <summary>
+ /// DO NOT USE
+ /// </summary>
+ public NamedObjectDefinition(string name, IObjectDefinition objectDefinition)
+ {
+ _name = name;
+ _objectDefinition = objectDefinition;
+ }
+
+ /// <summary>
+ /// DO NOT USE
+ /// </summary>
+ public string Name
+ {
+ get { return _name; }
+ }
+
+ /// <summary>
+ /// DO NOT USE
+ /// </summary>
+ public IObjectDefinition ObjectDefinition
+ {
+ get { return _objectDefinition; }
+ }
+ }
}
+
}
\ No newline at end of file
|