element = processComposition(parent, "src", attrs, id, false);
} else if ("ui:param".equals(nodeName)) {
// Handle "param"
Node nameAttNode = attrs.getNamedItem("name");
if (nameAttNode == null) {
throw new SyntaxException("The 'name' attribute is required on 'param'.");
}
Node valueNode = attrs.getNamedItem("value");
if (valueNode == null) {
throw new SyntaxException("The 'value' attribute is required on 'param'.");
}
// For now only handle cases where the parent is a LayoutComposition
if (!(parent instanceof LayoutComposition)) {
throw new SyntaxException("<" + nodeName
+ " name='" + nameAttNode.getNodeValue()
+ "' value='" + valueNode.getNodeValue()
+ "'> must be child of a 'composition' element!");
}
// Set the name=value on the parent LayoutComposition
((LayoutComposition) parent).setParameter(
nameAttNode.getNodeValue(), valueNode.getNodeValue());
} else if ("ui:remove".equals(nodeName)) {
// Let the element remain null
} else if ("ui:repeat".equals(nodeName)) {
} else if ("ui:event".equals(nodeName)) {
// per Ken, we need to append "/>" to allow the handler parser code
// to end correctly
String body = node.getTextContent();
body = (body == null) ? "/>" : (body.trim() + "/>");
Node type = node.getAttributes().getNamedItem("type");
if (type == null) {
// Ensure type != null
throw new SyntaxException(
"The 'type' attribute is required on 'ui:event'!");
}
String eventName = type.getNodeValue();
InputStream is = new ByteArrayInputStream(body.getBytes());
EventParserCommand command = new EventParserCommand();
try {
TemplateParser parser = new TemplateParser(is);
parser.open(); // Needed to initialize things.
// Setup the reader...
TemplateReader reader = new TemplateReader("foo", parser); // TODO: get a real ID
reader.pushTag("event"); // The tag will be popped at the end
// Read the handlers...
command.process(new BaseProcessingContext(),
new ProcessingContextEnvironment(reader, parent, true), eventName);
// Clean up
parser.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
} catch (Exception e) {
// ignore
}
}
}
} else if ("ui:if".equals(nodeName)) {
// Handle "if" conditions
String condition = attrs.getNamedItem("condition").getNodeValue();
element = new LayoutIf(parent, condition);
} else if ("ui:foreach".equals(nodeName)) {
// Handle "foreach" conditions
Node valueNode = attrs.getNamedItem("value");
if (valueNode == null) {
throw new SyntaxException("The 'value' property is required on 'foreach'.");
}
Node varNode = attrs.getNamedItem("var");
if (varNode == null) {
throw new SyntaxException("The 'var' property is required on 'foreach'.");
}
element = new LayoutForEach(parent, valueNode.getNodeValue(), varNode.getNodeValue());
} else if ("f:facet".equals(nodeName)) {
// FIXME: Need to take NameSpace into account