//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Collections;
using CommunityServer.Components;
using CommunityServer.Files.Components;

namespace CommunityServer.Files.Components
{
	/// <summary>
	/// Generates an XML feed by a specific category
	/// </summary>
	public class FileGalleryRssWriter : BaseRssWriter
	{
		public FileGalleryRssWriter(ArrayList posts, Folder folder, string baseUrl) : base(posts, folder, baseUrl)
		{
			Category = null;
		}
		public FileGalleryRssWriter(ArrayList posts, Folder folder, string baseUrl, PostCategory category) : base(posts, folder, baseUrl)
		{
			Category = category;
		}

		/// <summary>
		/// Appends the CategoryName to Title element
		/// </summary>
		protected override string Title
		{
			get
			{
				if(Category != null)
					return base.Title + " : " + Category.Name;
				else
					return base.Title;
			}
		}

		protected PostCategory Category = null;

		protected override string EnclosureUrl(PostAttachmentMetaData pa)
		{
			if(pa.IsRemote)
				return pa.FileName;

			return this.BaseUrl + FileGalleryUrls.Instance().Download(Entries.GetEntry(pa.PostID));
		}

		protected Folder CurrentFolder
		{
			get { return CurrentSection as Folder; }
		}

		protected override bool AllowComments
		{
			get { return base.AllowComments; }
		}

		protected override string BuildLink(Post p)
		{
			return FileGalleryUrls.Instance().ViewEntry(CurrentSection.ApplicationKey, p.PostID);
		}

		protected override void PostBody(Post p)
		{
			this.WriteElementString("description", p.FormattedBody);
		}

		protected override void WriteChannel()
		{
			BuildChannel(FileGalleryUrls.Instance().ViewFolder(CurrentSection.ApplicationKey), CurrentFolder.Description, CurrentFolder.DefaultLanguage);
		}

		protected override string GetUserName(Post p)
		{
			Entry fgp = p as Entry;
			if (fgp == null)
				return base.GetUserName(p);
			else
				return Globals.HtmlDecode(fgp.DisplayName);
		}

	}
}
