public static void updatePositionSet ( Element compViewParent , Element plfParent , IPerson person ) throws PortalException { if ( LOG . isDebugEnabled ( ) ) LOG . debug ( "Updating Position Set" ) ; if ( compViewParent . getChildNodes ( ) . getLength ( ) == 0 ) { // no nodes to position. if set exists reclaim the space. if ( LOG . isDebugEnabled ( ) ) LOG . debug ( "No Nodes to position" ) ; Element positions = getPositionSet ( plfParent , person , false ) ; if ( positions != null ) plfParent . removeChild ( positions ) ; return ; } Element posSet = ( Element ) getPositionSet ( plfParent , person , true ) ; Element position = ( Element ) posSet . getFirstChild ( ) ; Element viewNode = ( Element ) compViewParent . getFirstChild ( ) ; boolean ilfNodesFound = false ; while ( viewNode != null ) { String ID = viewNode . getAttribute ( Constants . ATT_ID ) ; String channelId = viewNode . getAttribute ( Constants . ATT_CHANNEL_ID ) ; String type = viewNode . getAttribute ( Constants . ATT_TYPE ) ; String hidden = viewNode . getAttribute ( Constants . ATT_HIDDEN ) ; if ( ID . startsWith ( Constants . FRAGMENT_ID_USER_PREFIX ) ) ilfNodesFound = true ; if ( ! channelId . equals ( "" ) || // its a channel node or ( type . equals ( "regular" ) && // a regular, visible folder hidden . equals ( "false" ) ) ) { if ( position != null ) position . setAttribute ( Constants . ATT_NAME , ID ) ; else position = createAndAppendPosition ( ID , posSet , person ) ; position = ( Element ) position . getNextSibling ( ) ; } viewNode = ( Element ) viewNode . getNextSibling ( ) ; } if ( ilfNodesFound == false ) // only plf nodes, no pos set needed plfParent . removeChild ( posSet ) ; else { // reclaim any leftover positions while ( position != null ) { Element nextPos = ( Element ) position . getNextSibling ( ) ; posSet . removeChild ( position ) ; position = nextPos ; } } }
This method updates the positions recorded in a position set to reflect the ids of the nodes in the composite view of the layout . Any position nodes already in existence are reused to reduce database interaction needed to generate a new ID attribute . If any are left over after updating those position elements are removed . If no position set existed a new one is created for the parent . If no ILF nodes are found in the parent node then the position set as a whole is reclaimed .