/**
* @param rundata The RunData object for the current request
*/
public void doPerform( RunData rundata ) throws Exception
{
JetspeedRunData jdata = (JetspeedRunData)rundata;
if (jdata.getUser() == null)
{
return;
}
if(jdata.getProfile() == null)
{
return;
}
// read some parameters
String editMediaType = jdata.getParameters().getString ("mtype");
String resetStack = jdata.getParameters().getString ("reset");
String peid = jdata.getParameters().getString("js_peid");
Entry entry = jdata.getProfile().getDocument().getEntryById(peid);
if (entry != null)
{
if (null != entry.getParameter(J2_ENTITY))
{
return; // JSR 168 portlet, let it handle its own Help Mode
}
}
// get the customization state for this page
SessionState customizationState = jdata.getPageSessionState();
// this will be the profile we are editing
Profile profile = null;
// the "reset" parameter's presence signals the start of customization
if ( (resetStack != null)
&& ((resetStack.equalsIgnoreCase("on")) || (resetStack.equalsIgnoreCase("1"))))
{
// clear out any prior customization state
jdata.cleanupFromCustomization();
}
// if we have not yet setup for customization, do so now
if (jdata.getCustomizedProfile() == null)
{
ProfileLocator locator = (ProfileLocator)jdata.getProfile().clone();
if (editMediaType != null)
{
locator.setMediaType(editMediaType);
}
// get a profile to edit
profile = (Profile) Profiler.getProfile(locator).clone();
jdata.setCustomizedProfile(profile);
}
// we are continuing an on-going customization
else
{
// get the profile we are working on
profile = jdata.getCustomizedProfile();
}
// Get js_peid parmameter.
// If it does not exist, we will customize the root of the profile
if ( peid == null )
{
// use the id of the root set of the profile
peid = profile.getRootSet().getID();
jdata.setJs_peid(peid);
}
// find the portlet within the profile with this peid %%% isn't there a better way to do this? -ggolden
Portlet found = null;
Stack sets = new Stack();
sets.push(profile.getRootSet());
while ((found==null) && (sets.size() > 0))
{
PortletSet set = (PortletSet)sets.pop();
if (set.getID().equals(peid))
{
found = set;
}
else
{
Enumeration en = set.getPortlets();
while((found==null) && en.hasMoreElements())
{
Portlet p = (Portlet)en.nextElement();
// unstack the controls to find the real PortletSets
Portlet real = p;
while (real instanceof PortletControl)
{
real = ((PortletControl)p).getPortlet();
}
if (real instanceof PortletSet)
{
if (real.getID().equals(peid))
{
found=real;
}
else
{
// we'll explore this set afterwards
sets.push(real);
}
}
else if (p.getID().equals(peid))
{
found = p;
}
}
}
}
if (found!=null)
{
PortalResource portalResource = new PortalResource(found);
try
{
JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata);
portalResource.setOwner(jsLink.getUserName());
JetspeedLinkFactory.putInstance(jsLink);
}
catch (Exception e)
{
logger.warn(e.toString());
portalResource.setOwner(null);
}
if(!JetspeedSecurity.checkPermission((JetspeedUser) jdata.getUser(),
portalResource,
JetspeedSecurity.PERMISSION_CUSTOMIZE))
{
logger.warn("User " + jdata.getUser().getUserName() + " has no customize permission for portlet with id " + peid);
jdata.setMessage("Sorry, you have no customize permission for this portlet");
return;
}
jdata.setCustomized(found);
jdata.setScreenTemplate("Customize");
}
}