{
throw new FailedToStorePortletDefinitionException("Cannot clone to portlet named " + newPortletName + ", name already exists");
}
// create new portlet in source portlet application
PortletDefinition copy = source.getApplication().addPortlet(newPortletName);
// First set display name
DisplayName displayName = copy.addDisplayName(JetspeedLocale.getDefaultLocale().getLanguage());
displayName.setDisplayName(newPortletName);
// And, then, copy all attributes
copy.setPortletClass(source.getPortletClass());
copy.setResourceBundle(source.getResourceBundle());
copy.setPreferenceValidatorClassname(source.getPreferenceValidatorClassname());
copy.setExpirationCache(source.getExpirationCache());
copy.setCacheScope(source.getCacheScope());
for (LocalizedField field : source.getMetadata().getFields())
{
copy.getMetadata().addField(field.getLocale(), field.getName(), field.getValue());
}
copy.setJetspeedSecurityConstraint(source.getJetspeedSecurityConstraint());
for (Description desc : source.getDescriptions())
{
Description copyDesc = copy.addDescription(desc.getLang());
copyDesc.setDescription(desc.getDescription());
}
for (InitParam initParam : source.getInitParams())
{
InitParam copyInitParam = copy.addInitParam(initParam.getParamName());
copyInitParam.setParamValue(initParam.getParamValue());
for (Description desc : initParam.getDescriptions())
{
Description copyDesc = copyInitParam.addDescription(desc.getLang());
copyDesc.setDescription(desc.getDescription());
}
}
for (EventDefinitionReference eventDefRef : source.getSupportedProcessingEvents())
{
copy.addSupportedProcessingEvent(eventDefRef.getQName());
}
for (EventDefinitionReference eventDefRef : source.getSupportedPublishingEvents())
{
copy.addSupportedPublishingEvent(eventDefRef.getQName());
}
for (SecurityRoleRef secRoleRef : source.getSecurityRoleRefs())
{
SecurityRoleRef copySecRoleRef = copy.addSecurityRoleRef(secRoleRef.getRoleName());
copySecRoleRef.setRoleLink(secRoleRef.getRoleLink());
for (Description desc : secRoleRef.getDescriptions())
{
Description copyDesc = copySecRoleRef.addDescription(desc.getLang());
copyDesc.setDescription(desc.getDescription());
}
}
for (Supports supports : source.getSupports())
{
Supports copySupports = copy.addSupports(supports.getMimeType());
for (String portletMode : supports.getPortletModes())
{
copySupports.addPortletMode(portletMode);
}
for (String windowState : supports.getWindowStates())
{
copySupports.addWindowState(windowState);
}
}
for (Language language : source.getLanguages())
{
Language copyLanguage = copy.addLanguage(language.getLocale());
copyLanguage.setTitle(language.getTitle());
copyLanguage.setShortTitle(language.getShortTitle());
copyLanguage.setKeywords(language.getKeywords());
copyLanguage.setSupportedLocale(language.isSupportedLocale());
}
for (ContainerRuntimeOption runtimeOption : source.getContainerRuntimeOptions())
{
ContainerRuntimeOption copyRuntimeOption = copy.addContainerRuntimeOption(runtimeOption.getName());
for (String value : runtimeOption.getValues())
{
copyRuntimeOption.addValue(value);
}
}
copy.getSupportedPublicRenderParameters().addAll(source.getSupportedPublicRenderParameters());
//savePortletDefinition(copy);
try
{
updatePortletApplication(source.getApplication());
}
catch (RegistryException e)
{
throw new FailedToStorePortletDefinitionException(e);
}
for (Preference pref : source.getPortletPreferences().getPortletPreferences())
{
Preference copyPref = copy.addDescriptorPreference(pref.getName());
copyPref.setReadOnly(pref.isReadOnly());
for (String value : pref.getValues())
{
copyPref.addValue(value);