* @
*/
private Collection getTabs(PortletSet portlets, RunData rundata, Context context)
{
TreeSet tabs = new TreeSet(new PortletTabComparator());
PanedPortletController controller = null;
// if portlet is a PortletSet, try to retrieve the Controller
// we need a PanedPortletController to work properly.
if (portlets.getController() instanceof PanedPortletController)
{
controller = (PanedPortletController) portlets.getController();
}
int count = 0;
for (Enumeration en = portlets.getPortlets(); en.hasMoreElements(); count++)
{
Portlet p = (Portlet) en.nextElement();
PortalResource portalResource = new PortalResource(p);
// Secure the tabs
try
{
JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata);
portalResource.setOwner(jsLink.getUserName());
JetspeedLinkFactory.putInstance(jsLink);
}
catch (Exception e)
{
logger.warn(e.toString(), e);
portalResource.setOwner(null);
}
JetspeedRunData jdata = (JetspeedRunData) rundata;
boolean hasView = JetspeedSecurity.checkPermission((JetspeedUser) jdata.getUser(),
portalResource,
JetspeedSecurity.PERMISSION_VIEW);
if (!hasView)
{
continue;
}
// skip any closed portlet
if ((p instanceof PortletState) && (((PortletState) p).isClosed(rundata)))
{
continue;
}
String mstate = p.getAttribute("_menustate", null, rundata);
PortletConfig pc= p.getPortletConfig();
if (mstate == null && pc != null)
{
mstate = pc.getInitParameter("_menustate", "open");
}
if (mstate.equals("closed"))
{
continue;
}
PortletTab tab = new PortletTab();
// Handle the portlet title
String title = null;
PortletInstance pi = PersistenceManager.getInstance(p, rundata);
if (pi != null)
{
title = pi.getTitle();
if (title == null)
{
title = (p.getTitle() != null) ? p.getTitle() : p.getName();
}
}
tab.setTitle(title);
tab.setPosition(p.getPortletConfig().getPosition());
if (tabs.contains(tab))
{
PortletTab lastTab = (PortletTab) tabs.last();
int nextPos = lastTab.getPosition() + 1;
tab.setPosition(nextPos);
}
if (controller != null)
{
tab.setSelected(controller.isSelected(p, rundata));
tab.setLink(controller.getPortletURI(p, rundata).toString());
}
tab.setActions(buildActionList(rundata, p));
tabs.add(tab);
}