You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel/Services/DOM/DSL/Model/TContentElement.cs

165 lines
5.2 KiB

6 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using ZeroLevel.DocumentObjectModel;
using ZeroLevel.DocumentObjectModel.Flow;
namespace DOM.DSL.Model
{
internal class TContentElement
{
private readonly Document _document;
public TContentElement(Document document)
{
_document = document;
}
private static void TraversElement(IContentElement element, ContentElementType type, Action<IContentElement> handler)
{
if (element.Type == type)
{
handler(element);
}
switch (element.Type)
{
// Containers
case ContentElementType.Section:
var section = (element as Section);
7 months ago
foreach (var item in section!.Parts)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.Paragraph:
var paragraph = (element as Paragraph);
7 months ago
foreach (var item in paragraph!.Parts)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.List:
var list = (element as List);
7 months ago
foreach (var item in list!.Items)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.Gallery:
var gallery = (element as Gallery);
7 months ago
foreach (var item in gallery!.Images)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.Audioplayer:
var audioplayer = (element as Audioplayer);
7 months ago
foreach (var item in audioplayer!.Tracks)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.Videoplayer:
var videoplayer = (element as Videoplayer);
7 months ago
foreach (var item in videoplayer!.Playlist)
6 years ago
{
TraversElement(item, type, handler);
}
break;
6 years ago
case ContentElementType.Table:
var table = (element as Table);
7 months ago
foreach (var column in table!.Columns)
6 years ago
{
TraversElement(column, type, handler);
}
foreach (var row in table.Rows)
{
TraversElement(row, type, handler);
foreach (var cell in row.Cells)
{
TraversElement(cell, type, handler);
}
}
break;
}
}
private ContentElementType ParseContentElementType(string element_name)
{
switch (element_name)
{
case "section":
return ContentElementType.Section;
6 years ago
case "paragraph":
return ContentElementType.Paragraph;
6 years ago
case "link":
return ContentElementType.Link;
6 years ago
case "list":
return ContentElementType.List;
6 years ago
case "table":
return ContentElementType.Table;
6 years ago
case "audio":
return ContentElementType.Audio;
6 years ago
case "audioplayer":
return ContentElementType.Audioplayer;
6 years ago
case "form":
return ContentElementType.Form;
6 years ago
case "gallery":
return ContentElementType.Gallery;
6 years ago
case "image":
return ContentElementType.Image;
6 years ago
case "video":
return ContentElementType.Video;
6 years ago
case "videoplayer":
return ContentElementType.Videoplayer;
6 years ago
case "quote":
return ContentElementType.Quote;
6 years ago
case "text":
return ContentElementType.Text;
6 years ago
case "column":
return ContentElementType.Column;
6 years ago
case "row":
return ContentElementType.Row;
}
return ContentElementType.Unknown;
}
public IEnumerable<IContentElement> Find(string elementName, string index)
{
var type = ParseContentElementType(elementName);
if (type == ContentElementType.Unknown) return Enumerable.Empty<IContentElement>();
var list = new List<IContentElement>();
foreach (var section in _document.Content.Sections)
{
TraversElement(section, type, e => list.Add(e));
6 years ago
}
return list;
}
public override string ToString()
{
return "Content";
}
}
}

Powered by TurnKey Linux.