Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

46 lines (37 sloc) 1.36 KB
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
using System.Xml;
namespace Fabrik.Common.Web
{
/// <summary>
/// Generates an XML sitemap from a collection of <see cref="ISitemapItem"/>
/// </summary>
public class SitemapResult : ActionResult
{
private readonly IEnumerable<ISitemapItem> items;
private readonly ISitemapGenerator generator;
public SitemapResult(IEnumerable<ISitemapItem> items) : this(items, new SitemapGenerator())
{
}
public SitemapResult(IEnumerable<ISitemapItem> items, ISitemapGenerator generator)
{
Ensure.Argument.NotNull(items, "items");
Ensure.Argument.NotNull(generator, "generator");
this.items = items;
this.generator = generator;
}
public override void ExecuteResult(ControllerContext context)
{
var response = context.HttpContext.Response;
response.ContentType = "text/xml";
response.ContentEncoding = Encoding.UTF8;
using (var writer = new XmlTextWriter(response.Output))
{
writer.Formatting = Formatting.Indented;
var sitemap = generator.GenerateSiteMap(items);
sitemap.WriteTo(writer);
}
}
}
}
You can’t perform that action at this time.