RssCommentHandler.cs :  » Bloggers » SubText » Subtext » Framework » Syndication » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » SubText 
SubText » Subtext » Framework » Syndication » RssCommentHandler.cs
#region Disclaimer/Info

///////////////////////////////////////////////////////////////////////////////////////////////////
// Subtext WebLog
// 
// Subtext is an open source weblog system that is a fork of the .TEXT
// weblog system.
//
// For updated news and information please visit http://subtextproject.com/
// Subtext is hosted at Google Code at http://code.google.com/p/subtext/
// The development mailing list is at subtext@googlegroups.com 
//
// This project is licensed under the BSD license.  See the License.txt file for more information.
///////////////////////////////////////////////////////////////////////////////////////////////////

#endregion

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Subtext.Framework.Components;
using Subtext.Framework.Data;
using Subtext.Framework.Web;

namespace Subtext.Framework.Syndication{
    /// <summary>
    /// RssCommentHandler is a proposed extention to the CommentApi. This is still beta/etc.
    /// The Main Rss feed now contains an element for each entry, which will generate a rss feed 
    /// containing the comments for each post.
    /// </summary>
    public class RssCommentHandler : EntryCollectionHandler<FeedbackItem>
    {
        ICollection<FeedbackItem> _comments;
        protected ICollection<FeedbackItem> Comments;
        protected Entry ParentEntry;

        public RssCommentHandler(ISubtextContext subtextContext) : base(subtextContext)
        {
        }

        protected override BaseSyndicationWriter SyndicationWriter
        {
            get { return new CommentRssWriter(HttpContext.Response.Output, _comments, ParentEntry, SubtextContext); }
        }

        /// <summary>
        /// Returns true if the feed is the main feed.  False for category feeds and comment feeds.
        /// </summary>
        protected override bool IsMainfeed
        {
            get { return false; }
        }

        /// <summary>
        /// Gets the feed entries.
        /// </summary>
        /// <returns></returns>
        protected override ICollection<FeedbackItem> GetFeedEntries()
        {
            if(ParentEntry == null)
            {
                ParentEntry = Cacher.GetEntryFromRequest(false, SubtextContext);
            }

            if(ParentEntry == null)
            {
                // bad news... we couldn't find the entry the request is looking for - return 404.
                HttpHelper.SetFileNotFoundResponse();
            }

            if(ParentEntry != null && Comments == null)
            {
                Comments = Cacher.GetFeedback(ParentEntry, SubtextContext);
            }

            return Comments;
        }

        protected virtual CommentRssWriter GetCommentWriter(ICollection<FeedbackItem> comments, Entry entry)
        {
            return new CommentRssWriter(HttpContext.Response.Output, comments, entry, SubtextContext);
        }

        /// <summary>
        /// Builds the feed using delta encoding if it's true.
        /// </summary>
        /// <returns></returns>
        protected override CachedFeed BuildFeed()
        {
            _comments = GetFeedEntries() ?? new List<FeedbackItem>();

            var feed = new CachedFeed();
            CommentRssWriter crw = GetCommentWriter(_comments, ParentEntry);
            feed.LastModified = _comments.Count > 0 ? ConvertLastUpdatedDate(_comments.Last().DateCreated) : ParentEntry.DateCreated;
            feed.Xml = crw.Xml;
            return feed;
        }

        protected override bool IsLocalCacheOk()
        {
            string dt = LastModifiedHeader;
            if(dt != null)
            {
                _comments = GetFeedEntries();

                if(_comments != null && _comments.Count > 0)
                {
                    return
                        DateTime.Compare(DateTime.Parse(dt, CultureInfo.InvariantCulture),
                                         ConvertLastUpdatedDate(_comments.Last().DateCreated)) == 0;
                }
            }
            return false;
        }

        /// <summary>
        /// Gets the item created date.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        protected override DateTime GetItemCreatedDate(FeedbackItem item)
        {
            return item.DateCreated;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.