From 51de9238ddbd6b7f4cdaa5e9a5918cae952891b2 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Mon, 12 Jan 2015 15:50:10 +0100 Subject: Tried to introduce another StructureNode class as common superclass for StructuredEntity, Anchor and DocumentPrimitive. Nearly seems to work, but not entirely so. There are still issues with the Manager it seems. --- src/plugins/html/DemoOutput.cpp | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/html/DemoOutput.cpp b/src/plugins/html/DemoOutput.cpp index 4cadf12..7dc1660 100644 --- a/src/plugins/html/DemoOutput.cpp +++ b/src/plugins/html/DemoOutput.cpp @@ -33,8 +33,7 @@ void DemoHTMLTransformer::writeHTML(Handle doc, { Manager &mgr = doc->getManager(); // Create an XML object tree for the document first. - Rooted html{new xml::Element{ - mgr, {nullptr}, "html"}}; + Rooted html{new xml::Element{mgr, {nullptr}, "html"}}; // add the head Element Rooted head{new xml::Element{mgr, html, "head"}}; html->addChild(head); @@ -117,8 +116,8 @@ Rooted DemoHTMLTransformer::transformSection( // check if we have a heading. if (section->hasField("heading") && section->getField("heading").size() > 0) { - Rooted heading = - section->getField("heading")[0]; + Handle heading = + section->getField("heading")[0].cast(); std::string headingclass; switch (type) { case SectionType::BOOK: @@ -147,8 +146,11 @@ Rooted DemoHTMLTransformer::transformSection( } // Then we get all the children. - NodeVector mainField = section->getField(); - for (auto &n : mainField) { + for (auto &n : section->getField()) { + if (!n->isa(RttiTypes::StructuredEntity)) { + continue; + } + Handle s = n.cast(); /* * Strictly speaking this is the wrong mechanism, because we would have * to make an "isa" call here because we can not rely on our knowledge @@ -156,14 +158,14 @@ Rooted DemoHTMLTransformer::transformSection( * to be a listener structure of transformations that check if they can * transform this specific node. */ - const std::string childDescriptorName = n->getDescriptor()->getName(); + const std::string childDescriptorName = s->getDescriptor()->getName(); Rooted child; if (childDescriptorName == "paragraph") { - child = transformParagraph(sec, n, startMap, endMap); + child = transformParagraph(sec, s, startMap, endMap); } else if (childDescriptorName == "ul" || childDescriptorName == "ol") { - child = transformList(sec, n, startMap, endMap); + child = transformList(sec, s, startMap, endMap); } else { - child = transformSection(sec, n, startMap, endMap); + child = transformSection(sec, s, startMap, endMap); } if (!child.isNull()) { sec->addChild(child); @@ -181,7 +183,9 @@ Rooted DemoHTMLTransformer::transformList( std::string listclass = list->getDescriptor()->getName(); Rooted l{new xml::Element{mgr, parent, listclass}}; // iterate through list items. - for (auto &item : list->getField()) { + for (auto &it : list->getField()) { + Handle item = + it.cast(); std::string itDescrName = item->getDescriptor()->getName(); if (itDescrName == "item") { // create the list item. @@ -259,7 +263,8 @@ Rooted DemoHTMLTransformer::transformParagraph( // check if we have a heading. if (par->hasField("heading") && par->getField("heading").size() > 0) { - Rooted heading = par->getField("heading")[0]; + Handle heading = + par->getField("heading")[0].cast(); // put the heading in a strong xml::Element. Rooted strong{new xml::Element{mgr, p, "strong"}}; p->addChild(strong); @@ -334,10 +339,15 @@ Rooted DemoHTMLTransformer::transformParagraph( continue; } // if this is not an anchor, we can only handle text. - std::string childDescriptorName = n->getDescriptor()->getName(); + if(!n->isa(RttiTypes::StructuredEntity)){ + continue; + } + Handle t = n.cast(); + + std::string childDescriptorName = t->getDescriptor()->getName(); if (childDescriptorName == "text") { Handle primitive = - n->getField()[0].cast(); + t->getField()[0].cast(); if (primitive.isNull()) { throw OusiaException("Text field is not primitive!"); } -- cgit v1.2.3