summaryrefslogtreecommitdiff
path: root/src/core/parser/stack/ImportIncludeHandler.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 14:58:46 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 14:58:46 +0100
commit69ebaddbeaea1aa651a0f0babbf9283240d9c07b (patch)
tree4b590c8ae6e634b8445a2f2d0f580a970bc1b669 /src/core/parser/stack/ImportIncludeHandler.cpp
parent2aced1289813b3dae9c79f3c6878788343e3d997 (diff)
Slightly adapted Handler instances to new Handler, once again passing non-const references to data and start, using "parseGenericString" in DocumentHandler for resolving non-string values, added unit test for testing whether "end()" is not called if "start()" fails.
Diffstat (limited to 'src/core/parser/stack/ImportIncludeHandler.cpp')
-rw-r--r--src/core/parser/stack/ImportIncludeHandler.cpp54
1 files changed, 10 insertions, 44 deletions
diff --git a/src/core/parser/stack/ImportIncludeHandler.cpp b/src/core/parser/stack/ImportIncludeHandler.cpp
index 94ee82d..797dd8d 100644
--- a/src/core/parser/stack/ImportIncludeHandler.cpp
+++ b/src/core/parser/stack/ImportIncludeHandler.cpp
@@ -18,48 +18,16 @@
#include "ImportIncludeHandler.hpp"
+#include <core/model/RootNode.hpp>
#include <core/parser/ParserScope.hpp>
+#include <core/parser/ParserContext.hpp>
namespace ousia {
-
-/* ImportIncludeHandler */
-
-void ImportIncludeHandler::start(Variant::mapType &args)
-{
- rel = args["rel"].asString();
- type = args["type"].asString();
- src = args["src"].asString();
- srcInArgs = !src.empty();
-}
-
-void ImportIncludeHandler::data(const std::string &data, int field)
-{
- if (srcInArgs) {
- logger().error("\"src\" attribute has already been set");
- return;
- }
- if (field != 0) {
- logger().error("Command has only one field.");
- return;
- }
- src.append(data);
-}
+namespace parser_stack {
/* ImportHandler */
-void ImportHandler::start(Variant::mapType &args)
-{
- ImportIncludeHandler::start(args);
-
- // Make sure imports are still possible
- if (scope().getFlag(ParserFlag::POST_HEAD)) {
- logger().error("Imports must be listed before other commands.",
- location());
- return;
- }
-}
-
-void ImportHandler::end()
+void ImportHandler::doHandle(const Variant &fieldData, Variant::mapType &args)
{
// Fetch the last node and check whether an import is valid at this
// position
@@ -75,8 +43,9 @@ void ImportHandler::end()
// Perform the actual import, register the imported node within the leaf
// node
- Rooted<Node> imported =
- context().import(src, type, rel, leafRootNode->getReferenceTypes());
+ Rooted<Node> imported = context().import(
+ fieldData.asString(), args["type"].asString(), args["rel"].asString(),
+ leafRootNode->getReferenceTypes());
if (imported != nullptr) {
leafRootNode->reference(imported);
}
@@ -84,13 +53,10 @@ void ImportHandler::end()
/* IncludeHandler */
-void IncludeHandler::start(Variant::mapType &args)
+void IncludeHandler::doHandle(const Variant &fieldData, Variant::mapType &args)
{
- ImportIncludeHandler::start(args);
+ context().include(fieldData.asString(), args["type"].asString(),
+ args["rel"].asString(), {&RttiTypes::Node});
}
-
-void IncludeHandler::end()
-{
- context().include(src, type, rel, {&RttiTypes::Node});
}
}