2016-05-27 14:26:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using Umbraco.Cms.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Cms.Core.Xml.XPath;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
namespace Umbraco.Cms.Infrastructure.PublishedCache.Navigable
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
2017-07-12 14:09:31 +02:00
|
|
|
|
internal class NavigableContent : INavigableContent
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
private readonly PublishedContent _content;
|
2022-03-30 13:34:56 +02:00
|
|
|
|
private readonly string?[] _builtInValues;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
public NavigableContent(IPublishedContent content)
|
|
|
|
|
|
{
|
2017-12-07 13:22:32 +01:00
|
|
|
|
InnerContent = content;
|
|
|
|
|
|
_content = PublishedContent.UnwrapIPublishedContent(InnerContent);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
var i = 0;
|
|
|
|
|
|
_builtInValues = new []
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlString(i++, _content.Name),
|
|
|
|
|
|
XmlString(i++, _content.ParentId),
|
|
|
|
|
|
XmlString(i++, _content.CreateDate),
|
|
|
|
|
|
XmlString(i++, _content.UpdateDate),
|
|
|
|
|
|
XmlString(i++, true), // isDoc
|
|
|
|
|
|
XmlString(i++, _content.SortOrder),
|
|
|
|
|
|
XmlString(i++, _content.Level),
|
|
|
|
|
|
XmlString(i++, _content.TemplateId),
|
|
|
|
|
|
XmlString(i++, _content.WriterId),
|
|
|
|
|
|
XmlString(i++, _content.CreatorId),
|
2018-04-28 16:35:33 +02:00
|
|
|
|
XmlString(i++, _content.UrlSegment),
|
2018-12-13 15:08:12 +01:00
|
|
|
|
XmlString(i, _content.IsDraft())
|
2016-05-27 14:26:28 +02:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-30 13:34:56 +02:00
|
|
|
|
private string? XmlString(int index, object? value)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
2018-05-10 22:40:32 +10:00
|
|
|
|
if (value == null) return string.Empty;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
var field = Type.FieldTypes[index];
|
|
|
|
|
|
return field.XmlStringConverter == null ? value.ToString() : field.XmlStringConverter(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region INavigableContent
|
|
|
|
|
|
|
2017-12-07 13:22:32 +01:00
|
|
|
|
public IPublishedContent InnerContent { get; }
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2017-07-12 14:09:31 +02:00
|
|
|
|
public int Id => _content.Id;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2017-07-12 14:09:31 +02:00
|
|
|
|
public int ParentId => _content.ParentId;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2017-07-12 14:09:31 +02:00
|
|
|
|
public INavigableContentType Type => NavigableContentType.GetContentType(_content.ContentType);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
// returns all child ids, will be filtered by the source
|
2022-03-30 13:34:56 +02:00
|
|
|
|
public IList<int>? ChildIds => _content.ChildIds;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
2022-03-30 13:34:56 +02:00
|
|
|
|
public object? Value(int index)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (index < 0)
|
2017-07-12 14:09:31 +02:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
if (index < NavigableContentType.BuiltinProperties.Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
// built-in field, ie attribute
|
|
|
|
|
|
//return XmlString(index, _builtInValues1[index]);
|
|
|
|
|
|
return _builtInValues[index];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
index -= NavigableContentType.BuiltinProperties.Length;
|
|
|
|
|
|
var properties = _content.PropertiesArray;
|
|
|
|
|
|
if (index >= properties.Length)
|
2017-07-12 14:09:31 +02:00
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
// custom property, ie element
|
2017-12-06 11:51:35 +01:00
|
|
|
|
return properties[index].GetXPathValue();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|