You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by jf...@apache.org on 2004/09/29 22:31:35 UTC
cvs commit: jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/portlet/impl PortletApplicationDefinitionImpl.java
jford 2004/09/29 13:31:35
Modified: applications/pam/src/java/org/apache/jetspeed/portlets/pam
PortletApplicationDetail.java
jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet
MutablePortletApplication.java
components/registry/src/java/org/apache/jetspeed/om/portlet/impl
PortletApplicationDefinitionImpl.java
Log:
Added convience method to add a user attribute
Revision Changes Path
1.21 +2 -2 jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationDetail.java
Index: PortletApplicationDetail.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/applications/pam/src/java/org/apache/jetspeed/portlets/pam/PortletApplicationDetail.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PortletApplicationDetail.java 23 Sep 2004 20:54:43 -0000 1.20
+++ PortletApplicationDetail.java 29 Sep 2004 20:31:35 -0000 1.21
@@ -5,5 +5,5 @@
{
response.setContentType("text/html");
String paName = (String)
request.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,
PortletSession.APPLICATION_SCOPE);
MutablePortletApplication pa = registry.getPortletApplication(paName);
if (null != pa)
{
request.setAttribute(VIEW_PA, new PortletApplicationBean(pa));
String pdefName = (String) request.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, PortletSession.APPLICATION_SCOPE);
PortletDefinitionComposite pdef = (PortletDefinitionComposite) pa.getPortletDefinitionByName(pdefName);
request.setAttribute(VIEW_PD, pdef);
request.setAttribute("tabs", paTabMap.values());
request.setAttribute("portlet_tabs", pdTabMap.values());
TabBean selectedTab = (TabBean) request.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, PortletSession.APPLICATION_SCOPE);
if(selectedTab == null)
{
selectedTab = (TabBean) paTabMap.values().iterator().next();
}
//this supports tabs for portlets
if(selectedTab.getId().equals("pa_portlets"))
{
TabBean selectedPortletTab = (TabBean) request.getPortletSession().getAttribute("selected_portlet_tab");
if(selectedPortletTab == null)
{
selectedPortletTab = (TabBean) pdTabMap.values().iterator().next();
}
request.setAttribute("selected_portlet_tab", selectedPortletTab);
}
request.setAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, selectedTab);
}
super.doView(request, response);
}
-
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException
{
//System.out.println("PorletApplicationDetail: processAction()");
String paName = (String)
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,
PortletSession.APPLICATION_SCOPE);
MutablePortletApplication pa = registry.getPortletApplication(paName);
String selectedPortlet = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_PORTLET);
if(selectedPortlet != null)
{
actionRequest.getPortletSession().setAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, selectedPortlet, PortletSession.APPLICATION_SCOPE);
}
String selectedTab = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_TAB);
if(selectedTab != null)
{
TabBean tab = (TabBean) paTabMap.get(selectedTab);
actionRequest.getPortletSession().setAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, tab, PortletSession.APPLICATION_SCOPE);
}
String selectedPortletTab = actionRequest.getParameter("selected_portlet_tab");
if(selectedPortletTab != null)
{
TabBean tab = (TabBean) pdTabMap.get(selectedPortletTab);
actionRequest.getPortletSession().setAttribute("selected_portlet_tab", tab);
}
String action = actionRequest.getParameter(PORTLET_ACTION);
if(action != null)
{
if(isAppAction(action))
{
action = getAction(PORTLET_APP_ACTION_PREFIX, action);
if(action.endsWith("metadata"))
{
processMetadataAction(actionRequest, actionResponse, pa.getMetadata(), action);
}
else if(action.endsWith("user_attribute"))
{
processUserAttributeAction(actionRequest, actionResponse, pa, action);
}
}
else if(isPortletAction(action))
{
action = getAction(PORTLET_ACTION_PREFIX, action);
String pdefName = (String) actionRequest.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, PortletSession.APPLICATION_SCOPE);
PortletDefinitionComposite pdef = (PortletDefinitionComposite) pa.getPortletDefinitionByName(pdefName);
if(action.endsWith("metadata"))
{
processMetadataAction(actionRequest, actionResponse, pdef.getMetadata(), action);
}
else if(action.endsWith("portlet"))
{
processPortletAction(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("preference"))
{
processPreferenceAction(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("language"))
{
processLanguage(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("parameter"))
{
processParameter(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("security"))
{
processSecurity(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("content_type"))
{
processContentType(actionRequest, actionResponse, pa, pdef, action);
}
}
}
}
private boolean isAppAction(String action)
{
return action.startsWith(PORTLET_APP_ACTION_PREFIX);
}
private boolean isPortletAction(String action)
{
return action.startsWith(PORTLET_ACTION_PREFIX);
}
private String getAction(String prefix, String action)
{
return action.substring(prefix.length());
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param action
*/
private void processUserAttributeAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, String action) throws PortletException, IOException
{
if(action.equals("edit_user_attribute"))
{
Iterator userAttrIter = pa.getUserAttributes().iterator();
while (userAttrIter.hasNext())
{
UserAttribute userAttr = (UserAttribute) userAttrIter.next();
String userAttrName = userAttr.getName();
String description = actionRequest.getParameter(userAttrName + ":description");
if(!userAttr.getDescription().equals(description))
{
userAttr.setDescription(description);
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("add_user_attribute"))
{
String userAttrName = actionRequest.getParameter("user_attr_name");
String userAttrDesc = actionRequest.getParameter("user_attr_desc");
if(userAttrName != null)
{
//TODO: should this come from a factory??
UserAttribute userAttribute = new UserAttributeImpl();
userAttribute.setName(userAttrName);
userAttribute.setDescription(userAttrDesc);
pa.addUserAttribute(userAttribute);
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("remove_user_attribute"))
{
String[] userAttrNames = actionRequest.getParameterValues("user_attr_id");
if(userAttrNames != null)
{
Iterator userAttrIter = pa.getUserAttributes().iterator();
while (userAttrIter.hasNext())
{
UserAttribute userAttr = (UserAttribute) userAttrIter.next();
for(int i=0; i<userAttrNames.length; i++)
{
String userAttrName = userAttrNames[i];
if(userAttr.getName().equals(userAttrName))
{
userAttrIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param action
* @throws PortletException
* @throws IOException
*/
private void processMetadataAction(ActionRequest actionRequest, ActionResponse actionResponse, GenericMetadata md, String action) throws PortletException, IOException
{
if(action.equals("edit_metadata"))
{
Iterator fieldsIter = md.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);
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_metadata"))
{
Iterator fieldsIter = md.getFields().iterator();
String[] ids = actionRequest.getParameterValues("metadata_id");
if(ids != null)
{
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();
break;
}
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("add_metadata"))
{
String name = actionRequest.getParameter("name");
String value = actionRequest.getParameter("value");
String localeParam = actionRequest.getParameter("locale");
if(localeParam == null)
{
localeParam = "en"; //need to default better
}
Locale locale = new Locale(localeParam);
md.addField(locale, name, value);
registry.getPersistenceStore().getTransaction().commit();
}
}
private void processPortletAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action) throws PortletException, IOException
{
if(action.equals("edit_portlet"))
{
String displayNameParam = actionRequest.getParameter("display_name");
if(displayNameParam == null)
{
int index = 0;
Iterator displayNameIter = portlet.getDisplayNameSet().iterator();
while (displayNameIter.hasNext())
{
MutableDisplayName displayName = (MutableDisplayName) displayNameIter.next();
displayNameParam = actionRequest.getParameter("display_name:" + index);
//this should never happen
if(displayNameParam != null)
{
if(displayNameParam.length() == 0)
{
displayNameIter.remove();
}
else if(!displayNameParam.equals(displayName.getDisplayName()))
{
displayName.setDisplayName(displayNameParam);
}
}
index++;
}
}
else
{
String locale = actionRequest.getParameter("locale");
portlet.addDisplayName(new Locale(locale), displayNameParam);
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_portlet"))
{
//TODO should this be allowed??
}
else if(action.equals("add_portlet"))
{
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processPreferenceAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_preference"))
{
String name = actionRequest.getParameter("name");
String value = actionRequest.getParameter("value");
PreferenceComposite pref = (PreferenceComposite) portlet.getPreferenceSet().get(name);
if(pref == null)
{
portlet.addPreference(name, new String[] { value });
}
else
{
pref.addValue(value);
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("edit_preference"))
{
String[] prefNames = actionRequest.getParameterValues("pref_edit_id");
for (int i = 0; i < prefNames.length; i++)
{
String prefName = prefNames[i];
PreferenceComposite prefComp = (PreferenceComposite) portlet.getPreferenceSet().get(prefName);
String[] values = prefComp.getValueArray();
for (int j = 0; j < values.length; j++)
{
String value = values[j];
String newValue = actionRequest.getParameter(prefName + ":" + j);
if(!value.equals(newValue))
{
prefComp.setValueAt(j, newValue);
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_preference"))
{
String[] prefNames = actionRequest.getParameterValues("pref_remove_id");
Iterator prefIter = portlet.getPreferenceSet().iterator();
while (prefIter.hasNext())
{
PreferenceComposite pref = (PreferenceComposite) prefIter.next();
String name = pref.getName();
for(int i=0; i<prefNames.length; i++)
{
String prefName = prefNames[i];
if(name.equals(prefName))
{
prefIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processLanguage(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_language"))
{
String title = actionRequest.getParameter("title");
String shortTitle = actionRequest.getParameter("short_title");
String keywords = actionRequest.getParameter("keyword");
String locale = actionRequest.getParameter("locale");
LanguageImpl language = new LanguageImpl();
language.setTitle(title);
language.setShortTitle(shortTitle);
language.setKeywords(keywords);
language.setLocale(new Locale(locale));
portlet.addLanguage(language);
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_language"))
{
String[] removeIds = actionRequest.getParameterValues("language_remove_id");
if(removeIds != null)
{
int id = 0;
Iterator langIter = portlet.getLanguageSet().iterator();
while (langIter.hasNext())
{
langIter.next();
int currentId = id++;
for(int i=0; i<removeIds.length; i++)
{
String removeId = removeIds[i];
String tempId = "" + currentId;
if(removeId.equals(tempId))
{
langIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_language"))
{
String[] editIds = actionRequest.getParameterValues("language_edit_id");
if(editIds != null)
{
//technically, the size and set of edit ids should be
//equal to the size and set of the language set
int id = 0;
Iterator langIter = portlet.getLanguageSet().iterator();
while (langIter.hasNext())
{
String title = actionRequest.getParameter("title:" + id);
String shortTitle = actionRequest.getParameter("short_title:" + id);
//must cast to interface to avoid class loader issues
MutableLanguage lang = (MutableLanguage) langIter.next();
if(!lang.getTitle().equals(title))
{
lang.setTitle(title);
}
Iterator keywordIter = lang.getKeywords();
int keywordIndex = 0;
ArrayList keywordList = new ArrayList();
while (keywordIter.hasNext())
{
String keyword = (String) keywordIter.next();
String keywordParam = actionRequest.getParameter("keyword:" + id + ":" + keywordIndex);
if(keywordParam != null && keywordParam.length() > 0)
{
keywordList.add(keywordParam);
}
keywordIndex++;
}
lang.setKeywords(keywordList);
if(!lang.getShortTitle().equals(shortTitle))
{
lang.setShortTitle(shortTitle);
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processParameter(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_parameter"))
{
String name = actionRequest.getParameter("name");
if(name != null)
{
String description = actionRequest.getParameter("description");
String locale = actionRequest.getParameter("locale");
ParameterComposite parameter = (ParameterComposite)portlet.getInitParameterSet().get(name);
if(parameter == null)
{
String value = actionRequest.getParameter("value");
parameter = portlet.addInitParameter(name, value, description, new Locale(locale));
}
else
{
parameter.addDescription(new Locale(locale), description);
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_parameter"))
{
String[] paramIds = actionRequest.getParameterValues("parameter_edit_id");
if(paramIds != null)
{
for(int i=0; i<paramIds.length; i++)
{
String paramId = paramIds[i];
ParameterComposite param = (ParameterComposite) portlet.getInitParameterSet().get(paramId);
String value = actionRequest.getParameter(paramId + ":value");
param.setValue(value);
int index = 0;
Iterator descIter = param.getDescriptionSet().iterator();
while (descIter.hasNext())
{
MutableDescription description = (MutableDescription) descIter.next();
String descParam = actionRequest.getParameter(paramId + ":description:" + index);
//changing locale not allowed.
if(descParam != null)
{
if(descParam.length() == 0)
{
descIter.remove();
}
else if(!descParam.equals(description.getDescription()))
{
description.setDescription(descParam);
}
}
index++;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_parameter"))
{
String[] paramIds = actionRequest.getParameterValues("parameter_remove_id");
if(paramIds != null)
{
Iterator paramIter = portlet.getInitParameterSet().iterator();
while (paramIter.hasNext())
{
ParameterComposite param = (ParameterComposite) paramIter.next();
for(int i=0; i<paramIds.length; i++)
{
String paramId = paramIds[i];
if(param.getName().equals(paramId))
{
paramIter.remove();
break;
}
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processSecurity(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_security"))
{
String name = actionRequest.getParameter("name");
if(name != null)
{
String link = actionRequest.getParameter("link");
SecurityRoleRefComposite securityRoleRef = (SecurityRoleRefComposite) portlet.getInitSecurityRoleRefSet().get(name);
if(securityRoleRef == null && link != null)
{
securityRoleRef = new SecurityRoleRefImpl();
securityRoleRef.setRoleName(name);
securityRoleRef.setRoleLink(link);
portlet.addSecurityRoleRef(securityRoleRef);
}
if(securityRoleRef != null)
{
String description = actionRequest.getParameter("description");
if(description != null && description.length() > 0)
{
String locale = actionRequest.getParameter("locale");
if(locale == null)
{
locale = "en";
}
securityRoleRef.addDescription(new Locale(locale), description);
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_security"))
{
Iterator securityIter = portlet.getInitSecurityRoleRefSet().iterator();
while (securityIter.hasNext())
{
SecurityRoleRefComposite secRef = (SecurityRoleRefComposite) securityIter.next();
String name = secRef.getRoleName();
//TODO: should this be editable
String newName = actionRequest.getParameter(name + ":name");
String link = actionRequest.getParameter(name + ":link");
if(!secRef.getRoleLink().equals(link))
{
secRef.setRoleLink(link);
}
int index = 0;
Iterator descIter = secRef.getDescriptionSet().iterator();
while (descIter.hasNext())
{
MutableDescription description = (MutableDescription) descIter.next();
String descParam = actionRequest.getParameter(name + ":description:" + index);
//changing locale not allowed.
if(descParam != null)
{
if(descParam.length() == 0)
{
descIter.remove();
}
else if(!descParam.equals(description.getDescription()))
{
description.setDescription(descParam);
}
}
index++;
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_security"))
{
String[] securityIds = actionRequest.getParameterValues("security_remove_id");
if(securityIds != null)
{
for(int i=0; i<securityIds.length; i++)
{
String id = securityIds[i];
SecurityRoleRef secRef = portlet.getInitSecurityRoleRefSet().get(id);
portlet.getInitSecurityRoleRefSet().remove(secRef);
}
/*
Iterator securityIter = portlet.getInitSecurityRoleRefSet()..iterator();
while (securityIter.hasNext())
{
SecurityRoleRefComposite secRef = (SecurityRoleRefComposite) securityIter.next();
for(int i=0; i<securityIds.length; i++)
{
String id = securityIds[i];
if(secRef.getRoleName().equals(id))
{
securityIter.remove();
break;
}
}
}
*/
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processContentType(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_content_type"))
{
String contentType = actionRequest.getParameter("content_type");
if(contentType != null)
{
ContentTypeImpl contentTypeImpl = new ContentTypeImpl();
contentTypeImpl.setContentType(contentType);
String[] modes = actionRequest.getParameterValues("mode");
if(modes != null)
{
for(int i=0; i<modes.length; i++)
{
String mode = modes[i];
contentTypeImpl.addPortletMode(mode);
}
}
String customModes = actionRequest.getParameter("custom_modes");
StringTokenizer tok = new StringTokenizer(customModes, ",");
while (tok.hasMoreTokens())
{
contentTypeImpl.addPortletMode(tok.nextToken());
}
portlet.addContentType(contentTypeImpl);
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_content_type"))
{
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_content_type"))
{
String[] contentIds = actionRequest.getParameterValues("content_type_remove_id");
if(contentIds != null)
{
Iterator contentIter = portlet.getContentTypeSet().iterator();
while (contentIter.hasNext())
{
ContentType contentType = (ContentType) contentIter.next();
for(int i=0; i<contentIds.length; i++)
{
String id = contentIds[i];
if(contentType.getContentType().equals(id))
{
contentIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
+
public void processAction(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException
{
//System.out.println("PorletApplicationDetail: processAction()");
String paName = (String)
actionRequest.getPortletSession().getAttribute(PortletApplicationResources.PAM_CURRENT_PA,
PortletSession.APPLICATION_SCOPE);
MutablePortletApplication pa = registry.getPortletApplication(paName);
String selectedPortlet = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_PORTLET);
if(selectedPortlet != null)
{
actionRequest.getPortletSession().setAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, selectedPortlet, PortletSession.APPLICATION_SCOPE);
}
String selectedTab = actionRequest.getParameter(PortletApplicationResources.REQUEST_SELECT_TAB);
if(selectedTab != null)
{
TabBean tab = (TabBean) paTabMap.get(selectedTab);
actionRequest.getPortletSession().setAttribute(PortletApplicationResources.REQUEST_SELECT_TAB, tab, PortletSession.APPLICATION_SCOPE);
}
String selectedPortletTab = actionRequest.getParameter("selected_portlet_tab");
if(selectedPortletTab != null)
{
TabBean tab = (TabBean) pdTabMap.get(selectedPortletTab);
actionRequest.getPortletSession().setAttribute("selected_portlet_tab", tab);
}
String action = actionRequest.getParameter(PORTLET_ACTION);
if(action != null)
{
if(isAppAction(action))
{
action = getAction(PORTLET_APP_ACTION_PREFIX, action);
if(action.endsWith("metadata"))
{
processMetadataAction(actionRequest, actionResponse, pa.getMetadata(), action);
}
else if(action.endsWith("user_attribute"))
{
processUserAttributeAction(actionRequest, actionResponse, pa, action);
}
}
else if(isPortletAction(action))
{
action = getAction(PORTLET_ACTION_PREFIX, action);
String pdefName = (String) actionRequest.getPortletSession().getAttribute(PortletApplicationResources.REQUEST_SELECT_PORTLET, PortletSession.APPLICATION_SCOPE);
PortletDefinitionComposite pdef = (PortletDefinitionComposite) pa.getPortletDefinitionByName(pdefName);
if(action.endsWith("metadata"))
{
processMetadataAction(actionRequest, actionResponse, pdef.getMetadata(), action);
}
else if(action.endsWith("portlet"))
{
processPortletAction(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("preference"))
{
processPreferenceAction(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("language"))
{
processLanguage(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("parameter"))
{
processParameter(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("security"))
{
processSecurity(actionRequest, actionResponse, pa, pdef, action);
}
else if(action.endsWith("content_type"))
{
processContentType(actionRequest, actionResponse, pa, pdef, action);
}
}
}
}
private boolean isAppAction(String action)
{
return action.startsWith(PORTLET_APP_ACTION_PREFIX);
}
private boolean isPortletAction(String action)
{
return action.startsWith(PORTLET_ACTION_PREFIX);
}
private String getAction(String prefix, String action)
{
return action.substring(prefix.length());
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param action
*/
private void processUserAttributeAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, String action) throws PortletException, IOException
{
if(action.equals("edit_user_attribute"))
{
Iterator userAttrIter = pa.getUserAttributes().iterator();
while (userAttrIter.hasNext())
{
UserAttribute userAttr = (UserAttribute) userAttrIter.next();
String userAttrName = userAttr.getName();
String description = actionRequest.getParameter(userAttrName + ":description");
if(!userAttr.getDescription().equals(description))
{
userAttr.setDescription(description);
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("add_user_attribute"))
{
String userAttrName = actionRequest.getParameter("user_attr_name");
String userAttrDesc = actionRequest.getParameter("user_attr_desc");
if(userAttrName != null)
{
pa.addUserAttribute(userAttrName, userAttrDesc);
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("remove_user_attribute"))
{
String[] userAttrNames = actionRequest.getParameterValues("user_attr_id");
if(userAttrNames != null)
{
Iterator userAttrIter = pa.getUserAttributes().iterator();
while (userAttrIter.hasNext())
{
UserAttribute userAttr = (UserAttribute) userAttrIter.next();
for(int i=0; i<userAttrNames.length; i++)
{
String userAttrName = userAttrNames[i];
if(userAttr.getName().equals(userAttrName))
{
userAttrIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param action
* @throws PortletException
* @throws IOException
*/
private void processMetadataAction(ActionRequest actionRequest, ActionResponse actionResponse, GenericMetadata md, String action) throws PortletException, IOException
{
if(action.equals("edit_metadata"))
{
Iterator fieldsIter = md.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);
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_metadata"))
{
Iterator fieldsIter = md.getFields().iterator();
String[] ids = actionRequest.getParameterValues("metadata_id");
if(ids != null)
{
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();
break;
}
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("add_metadata"))
{
String name = actionRequest.getParameter("name");
String value = actionRequest.getParameter("value");
String localeParam = actionRequest.getParameter("locale");
if(localeParam == null)
{
localeParam = "en"; //need to default better
}
Locale locale = new Locale(localeParam);
md.addField(locale, name, value);
registry.getPersistenceStore().getTransaction().commit();
}
}
private void processPortletAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action) throws PortletException, IOException
{
if(action.equals("edit_portlet"))
{
String displayNameParam = actionRequest.getParameter("display_name");
if(displayNameParam == null)
{
int index = 0;
Iterator displayNameIter = portlet.getDisplayNameSet().iterator();
while (displayNameIter.hasNext())
{
MutableDisplayName displayName = (MutableDisplayName) displayNameIter.next();
displayNameParam = actionRequest.getParameter("display_name:" + index);
//this should never happen
if(displayNameParam != null)
{
if(displayNameParam.length() == 0)
{
displayNameIter.remove();
}
else if(!displayNameParam.equals(displayName.getDisplayName()))
{
displayName.setDisplayName(displayNameParam);
}
}
index++;
}
}
else
{
String locale = actionRequest.getParameter("locale");
portlet.addDisplayName(new Locale(locale), displayNameParam);
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_portlet"))
{
//TODO should this be allowed??
}
else if(action.equals("add_portlet"))
{
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processPreferenceAction(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_preference"))
{
String name = actionRequest.getParameter("name");
String value = actionRequest.getParameter("value");
PreferenceComposite pref = (PreferenceComposite) portlet.getPreferenceSet().get(name);
if(pref == null)
{
portlet.addPreference(name, new String[] { value });
}
else
{
pref.addValue(value);
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("edit_preference"))
{
String[] prefNames = actionRequest.getParameterValues("pref_edit_id");
for (int i = 0; i < prefNames.length; i++)
{
String prefName = prefNames[i];
PreferenceComposite prefComp = (PreferenceComposite) portlet.getPreferenceSet().get(prefName);
String[] values = prefComp.getValueArray();
for (int j = 0; j < values.length; j++)
{
String value = values[j];
String newValue = actionRequest.getParameter(prefName + ":" + j);
if(!value.equals(newValue))
{
prefComp.setValueAt(j, newValue);
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_preference"))
{
String[] prefNames = actionRequest.getParameterValues("pref_remove_id");
Iterator prefIter = portlet.getPreferenceSet().iterator();
while (prefIter.hasNext())
{
PreferenceComposite pref = (PreferenceComposite) prefIter.next();
String name = pref.getName();
for(int i=0; i<prefNames.length; i++)
{
String prefName = prefNames[i];
if(name.equals(prefName))
{
prefIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processLanguage(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_language"))
{
String title = actionRequest.getParameter("title");
String shortTitle = actionRequest.getParameter("short_title");
String keywords = actionRequest.getParameter("keyword");
String locale = actionRequest.getParameter("locale");
LanguageImpl language = new LanguageImpl();
language.setTitle(title);
language.setShortTitle(shortTitle);
language.setKeywords(keywords);
language.setLocale(new Locale(locale));
portlet.addLanguage(language);
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_language"))
{
String[] removeIds = actionRequest.getParameterValues("language_remove_id");
if(removeIds != null)
{
int id = 0;
Iterator langIter = portlet.getLanguageSet().iterator();
while (langIter.hasNext())
{
langIter.next();
int currentId = id++;
for(int i=0; i<removeIds.length; i++)
{
String removeId = removeIds[i];
String tempId = "" + currentId;
if(removeId.equals(tempId))
{
langIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_language"))
{
String[] editIds = actionRequest.getParameterValues("language_edit_id");
if(editIds != null)
{
//technically, the size and set of edit ids should be
//equal to the size and set of the language set
int id = 0;
Iterator langIter = portlet.getLanguageSet().iterator();
while (langIter.hasNext())
{
String title = actionRequest.getParameter("title:" + id);
String shortTitle = actionRequest.getParameter("short_title:" + id);
//must cast to interface to avoid class loader issues
MutableLanguage lang = (MutableLanguage) langIter.next();
if(!lang.getTitle().equals(title))
{
lang.setTitle(title);
}
Iterator keywordIter = lang.getKeywords();
int keywordIndex = 0;
ArrayList keywordList = new ArrayList();
while (keywordIter.hasNext())
{
String keyword = (String) keywordIter.next();
String keywordParam = actionRequest.getParameter("keyword:" + id + ":" + keywordIndex);
if(keywordParam != null && keywordParam.length() > 0)
{
keywordList.add(keywordParam);
}
keywordIndex++;
}
lang.setKeywords(keywordList);
if(!lang.getShortTitle().equals(shortTitle))
{
lang.setShortTitle(shortTitle);
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processParameter(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_parameter"))
{
String name = actionRequest.getParameter("name");
if(name != null)
{
String description = actionRequest.getParameter("description");
String locale = actionRequest.getParameter("locale");
ParameterComposite parameter = (ParameterComposite)portlet.getInitParameterSet().get(name);
if(parameter == null)
{
String value = actionRequest.getParameter("value");
parameter = portlet.addInitParameter(name, value, description, new Locale(locale));
}
else
{
parameter.addDescription(new Locale(locale), description);
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_parameter"))
{
String[] paramIds = actionRequest.getParameterValues("parameter_edit_id");
if(paramIds != null)
{
for(int i=0; i<paramIds.length; i++)
{
String paramId = paramIds[i];
ParameterComposite param = (ParameterComposite) portlet.getInitParameterSet().get(paramId);
String value = actionRequest.getParameter(paramId + ":value");
param.setValue(value);
int index = 0;
Iterator descIter = param.getDescriptionSet().iterator();
while (descIter.hasNext())
{
MutableDescription description = (MutableDescription) descIter.next();
String descParam = actionRequest.getParameter(paramId + ":description:" + index);
//changing locale not allowed.
if(descParam != null)
{
if(descParam.length() == 0)
{
descIter.remove();
}
else if(!descParam.equals(description.getDescription()))
{
description.setDescription(descParam);
}
}
index++;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_parameter"))
{
String[] paramIds = actionRequest.getParameterValues("parameter_remove_id");
if(paramIds != null)
{
Iterator paramIter = portlet.getInitParameterSet().iterator();
while (paramIter.hasNext())
{
ParameterComposite param = (ParameterComposite) paramIter.next();
for(int i=0; i<paramIds.length; i++)
{
String paramId = paramIds[i];
if(param.getName().equals(paramId))
{
paramIter.remove();
break;
}
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processSecurity(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_security"))
{
String name = actionRequest.getParameter("name");
if(name != null)
{
String link = actionRequest.getParameter("link");
SecurityRoleRefComposite securityRoleRef = (SecurityRoleRefComposite) portlet.getInitSecurityRoleRefSet().get(name);
if(securityRoleRef == null && link != null)
{
securityRoleRef = new SecurityRoleRefImpl();
securityRoleRef.setRoleName(name);
securityRoleRef.setRoleLink(link);
portlet.addSecurityRoleRef(securityRoleRef);
}
if(securityRoleRef != null)
{
String description = actionRequest.getParameter("description");
if(description != null && description.length() > 0)
{
String locale = actionRequest.getParameter("locale");
if(locale == null)
{
locale = "en";
}
securityRoleRef.addDescription(new Locale(locale), description);
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_security"))
{
Iterator securityIter = portlet.getInitSecurityRoleRefSet().iterator();
while (securityIter.hasNext())
{
SecurityRoleRefComposite secRef = (SecurityRoleRefComposite) securityIter.next();
String name = secRef.getRoleName();
//TODO: should this be editable
String newName = actionRequest.getParameter(name + ":name");
String link = actionRequest.getParameter(name + ":link");
if(!secRef.getRoleLink().equals(link))
{
secRef.setRoleLink(link);
}
int index = 0;
Iterator descIter = secRef.getDescriptionSet().iterator();
while (descIter.hasNext())
{
MutableDescription description = (MutableDescription) descIter.next();
String descParam = actionRequest.getParameter(name + ":description:" + index);
//changing locale not allowed.
if(descParam != null)
{
if(descParam.length() == 0)
{
descIter.remove();
}
else if(!descParam.equals(description.getDescription()))
{
description.setDescription(descParam);
}
}
index++;
}
}
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_security"))
{
String[] securityIds = actionRequest.getParameterValues("security_remove_id");
if(securityIds != null)
{
for(int i=0; i<securityIds.length; i++)
{
String id = securityIds[i];
SecurityRoleRef secRef = portlet.getInitSecurityRoleRefSet().get(id);
portlet.getInitSecurityRoleRefSet().remove(secRef);
}
/*
Iterator securityIter = portlet.getInitSecurityRoleRefSet()..iterator();
while (securityIter.hasNext())
{
SecurityRoleRefComposite secRef = (SecurityRoleRefComposite) securityIter.next();
for(int i=0; i<securityIds.length; i++)
{
String id = securityIds[i];
if(secRef.getRoleName().equals(id))
{
securityIter.remove();
break;
}
}
}
*/
}
registry.getPersistenceStore().getTransaction().commit();
}
}
/**
* @param actionRequest
* @param actionResponse
* @param pa
* @param pdef
* @param action
*/
private void processContentType(ActionRequest actionRequest, ActionResponse actionResponse, MutablePortletApplication pa, PortletDefinitionComposite portlet, String action)
{
if(action.equals("add_content_type"))
{
String contentType = actionRequest.getParameter("content_type");
if(contentType != null)
{
ContentTypeImpl contentTypeImpl = new ContentTypeImpl();
contentTypeImpl.setContentType(contentType);
String[] modes = actionRequest.getParameterValues("mode");
if(modes != null)
{
for(int i=0; i<modes.length; i++)
{
String mode = modes[i];
contentTypeImpl.addPortletMode(mode);
}
}
String customModes = actionRequest.getParameter("custom_modes");
StringTokenizer tok = new StringTokenizer(customModes, ",");
while (tok.hasMoreTokens())
{
contentTypeImpl.addPortletMode(tok.nextToken());
}
portlet.addContentType(contentTypeImpl);
registry.getPersistenceStore().getTransaction().commit();
}
}
else if(action.equals("edit_content_type"))
{
registry.getPersistenceStore().getTransaction().commit();
}
else if(action.equals("remove_content_type"))
{
String[] contentIds = actionRequest.getParameterValues("content_type_remove_id");
if(contentIds != null)
{
Iterator contentIter = portlet.getContentTypeSet().iterator();
while (contentIter.hasNext())
{
ContentType contentType = (ContentType) contentIter.next();
for(int i=0; i<contentIds.length; i++)
{
String id = contentIds[i];
if(contentType.getContentType().equals(id))
{
contentIter.remove();
break;
}
}
}
registry.getPersistenceStore().getTransaction().commit();
}
}
}
}
1.9 +7 -1 jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet/MutablePortletApplication.java
Index: MutablePortletApplication.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/jetspeed-api/src/java/org/apache/jetspeed/om/common/portlet/MutablePortletApplication.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- MutablePortletApplication.java 14 Aug 2004 00:22:15 -0000 1.8
+++ MutablePortletApplication.java 29 Sep 2004 20:31:35 -0000 1.9
@@ -76,6 +76,12 @@
* @param userAttribute The user attribute.
*/
void addUserAttribute(UserAttribute userAttribute);
+
+ /**
+ * <p>Adds a user attribute to the user attribute set.</p>
+ * @param userAttribute The user attribute.
+ */
+ void addUserAttribute(String name, String description);
/**
* <p>Sets a user-attribute-ref to the collection of user attribute refs associated
1.20 +13 -1 jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletApplicationDefinitionImpl.java
Index: PortletApplicationDefinitionImpl.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/portlet/impl/PortletApplicationDefinitionImpl.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- PortletApplicationDefinitionImpl.java 16 Aug 2004 18:29:13 -0000 1.19
+++ PortletApplicationDefinitionImpl.java 29 Sep 2004 20:31:35 -0000 1.20
@@ -28,6 +28,7 @@
import org.apache.jetspeed.om.common.UserAttributeRef;
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.om.impl.UserAttributeImpl;
import org.apache.jetspeed.util.JetspeedObjectID;
import org.apache.pluto.om.common.ObjectID;
import org.apache.pluto.om.portlet.PortletDefinition;
@@ -252,6 +253,17 @@
*/
public void addUserAttribute(UserAttribute userAttribute)
{
+ userAttributes.add(userAttribute);
+ }
+
+ /**
+ * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttribute(java.lang.String, java.lang.String)
+ */
+ public void addUserAttribute(String userName, String description)
+ {
+ UserAttributeImpl userAttribute = new UserAttributeImpl();
+ userAttribute.setName(userName);
+ userAttribute.setDescription(description);
userAttributes.add(userAttribute);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org