Example #1
0
        public void Attached_path_values_doesnt_mutate_original()
        {
            var path = new PathData { Action = "hej", CurrentItem = item, Ignore = true, IsCacheable = true, IsPubliclyAvailable = true, IsRewritable = true, Path = "/x", StopItem = page, TemplateUrl = "/hello.aspx" };

            var detached = path.Detach();
            var reattached = detached.Attach(persister);

            detached.Action = "hejdå";
            detached.CurrentItem = page;
            detached.Ignore = false;
            detached.IsCacheable = false;
            detached.IsPubliclyAvailable = false;
            detached.IsRewritable = false;
            detached.Path = "/y";
            detached.StopItem = item;
            detached.TemplateUrl = "/world.aspx";
            detached.QueryParameters["Hello"] = "world";

            reattached.Action.ShouldNotBe("hejdå");
            reattached.CurrentItem.ShouldNotBe(page);
            reattached.Ignore.ShouldNotBe(false);
            reattached.IsCacheable.ShouldNotBe(false);
            reattached.IsPubliclyAvailable.ShouldNotBe(false);
            reattached.IsRewritable.ShouldNotBe(false);
            reattached.Path.ShouldNotBe("/y");
            reattached.StopItem.ShouldNotBe(item);
            reattached.TemplateUrl.ShouldNotBe("/world.aspx");
            reattached.QueryParameters.ContainsKey("Hello").ShouldBe(false);
        }
Example #2
0
		public void SetItem()
		{
			var path = new PathData(page);

			path.CurrentItem.ID.ShouldBe(1);
			path.ID.ShouldBe(1);
		}
Example #3
0
 /// <summary>Inject the current page into the page handler.</summary>
 /// <param name="handler">The handler executing the request.</param>
 public virtual void InjectCurrentPage(PathData path, IHttpHandler handler)
 {
     IContentTemplate template = handler as IContentTemplate;
     if (template != null && path != null)
     {
         template.CurrentItem = path.CurrentPage;
     }
 }
Example #4
0
        /// <summary>Rewrites a dynamic/computed url to an actual template url.</summary>
        public virtual void RewriteRequest(PathData path, RewriteMethod rewriteMethod)
        {
            if (path == null || path.IsEmpty() || !path.IsRewritable || path.Ignore || rewriteMethod == RewriteMethod.None)
                return;

            string templateUrl = GetHandlerPath(path);
            WebContext.HttpContext.RewritePath(templateUrl, false);
        }
Example #5
0
        public void Attach_creates_cloned_object()
        {
            var path = new PathData { Action = "hej", CurrentItem = item, Ignore = true, IsCacheable = true, IsPubliclyAvailable = true, IsRewritable = true, Path = "/x", StopItem = page, TemplateUrl = "/hello.aspx" };

            var detached = path.Detach();
            var reattached = detached.Attach(persister);

            reattached.ShouldNotBeSameAs(detached);
        }
Example #6
0
        public void Attach_uses_persister_to_load_page()
        {
            var path = new PathData { CurrentPage = page };
            path = path.Detach();
            path.CurrentPage.ShouldBe(null);

            var loadedPath = path.Attach(persister);
            loadedPath.CurrentPage.ID.ShouldBe(1);
        }
Example #7
0
		public void Page_MayBe_null()
		{
			var path = new PathData();

			path.CurrentPage = page;
			path.CurrentPage = null;

			path.CurrentPage.ShouldBe(null);
			path.PageID.ShouldBe(0);
		}
Example #8
0
		public void Item_MayBe_null()
		{
			var path = new PathData();

			path.CurrentItem = item;
			path.CurrentItem = null;

			path.CurrentItem.ShouldBe(null);
			path.ID.ShouldBe(0);
		}
Example #9
0
		public void Item_and_Page_MayDiffer()
		{
			var path = new PathData();

			path.CurrentItem = item;
			path.CurrentPage = page;

			path.CurrentPage.ShouldNotBe(item);
			path.CurrentItem.ShouldNotBe(page);
		}
Example #10
0
        /// <summary>Rewrites a dynamic/computed url to an actual template url.</summary>
        public virtual void RewriteRequest(PathData path, RewriteMethod rewriteMethod)
        {
            if (path == null || path.IsEmpty() || !path.IsRewritable || path.Ignore)
                return;

            string templateUrl = GetHandlerPath(path);

            if(rewriteMethod == RewriteMethod.BeginRequest || rewriteMethod == RewriteMethod.SurroundMapRequestHandler)
                WebContext.RewritePath(templateUrl);
            else if(rewriteMethod == RewriteMethod.TransferRequest)
                WebContext.TransferRequest(templateUrl);
        }
Example #11
0
		public void Detach_removes_reference_to_page_but_leaves_id()
		{
			var path = new PathData { CurrentPage = page };
			path = path.Detach();

			path.CurrentPage.ShouldBe(null);
			path.PageID.ShouldBe(1);
		}
Example #12
0
		public void Detach_removes_reference_to_item_but_leaves_id()
		{
			var path = new PathData { CurrentItem = page };
			path = path.Detach();

			path.CurrentItem.ShouldBe(null);
			path.ID.ShouldBe(1);
		}
		public override void InjectCurrentPage(PathData path, System.Web.IHttpHandler handler)
		{
			logger.Debug("InjectCurrentPage");
			base.InjectCurrentPage(path, handler);
		}
		public override void AuthorizeRequest(PathData path, System.Security.Principal.IPrincipal user)
		{
			logger.Debug("AuthorizeRequest");
			base.AuthorizeRequest(path, user);
		}
Example #15
0
			public ContentScope(PathData newCurrentPath, ContentHelperBase contentHelper)
			{
				this.contentHelper = contentHelper;
				previousGetter = contentHelper.Current.PathGetter;
				contentHelper.Current.PathGetter = () => newCurrentPath;
			}
Example #16
0
 /// <summary>Authorize the user against the current content item. Throw an exception if not authorized.</summary>
 /// <param name="user">The user for which to authorize the request.</param>
 public virtual void AuthorizeRequest(PathData path, IPrincipal user)
 {
     SecurityEnforcer.AuthorizeRequest(user, path.CurrentPage, Permission.Read);
 }
Example #17
0
		public void PubliclyAvailable_is_determined_by_current_nonpublished_page(ContentState state, bool expectedAvailability)
		{
			var path = new PathData { CurrentItem = item, CurrentPage = new Items.PageItem { State = state } };

			path.IsPubliclyAvailable.ShouldBe(expectedAvailability);
		}
Example #18
0
		public void PubliclyAvailable_is_determined_by_current_nonpublic_page()
		{
			var path = new PathData { CurrentItem = item, CurrentPage = new Items.PageItem { AlteredPermissions = N2.Security.Permission.Read } };

			path.IsPubliclyAvailable.ShouldBe(false);
		}
Example #19
0
		public void PubliclyAvailable_is_determined_by_current()
		{
			var path = new PathData { CurrentItem = item, CurrentPage = page };

			path.IsPubliclyAvailable.ShouldBe(true);
		}
Example #20
0
		public void Attach_uses_persister_to_load_stop()
		{
			var path = new PathData { StopItem = page };
			path = path.Detach();
			path.StopItem.ShouldBe(null);

			var loadedPath = path.Attach(persister);
			loadedPath.StopItem.ID.ShouldBe(1);
		}
Example #21
0
		public void Detach_creates_cloned_object()
		{
			var path = new PathData();
			var detached = path.Detach();

			detached.ShouldNotBeSameAs(path);
		}
Example #22
0
		/// <summary>Begins a new scope using the current content helper.</summary>
		/// <param name="newCurrentPath">The current path to use in the new scope.</param>
		/// <returns>An object that restores the scope upon disposal.</returns>
		public IDisposable BeginScope(PathData newCurrentPath)
		{
			if (newCurrentPath == null) return new EmptyDisposable();

			return new ContentScope(newCurrentPath, this);
		}
Example #23
0
		public void Cloned_path_data_has_same_values()
		{
			var path = new PathData(page, item) { Action = "hello", Argument = "world", Ignore = true, IsCacheable = false, IsPubliclyAvailable = true, IsRewritable = false, TemplateUrl = "asdf" };
			var clone = path.Clone();

			path.Action.ShouldBe(clone.Action);
			path.Argument.ShouldBe(clone.Argument);
			path.CurrentItem.ShouldBe(clone.CurrentItem);
			path.CurrentPage.ShouldBe(clone.CurrentPage);
			path.ID.ShouldBe(clone.ID);
			path.Ignore.ShouldBe(clone.Ignore);
			path.IsCacheable.ShouldBe(clone.IsCacheable);
			path.IsPubliclyAvailable.ShouldBe(clone.IsPubliclyAvailable);
			path.IsRewritable.ShouldBe(clone.IsRewritable);
			path.PageID.ShouldBe(clone.PageID);
			path.Path.ShouldBe(clone.Path);
			path.QueryParameters.Count.ShouldBe(clone.QueryParameters.Count);
			path.StopID.ShouldBe(clone.StopID);
			path.StopItem.ShouldBe(clone.StopItem);
			path.TemplateUrl.ShouldBe(clone.TemplateUrl);
		}
Example #24
0
		public void Cloned_path_data_should_not_be_same_item()
		{
			var path = new PathData(page, item);
			var clone = path.Clone();

			clone.ShouldNotBeSameAs(path);
			clone.QueryParameters.ShouldNotBeSameAs(path.QueryParameters);
		}
Example #25
0
		public void ToString_should_maintina_page_and_item_info()
		{
			var path = new PathData(page, item);

			var reparsed = PathData.Parse(path.ToString(), persister);

			reparsed.CurrentItem.ShouldBe(path.CurrentItem);
			reparsed.CurrentPage.ShouldBe(path.CurrentPage);
		}
Example #26
0
 /// <summary>Gets the path to the handler (aspx template) to rewrite to.</summary>
 /// <returns></returns>
 protected virtual string GetHandlerPath(PathData path)
 {
     return path.GetRewrittenUrl();
 }
Example #27
0
		public void SetItem_ShouldBeFallback_OfPage()
		{
			var path = new PathData(page);

			path.CurrentPage.ID.ShouldBe(1);
		}
		protected override string GetHandlerPath(PathData path)
		{
			logger.Debug("GetHandlerPath");
			return base.GetHandlerPath(path);
		}
Example #29
0
		public void SetItem_ToNull_ShouldGiveNullItem()
		{
			var path = new PathData(null);

			path.CurrentItem.ShouldBe(null);
		}
		public override void RewriteRequest(PathData path, N2.Configuration.RewriteMethod rewriteMethod)
		{
			logger.Debug("RewriteRequest");
			base.RewriteRequest(path, rewriteMethod);
		}
Example #31
0
        /// <summary>Finds the path associated with an url.</summary>
        /// <param name="url">The url to the template to locate.</param>
        /// <param name="startNode">The node to start finding path from if none supplied will start from StartNode</param>
        /// <param name="remainingPath">The remaining path to search</param>
        /// <returns>A PathData object. If no template was found the object will have empty properties.</returns>
        public PathData FindPath(Url url, ContentItem startNode = null, string remainingPath = null)
        {
            if (url == null)
            {
                return(PathData.Empty);
            }
            if (!IsOnline)
            {
                return(PathData.Empty);
            }

            Url         requestedUrl = url;
            ContentItem item         = TryLoadingFromQueryString(requestedUrl, PathData.ItemQueryKey);
            ContentItem page         = TryLoadingFromQueryString(requestedUrl, PathData.PageQueryKey);

            if (page != null)
            {
                var directPath = page.FindPath(requestedUrl["action"] ?? PathData.DefaultAction)
                                 .SetArguments(requestedUrl["arguments"])
                                 .UpdateParameters(requestedUrl.GetQueries());

                var directData = UseItemIfAvailable(item, directPath);
                // check whether to rewrite requests with page in query string since this might be already rewritten
                directData.IsRewritable &= !string.Equals(url.ApplicationRelativePath, directData.TemplateUrl, StringComparison.InvariantCultureIgnoreCase);
                return(directData);
            }

            ContentItem startPage = startNode ?? GetStartPage(requestedUrl);

            if (startPage == null)
            {
                return(PathData.Empty);
            }

            string   path = remainingPath ?? Url.ToRelative(requestedUrl.Path).TrimStart('~');
            PathData data = startPage.FindPath(path).UpdateParameters(requestedUrl.GetQueries());

            if (data.IsEmpty())
            {
                if (!string.IsNullOrEmpty(DefaultDocument) && path.EndsWith(DefaultDocument, StringComparison.OrdinalIgnoreCase))
                {
                    // Try to find path without default document.
                    data = StartPage
                           .FindPath(StripDefaultDocument(path))
                           .UpdateParameters(requestedUrl.GetQueries());
                }

                if (data.IsEmpty())
                {
                    // Allow user code to set path through event
                    if (PageNotFound != null)
                    {
                        PageNotFoundEventArgs args = new PageNotFoundEventArgs(requestedUrl);
                        args.AffectedPath = data;
                        PageNotFound(this, args);
                        data = args.AffectedPath;
                    }
                }
            }

            data.Ignore = !IgnoreExisting(webContext.HttpContext.Request.PhysicalPath);
            data        = UseItemIfAvailable(item, data);
            return(data);
        }