From 2c3b327739b79d5ba7fe931e205bec1ad320b360 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 8 Jan 2015 18:11:21 +0100 Subject: further extended the advanced document example, slightly improved XML serialization and fixed a bug in DemoOutput leading to errors if a section/paragraph had no heading. --- test/core/model/TestAdvanced.hpp | 90 +++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index 95c5402..bb7671a 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -26,7 +26,6 @@ namespace ousia { namespace model { - static Rooted resolveDescriptor(Handle domain, const std::string &className) { @@ -76,14 +75,52 @@ static Rooted constructHeadingDomain(Manager &mgr, return domain; } +static bool addText(Handle parent, + std::vector> &doms, + const std::string &content) +{ + // Add its text. + Rooted text = + StructuredEntity::buildEntity(parent, doms, "text"); + if (text.isNull()) { + return false; + } + // And its primitive content + Variant content_var{content.c_str()}; + Rooted primitive = + DocumentPrimitive::buildEntity(text, content_var, "content"); + if (primitive.isNull()) { + return false; + } + + return true; +} + +static bool addHeading(Handle parent, + std::vector> &doms, + const std::string &text) +{ + // Add the heading. + Rooted heading = StructuredEntity::buildEntity( + parent, doms, "heading", "heading", {}, ""); + if (heading.isNull()) { + return false; + } + // Add its text. + if (!addText(heading, doms, text)) { + return false; + } + return true; +} + /** * This constructs a more advanced book document using not only the book * domain but also headings, emphasis and lists. * TODO: insert emphasis and lists. */ static Rooted constructAdvancedDocument(Manager &mgr, - Rooted bookDom, - Rooted headingDom) + Rooted bookDom, + Rooted headingDom) { std::vector> doms{bookDom, headingDom}; @@ -96,29 +133,44 @@ static Rooted constructAdvancedDocument(Manager &mgr, if (book.isNull()) { return {nullptr}; } - { + // Add the heading. - Rooted heading = StructuredEntity::buildEntity( - book, doms, "heading", "heading", {}, ""); - if (heading.isNull()) { + // TODO: use em here. + if (!addHeading(book, doms, + "Beantwortung der Frage: Was ist Aufklärung?")) { + return {nullptr}; + } + + // Add the main section. + Rooted sec = + StructuredEntity::buildEntity(book, doms, "section"); + + // Add the heading. + if (!addHeading(sec, doms, "Was ist Aufklärung?")) { return {nullptr}; } + + // Add paragraph with main text. { + Rooted p = + StructuredEntity::buildEntity(sec, doms, "paragraph"); // Add its text. - Rooted text = - StructuredEntity::buildEntity(heading, doms, "text"); - if (text.isNull()) { + // TODO: Use em and strong here + if (!addText(p, doms, + " Aufklärung ist der Ausgang des Menschen aus " + "seiner selbstverschuldeten Unmündigkeit. " + "Unmündigkeit ist das Unvermögen, sich seines " + "Verstandes ohne Leitung eines anderen zu bedienen. " + "Selbstverschuldet ist diese Unmündigkeit, wenn " + "die Ursache derselben nicht am Mangel des Verstandes, " + "sondern der Entschließung und des Mutes liegt, sich " + "seiner ohne Leitung eines andern zu bedienen. Sapere " + "aude! Habe Mut, dich deines eigenen Verstandes zu " + "bedienen! ist also der Wahlspruch der " + "Aufklärung.")) { return {nullptr}; } - // And its primitive content - // TODO: use em here. - Variant content {"Beantwortung der Frage: Was ist Aufklärung?"}; - Rooted main_primitive = - DocumentPrimitive::buildEntity(text, content, "content"); - if (main_primitive.isNull()) { - return {nullptr}; - } - }} + } return doc; } -- cgit v1.2.3