{
unregisterPortletApplication(oldPA, false);
oldPA = null;
}
MutablePortletApplication pa = null;
boolean registered = false;
String paName = paWar.getPortletApplicationName();
try
{
log.info("Loading portlet.xml...." + paName);
pa = paWar.createPortletApp(paClassLoader);
pa.setApplicationType(paType);
// load the web.xml
log.info("Loading web.xml...." + paName);
MutableWebApplication wa = paWar.createWebApp();
paWar.validate();
if (paType == MutablePortletApplication.LOCAL)
{
wa.setContextRoot("<portal>");
}
else if (paType == MutablePortletApplication.INTERNAL)
{
// TODO: this is screwing up the PSML as its set all over the place to "jetspeed-layouts", not good
wa.setContextRoot("/" + paName);
}
pa.setWebApplicationDefinition(wa);
// Make sure existing entities are refreshed with the most
// recent PortletDefintion.
Collection portletDefs = pa.getPortletDefinitions();
if(portletDefs != null && portletDefs.size() > 0)
{
Iterator pdItr = portletDefs.iterator();
while(pdItr.hasNext())
{
PortletDefinition pd = (PortletDefinition) pdItr.next();
Collection portletEntites = entityAccess.getPortletEntities(pd);
if(portletEntites != null && portletEntites.size() > 0)
{
Iterator peItr = portletEntites.iterator();
while(peItr.hasNext())
{
PortletEntityCtrl portletEntity = (PortletEntityCtrl) peItr.next();
portletEntity.setPortletDefinition(pd);
}
}
}
}
}
catch (Exception e)
{
String msg = "Failed to load portlet application for "
+ paWar.getPortletApplicationName();
log.error(msg, e);
throw new RegistryException(msg);
}
// register the portlet application
try
{
registry.registerPortletApplication(pa);
registered = true;
log.info("Registered the portlet application " + paName);
// add to search engine result
this.updateSearchEngine(false, pa);
// and add to the current node info
nodeManager.addNode(new Long(pa.getId().toString()), pa.getName());
// grant default permissions to portlet application
grantDefaultPermissions(paName);
if ( autoCreateRoles && roleManager != null && pa.getWebApplicationDefinition().getSecurityRoles() != null )
{
try
{
Iterator rolesIter = pa.getWebApplicationDefinition().getSecurityRoles().iterator();
SecurityRole sr;
while ( rolesIter.hasNext() )
{
sr = (SecurityRole)rolesIter.next();
if ( !roleManager.roleExists(sr.getRoleName()) )