public Fragment copyFragment(Fragment source, String name)
throws NodeException
{
// create the new fragment and copy attributes
Fragment copy = newFragment();
copy.setDecorator(source.getDecorator());
copy.setName(name);
copy.setShortTitle(source.getShortTitle());
copy.setSkin(source.getSkin());
copy.setTitle(source.getTitle());
copy.setType(source.getType());
copy.setState(source.getState());
// copy security constraints
SecurityConstraints srcSecurity = source.getSecurityConstraints();
if ((srcSecurity != null) && !srcSecurity.isEmpty())
{
SecurityConstraints copiedSecurity = copySecurityConstraints(FRAGMENT_NODE_TYPE, srcSecurity);
copy.setSecurityConstraints(copiedSecurity);
}
// copy properties
Iterator props = source.getProperties().entrySet().iterator();
while (props.hasNext())
{
Map.Entry prop = (Map.Entry)props.next();
copy.getProperties().put(prop.getKey(), prop.getValue());
}
// copy preferences
copy.setPreferences(DatabasePageManagerUtils.createList());
Iterator prefs = source.getPreferences().iterator();
while (prefs.hasNext())
{
FragmentPreference pref = (FragmentPreference)prefs.next();
FragmentPreference newPref = this.newFragmentPreference();
newPref.setName(pref.getName());
newPref.setReadOnly(pref.isReadOnly());
newPref.setValueList(DatabasePageManagerUtils.createList());
Iterator values = pref.getValueList().iterator();
while (values.hasNext())
{
String value = (String)values.next();
newPref.getValueList().add(value);
}
copy.getPreferences().add(newPref);
}
// recursively copy fragments
Iterator fragments = source.getFragments().iterator();
while (fragments.hasNext())
{
Fragment fragment = (Fragment)fragments.next();
Fragment copiedFragment = copyFragment(fragment, fragment.getName());
copy.getFragments().add(copiedFragment);
}
return copy;
}