/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Everest.CmsServices.DataRule;
using Everest.CmsServices.Models;
using Everest.CmsServices.MvcHelper;
using Everest.CmsServices.Services;
using Everest.Library;
using Everest.Library.ExtensionMethod;
using Everest.Library.Data.Entity;
using Everest.CmsServices.Rfc;
using System.Text.RegularExpressions;
using Everest.Library.Mvc;
namespace Everest.CmsServices.Controllers{
public class RfcController : EverestControllerBase
{
#region Rss
const string RssSpec = @"<?xml version=""1.0""?>
<rss version=""2.0"">
<channel>
<title><![CDATA[{0}]]></title>
<link>{1}</link>
<description><![CDATA[{2}]]></description>
{3}
{4}
</channel>
</rss>
";
const string ItemSpec = @"
<item>
<title><![CDATA[{0}]]></title>
<link>{1}</link>
<description><![CDATA[{2}]]></description>
<pubDate>{3}</pubDate>
<category>{4}</category>
<author>{5}</author>
{6}
</item>
";
/// <summary>
/// RSSs the specified RSS name.
/// </summary>
/// <param name="rssName">Name of the RSS.</param>
/// <param name="application">The application.</param>
/// <returns></returns>
public ActionResult Rss(string rssName, string application)
{
ContentResult contentResult = new ContentResult() { ContentType = "text/xml" };
if (string.IsNullOrEmpty(application) && ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication != null)
{
application = ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication.ApplicationName;
}
if (string.IsNullOrEmpty(application))
{
throw new ArgumentNullException("application");
}
if (string.IsNullOrEmpty(rssName))
{
throw new ArgumentNullException("rssName");
}
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
var rssChannel = dataContext.Cms_RssChannel.Where(r => r.aspnet_Applications.ApplicationName == application && r.ChannelName == rssName).FirstOrDefault();
if (rssChannel == null)
{
throw new NullReferenceException(Resources.RssChannelDoesNotExist);
}
rssChannel.Cms_DataRule.Load();
var itemElements = BuildItemElements(application, rssChannel);
if (rssChannel.ShowGenerator)
{
itemElements = string.Format("<generator>{0}</generator>", CmsGlobal.PowerBy) + itemElements;
}
contentResult.Content = BuildRss(rssChannel.ChannelTitle, rssChannel.ChannelLink, rssChannel.ChannelDescription, itemElements, rssChannel.ChannelOptionalElements);
return contentResult;
}
/// <summary>
/// Builds the item elements.
/// </summary>
/// <param name="application">The application.</param>
/// <param name="rssChannel">The RSS channel.</param>
/// <returns></returns>
private string BuildItemElements(string application, Cms_RssChannel rssChannel)
{
CmsContext cmsContext = HttpContext.GetCmsContext();
DataRuleContext dataRuleContext = new DataRuleContext(Request.QueryString, ViewData, cmsContext);
DataRuleEvaluator.Evaluate(dataRuleContext, rssChannel.Cms_DataRule);
StringBuilder itemElements = new StringBuilder();
foreach (var data in ViewData.Values)
{
if (data is IEnumerable)
{
foreach (var item in (IEnumerable)data)
{
if (item is IDictionary<string, object>)
{
IDictionary<string, object> content = (IDictionary<string, object>)item;
var title = GetFieldValue(content, rssChannel.ItemTitleField);
var description = GetFieldValue(content, rssChannel.ItemDescriptionField);
string link = string.Empty;
if (!string.IsNullOrEmpty(rssChannel.ItemLink))
{
link = string.Format(rssChannel.ItemLink, content["ContentId"], content["UserKey"], content["UUID"], content["Application"], content["Title"]);
link = Url.GenerateContextPageUrl("", link);
link = new Uri(new Uri(Request.Url.AbsoluteUri), link).ToString();
}
string pubDate = ((DateTime)content["PostDate"]).ToString("R");
string category = "";
string author = content["UserName"].ToString();
//string guid = content["UUID"].ToString();
itemElements.AppendLine(BuildRssItem(title, link, description, pubDate, category, author, RelaceItemOptionalElementsValue(content, rssChannel.ItemOptionalElements)));
}
}
}
}
return itemElements.ToString();
}
static Regex fieldHolderRegex = new Regex("{[^}]+}", RegexOptions.Compiled);
private string RelaceItemOptionalElementsValue(IDictionary<string, object> content, string optionalElements)
{
if (string.IsNullOrEmpty(optionalElements))
{
return optionalElements;
}
var matches = fieldHolderRegex.Matches(optionalElements);
if (matches.Count > 0)
{
StringBuilder stringBuilder = new StringBuilder(optionalElements);
foreach (Match m in matches)
{
var fieldValue = GetFieldValue(content, m.Value);
var strFieldValue = fieldValue == null ? "" : fieldValue.ToString();
stringBuilder.Replace(m.Value, strFieldValue);
}
return stringBuilder.ToString();
}
return optionalElements;
}
/// <summary>
/// Gets the field value.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="fieldHolder">The field holder. like {Title}, {Description} etc.</param>
/// <returns></returns>
private object GetFieldValue(IDictionary<string, object> content, string fieldHolder)
{
if (string.IsNullOrEmpty(fieldHolder))
{
return null;
}
if (fieldHolder.Length > 2 && fieldHolder.StartsWith("{") && fieldHolder.EndsWith("}"))
{
var fieldName = fieldHolder.Substring(1, fieldHolder.Length - 2);
if (content.ContainsKey(fieldName))
{
return content[fieldName];
}
else
{
return null;
}
}
else
{
return fieldHolder;
}
}
private static string BuildRssItem(object title, object link, object description, object pubDate, object category, object author, string optionalElements)
{
return string.Format(ItemSpec, title.ToGlobalizedString(), link.ToGlobalizedString(), description.ToGlobalizedString(), pubDate.ToGlobalizedString(), category.ToGlobalizedString(), author.ToGlobalizedString(), optionalElements.ToGlobalizedString());
}
private static string BuildRss(string title, string link, string description, string itemElements, string optionalElements)
{
return string.Format(RssSpec, title.ToGlobalizedString(), link.ToGlobalizedString(), description.ToGlobalizedString(), itemElements.ToGlobalizedString(), optionalElements.ToGlobalizedString());
}
#endregion
#region Metaweblog
public ActionResult Metaweblog(string application)
{
if (string.IsNullOrEmpty(application) && ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication != null)
{
application = ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication.ApplicationName;
}
IHttpHandler httpHandler = new Everest.CmsServices.Rfc.MetaWeblogHandler() { Application = application };
httpHandler.ProcessRequest(System.Web.HttpContext.Current);
return null;
}
#endregion
//#region WebDav
//public ActionResult WebDav(string application)
//{
// if (string.IsNullOrEmpty(application) && ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication != null)
// {
// application = ((Everest.CmsServices.Web.KoobooHttpRequestWrapper)Request).CmsApplication.ApplicationName;
// }
// var webDavHandler = new WebDAVHandler() { Application = application };
// webDavHandler.ProcessRequest(System.Web.HttpContext.Current);
// return new EmptyResult();
//}
////[System.Web.Mvc.AcceptVerbs("PROPFIND")]
////public ActionResult WebDav()
////{
//// ContentResult contentResult = new ContentResult() { ContentType = "text/xml" };
//// contentResult.Content = @"<?xml version=""1.0"" encoding=""utf-8""?><D:multistatus xmlns:D=""DAV:""><D:response><D:href>http://192.168.1.29:804/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Mon, 08 Mar 2010 07:34:42 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/2.0.0.0/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 11 Mar 2010 01:27:21 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/koobooSQLite/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 21 Jan 2010 05:53:16 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/0302/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Tue, 02 Mar 2010 09:57:33 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/MVCTest/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Tue, 19 Jan 2010 07:27:26 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/2.0.1.0SQLite/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 10 Feb 2010 05:01:52 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Kooboo/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 04 Mar 2010 02:20:41 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/2.0.1.0/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 10 Feb 2010 04:49:49 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/ContentSync/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 21 Jan 2010 01:24:57 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/ContentTrigger/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 10:40:56 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/CustomError/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 18 Nov 2009 08:18:36 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Export-import/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 12 Nov 2009 03:36:44 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Extform/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Tue, 17 Nov 2009 05:32:01 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/HelloModule/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 13:34:34 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/inline-editing/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 12:12:57 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/IntegrateWithVS/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 12 Nov 2009 05:12:40 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/intellisense/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 12:25:29 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/ModuleUsing/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 19 Nov 2009 07:28:23 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/PagePlugin/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 12 Nov 2009 06:10:26 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/quickstart/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Thu, 12 Nov 2009 01:26:11 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Relation/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 13:36:00 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Schedular/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 12:40:20 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Search/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 13:36:14 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/SEO/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Tue, 10 Nov 2009 01:07:56 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/StaticCode/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Wed, 11 Nov 2009 12:56:43 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Umbraco/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype/><D:getlastmodified>Tue, 02 Mar 2010 07:48:32 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag/><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/word1.docx</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>application/vnd.openxmlformats-officedocument.wordprocessingml.document</D:getcontenttype><D:getlastmodified>Sat, 20 Feb 2010 08:18:51 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag>""a6263555b2ca1:0""</D:getetag><D:getcontentlength>0</D:getcontentlength><D:resourcetype/></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/Workflow/</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>application/vnd.openxmlformats-officedocument.wordprocessingml.document</D:getcontenttype><D:getlastmodified>Wed, 11 Nov 2009 13:36:45 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag>""a6263555b2ca1:0""</D:getetag><D:getcontentlength>0</D:getcontentlength><D:resourcetype><D:collection/></D:resourcetype></D:prop></D:propstat></D:response><D:response><D:href>http://192.168.1.29:804/%E6%97%A0%E7%BA%BF%E7%BD%91%E7%BB%9C%E5%AF%86%E7%A0%81.txt</D:href><D:propstat><D:status>HTTP/1.1 200 OK</D:status><D:prop><D:getcontenttype>text/plain</D:getcontenttype><D:getlastmodified>Sat, 20 Feb 2010 08:50:30 GMT</D:getlastmodified><D:lockdiscovery/><D:getetag>""b26067c19b2ca1:0""</D:getetag><D:getcontentlength>10</D:getcontentlength><D:resourcetype/></D:prop></D:propstat></D:response></D:multistatus>";
//// return contentResult;
////}
//#endregion
}
}
|