*/
public BaseFragmentElement copyFragment(BaseFragmentElement source, String name, boolean copyIds)
throws NodeException
{
// create the new fragment and copy attributes
BaseFragmentElement copy;
if (source instanceof Fragment)
{
copy = newFragment();
}
else if (source instanceof FragmentReference)
{
copy = newFragmentReference();
}
else if (source instanceof PageFragment)
{
copy = newPageFragment();
}
else
{
throw new IllegalArgumentException("Unsupported fragment type: "+((source != null) ? source.getClass().getName() : "null"));
}
if (copyIds)
{
copy.setId(source.getId());
}
copy.setDecorator(source.getDecorator());
copy.setLayoutColumn(source.getLayoutColumn());
copy.setLayoutHeight(source.getLayoutHeight());
copy.setLayoutRow(source.getLayoutRow());
copy.setLayoutSizes(source.getLayoutSizes());
copy.setLayoutX(source.getLayoutX());
copy.setLayoutY(source.getLayoutY());
copy.setLayoutZ(source.getLayoutZ());
copy.setLayoutWidth(source.getLayoutWidth());
copy.setMode(source.getMode());
copy.setShortTitle(source.getShortTitle());
copy.setSkin(source.getSkin());
copy.setState(source.getState());
copy.setTitle(source.getTitle());
// copy security constraints
SecurityConstraints srcSecurity = source.getSecurityConstraints();
if ((srcSecurity != null) && !srcSecurity.isEmpty())
{
SecurityConstraints copiedSecurity = copySecurityConstraints(FRAGMENT_NODE_TYPE, srcSecurity);
copy.setSecurityConstraints(copiedSecurity);
}
// copy properties, (only properties for global and
// current user/group/role specific values copied)
Iterator props = source.getProperties().iterator();
while (props.hasNext())
{
FragmentProperty prop = (FragmentProperty)props.next();
String propName = prop.getName();
String propScope = prop.getScope();
String propScopeValue = prop.getScopeValue();
if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED ||
(propScope == null) ||
(!propScope.equals(FragmentProperty.GROUP_PROPERTY_SCOPE) && !propScope.equals(FragmentProperty.ROLE_PROPERTY_SCOPE)))
{
if (copy.getProperty(propName, propScope, propScopeValue) == null)
{
copy.setProperty(propName, propScope, propScopeValue, prop.getValue());
}
}
}
// copy preferences
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);
}
if (source instanceof Fragment)
{
Fragment copyFragment = (Fragment)copy;
Fragment sourceFragment = (Fragment)source;
if (name == null)
{
name = sourceFragment.getName();
}
copyFragment.setName(name);
copyFragment.setType(sourceFragment.getType());
// recursively copy fragments
Iterator fragments = sourceFragment.getFragments().iterator();
while (fragments.hasNext())
{
BaseFragmentElement fragment = (BaseFragmentElement)fragments.next();
BaseFragmentElement copiedFragment = copyFragment(fragment, null, copyIds);
copyFragment.getFragments().add(copiedFragment);
}
}
else if (source instanceof FragmentReference)
{