Moving interfaces for services to Umbraco.Core.

Adding xml extensions for Content to generate xml for the xml cache.
Adding test for xml generation.
This commit is contained in:
sitereactor
2012-11-06 10:47:14 -01:00
parent f438ad16e0
commit ec9880968f
37 changed files with 247 additions and 97 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
namespace Umbraco.Core.Models
{
@@ -41,6 +43,44 @@ namespace Umbraco.Core.Models
}
}
//TODO Possibly add a ToXml method, which will generate valid xml for the current Content object
/// <summary>
/// Creates the xml representation for the <see cref="IContent"/> object
/// </summary>
/// <param name="content"><see cref="IContent"/> to generate xml for</param>
/// <returns>Xml representation of the passed in <see cref="IContent"/></returns>
public static XElement ToXml(this IContent content)
{
//nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias);
var nodeName = content.ContentType.Alias.ToUmbracoAlias(StringAliasCaseType.CamelCase, true);
var xml = new XElement(nodeName,
new XAttribute("id", content.Id),
new XAttribute("parentID", content.Level > 1 ? content.ParentId : -1),
new XAttribute("level", content.Level),
new XAttribute("writerID", content.Writer.Id),
new XAttribute("creatorID", content.Creator.Id),
new XAttribute("nodeType", content.ContentType.Id),
new XAttribute("template", content.Template),//Template name versus Id
new XAttribute("sortOrder", content.SortOrder),
new XAttribute("createDate", content.CreateDate),
new XAttribute("updateDate", content.UpdateDate),
new XAttribute("nodeName", content.Name),
new XAttribute("urlName", content.UrlName),//Format Url ?
new XAttribute("writerName", content.Writer.Name),
new XAttribute("creatorName", content.Creator.Name),
new XAttribute("path", content.Path));
foreach (var property in content.Properties)
{
if (property == null) continue;
xml.Add(property.ToXml());
if (property.Alias == "umbracoUrlName" && property.Value.ToString().Trim() != string.Empty)
xml.SetAttributeValue("urlName", property.Value);
}
return xml;
}
}
}