Context context,
RunData rundata) throws Exception
{
JetspeedRunData jdata = (JetspeedRunData) rundata;
SessionState customizationState = jdata.getPageSessionState();
Profile profile = jdata.getCustomizedProfile();
String mediaType = profile.getMediaType ();
// set velocity variable of mediatype (displayed in the customizer menu)
context.put("mtype", profile.getMediaType());
// make the list of already used panes/portlets available through the 'runs' reference
context.put("runs", AutoProfile.getPortletList(rundata));
// we should first retrieve the portlet to customize
PortletSet set = (PortletSet) (jdata).getCustomized();
//identify the portlet submode and build the appropriate subt-template path
String mode = rundata.getParameters().getString("mode");
if (mode == null)
{
mode = (String) customizationState.getAttribute("customize-mode");
if ((mode == null) || (mode.equalsIgnoreCase("addset")) || (mode.equalsIgnoreCase("general")))
{
mode = "layout";
}
}
else
{
if ((mediaType.equalsIgnoreCase("wml")) && (!mode.equalsIgnoreCase("add")))
{
mode = "layout";
}
customizationState.setAttribute("customize-mode", mode);
}
String template = (String) context.get("template");
if (template != null)
{
int idx = template.lastIndexOf(".");
if (idx > 0)
{
template = template.substring(0, idx);
}
StringBuffer buffer = new StringBuffer(template);
buffer.append("-").append(mode).append(".vm");
template = TemplateLocator.locatePortletTemplate(rundata, buffer.toString());
context.put("feature", template);
}
if (set == null)
{
return;
}
// get the customization state for this page
String customizedPaneName = (String) customizationState.getAttribute("customize-paneName");
if (customizedPaneName == null)
{
customizedPaneName = "*";
}
// generic context stuff
context.put("panename", customizedPaneName);
context.put("skin", set.getPortletConfig().getPortletSkin());
context.put("set", set);
context.put("action", "portlets.CustomizeSetAction");
context.put("controllers", buildInfoList(rundata, Registry.PORTLET_CONTROLLER, mediaType));
//context.put("skins", buildList(rundata, Registry.SKIN));
//context.put("securitys", buildList(rundata, Registry.SECURITY));
context.put("customizer", portlet);
String controllerName = set.getController().getConfig().getName();
context.put("currentController", controllerName);
context.put("currentSecurityRef", set.getPortletConfig().getSecurityRef());
/**
* Special handling for wml profiles
* no skins, no properties menuentry, no panes
* --------------------------------------------------------------------------
* last modified: 12/10/01
* Andreas Kempf, Siemens ICM S CP OP, Munich
* mailto: A.Kempf@web.de
*/
if (mediaType.equalsIgnoreCase("wml"))
{
context.put("currentSkin", "Not for wml!");
context.put("allowproperties", "false");
}
else
{
if (set.getPortletConfig().getSkin() != null)
{
context.put("currentSkin", set.getPortletConfig().getPortletSkin().getName());
}
context.put("allowproperties", "true");
}
context.put("allowpane", "false");
// do not allow panes for wml profiles
if ((!mediaType.equalsIgnoreCase("wml")) && (set.getController() instanceof PortletSetController))
{
if (customizedPaneName != null)
{
context.put("allowpane", "true");
}
}
else
{
context.put("allowportlet", "true");
}
// --------------------------------------------------------------------------
if ("add".equals(mode)) // build context for add mode
{
int start = rundata.getParameters().getInt("start", -1);
if (start < 0)
{
//System.out.println("Clearing session variables");
start = 0;
PortletSessionState.clearAttribute(rundata, USER_SELECTIONS);
PortletSessionState.clearAttribute(rundata, PORTLET_LIST);
}
ArrayList allPortlets = new ArrayList();
List portlets = buildPortletList(rundata, set, mediaType, allPortlets);
Map userSelections = getUserSelections(rundata);
// Build a list of categories from the available portlets
List categories = buildCategoryList(rundata, mediaType, allPortlets);
context.put("categories", categories);
int size = getSize(portlet);
int end = Math.min(start + size, portlets.size());
if (start > 0)
{
context.put("prev", String.valueOf(Math.max(start - size, 0)));
}
if (start + size < portlets.size())
{
context.put("next", String.valueOf(start + size));
}
context.put("browser", portlets.subList(start, end));
context.put("size", new Integer(size));
context.put(UI_PORTLETS_SELECTED, userSelections);
context.put("portlets", portlets);
}
else if ("addref".equals(mode))
{
Iterator psmlIterator = null;
psmlIterator = Profiler.query(new QueryLocator(QueryLocator.QUERY_ALL));
// Set Start and End
int start = rundata.getParameters().getInt("start", 0);
int size = getSize(portlet);
// Only include entries in compatibale with the Media-type/Country/Language
List psmlList = new LinkedList();
Profile refProfile = null;
int profileCounter = 0;
while (psmlIterator.hasNext())
{
refProfile = (Profile) psmlIterator.next();
if (refProfile.getMediaType() != null)
{
if (profile.getMediaType().equals(refProfile.getMediaType()) == false)
{
continue;
}
}
if (profile.getLanguage() != null)
{
if (refProfile.getLanguage() != null)
{
if (profile.getLanguage().equals(refProfile.getLanguage()) == true)
{
if (profile.getCountry() != null)
{
if (refProfile.getCountry() != null)
{
if (profile.getCountry().equals(refProfile.getCountry()) == false)
{
// Profile and Ref are different countries
continue;
}
}
}
else
{
if (refProfile.getCountry() != null)
{
// Profile has no country and Ref has a country
continue;
}
}
}
else
{
// Profile and Ref are different languages
continue;
}
}
}
else
{
if (refProfile.getLanguage() != null)
{
// Profile has no Language and Ref has a country
continue;
}
}
if (profile.getPath().equals(refProfile.getPath()) == true)
{
// Do not allow Profile to reference it self
continue;
}