2012-08-10 13:08:47 +06:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using System.Xml.XPath;
|
2012-09-02 07:35:57 +07:00
|
|
|
using Umbraco.Core;
|
2012-08-10 13:08:47 +06:00
|
|
|
using Umbraco.Core.Configuration;
|
|
|
|
|
using Umbraco.Core.Models;
|
2012-12-09 03:22:11 +05:00
|
|
|
using Umbraco.Web.Routing;
|
2012-08-10 13:08:47 +06:00
|
|
|
|
2012-08-10 13:19:25 +06:00
|
|
|
namespace Umbraco.Web.Models
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2012-10-02 01:35:39 +05:00
|
|
|
/// Represents an IPublishedContent which is created based on an Xml structure
|
2012-08-10 13:08:47 +06:00
|
|
|
/// </summary>
|
|
|
|
|
[Serializable]
|
|
|
|
|
[XmlType(Namespace = "http://umbraco.org/webservices/")]
|
2012-12-09 03:22:11 +05:00
|
|
|
internal class XmlPublishedContent : PublishedContentBase
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="xmlNode"></param>
|
2012-10-02 01:35:39 +05:00
|
|
|
public XmlPublishedContent(XmlNode xmlNode)
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
_pageXmlNode = xmlNode;
|
|
|
|
|
InitializeStructure();
|
|
|
|
|
Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="xmlNode"></param>
|
|
|
|
|
/// <param name="disableInitializing"></param>
|
2012-10-02 01:35:39 +05:00
|
|
|
internal XmlPublishedContent(XmlNode xmlNode, bool disableInitializing)
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
_pageXmlNode = xmlNode;
|
|
|
|
|
InitializeStructure();
|
|
|
|
|
if (!disableInitializing)
|
|
|
|
|
Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool _initialized = false;
|
2012-10-02 01:35:39 +05:00
|
|
|
private readonly ICollection<IPublishedContent> _children = new Collection<IPublishedContent>();
|
|
|
|
|
private IPublishedContent _parent = null;
|
2012-08-10 13:08:47 +06:00
|
|
|
private int _id;
|
|
|
|
|
private int _template;
|
|
|
|
|
private string _name;
|
|
|
|
|
private string _docTypeAlias;
|
|
|
|
|
private int _docTypeId;
|
|
|
|
|
private string _writerName;
|
|
|
|
|
private string _creatorName;
|
|
|
|
|
private int _writerId;
|
|
|
|
|
private int _creatorId;
|
|
|
|
|
private string _urlName;
|
|
|
|
|
private string _path;
|
|
|
|
|
private DateTime _createDate;
|
|
|
|
|
private DateTime _updateDate;
|
|
|
|
|
private Guid _version;
|
2012-10-04 03:26:56 +05:00
|
|
|
private readonly Collection<IPublishedContentProperty> _properties = new Collection<IPublishedContentProperty>();
|
2012-08-10 13:08:47 +06:00
|
|
|
private readonly XmlNode _pageXmlNode;
|
|
|
|
|
private int _sortOrder;
|
|
|
|
|
private int _level;
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override IEnumerable<IPublishedContent> Children
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _children;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override IPublishedContentProperty GetProperty(string alias)
|
2012-09-20 14:17:40 +07:00
|
|
|
{
|
|
|
|
|
return Properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
/// <summary>
|
|
|
|
|
/// returns 'Content' as the ItemType
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override PublishedItemType ItemType
|
|
|
|
|
{
|
|
|
|
|
get { return PublishedItemType.Content; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IPublishedContent Parent
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int Id
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int TemplateId
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _template;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int SortOrder
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _sortOrder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override string Name
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _name;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-12-09 03:22:11 +05:00
|
|
|
|
|
|
|
|
public override string DocumentTypeAlias
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _docTypeAlias;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int DocumentTypeId
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _docTypeId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override string WriterName
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _writerName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override string CreatorName
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _creatorName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int WriterId
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _writerId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int CreatorId
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _creatorId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override string Path
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _path;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override DateTime CreateDate
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _createDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override DateTime UpdateDate
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _updateDate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override Guid Version
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override string UrlName
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _urlName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override int Level
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _level;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-09 03:22:11 +05:00
|
|
|
public override ICollection<IPublishedContentProperty> Properties
|
2012-08-10 13:08:47 +06:00
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (!_initialized)
|
|
|
|
|
Initialize();
|
|
|
|
|
return _properties;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-08 13:22:45 +07:00
|
|
|
|
2012-08-10 13:08:47 +06:00
|
|
|
|
|
|
|
|
private void InitializeStructure()
|
|
|
|
|
{
|
|
|
|
|
// Load parent if it exists and is a node
|
|
|
|
|
|
|
|
|
|
if (_pageXmlNode != null && _pageXmlNode.SelectSingleNode("..") != null)
|
|
|
|
|
{
|
|
|
|
|
XmlNode parent = _pageXmlNode.SelectSingleNode("..");
|
|
|
|
|
if (parent != null && (parent.Name == "node" || (parent.Attributes != null && parent.Attributes.GetNamedItem("isDoc") != null)))
|
2012-10-02 01:35:39 +05:00
|
|
|
_parent = new XmlPublishedContent(parent, true);
|
2012-08-10 13:08:47 +06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Initialize()
|
|
|
|
|
{
|
|
|
|
|
if (_pageXmlNode != null)
|
|
|
|
|
{
|
|
|
|
|
_initialized = true;
|
|
|
|
|
if (_pageXmlNode.Attributes != null)
|
|
|
|
|
{
|
|
|
|
|
_id = int.Parse(_pageXmlNode.Attributes.GetNamedItem("id").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("template") != null)
|
|
|
|
|
_template = int.Parse(_pageXmlNode.Attributes.GetNamedItem("template").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("sortOrder") != null)
|
|
|
|
|
_sortOrder = int.Parse(_pageXmlNode.Attributes.GetNamedItem("sortOrder").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("nodeName") != null)
|
|
|
|
|
_name = _pageXmlNode.Attributes.GetNamedItem("nodeName").Value;
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("writerName") != null)
|
|
|
|
|
_writerName = _pageXmlNode.Attributes.GetNamedItem("writerName").Value;
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("urlName") != null)
|
|
|
|
|
_urlName = _pageXmlNode.Attributes.GetNamedItem("urlName").Value;
|
|
|
|
|
// Creatorname is new in 2.1, so published xml might not have it!
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_creatorName = _pageXmlNode.Attributes.GetNamedItem("creatorName").Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
_creatorName = _writerName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Added the actual userID, as a user cannot be looked up via full name only...
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("creatorID") != null)
|
|
|
|
|
_creatorId = int.Parse(_pageXmlNode.Attributes.GetNamedItem("creatorID").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("writerID") != null)
|
|
|
|
|
_writerId = int.Parse(_pageXmlNode.Attributes.GetNamedItem("writerID").Value);
|
|
|
|
|
|
|
|
|
|
if (UmbracoSettings.UseLegacyXmlSchema)
|
|
|
|
|
{
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("nodeTypeAlias") != null)
|
|
|
|
|
_docTypeAlias = _pageXmlNode.Attributes.GetNamedItem("nodeTypeAlias").Value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_docTypeAlias = _pageXmlNode.Name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("nodeType") != null)
|
|
|
|
|
_docTypeId = int.Parse(_pageXmlNode.Attributes.GetNamedItem("nodeType").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("path") != null)
|
|
|
|
|
_path = _pageXmlNode.Attributes.GetNamedItem("path").Value;
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("version") != null)
|
|
|
|
|
_version = new Guid(_pageXmlNode.Attributes.GetNamedItem("version").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("createDate") != null)
|
|
|
|
|
_createDate = DateTime.Parse(_pageXmlNode.Attributes.GetNamedItem("createDate").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("updateDate") != null)
|
|
|
|
|
_updateDate = DateTime.Parse(_pageXmlNode.Attributes.GetNamedItem("updateDate").Value);
|
|
|
|
|
if (_pageXmlNode.Attributes.GetNamedItem("level") != null)
|
|
|
|
|
_level = int.Parse(_pageXmlNode.Attributes.GetNamedItem("level").Value);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// load data
|
|
|
|
|
var dataXPath = UmbracoSettings.UseLegacyXmlSchema ? "data" : "* [not(@isDoc)]";
|
|
|
|
|
foreach (XmlNode n in _pageXmlNode.SelectNodes(dataXPath))
|
2012-10-04 03:26:56 +05:00
|
|
|
_properties.Add(new XmlPublishedContentProperty(n));
|
2012-08-10 13:08:47 +06:00
|
|
|
|
|
|
|
|
// load children
|
|
|
|
|
var childXPath = UmbracoSettings.UseLegacyXmlSchema ? "node" : "* [@isDoc]";
|
|
|
|
|
var nav = _pageXmlNode.CreateNavigator();
|
|
|
|
|
var expr = nav.Compile(childXPath);
|
|
|
|
|
expr.AddSort("@sortOrder", XmlSortOrder.Ascending, XmlCaseOrder.None, "", XmlDataType.Number);
|
|
|
|
|
var iterator = nav.Select(expr);
|
|
|
|
|
while (iterator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
_children.Add(
|
2012-10-02 01:35:39 +05:00
|
|
|
new XmlPublishedContent(((IHasXmlNode)iterator.Current).GetNode(), true)
|
2012-08-10 13:08:47 +06:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// else
|
|
|
|
|
// throw new ArgumentNullException("Node xml source is null");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|