String parentId,
String nextSiblingId )
throws PortalException
{
boolean isChannel=false;
IUserLayoutNodeDescription parent=this.getNode(parentId);
if( canAddNode( node, parent, nextSiblingId ) )
{
// assign new Id
try {
if(node instanceof IUserLayoutChannelDescription) {
isChannel=true;
node.setId(this.distributedLayoutStore.generateNewChannelSubscribeId(owner));
} else {
node.setId(this.distributedLayoutStore.generateNewFolderId(owner));
}
} catch (Exception e) {
throw new PortalException("Exception encountered while " +
"generating new user layout node Id for for "
+ owner.getAttribute(IPerson.USERNAME), e);
}
Document uld=getUserLayoutDOM();
Element childElement=node.getXML(uld);
Element parentElement= uld.getElementById(parentId);
if(nextSiblingId==null) {
parentElement.appendChild(childElement);
} else {
Node nextSibling=uld.getElementById(nextSiblingId);
parentElement.insertBefore(childElement,nextSibling);
}
// register element id
childElement.setIdAttribute(Constants.ATT_ID, true);
childElement.setAttribute(Constants.ATT_ID, node.getId());
this.updateCacheKey();
// push into the user's real layout that gets persisted.
HandlerUtils.createPlfNodeAndPath( childElement,
isChannel, owner );
// fire event
final int layoutId = this.getLayoutId();
if(isChannel) {
this.channelsAdded = true;
final String fname = ((IUserLayoutChannelDescription)node).getFunctionalName();
this.portalEventFactory.publishPortletAddedToLayoutPortalEvent(this, this.owner, layoutId, parent.getId(), fname);
}
else {
this.portalEventFactory.publishFolderAddedToLayoutPortalEvent(this, this.owner, layoutId, node.getId());
}