mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 17:25:32 +00:00
A lot of stuff related to parsing; index page input validation
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HaDocument.Models {
|
||||
public class App {
|
||||
public class App : IHaElement {
|
||||
public string ElementName { get; } = "appDef";
|
||||
public string[] XPath { get; } = {
|
||||
"/opus/data/definitions/appDefs/appDef",
|
||||
"/opus/definitions/appDefs/appDef"
|
||||
};
|
||||
public string ElementRules { get; } = "Pfad: /opus/definitions/appDefs. Pflicht-Attribute: index (einmalig), name, category.";
|
||||
public bool Searchable { get; } = false;
|
||||
public XElement? XElement { get; }
|
||||
|
||||
public string Index { get; } = "";
|
||||
public string Name { get; } = "";
|
||||
public string Category { get; } = "";
|
||||
|
||||
public XElement? XElement { get; }
|
||||
|
||||
public App(
|
||||
string index,
|
||||
string name,
|
||||
@@ -28,7 +35,17 @@ namespace HaDocument.Models {
|
||||
element.Attribute("name")!.Value,
|
||||
element.Attribute("category")!.Value,
|
||||
element
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
public string GetKey() => this.Index;
|
||||
|
||||
public int CompareTo(object? obj) {
|
||||
if (obj == null) return 1;
|
||||
var other = (App)obj;
|
||||
if (Int32.TryParse(Index, out var thisindex) && Int32.TryParse(other.Index, out var otherindex) )
|
||||
return thisindex.CompareTo(otherindex);
|
||||
return String.Compare(this.Index, other.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,21 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HaDocument.Models {
|
||||
public class Backlink {
|
||||
public string Href { get; } = "";
|
||||
public class Backlink : IHaElement {
|
||||
public string ElementName { get; } = "link";
|
||||
public string[] XPath { get; } = {
|
||||
"/opus/data/marginalien/marginal//link",
|
||||
"/opus/marginalien/marginal//link",
|
||||
"/opus/kommentare/kommentar//link",
|
||||
"/opus/data/kommentare/kommentar//link",
|
||||
"/opus/traditions/letterTradition//link",
|
||||
"/opus/data/traditions/letterTradition//link",
|
||||
};
|
||||
public string ElementRules { get; } = "Pfad: /opus/marginalien, /opus/kommentare, /opus/traditions. Pflicht-Attribute: letter.";
|
||||
public bool Searchable { get; } = false;
|
||||
public XElement? XElement { get; } = null;
|
||||
|
||||
public string Href { get; } = "";
|
||||
public string? Letter { get; } = "";
|
||||
public string? Page { get; } = "";
|
||||
public string? Line { get; } = "";
|
||||
@@ -14,13 +26,15 @@ namespace HaDocument.Models {
|
||||
string? letter,
|
||||
string? page,
|
||||
string? line,
|
||||
string? comment = null
|
||||
string? comment = null,
|
||||
XElement? xElement = null
|
||||
) {
|
||||
Href = href;
|
||||
Letter = letter;
|
||||
Page = page;
|
||||
Line = line;
|
||||
Comment = comment;
|
||||
XElement = xElement;
|
||||
}
|
||||
|
||||
public static Backlink? FromXElement(XElement element) {
|
||||
@@ -34,7 +48,9 @@ namespace HaDocument.Models {
|
||||
element.Attribute("subref")?.Value ?? element.Attribute("ref")!.Value,
|
||||
marginal.Attribute("letter")!.Value,
|
||||
marginal.Attribute("page")!.Value,
|
||||
marginal.Attribute("line")!.Value
|
||||
marginal.Attribute("line")!.Value,
|
||||
null,
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,7 +62,8 @@ namespace HaDocument.Models {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
subsection.Attribute("id")!.Value
|
||||
subsection.Attribute("id")!.Value,
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,11 +75,20 @@ namespace HaDocument.Models {
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
kommentar.Attribute("id")!.Value
|
||||
kommentar.Attribute("id")!.Value,
|
||||
element
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetKey() {
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public int CompareTo(object? obj) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HaDocument.Models {
|
||||
public class Comment : IHaElement {
|
||||
public string ElementName { get; } = "link";
|
||||
public string[] XPath { get; } = {
|
||||
"/opus/kommentare/kommentar/kommcat/kommentar",
|
||||
"/opus/data/kommentare/kommentar/kommcat/kommentar",
|
||||
};
|
||||
public string ElementRules { get; } = "Pfad: /opus/kommentare/kommentar. Pflicht-Attribute: id (einmalig).";
|
||||
public bool Searchable { get; } = true;
|
||||
public XElement? XElement { get; }
|
||||
|
||||
namespace HaDocument.Models{
|
||||
public class Comment {
|
||||
public string Element { get; } = "";
|
||||
public string Index { get; } = "";
|
||||
public string Type { get; } = "";
|
||||
public string Lemma { get; } = "";
|
||||
public string Parent { get; } = "";
|
||||
public int Order { get; } = -1;
|
||||
public ImmutableSortedDictionary<string, Comment> Kommentare { get; }
|
||||
public int? Order { get; } = null;
|
||||
public ImmutableSortedDictionary<string, Comment>? Kommentare { get; }
|
||||
|
||||
public Comment(
|
||||
string entry,
|
||||
string index,
|
||||
string type,
|
||||
string lemma,
|
||||
int order,
|
||||
SortedDictionary<string, Comment> subComments,
|
||||
string parent=""
|
||||
string? type,
|
||||
string? lemma,
|
||||
int? order,
|
||||
ImmutableSortedDictionary<string, Comment>? subComments,
|
||||
string? parent = null,
|
||||
XElement? xelement = null
|
||||
) {
|
||||
Element = entry;
|
||||
Index = index;
|
||||
@@ -27,10 +38,58 @@ namespace HaDocument.Models{
|
||||
Lemma = lemma;
|
||||
Order = order;
|
||||
Parent = parent;
|
||||
if (subComments != null)
|
||||
Kommentare = ImmutableSortedDictionary.ToImmutableSortedDictionary(subComments);
|
||||
else
|
||||
Kommentare = null;
|
||||
XElement = xelement;
|
||||
Kommentare = subComments;
|
||||
}
|
||||
|
||||
public String GetKey() => Index;
|
||||
|
||||
public int CompareTo(object? obj) {
|
||||
if (obj == null) return 1;
|
||||
var other = (Comment)obj;
|
||||
if (!String.IsNullOrWhiteSpace(Parent) && !String.IsNullOrWhiteSpace(other.Parent) &&
|
||||
(Parent == other.Parent)) {
|
||||
if (Order.HasValue && other.Order.HasValue)
|
||||
return Order.Value!.CompareTo(other.Order.Value);
|
||||
else if (Order.HasValue)
|
||||
return 1;
|
||||
else if (other.Order.HasValue)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
return String.Compare(Index, other.Index);
|
||||
}
|
||||
|
||||
public Comment? FromXElement(XElement? element) {
|
||||
if (element == null || !element.HasAttributes || element.IsEmpty) return null;
|
||||
if (element.Attribute("id")?.Value == null) return null;
|
||||
var cat = element.Ancestors("kommcat");
|
||||
if (element.Name == "kommentar")
|
||||
return new Comment(
|
||||
element.ToString(),
|
||||
element.Attribute("id")!.Value,
|
||||
(cat.Any() ? cat.First().Attribute("value")?.Value : null) ?? element.Attribute("type")?.Value,
|
||||
element.Element("lemma")?.Value,
|
||||
element.Attribute("sort")?.Value != null ? (Int32.TryParse(element.Attribute("sort")!.Value, out var s) ? s : null) : null,
|
||||
element.Elements("subsection").Any() ? element.Elements("subsection").Select(x => FromXElement(x)).ToImmutableSortedDictionary(x => x.Index, y => y) : null,
|
||||
null,
|
||||
element
|
||||
);
|
||||
else if (element.Name == "subsection") {
|
||||
if (element.Ancestors("kommentar").Any() || element.Ancestors("kommentar")!.First().Attribute("id")?.Value == null) return null;
|
||||
return new Comment(
|
||||
element.ToString(),
|
||||
element.Attribute("id")!.Value,
|
||||
(cat.Any() ? cat.First().Attribute("value")?.Value : null) ?? element.Attribute("type")?.Value,
|
||||
element.Element("lemma")?.Value,
|
||||
element.Attribute("sort")?.Value != null ? (Int32.TryParse(element.Attribute("sort")!.Value, out var s) ? s : null) : null,
|
||||
null,
|
||||
element.Ancestors("kommentar")!.First().Attribute("id")!.Value,
|
||||
element
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,8 +31,9 @@ namespace HaDocument.Models {
|
||||
Reference = reference;
|
||||
}
|
||||
|
||||
public static Editreason? FromXElement(XElement element) {
|
||||
throw new NotImplementedException("We need two Elements for editreason");
|
||||
public static Editreason? FromXElement(XElement edit, XElement editreason) {
|
||||
if (edit == null || editreason == null || !edit.HasAttributes || !editreason.HasAttributes) return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user