String method = request.getParameter("position");
IChannelRegistryStore channelRegistryStore = ChannelRegistryStoreFactory.getChannelRegistryStoreImpl();
IChannelDefinition definition = channelRegistryStore.getChannelDefinition(sourceId);
IUserLayoutChannelDescription channel = new UserLayoutChannelDescription(definition);
for (IChannelParameter param : definition.getParameters()) {
if (param.getOverride()) {
String paramValue = request.getParameter(param.getName());
if (paramValue != null) {
channel.setParameterValue(param.getName(), param.getValue());
}
}
}
IUserLayoutNodeDescription node = null;
if (isTab(ulm, destinationId)) {
Enumeration columns = ulm.getChildIds(destinationId);
if (columns.hasMoreElements()) {
while (columns.hasMoreElements()) {
// attempt to add this channel to the column
node = ulm.addNode(channel, (String) columns.nextElement(),
null);
// if it couldn't be added to this column, go on and try the next
// one. otherwise, we're set.
if (node != null)
break;
}
} else {
IUserLayoutFolderDescription newColumn = new UserLayoutFolderDescription();
newColumn.setName("Column");
newColumn.setId("tbd");
newColumn
.setFolderType(IUserLayoutFolderDescription.REGULAR_TYPE);
newColumn.setHidden(false);
newColumn.setUnremovable(false);
newColumn.setImmutable(false);
// add the column to our layout
IUserLayoutNodeDescription col = ulm.addNode(newColumn,
destinationId, null);
// add the channel
node = ulm.addNode(channel, col.getId(), null);
}
} else if (isColumn(ulm, destinationId)) {
// move the channel into the column
node = ulm.addNode(channel, destinationId, null);
} else {
// If we're moving this element before another one, we need
// to know what the target is. If there's no target, just
// assume we're moving it to the very end of the column.
String siblingId = null;
if (method.equals("insertBefore"))
siblingId = destinationId;
// move the node as requested and save the layout
node = ulm.addNode(channel, ulm.getParentId(destinationId),
siblingId);
}
String nodeId = node.getId();
// instantiate the channel in the user's layout
final HttpSession session = request.getSession(false);
ChannelManager cm = new ChannelManager(upm, session);
cm.instantiateChannel(new PortalHttpServletRequestWrapper(request, response, userInstanceManager), response, channel.getId());
try {
// save the user's layout
saveUserLayoutPreservingTab(ulm, upm, per);
} catch (Exception e) {