{
Workspace workspace = session.getWorkspace();
Site site = workspace.getSite(siteType, ownerId);
//
Customization customization = null;
if (site != null)
{
if (instanceName.startsWith("@"))
{
String id = instanceName.substring(1);
UIWindow window = session.findObjectById(ObjectType.WINDOW, id);
// Should check it's pointing to same instance though
customization = window.getCustomization();
}
else
{
int pos = instanceName.indexOf("#");
if (pos != -1)
{
String a = instanceName.substring(0, pos);
String b = instanceName.substring(pos + 1);
Page page = site.getRootPage().getChild("pages").getChild(b);
Customization c = page.getCustomizationContext().getCustomization(a);
if (c != null)
{
c.destroy();
}
customization =
page.getCustomizationContext().customize(a, Portlet.CONTENT_TYPE, applicationName + "/" + portletName,
new PortletBuilder().build());
}
else
{
Customization c = site.getCustomizationContext().getCustomization(instanceName);
if (c != null)
{
c.destroy();
}
customization =
site.getCustomizationContext().customize(instanceName, Portlet.CONTENT_TYPE, applicationName + "/" + portletName,
new PortletBuilder().build());
}