menuDefinitions.add(definition);
}
protected Object copyMenuElement(String type, Object srcElement)
{
PageManager pageManger = getServiceLocator().getPageManager();
if (srcElement instanceof MenuDefinition)
{
// create the new menu element and copy attributes
MenuDefinition source = (MenuDefinition) srcElement;
MenuDefinition menu = null;
if (type.equals(PAGE_NODE_TYPE))
{
menu = pageManger.newPageMenuDefinition();
} else if (type.equals(FOLDER_NODE_TYPE))
{
menu = pageManger.newFolderMenuDefinition();
}
menu.setDepth(source.getDepth());
menu.setName(source.getName());
menu.setOptions(source.getOptions());
menu.setOrder(source.getOrder());
menu.setPaths(source.isPaths());
menu.setProfile(source.getProfile());
menu.setRegexp(source.isRegexp());
menu.setShortTitle(source.getShortTitle());
menu.setSkin(source.getSkin());
menu.setTitle(source.getTitle());
// copy locale specific metadata
menu.getMetadata().copyFields(source.getMetadata().getFields());
// recursively copy menu elements
List elements = source.getMenuElements();
if (elements != null)
{
List copiedElements = new ArrayList();
Iterator elementsIter = elements.iterator();
while (elementsIter.hasNext())
{
Object element = elementsIter.next();
Object copiedElement = copyMenuElement(type, element);
if (copiedElement != null)
{
copiedElements.add(copiedElement);
}
}
menu.setMenuElements(copiedElements);
}
return menu;
} else if (srcElement instanceof MenuExcludeDefinition)
{
// create the new menu exclude element and copy attributes
MenuExcludeDefinition source = (MenuExcludeDefinition) srcElement;
MenuExcludeDefinition menuExclude = null;
if (type.equals(PAGE_NODE_TYPE))
{
menuExclude = pageManger.newPageMenuExcludeDefinition();
} else if (type.equals(FOLDER_NODE_TYPE))
{
menuExclude = pageManger.newFolderMenuExcludeDefinition();
}
menuExclude.setName(source.getName());
return menuExclude;
} else if (srcElement instanceof MenuIncludeDefinition)
{
// create the new menu include element and copy attributes
MenuIncludeDefinition source = (MenuIncludeDefinition) srcElement;
MenuIncludeDefinition menuInclude = null;
if (type.equals(PAGE_NODE_TYPE))
{
menuInclude = pageManger.newPageMenuIncludeDefinition();
} else if (type.equals(FOLDER_NODE_TYPE))
{
menuInclude = pageManger.newFolderMenuIncludeDefinition();
}
menuInclude.setName(source.getName());
menuInclude.setNest(source.isNest());
return menuInclude;
} else if (srcElement instanceof MenuOptionsDefinition)
{
// create the new menu options element and copy attributes
MenuOptionsDefinition source = (MenuOptionsDefinition) srcElement;
MenuOptionsDefinition menuOptions = null;
if (type.equals(PAGE_NODE_TYPE))
{
menuOptions = pageManger.newPageMenuOptionsDefinition();
} else if (type.equals(FOLDER_NODE_TYPE))
{
menuOptions = pageManger.newFolderMenuOptionsDefinition();
}
menuOptions.setDepth(source.getDepth());
menuOptions.setOptions(source.getOptions());
menuOptions.setOrder(source.getOrder());
menuOptions.setPaths(source.isPaths());
menuOptions.setProfile(source.getProfile());
menuOptions.setRegexp(source.isRegexp());
menuOptions.setSkin(source.getSkin());
return menuOptions;
} else if (srcElement instanceof MenuSeparatorDefinition)
{
// create the new menu separator element and copy attributes
MenuSeparatorDefinition source = (MenuSeparatorDefinition) srcElement;
MenuSeparatorDefinition menuSeparator = null;
if (type.equals(PAGE_NODE_TYPE))
{
menuSeparator = pageManger.newPageMenuSeparatorDefinition();
} else if (type.equals(FOLDER_NODE_TYPE))
{
menuSeparator = pageManger.newFolderMenuSeparatorDefinition();
}
menuSeparator.setSkin(source.getSkin());
menuSeparator.setTitle(source.getTitle());
menuSeparator.setText(source.getText());
// copy locale specific metadata