if (pa == null)
{
return;
}
PortletDefinitionComposite pd = null;
GenericMetadata meta = null;
if (pdName != null)
{
pd = (PortletDefinitionComposite) pa.getPortletDefinitionByName(pdName);
if (pd != null)
{
meta = pd.getMetadata();
}
else
{
return;
}
}
else
{
meta = pa.getMetadata();
}
if (meta == null)
{
return;
}
if(action.equals("edit_metadata"))
{
try
{
boolean modified = false;
Iterator fieldsIter = meta.getFields().iterator();
while (fieldsIter.hasNext())
{
LocalizedField field = (LocalizedField) fieldsIter.next();
String id = field.getId().toString();
String value = actionRequest.getParameter(id + ":value");
if (value != null)
{
if (!value.equals(field.getValue()))
{
field.setValue(value);
modified = true;
}
}
}
if (modified)
{
if (pd == null)
{
registry.updatePortletApplication(pa);
}
else
{
registry.savePortletDefinition(pd);
}
}
}
catch (RegistryException e)
{
throw new PortletException("Failed update meta data attributes: "
+ paName + ", " + ((pdName == null) ? "" : pdName), e);
}
}
else if (action.equals("remove_metadata"))
{
String[] ids = actionRequest.getParameterValues("metadata_id");
if (ids != null)
{
try
{
Iterator fieldsIter = meta.getFields().iterator();
int count = 0;
while (fieldsIter.hasNext())
{
LocalizedField field = (LocalizedField) fieldsIter.next();
String id = field.getId().toString();
for(int i=0; i<ids.length; i++)
{
String mid = ids[i];
if(mid.equals(id))
{
fieldsIter.remove();
count++;
break;
}
}
}
if (count > 0)
{
if (pd == null)
{
registry.updatePortletApplication(pa);
}
else
{
registry.savePortletDefinition(pd);
}
}
}
catch (RegistryException e)
{
throw new PortletException("Failed remove meta data attributes: "
+ paName + ", " + ((pdName == null) ? "" : pdName), e);
}
}
}
else if(action.equals("add_metadata"))
{
String name = actionRequest.getParameter("name");
String value = actionRequest.getParameter("value");
String localeParam = actionRequest.getParameter("locale");
if(localeParam == null || name.trim().length() == 0)
{
localeParam = "en"; //need to default better
}
Locale locale = new Locale(localeParam);
if (name != null && name.trim().length() > 0)
{
try
{
meta.addField(locale, name, value);
if (pd == null)
{
registry.updatePortletApplication(pa);
}
else