private WOElement template(WOComponent component) {
WOElement content = component._childTemplate();
WOElement result = null;
String templateName = (_templateName == null) ? null : (String) _templateName.valueInComponent(component);
if (content instanceof WODynamicGroup) {
WODynamicGroup group = (WODynamicGroup) content;
if (templateName == null) {
// MS: If you don't set a template name, then let's construct all the children of
// this element that are NOT ERXWOTemplate's, so we don't double-display. This lets
// you use an ERXWOComponentContent and have it just act like a "default" template
// that skips all the children that are explicitly wrapped in an ERXWOTemplate.
NSMutableArray<WOElement> originalChildrenElements = group.childrenElements();
if (originalChildrenElements != null && originalChildrenElements.count() > 0) {
NSMutableArray<WOElement> nonTemplateChildrenElements = new NSMutableArray<WOElement>();
for (WOElement originalChild : originalChildrenElements) {
if (!(originalChild instanceof ERXWOTemplate)) {
nonTemplateChildrenElements.addObject(originalChild);
}
}
result = new WODynamicGroup(null, null, nonTemplateChildrenElements);
}
}
else {
for(Enumeration e = group.childrenElements().objectEnumerator(); e.hasMoreElements() && result == null ; ) {
WOElement current = (WOElement) e.nextElement();
if(current instanceof ERXWOTemplate) {
ERXWOTemplate template = (ERXWOTemplate)current;
String name = template.templateName(component);
if(name.equals(templateName)) {