String value = node.getNodeValue();
// TODO: find out what "name" should be in the ctors
switch (node.getNodeType()) {
case Node.TEXT_NODE :
if (!value.trim().equals("")) {
element = new LayoutStaticText(parent,
LayoutElementUtil.getGeneratedId(node.getNodeName(), getNextIdNumber()),
value);
}
break;
case Node.ELEMENT_NODE:
element = createComponent(parent, node, nested);
if (element instanceof LayoutStaticText) {
// We have a element node that needs to be static text
endElement = true;
} else if (element instanceof LayoutForEach) {
newParent = element;
} else if (element instanceof LayoutIf) {
newParent = element;
} else if (element instanceof LayoutComponent) {
nested = true;
newParent = element;
} else if (element instanceof LayoutComposition) {
abortProcessing = ((LayoutComposition)element).isTrimming();
newParent = element;
} else if (element instanceof LayoutDefine) {
newParent = element;
} else if (element instanceof LayoutFacet) {
newParent = element;
} else if (element instanceof LayoutInsert) {
newParent = element;
}
// FIXME: Jason, this code may need to be refactored. I think almost
// FIXME: everything should have newParent = element. The problem comes when
// FIXME: you are turning <html> and </html> into 2 separate staticText
// FIXME: components. This should be a single component, then it could contain
// FIXME: children also. You may want a to create a component like Woodstock's
// FIXME: "markup" component to do this.
break;
default:
// just because... :P
}
if (element != null) {
parent.addChildLayoutElement(element);
NodeList nodeList = node.getChildNodes();
boolean abortChildProcessing = false;
for (int i = 0; i < nodeList.getLength() && (abortChildProcessing != true); i++) {
abortChildProcessing = process(newParent, nodeList.item(i), nested);
}
if (abortChildProcessing == true) {
abortProcessing = abortChildProcessing;
}else {
if (endElement) {
String nodeName = node.getNodeName();
element = new LayoutStaticText(parent, LayoutElementUtil.getGeneratedId(nodeName, getNextIdNumber()), "</" + nodeName + ">");
parent.addChildLayoutElement(element);
}
}
}