Renamed Umbraco.Abstractions to Umbraco.Core

This commit is contained in:
Bjarke Berg
2020-02-24 08:21:53 +01:00
parent 46f00cf960
commit 90c2381c86
1117 changed files with 30 additions and 30 deletions

View File

@@ -0,0 +1,59 @@
using System.Collections.Generic;
namespace Umbraco.Core.Xml.XPath
{
/// <summary>
/// Represents a content that can be navigated via XPath.
/// </summary>
public interface INavigableContent
{
/// <summary>
/// Gets the unique identifier of the navigable content.
/// </summary>
/// <remarks>The root node identifier should be <c>-1</c>.</remarks>
int Id { get; }
/// <summary>
/// Gets the unique identifier of parent of the navigable content.
/// </summary>
/// <remarks>The top-level content parent identifiers should be <c>-1</c> ie the identifier
/// of the root node, whose parent identifier should in turn be <c>-1</c>.</remarks>
int ParentId { get; }
/// <summary>
/// Gets the type of the navigable content.
/// </summary>
INavigableContentType Type { get; }
/// <summary>
/// Gets the unique identifiers of the children of the navigable content.
/// </summary>
IList<int> ChildIds { get; }
/// <summary>
/// Gets the value of a field of the navigable content for XPath navigation use.
/// </summary>
/// <param name="index">The field index.</param>
/// <returns>The value of the field for XPath navigation use.</returns>
/// <remarks>
/// <para>Fields are attributes or elements depending on their relative index value compared
/// to source.LastAttributeIndex.</para>
/// <para>For attributes, the value must be a string.</para>
/// <para>For elements, the value should an <c>XPathNavigator</c> instance if the field is xml
/// and has content (is not empty), <c>null</c> to indicate that the element is empty, or a string
/// which can be empty, whitespace... depending on what the data type wants to expose.</para>
/// </remarks>
object Value(int index);
// TODO: implement the following one
///// <summary>
///// Gets the value of a field of the navigable content, for a specified language.
///// </summary>
///// <param name="index">The field index.</param>
///// <param name="languageKey">The language key.</param>
///// <returns>The value of the field for the specified language.</returns>
///// <remarks>...</remarks>
//object Value(int index, string languageKey);
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Core.Xml.XPath
{
/// <summary>
/// Represents the type of a content that can be navigated via XPath.
/// </summary>
public interface INavigableContentType
{
/// <summary>
/// Gets the name of the content type.
/// </summary>
string Name { get; }
/// <summary>
/// Gets the field types of the content type.
/// </summary>
/// <remarks>This includes the attributes and the properties.</remarks>
INavigableFieldType[] FieldTypes { get; }
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Core.Xml.XPath
{
/// <summary>
/// Represents the type of a field of a content that can be navigated via XPath.
/// </summary>
/// <remarks>A field can be an attribute or a property.</remarks>
public interface INavigableFieldType
{
/// <summary>
/// Gets the name of the field type.
/// </summary>
string Name { get; }
/// <summary>
/// Gets a method to convert the field value to a string.
/// </summary>
/// <remarks>This is for built-in properties, ie attributes. User-defined properties have their
/// own way to convert their value for XPath.</remarks>
Func<object, string> XmlStringConverter { get; }
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Core.Xml.XPath
{
/// <summary>
/// Represents a source of content that can be navigated via XPath.
/// </summary>
public interface INavigableSource
{
/// <summary>
/// Gets a content identified by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier.</param>
/// <returns>The content identified by the unique identifier, or null.</returns>
/// <remarks>When <c>id</c> is <c>-1</c> (root content) implementations should return <c>null</c>.</remarks>
INavigableContent Get(int id);
/// <summary>
/// Gets the index of the last attribute in the fields collections.
/// </summary>
int LastAttributeIndex { get; }
/// <summary>
/// Gets the content at the root of the source.
/// </summary>
/// <remarks>That content should have unique identifier <c>-1</c> and should not be gettable,
/// ie Get(-1) should return null. Its <c>ParentId</c> should be <c>-1</c>. It should provide
/// values for the attribute fields.</remarks>
INavigableContent Root { get; }
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,119 @@
using System.Xml;
using System.Xml.XPath;
namespace Umbraco.Core.Xml.XPath
{
public class RenamedRootNavigator : XPathNavigator
{
private readonly XPathNavigator _navigator;
private readonly string _rootName;
public RenamedRootNavigator(XPathNavigator navigator, string rootName)
{
_navigator = navigator;
_rootName = rootName;
}
public override string BaseURI => _navigator.BaseURI;
public override XPathNavigator Clone()
{
return new RenamedRootNavigator(_navigator.Clone(), _rootName);
}
public override bool IsEmptyElement => _navigator.IsEmptyElement;
public override bool IsSamePosition(XPathNavigator other)
{
return _navigator.IsSamePosition(other);
}
public override string LocalName
{
get
{
// local name without prefix
var nav = _navigator.Clone();
if (nav.MoveToParent() && nav.MoveToParent())
return _navigator.LocalName;
return _rootName;
}
}
public override bool MoveTo(XPathNavigator other)
{
return _navigator.MoveTo(other);
}
public override bool MoveToFirstAttribute()
{
return _navigator.MoveToFirstAttribute();
}
public override bool MoveToFirstChild()
{
return _navigator.MoveToFirstChild();
}
public override bool MoveToFirstNamespace(XPathNamespaceScope namespaceScope)
{
return _navigator.MoveToFirstNamespace(namespaceScope);
}
public override bool MoveToId(string id)
{
return _navigator.MoveToId(id);
}
public override bool MoveToNext()
{
return _navigator.MoveToNext();
}
public override bool MoveToNextAttribute()
{
return _navigator.MoveToNextAttribute();
}
public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope)
{
return _navigator.MoveToNextNamespace(namespaceScope);
}
public override bool MoveToParent()
{
return _navigator.MoveToParent();
}
public override bool MoveToPrevious()
{
return _navigator.MoveToPrevious();
}
public override string Name
{
get
{
// qualified name with prefix
var nav = _navigator.Clone();
if (nav.MoveToParent() && nav.MoveToParent())
return _navigator.Name;
var name = _navigator.Name;
var pos = name.IndexOf(':');
return pos < 0 ? _rootName : (name.Substring(0, pos + 1) + _rootName);
}
}
public override XmlNameTable NameTable => _navigator.NameTable;
public override string NamespaceURI => _navigator.NamespaceURI;
public override XPathNodeType NodeType => _navigator.NodeType;
public override string Prefix => _navigator.Prefix;
public override string Value => _navigator.Value;
}
}