/// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public override string BuildUrl(ContentItem item)
        {
            if (item == null) throw new ArgumentNullException("item");

            ContentItem current = item;

            if (item.VersionOf.HasValue)
            {
                current = item.VersionOf;
            }

            // move up until first real page
            while(current != null && !current.IsPage)
            {
                current = current.Parent;
            }

            // no start page found, use rewritten url
            if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();

            Url url;
            if (host.IsStartPage(current))
            {
                // we move right up to the start page
                url = "/";
            }
            else
            {
                // at least one node before the start page
                url = new Url("/" + current.Name + current.Extension);
                current = current.Parent;
                // build path until a start page
                while (current != null && !host.IsStartPage(current))
                {
                    url = url.PrependSegment(current.Name);
                    current = current.Parent;
                }
            }

            // no start page found, use rewritten url
            if (current == null) return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();

            if (item.IsPage && item.VersionOf.HasValue)
                // the item was a version, add this information as a query string
                url = url.AppendQuery(PathData.PageQueryKey, item.ID);
            else if(!item.IsPage)
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);

            if (current.ID == host.CurrentSite.StartPageID)
            {
                // the start page belongs to the current site, use relative url
                return Url.ToAbsolute("~" + url.PathAndQuery);
            }

            var site = host.GetSite(current.ID) ?? host.DefaultSite;

            return GetHostedUrl(item, url, site);
        }
Пример #2
0
        public override PathData ResolvePath(ContentItem startingPoint, string path)
        {
            if (path.Contains("virtual-grouping"))
            {
                var parentPath = startingPoint.FindPath(path);
                if (parentPath.StopItem != null)
                {
                    var parent = parentPath.StopItem;

                    if (parent == null)
                    {
                        return(base.ResolvePath(startingPoint, path));
                    }

                    var attributes = map.GetOrCreateDefinition(parent).GetCustomAttributes <GroupChildrenAttribute>();
                    foreach (var attribute in attributes)
                    {
                        var name     = HttpUtility.UrlDecode(parentPath.Argument).Trim('/');
                        var argument = name.Split('/')[1];

                        var group = Sources.GetChildren(new Query {
                            Parent = parent, OnlyPages = null
                        }).FirstOrDefault(i => i.Name == name);
                        if (group != null)
                        {
                            return(new PathData(group));
                        }
                    }
                }
            }
            return(base.ResolvePath(startingPoint, path));
        }
Пример #3
0
        private string GetHostedUrl(ContentItem item, string url, Site site)
        {
        	if (string.IsNullOrEmpty(site.Authority))
				return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();
        	
			return Url.Parse(url).SetAuthority(site.Authority);
        }
Пример #4
0
        public PathData ResolvePath(Url url)
        {
            if (url == null)
            {
                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 = GetStartPage(requestedUrl);

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

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

            if (data.IsEmpty())
            {
                if (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);
            return(UseItemIfAvailable(item, data));
        }
Пример #5
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public override Url BuildUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (item.VersionOf.HasValue)
            {
                return(BuildUrl(item.VersionOf)
                       .SetQueryParameter(PathData.VersionQueryKey, item.VersionIndex));
            }
            else if (item.ID == 0)
            {
                var page = Find.ClosestPage(item);
                if (page != null && page != item)
                {
                    return(BuildUrl(page)
                           .SetQueryParameter(PathData.VersionQueryKey, page.VersionIndex)
                           .SetQueryParameter("versionKey", item.GetVersionKey()));
                }
            }

            // move up until first real page
            var current = Find.ClosestPage(item);

            // no page found, throw
            if (current == null)
            {
                throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);
            }

            Url url = BuildPageUrl(current, ref current);

            var startPage = FindStartPage(current);

            // no start page found, use rewritten url
            if (startPage == null)
            {
                return(item.FindPath(PathData.DefaultAction).GetRewrittenUrl());
            }

            if (!item.IsPage)
            {
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
            }

            if (startPage.ID == host.CurrentSite.StartPageID)
            {
                // the start page belongs to the current site, use relative url
                return(Url.ToAbsolute("~" + url.PathAndQuery));
            }

            var site = host.GetSite(startPage.ID) ?? host.DefaultSite;

            return(GetHostedUrl(item, url, site));
        }
Пример #6
0
        protected override string GetPreviewUrl(ContentItem item)
        {
            if (item.VersionOf == null)
                return item.Url;

            return Url.Parse(item.FindPath(PathData.DefaultAction).RewrittenUrl)
                .AppendQuery("preview", item.ID)
                .AppendQuery("original", item.VersionOf.ID);
        }
Пример #7
0
        public static Control AddUserControl(Control container, ContentItem item)
        {
            PathData path = item.FindPath(PathData.DefaultAction);

            if (!path.IsEmpty())
            {
                return(AddUserControl(path.TemplateUrl, container, item));
            }
            return(null);
        }
Пример #8
0
        /// <summary>Creates the url used for rewriting friendly urls to the url of a template.</summary>
        /// <param name="path">The path containing item information to route.</param>
        /// <returns>The path to a template.</returns>
        /// <remarks>This method may throw <see cref="TemplateNotFoundException"/> if the template cannot be computed.</remarks>
        public static Url GetRewrittenUrl(this PathData path)
        {
            if (path.IsEmpty() || string.IsNullOrEmpty(path.TemplateUrl))
            {
                return(null);
            }

            if (path.CurrentPage.IsPage)
            {
                Url url = Url.Parse(path.TemplateUrl)
                          .UpdateQuery(path.QueryParameters);
                if (path.CurrentPage.ID == 0 && path.CurrentPage.VersionOf.HasValue)
                {
                    url = url.SetQueryParameter(PathData.PageQueryKey, path.CurrentPage.VersionOf.ID.Value)
                          .SetQueryParameter(PathData.VersionIndexQueryKey, path.CurrentPage.VersionIndex);
                }
                else
                {
                    url = url.SetQueryParameter(PathData.PageQueryKey, path.CurrentPage.ID);
                }

                if (!string.IsNullOrEmpty(path.Argument))
                {
                    url = url.SetQueryParameter("argument", path.Argument);
                }

                return(url.ResolveTokens());
            }

            for (ContentItem ancestor = path.CurrentItem.Parent; ancestor != null; ancestor = ancestor.Parent)
            {
                if (ancestor.IsPage)
                {
                    var url = ancestor.FindPath(PathData.DefaultAction).GetRewrittenUrl()
                              .UpdateQuery(path.QueryParameters);
                    if (path.CurrentItem.VersionOf.HasValue)
                    {
                        return(url.SetQueryParameter(PathData.ItemQueryKey, path.CurrentItem.VersionOf.ID.Value)
                               .SetQueryParameter(PathData.VersionIndexQueryKey, ancestor.VersionIndex));
                    }
                    else
                    {
                        return(url.SetQueryParameter(PathData.ItemQueryKey, path.CurrentItem.ID));
                    }
                }
            }
            if (path.CurrentItem.VersionOf.HasValue)
            {
                return(path.CurrentItem.VersionOf.FindPath(PathData.DefaultAction).GetRewrittenUrl()
                       .UpdateQuery(path.QueryParameters)
                       .SetQueryParameter(PathData.ItemQueryKey, path.CurrentItem.ID));
            }

            return(null);
        }
Пример #9
0
        protected override string GetPreviewUrl(ContentItem item)
        {
            if (item.VersionOf == null)
            {
                return(item.Url);
            }

            return(Url.Parse(item.FindPath(PathData.DefaultAction).RewrittenUrl)
                   .AppendQuery("preview", item.ID)
                   .AppendQuery("original", item.VersionOf.ID));
        }
        public void PagesOutsideStartPage_AreReferenced_ThroughTheirRewrittenUrl()
        {
            host   = new Host(wrapper, 10, 1);
            parser = TestSupport.Setup(persister, wrapper, host);

            CreateDefaultStructure();
            ContentItem root = CreateOneItem <PageItem>(10, "root", null);

            startItem.AddTo(root);
            ContentItem outside1 = CreateOneItem <PageItem>(11, "outside1", root);

            mocks.ReplayAll();

            Assert.AreEqual(parser.BuildUrl(root).ToString(), root.FindPath(PathData.DefaultAction).GetRewrittenUrl().ToString());
            Assert.AreEqual(parser.BuildUrl(outside1).ToString(), outside1.FindPath(PathData.DefaultAction).GetRewrittenUrl().ToString());
        }
Пример #11
0
		/// <summary>Gets the url for the preview frame.</summary>
		/// <param name="selectedItem">The currently selected item.</param>
		/// <returns>An url.</returns>
		public virtual string GetPreviewUrl(ContentItem selectedItem)
		{
			try
			{
				// If hostname == localhost, then don't use custom hostnames in the management navigation tree
				if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host == "localhost")
					return selectedItem.FindPath(PathData.DefaultAction).GetRewrittenUrl();

				Url url = ResolveResourceUrl(parser.BuildUrl(selectedItem));
				return url;
			}
			catch (N2Exception)
			{
				return Url.ResolveTokens("{ManagementUrl}/Empty.aspx?item=" + selectedItem.ID);
			}
		}
		/// <summary>Calculates an item url by walking it's parent path.</summary>
		/// <param name="item">The item whose url to compute.</param>
		/// <returns>A friendly url to the supplied item.</returns>
		public override Url BuildUrl(ContentItem item)
		{
			if (item == null) throw new ArgumentNullException("item");

			if (item.VersionOf.HasValue && item.VersionOf.Value != null)
			{
				return BuildUrl(item.VersionOf.Value)
					.SetQueryParameter(PathData.VersionIndexQueryKey, item.VersionIndex);
			}
			else if (item.ID == 0)
			{
				var page = Find.ClosestPage(item);
				if (page != null && page != item)
				{
					return BuildUrl(page)
						.SetQueryParameter(PathData.VersionIndexQueryKey, page.VersionIndex)
						.SetQueryParameter("versionKey", item.GetVersionKey());
				}
			}

			// move up until first real page
			var current = Find.ClosestPage(item);

			// no page found, throw
			if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);

			Url url = BuildPageUrl(current, ref current);

			var startPage = FindStartPage(current);
			// no start page found, use rewritten url
			if (startPage == null)
				return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();

			if (!item.IsPage)
				// the item was not a page, add this information as a query string
				url = url.AppendQuery(PathData.ItemQueryKey, item.ID);

			if (startPage.ID == host.CurrentSite.StartPageID)
            {
                // the start page belongs to the current site, use relative url
            	return Url.ToAbsolute("~" + url.PathAndQuery);
            }

			var site = host.GetSite(startPage.ID) ?? host.DefaultSite;

            return GetHostedUrl(item, url, site);
        }
Пример #13
0
        /// <summary>Gets the url to the edit page where to edit an existing item.</summary>
        /// <param name="item">The item to edit.</param>
        /// <returns>The url to the edit page</returns>
        public virtual string GetEditExistingItemUrl(ContentItem item)
        {
            if (item == null)
            {
                return(null);
            }

            string editUrl = Url.ResolveTokens(EditItemUrl);

            if (item.VersionOf.HasValue)
            {
                return(string.Format("{0}?selectedUrl={1}", editUrl,
                                     HttpUtility.UrlEncode(item.FindPath(PathData.DefaultAction).GetRewrittenUrl())));
            }

            return(Url.Parse(editUrl).AppendQuery(SelectionUtility.SelectedQueryKey, item.Path));
        }
Пример #14
0
        /// <summary>Gets the url for the preview frame.</summary>
        /// <param name="selectedItem">The currently selected item.</param>
        /// <returns>An url.</returns>
        public virtual string GetPreviewUrl(ContentItem selectedItem)
        {
            try
            {
                // If hostname == localhost, then don't use custom hostnames in the management navigation tree
                if (HttpContext.Current != null && HttpContext.Current.Request.Url.Host == "localhost")
                {
                    return(selectedItem.FindPath(PathData.DefaultAction).GetRewrittenUrl());
                }

                Url url = ResolveResourceUrl(parser.BuildUrl(selectedItem));
                return(url);
            }
            catch (N2Exception)
            {
                return(Url.ResolveTokens("{ManagementUrl}/Empty.aspx?item=" + selectedItem.ID));
            }
        }
Пример #15
0
        public virtual ActionResult Index()
        {
            try
            {
                //Need to find the 404 error page
                ContentItem errorPage = SiteSettings.Instance.NotFoundPageInstance;

                HttpContext.Response.TrySkipIisCustomErrors = true;
                HttpContext.Response.StatusCode             = 404;
                string url = errorPage.FindPath(PathData.DefaultAction).GetRewrittenUrl();

                return(new TransferResult(url));
            }
            catch (Exception exc) when(Log.WriteError(exc))
            {
                throw;
            }
        }
Пример #16
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public override string BuildUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            ContentItem current = item;

            if (item.VersionOf != null)
            {
                current = item.VersionOf;
            }

            // move up until first real page
            while (current != null && !current.IsPage)
            {
                current = current.Parent;
            }

            // no start page found, use rewritten url
            if (current == null)
            {
                return(item.FindPath(PathData.DefaultAction).RewrittenUrl);
            }

            Url url;

            if (host.IsStartPage(current))
            {
                // we move right up to the start page
                url = "/";
            }
            else
            {
                // at least one node before the start page
                url     = new Url("/" + current.Name + current.Extension);
                current = current.Parent;
                // build path until a start page
                while (current != null && !host.IsStartPage(current))
                {
                    url     = url.PrependSegment(current.Name);
                    current = current.Parent;
                }
            }

            // no start page found, use rewritten url
            if (current == null)
            {
                return(item.FindPath(PathData.DefaultAction).RewrittenUrl);
            }

            if (item.IsPage && item.VersionOf != null)
            {
                // the item was a version, add this information as a query string
                url = url.AppendQuery(PathData.PageQueryKey, item.ID);
            }
            else if (!item.IsPage)
            {
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
            }

            if (current.ID == host.CurrentSite.StartPageID)
            {
                // the start page belongs to the current site, use relative url
                return(Url.ToAbsolute("~" + url.PathAndQuery));
            }

            var site = host.GetSite(current.ID) ?? host.DefaultSite;

            return(GetHostedUrl(item, url, site));
        }
Пример #17
0
        private static string GetHostedUrl(ContentItem item, string url, Site site)
        {
            string hostName = site.GetHostName(item.Language);
            if (string.IsNullOrEmpty(hostName))
                return item.FindPath(PathData.DefaultAction).RewrittenUrl;

            return Url.Parse(url).SetAuthority(hostName);
        }
Пример #18
0
		/// <summary>Calculates an item url by walking it's parent path.</summary>
		/// <param name="item">The item whose url to compute.</param>
		/// <returns>A friendly url to the supplied item.</returns>
		public virtual Url BuildUrl(ContentItem item)
		{
			if (item == null) throw new ArgumentNullException("item");

			if (item.VersionOf.HasValue)
			{
				ContentItem version = item.VersionOf;
				if (version != null)
					return BuildUrl(version).SetQueryParameter(PathData.VersionIndexQueryKey, item.VersionIndex);
			}
			else if (item.ID == 0)
			{
				var page = Find.ClosestPage(item);
				if (page != null && page != item)
				{
					return BuildUrl(page)
						.SetQueryParameter(PathData.VersionIndexQueryKey, page.VersionIndex)
						.SetQueryParameter("versionKey", item.GetVersionKey());
				}
			}

			var current = Find.ClosestPage(item);

			// no page found, throw
			if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);

			Url url = BuildPageUrl(current, ref current);

			if (current == null)
				// no start page found, use rewritten url
				return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();

			if (!item.IsPage)
				// the item was not a page, add this information as a query string
				url = url.AppendQuery(PathData.ItemQueryKey, item.ID);

			var absoluteUrl = Url.ToAbsolute("~" + url);
			if (BuiltUrl != null)
			{
				var args = new UrlEventArgs(item) { Url = absoluteUrl };
				BuiltUrl(this, args);
				return args.Url;
			}
			else
				return absoluteUrl;
		}
Пример #19
0
        protected virtual void RegisterRefreshNavigationScript(ContentItem item)
        {
            string script = string.Format(refreshScriptFormat,
                VirtualPathUtility.ToAbsolute(Engine.ManagementPaths.ResolveResourceUrl("{ManagementUrl}/Content/Default.aspx")), // 0
                GetNavigationUrl(item), // 1
                item.ID, // 2
                item.FindPath(PathData.DefaultAction).RewrittenUrl, // 3
                item.Path // 4
                );

            ClientScript.RegisterClientScriptBlock(
                typeof(Default),
                "AddRefreshEditScript",
                script, true);
        }
Пример #20
0
		public override PathData ResolvePath(ContentItem startingPoint, string path)
		{
			return startingPoint.FindPath(path);
		}
Пример #21
0
		/// <summary>Gets the path to the given item's template. This is a way to override the default template provided by the content item.</summary>
		/// <param name="item">The item whose path is requested.</param>
		/// <returns>The virtual path of the template or null if the item is not supposed to be added.</returns>
		protected virtual string GetTemplateUrl(ContentItem item)
		{
			return item.FindPath(PathData.DefaultAction).TemplateUrl;
		}
Пример #22
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public virtual string BuildUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            ContentItem current = item;

            if (item.VersionOf != null)
            {
                current = item.VersionOf;
            }

            // move up until first real page
            while (current != null && !current.IsPage)
            {
                current = current.Parent;
            }

            // no page found, use rewritten url
            if (current == null)
            {
                throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);
            }

            Url url;

            if (host.IsStartPage(current))
            {
                // we move right up to the start page
                url = "/";
            }
            else
            {
                // at least one node before the start page
                url     = new Url("/" + current.Name + current.Extension);
                current = current.Parent;
                // build path until a start page
                while (current != null && !host.IsStartPage(current))
                {
                    url     = url.PrependSegment(current.Name);
                    current = current.Parent;
                }
            }

            // no start page found, use rewritten url
            if (current == null)
            {
                return(item.FindPath(PathData.DefaultAction).RewrittenUrl);
            }

            if (item.IsPage && item.VersionOf != null)
            {
                // the item was a version, add this information as a query string
                url = url.AppendQuery(PathData.PageQueryKey, item.ID);
            }
            else if (!item.IsPage)
            {
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
            }

            return(Url.ToAbsolute("~" + url));
        }
        private string GetHostedUrl(ContentItem item, string url, Site site)
        {
            if (string.IsNullOrEmpty(site.Authority))
                return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();

            return Url.Parse(url).SetAuthority(site.Authority);
        }
Пример #24
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public virtual Url BuildUrl(ContentItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (item.VersionOf.HasValue)
            {
                ContentItem version = item.VersionOf;
                if (version != null)
                {
                    return(BuildUrl(version)
                           .SetQueryParameter(PathData.VersionQueryKey, item.VersionIndex));
                }
            }
            else if (item.ID == 0)
            {
                var page = Find.ClosestPage(item);
                if (page != null && page != item)
                {
                    return(BuildUrl(page)
                           .SetQueryParameter(PathData.VersionQueryKey, page.VersionIndex)
                           .SetQueryParameter("versionKey", item.GetVersionKey()));
                }
            }

            var current = Find.ClosestPage(item);

            // no page found, throw
            if (current == null)
            {
                throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);
            }

            Url url = BuildPageUrl(current, ref current);

            if (current == null)
            {
                // no start page found, use rewritten url
                return(item.FindPath(PathData.DefaultAction).GetRewrittenUrl());
            }

            if (!item.IsPage)
            {
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);
            }

            var absoluteUrl = Url.ToAbsolute("~" + url);

            if (BuiltUrl != null)
            {
                var args = new UrlEventArgs(item)
                {
                    Url = absoluteUrl
                };
                BuiltUrl(this, args);
                return(args.Url);
            }
            else
            {
                return(absoluteUrl);
            }
        }
Пример #25
0
 public override string GetPreviewUrl(ContentItem item)
 {
     return(item.FindPath(PathData.DefaultAction).RewrittenUrl);
 }
Пример #26
0
        /// <summary>Gets the url to the edit page where to edit an existing item.</summary>
        /// <param name="item">The item to edit.</param>
        /// <param name="language">The language to edit (or create if it doesn't exist).</param>
        /// <returns>The url to the edit page</returns>
        public string GetEditExistingItemUrl(ContentItem item, string languageCode)
        {
            if (item == null)
                return null;

            if (string.IsNullOrEmpty(languageCode))
                languageCode = item.Language;

            if (item.VersionOf != null)
                return string.Format("{0}?selectedUrl={1}&language={2}", EditItemUrl, HttpUtility.UrlEncode(item.FindPath(PathData.DefaultAction).RewrittenUrl), languageCode);

            return string.Format("{0}?selected={1}&language={2}", EditItemUrl, item.Path, languageCode);
        }
Пример #27
0
 /// <summary>Gets the path to the given item's template. This is a way to override the default template provided by the content item.</summary>
 /// <param name="item">The item whose path is requested.</param>
 /// <returns>The virtual path of the template or null if the item is not supposed to be added.</returns>
 protected virtual string GetTemplateUrl(ContentItem item)
 {
     return(item.FindPath(PathData.DefaultAction).TemplateUrl);
 }
Пример #28
0
 public override PathData ResolvePath(ContentItem startingPoint, string path)
 {
     return(startingPoint.FindPath(path));
 }
Пример #29
0
 public override string GetPreviewUrl(ContentItem item)
 {
     return item.FindPath(PathData.DefaultAction).GetRewrittenUrl();
 }
Пример #30
0
 public override string GetPreviewUrl(ContentItem item, bool allowDraft)
 {
     return(item.FindPath(PathData.DefaultAction).GetRewrittenUrl());
 }
Пример #31
0
        public void Instance_DoesntGet_TemplateUrl_FromDefinition_WhenEmpty()
        {
            PathData path = page.FindPath(PathData.DefaultAction);

            Assert.That(path.TemplateUrl, Is.EqualTo("~/Default.aspx"));
        }
Пример #32
0
 public override string GetPreviewUrl(ContentItem item)
 {
     return(N2.Web.Url.Parse(item.FindPath("info").TemplateUrl).AppendQuery(SelectionUtility.SelectedQueryKey, item.Path).ResolveTokens());
 }
Пример #33
0
        /// <summary>Calculates an item url by walking it's parent path.</summary>
        /// <param name="item">The item whose url to compute.</param>
        /// <returns>A friendly url to the supplied item.</returns>
        public virtual string BuildUrl(ContentItem item)
        {
            if (item == null) throw new ArgumentNullException("item");

            ContentItem current = item;

            if (item.VersionOf != null)
            {
                current = item.VersionOf;
            }

            // move up until first real page
            while (current != null && !current.IsPage)
            {
                current = current.Parent;
            }

            // no page found, use rewritten url
            if (current == null) throw new N2Exception("Cannot build url to data item '{0}' with no containing page item.", item);

            Url url;
            if (host.IsStartPage(current))
            {
                // we move right up to the start page
                url = "/";
            }
            else
            {
                // at least one node before the start page
                url = new Url("/" + current.Name + current.Extension);
                current = current.Parent;
                // build path until a start page
                while (current != null && !host.IsStartPage(current))
                {
                    url = url.PrependSegment(current.Name);
                    current = current.Parent;
                }
            }

            // no start page found, use rewritten url
            if (current == null) return item.FindPath(PathData.DefaultAction).RewrittenUrl;

            if (item.IsPage && item.VersionOf != null)
                // the item was a version, add this information as a query string
                url = url.AppendQuery(PathData.PageQueryKey, item.ID);
            else if (!item.IsPage)
                // the item was not a page, add this information as a query string
                url = url.AppendQuery(PathData.ItemQueryKey, item.ID);

            return Url.ToAbsolute("~" + url);
        }
Пример #34
0
        /// <summary>Gets the url to the edit page where to edit an existing item.</summary>
        /// <param name="item">The item to edit.</param>
        /// <returns>The url to the edit page</returns>
        public virtual string GetEditExistingItemUrl(ContentItem item)
        {
            if (item == null)
                return null;

            string editUrl = Url.ResolveTokens(EditItemUrl);
            if (item.VersionOf != null)
                return string.Format("{0}?selectedUrl={1}", editUrl,
                                     HttpUtility.UrlEncode(item.FindPath(PathData.DefaultAction).RewrittenUrl));

            return Url.Parse(editUrl).AppendQuery("selected", item.Path);
        }
Пример #35
0
        public void Instance_GetsTemplateUrl_FromDefinition_WhenDefined()
        {
            PathData path = item.FindPath(PathData.DefaultAction);

            Assert.That(path.TemplateUrl, Is.EqualTo("~/My/Template.ascx"));
        }