Last active
August 29, 2015 14:16
-
-
Save achudars/74ee29976da21ebff13a to your computer and use it in GitHub Desktop.
HTML2IFML mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pre { | |
// initial setup of the IFML model structure | |
var IFMLModel := new IFML!IFMLModel; | |
IFMLModel.id = "journey"; | |
IFMLModel.name = "journey"; | |
IFMLModel.contentModel := new IFML!ContentModel; | |
IFMLModel.contentModel.id = "ContentModel"; | |
IFMLModel.contentModel.name = "ContentModel"; | |
IFMLModel.interactionFlowModel := new IFML!InteractionFlowModel; | |
IFMLModel.interactionFlowModel.id = "InteractionFlowModel"; | |
IFMLModel.interactionFlowModel.name = "InteractionFlowModel"; | |
} | |
rule XML2IFML | |
transform xml : XML!t_journey | |
to ifml : IFML!Window { | |
traverse(xml, ifml); | |
IFMLModel.interactionFlowModel.interactionFlowModelElements.add(ifml); | |
} | |
operation traverse(xml : Any, ifml : Any) { | |
ifml.id = xml.getNodeName(); | |
ifml.name = xml.getNodeName(); | |
for (child in xml.children) { | |
var node; | |
if (child.isTypeOf(t_transition)) { | |
node := new IFML!Event; | |
//} else if (child.isTypeOf(t_form) or child.isTypeOf(t_ul) or child.isTypeOf(t_input)){ | |
// node := new IFML!ViewComponent; | |
//} else if (child.isTypeOf(t_li)) { node := new IFML!ViewComponentPart; | |
// << OMITTED MAPPING RULES GO HERE >> | |
} else { node := new IFML!ViewContainer; } | |
setIdentification(node,child); | |
if (node.isTypeOf(IFML!Event) or node.isTypeOf(IFML!ViewContainer)) { | |
ifml.viewElements.add(node); | |
} else if (node.isTypeOf(IFML!ViewComponentPart)) { | |
ifml.viewComponentParts.add(node); | |
} else { | |
ifml.viewElements.add(node); | |
} | |
// recursively traverse | |
traverse(child,node); | |
} | |
} | |
operation setIdentification(node : Any, child : Any) { | |
node.id = child.a_id; | |
node.name = child.getNodeName(); | |
// property parentViewComponentPart for ViewComponentPart must be set | |
if (node.isTypeOf(IFML!ViewComponentPart)) { | |
node.parentViewComponentPart := node; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment