final PortletMode previousPortletMode = portletWindow.getPortletMode();
//Only do this stuff for the top level window
if (delegationParentId == null) {
//Get the channel runtime data from the request attributes, it should have been set there by the portlet adapter
final ChannelRuntimeData channelRuntimeData = (ChannelRuntimeData)request.getAttribute(IPortletAdaptor.ATTRIBUTE__RUNTIME_DATA);
if (channelRuntimeData == null) {
throw new IllegalStateException("No ChannelRuntimeData was found as a request attribute for key '" + IPortletAdaptor.ATTRIBUTE__RUNTIME_DATA + "' on request '" + request + "'");
}
// Determine the base path for the URL
// If the next state is EXCLUSIVE or there is no state change and the current state is EXCLUSIVE use the worker URL base
if (IPortletAdaptor.EXCLUSIVE.equals(windowState) || (windowState == null && IPortletAdaptor.EXCLUSIVE.equals(previousWindowState))) {
final String urlBase = channelRuntimeData.getBaseWorkerURL(UPFileSpec.FILE_DOWNLOAD_WORKER);
url.append(urlBase);
}
//In detached, need to make sure the URL is right
else if (IPortletAdaptor.DETACHED.equals(windowState) || (windowState == null && IPortletAdaptor.DETACHED.equals(previousWindowState))) {
final UPFileSpec upFileSpec = new UPFileSpec(channelRuntimeData.getUPFile());
upFileSpec.setMethodNodeId(channelSubscribeId);
upFileSpec.setTargetNodeId(channelSubscribeId);
final String urlBase = upFileSpec.getUPFile();
url.append(urlBase);
}
//Switching back from detached to a normal state
else if (IPortletAdaptor.DETACHED.equals(previousWindowState) && windowState != null && !previousWindowState.equals(windowState)) {
final UPFileSpec upFileSpec = new UPFileSpec(channelRuntimeData.getUPFile());
upFileSpec.setMethodNodeId(UPFileSpec.USER_LAYOUT_ROOT_NODE);
final String urlBase = upFileSpec.getUPFile();
url.append(urlBase);
}
//No special handling, just use the base action URL
else {
final String urlBase = channelRuntimeData.getBaseActionURL();
url.append(urlBase);
}
if (this.logger.isTraceEnabled()) {
this.logger.trace("Using root url base '" + url + "' for " + portletUrl);