// check if the user has permissions to instantiate this channel
final IChannel channel;
if(authorizationPrincipal.canRender(Integer.parseInt(channelPublishId))) {
if (request == null) {
channel = new CError(ErrorCode.GENERAL_ERROR, "Unable to get SessionId. No HttpServletRequest provided.", channelSubscribeId, null);
}
else {
final HttpSession session = request.getSession();
final String sessionId = session.getId();
channel = ChannelFactory.instantiateLayoutChannel(channelDescription, sessionId);
if (channel == null) {
throw new IllegalStateException("ChannelFactory returned null on request to instantiate layout channel with id [" + sessionId + "] and description [" + channelDescription + "]");
}
final IPerson person = userPreferencesManager.getPerson();
final ApplicationEventPublisher applicationEventPublisher = EventPublisherLocator.getApplicationEventPublisher();
final UserProfile currentProfile = userPreferencesManager.getCurrentProfile();
IUserLayoutNodeDescription parentNode = null;
try {
final IUserLayoutManager userLayoutManager = userPreferencesManager.getUserLayoutManager();
final String parentNodeId = userLayoutManager.getParentId(channelDescription.getId());
if (parentNodeId != null) {
parentNode = userLayoutManager.getNode(parentNodeId);
}
}
catch (PortalException pe) {
log.warn("Failed to load parent IUserLayoutNodeDescription for channel with subscribe id: " + channelDescription.getChannelPublishId(), pe);
}
applicationEventPublisher.publishEvent(new ChannelInstanciatedInLayoutPortalEvent(this, person, currentProfile, channelDescription, parentNode));
// Create and stuff the channel static data
final ChannelStaticData channelStaticData = new ChannelStaticData(channelDescription.getParameterMap(), userPreferencesManager.getUserLayoutManager());
channelStaticData.setChannelSubscribeId(channelSubscribeId);
channelStaticData.setTimeout(channelDescription.getTimeout());
channelStaticData.setPerson(person);
channelStaticData.setJNDIContext(channelContext);
channelStaticData.setICCRegistry(new ICCRegistry(this, channelSubscribeId));
channelStaticData.setChannelPublishId(channelDescription.getChannelPublishId());
channelStaticData.setSerializerName(serializerName);
channelStaticData.setWebApplicationContext(PortalApplicationContextLocator.getRequiredWebApplicationContext());
if (channel instanceof IPrivileged) {
this.feedPortalControlStructuresToChannel(request, response, channelSubscribeId, (IPrivileged)channel);
}
channel.setStaticData(channelStaticData);
}
}
else {
// user is not authorized to instantiate this channel
// create an instance of an error channel instead
channel = new CError(ErrorCode.CHANNEL_AUTHORIZATION_EXCEPTION, "You don't have authorization to render this channel.", channelSubscribeId, null);
}
this.channelTable.put(channelSubscribeId, channel);
return channel;
}