You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by sm...@apache.org on 2007/10/26 02:40:57 UTC

svn commit: r588454 [1/2] - in /portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl: AddPortletAction.java MovePortletAction.java PortletPlacementContextImpl.java RemovePortletAction.java

Author: smilek
Date: Thu Oct 25 17:40:57 2007
New Revision: 588454

URL: http://svn.apache.org/viewvc?rev=588454&view=rev
Log:
made changes to properly support moving fragments in and out of nested layout fragments - previously, PortletPlacementContextImpl was not coded properly to deal with nested layouts - now PortletPlacementContextImpl represents a single layout fragment, maintaining a representation of each column in the layout and the set of child fragments in each column - no further depth is maintained, so for a child layout fragment, no information is maintained about its columns or its children (previously, the object tried to do this but it did a very poor of it); made changed to MovePortletAction to allow RemovePortletAction and AddPorletAction to add-to/remove-from nested layouts

Modified:
    portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
    portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
    portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
    portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java?rev=588454&r1=588453&r2=588454&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java Thu Oct 25 17:40:57 2007
@@ -1,223 +1,225 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jetspeed.layout.impl;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.JetspeedActions;
-import org.apache.jetspeed.ajax.AJAXException;
-import org.apache.jetspeed.ajax.AjaxAction;
-import org.apache.jetspeed.ajax.AjaxBuilder;
-import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
-import org.apache.jetspeed.om.page.Fragment;
-import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.request.RequestContext;
-
-
-/**
- * Add Portlet portlet placement action
- * 
- * AJAX Parameters: 
- *    id = portlet full name (pa::portletName) to be added
- *    page = (implied in the URL)
- * Optional Parameters:  
- *    row = the new row to move to
- *    col = the new column to move to
- *    
- * @author <a>David Gurney </a>
- * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
- * @version $Id: $
- */
-public class AddPortletAction 
-    extends MovePortletAction 
-    implements AjaxAction, AjaxBuilder, Constants
-{
-    protected Log log = LogFactory.getLog(AddPortletAction.class);
-    protected GetPortletsAction getPortletsAction = null;
-    protected boolean allowDuplicatePortlets = true;
-
-    public AddPortletAction(String template, String errorTemplate, GetPortletsAction getPortletsAction)
-        throws AJAXException
-    {
-        this(template, errorTemplate, null, null, getPortletsAction, true);
-    }
-
-    public AddPortletAction(String template, 
-                            String errorTemplate, 
-                            PageManager pageManager,
-                            PortletActionSecurityBehavior securityBehavior,
-                            GetPortletsAction getPortletsAction)
-        throws AJAXException
-    {
-        this(template, errorTemplate, pageManager, securityBehavior, getPortletsAction, true);
-    }
-
-    public AddPortletAction(String template, 
-                            String errorTemplate, 
-                            PageManager pageManager,
-                            PortletActionSecurityBehavior securityBehavior,
-                            GetPortletsAction getPortletsAction,
-                            boolean allowDuplicatePortlets)
-        throws AJAXException
-    {
-        super(template, errorTemplate, pageManager, securityBehavior); 
-        this.getPortletsAction = getPortletsAction;
-        this.allowDuplicatePortlets = allowDuplicatePortlets;
-    }
-    
-    protected boolean runAction( RequestContext requestContext, Map resultMap, boolean batch ) throws AJAXException
-    {
-        boolean success = true;
-        String status = "success";
-        try
-        {
-            resultMap.put(ACTION, "add");
-            // Get the necessary parameters off of the request
-            String portletId = getActionParameter(requestContext, PORTLETID);
-            if (portletId == null) 
-            { 
-                throw new RuntimeException("portlet id not provided"); 
-            }
-            resultMap.put(PORTLETID, portletId);
-            
-            // Verify that the specified portlet id is valid and accessible
-            // If the portletid is not valid an exception will be thrown
-            verifyPortletId(requestContext, portletId);
-            
-            if(allowDuplicatePortlets == false) {
-            	// Check to see if this portlet has already been added to the page
-            	checkForDuplicatePortlet(requestContext, resultMap, portletId);
-            }
-            
-            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
-            {
-                if (!createNewPageOnEdit(requestContext))
-                {
-                    success = false;
-                    resultMap.put(REASON, "Insufficient access to edit page");                
-                    return success;
-                }
-                status = "refresh";
-            }           
-            
-            Page page = requestContext.getPage();
-            String layoutId = getActionParameter(requestContext, LAYOUTID);
-            Fragment fragment = pageManager.newFragment();
-            fragment.setType(Fragment.PORTLET);
-            fragment.setName(portletId);
-            //fragment.setLayoutColumn(iCol);
-            //fragment.setLayoutRow(iRow);
-            
-            Fragment placeInLayoutFragment = null;
-            if ( layoutId != null && layoutId.length() > 0 )
-            {
-                placeInLayoutFragment = page.getFragmentById( layoutId );
-                if ( placeInLayoutFragment == null )
-                {
-                    throw new Exception( "layout id not found: " + layoutId );
-                }
-            }
-            else
-            {
-                placeInLayoutFragment = page.getRootFragment();
-            }
-
-            success = placeFragment( requestContext,
-                                     pageManager,
-                                     batch,
-                                     resultMap,
-                                     fragment,
-                                     placeInLayoutFragment ) ;
-
-            resultMap.put(STATUS, status);
-            resultMap.put(PORTLETENTITY, fragment.getId());            
-        } 
-        catch (Exception e)
-        {
-            // Log the exception
-            log.error("exception while adding a portlet", e);
-            resultMap.put(REASON, e.toString());
-
-            // Return a failure indicator
-            success = false;
-        }
-
-        return success;
-    }
-    
-    protected void verifyPortletId(RequestContext requestContext, String portletId) throws Exception
-    {
-    	// Get the list of valid portlets from the getPortletAction
-    	List portletList = getPortletsAction.retrievePortlets(requestContext, null);
-    	if(portletList != null) {
-    		for(int i = 0; i < portletList.size(); i++) {
-    			PortletInfo portletInfo = (PortletInfo)portletList.get(i);
-    			if(portletInfo != null) {
-    				if(portletInfo.getName().equalsIgnoreCase(portletId)) {
-    					// A match was found there is no need to continue
-    					return;
-    				}
-    			}
-    		}
-    	}
-    	// If we got here, then no match was found
-    	throw new Exception(portletId + " is not a valid portlet or not allowed for this user");
-    }
-    
-    protected void checkForDuplicatePortlet(RequestContext requestContext, Map resultMap, String portletId)
-    throws AJAXException
-    {
-    	// Look at each portlet currently on the page
-    	Page page = requestContext.getPage();
-    	
-    	boolean duplicateFound = isDuplicateFragment(page.getRootFragment(), portletId);
-    	
-    	// Throw an exception if a duplicate is found
-    	if(duplicateFound == true) {
-    		throw new AJAXException(portletId + " is already on the page, duplicates are not allowed");
-    	}
-    }
-
-    protected boolean isDuplicateFragment(Fragment fragment, String portletId) {
-    	if(fragment != null) {
-	    	// Get the name of this fragment
-	    	String fragmentName = fragment.getName();
-	    	if(fragmentName.equals(portletId)) {
-	    		// Duplicate was found
-	    		return true;
-	    	} else {
-	    		// Process the child fragments if found
-	    		List childFragments = fragment.getFragments();
-	    		if(childFragments != null) {
-	    			for(int i = 0; i < childFragments.size(); i++) {
-	    				// Recursively call this method again to process the child fragments
-	    				if(isDuplicateFragment((Fragment)childFragments.get(i),portletId) == true) {
-	    					// No need to continue to loop if a duplicate was found
-	    					return true;
-	    				}
-	    			}
-	    		}
-	    	}
-    	}
-    	// We will only get here if no duplicates were found
-    	return false;
-    }
-}
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.layout.impl;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.ajax.AJAXException;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.request.RequestContext;
+
+
+/**
+ * Add Portlet portlet placement action
+ * 
+ * AJAX Parameters: 
+ *    id = portlet full name (pa::portletName) to be added
+ *    page = (implied in the URL)
+ * Optional Parameters:  
+ *    row = the new row to move to
+ *    col = the new column to move to
+ *    
+ * @author <a>David Gurney </a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
+ * @version $Id: $
+ */
+public class AddPortletAction 
+    extends MovePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    protected Log log = LogFactory.getLog(AddPortletAction.class);
+    protected GetPortletsAction getPortletsAction = null;
+    protected boolean allowDuplicatePortlets = true;
+
+    public AddPortletAction(String template, String errorTemplate, GetPortletsAction getPortletsAction)
+        throws AJAXException
+    {
+        this(template, errorTemplate, null, null, getPortletsAction, true);
+    }
+
+    public AddPortletAction(String template, 
+                            String errorTemplate, 
+                            PageManager pageManager,
+                            PortletActionSecurityBehavior securityBehavior,
+                            GetPortletsAction getPortletsAction)
+        throws AJAXException
+    {
+        this(template, errorTemplate, pageManager, securityBehavior, getPortletsAction, true);
+    }
+
+    public AddPortletAction(String template, 
+                            String errorTemplate, 
+                            PageManager pageManager,
+                            PortletActionSecurityBehavior securityBehavior,
+                            GetPortletsAction getPortletsAction,
+                            boolean allowDuplicatePortlets)
+        throws AJAXException
+    {
+        super(template, errorTemplate, pageManager, securityBehavior); 
+        this.getPortletsAction = getPortletsAction;
+        this.allowDuplicatePortlets = allowDuplicatePortlets;
+    }
+    
+    protected boolean runAction( RequestContext requestContext, Map resultMap, boolean batch ) throws AJAXException
+    {
+        boolean success = true;
+        String status = "success";
+        try
+        {
+            resultMap.put(ACTION, "add");
+            // Get the necessary parameters off of the request
+            String portletId = getActionParameter(requestContext, PORTLETID);
+            if (portletId == null) 
+            { 
+                throw new RuntimeException("portlet id not provided"); 
+            }
+            resultMap.put(PORTLETID, portletId);
+            
+            // Verify that the specified portlet id is valid and accessible
+            // If the portletid is not valid an exception will be thrown
+            verifyPortletId(requestContext, portletId);
+            
+            if(allowDuplicatePortlets == false) {
+            	// Check to see if this portlet has already been added to the page
+            	checkForDuplicatePortlet(requestContext, resultMap, portletId);
+            }
+            
+            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
+            {
+                if (!createNewPageOnEdit(requestContext))
+                {
+                    success = false;
+                    resultMap.put(REASON, "Insufficient access to edit page");                
+                    return success;
+                }
+                status = "refresh";
+            }           
+            
+            Page page = requestContext.getPage();
+            String layoutId = getActionParameter(requestContext, LAYOUTID);
+            Fragment fragment = pageManager.newFragment();
+            fragment.setType(Fragment.PORTLET);
+            fragment.setName(portletId);
+            //fragment.setLayoutColumn(iCol);
+            //fragment.setLayoutRow(iRow);
+            
+            Fragment placeInLayoutFragment = null;
+            if ( layoutId != null && layoutId.length() > 0 )
+            {
+                placeInLayoutFragment = page.getFragmentById( layoutId );
+                if ( placeInLayoutFragment == null )
+                {
+                    throw new Exception( "layout id not found: " + layoutId );
+                }
+            }
+            else
+            {
+                placeInLayoutFragment = page.getRootFragment();
+            }
+
+            success = placeFragment( requestContext,
+                                     batch,
+                                     resultMap,
+                                     fragment,
+                                     placeInLayoutFragment ) ;
+            
+            resultMap.put( PORTLETENTITY, fragment.getId() );
+            if ( success )
+            {
+            	resultMap.put( STATUS, status );
+            }
+        } 
+        catch ( Exception e )
+        {
+            // Log the exception
+            log.error("exception while adding a portlet", e);
+            resultMap.put(REASON, e.toString());
+
+            // Return a failure indicator
+            success = false;
+        }
+
+        return success;
+    }
+    
+    protected void verifyPortletId(RequestContext requestContext, String portletId) throws Exception
+    {
+    	// Get the list of valid portlets from the getPortletAction
+    	List portletList = getPortletsAction.retrievePortlets(requestContext, null);
+    	if(portletList != null) {
+    		for(int i = 0; i < portletList.size(); i++) {
+    			PortletInfo portletInfo = (PortletInfo)portletList.get(i);
+    			if(portletInfo != null) {
+    				if(portletInfo.getName().equalsIgnoreCase(portletId)) {
+    					// A match was found there is no need to continue
+    					return;
+    				}
+    			}
+    		}
+    	}
+    	// If we got here, then no match was found
+    	throw new Exception(portletId + " is not a valid portlet or not allowed for this user");
+    }
+    
+    protected void checkForDuplicatePortlet(RequestContext requestContext, Map resultMap, String portletId)
+    throws AJAXException
+    {
+    	// Look at each portlet currently on the page
+    	Page page = requestContext.getPage();
+    	
+    	boolean duplicateFound = isDuplicateFragment(page.getRootFragment(), portletId);
+    	
+    	// Throw an exception if a duplicate is found
+    	if(duplicateFound == true) {
+    		throw new AJAXException(portletId + " is already on the page, duplicates are not allowed");
+    	}
+    }
+
+    protected boolean isDuplicateFragment(Fragment fragment, String portletId) {
+    	if(fragment != null) {
+	    	// Get the name of this fragment
+	    	String fragmentName = fragment.getName();
+	    	if(fragmentName.equals(portletId)) {
+	    		// Duplicate was found
+	    		return true;
+	    	} else {
+	    		// Process the child fragments if found
+	    		List childFragments = fragment.getFragments();
+	    		if(childFragments != null) {
+	    			for(int i = 0; i < childFragments.size(); i++) {
+	    				// Recursively call this method again to process the child fragments
+	    				if(isDuplicateFragment((Fragment)childFragments.get(i),portletId) == true) {
+	    					// No need to continue to loop if a duplicate was found
+	    					return true;
+	    				}
+	    			}
+	    		}
+	    	}
+    	}
+    	// We will only get here if no duplicates were found
+    	return false;
+    }
+}

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java?rev=588454&r1=588453&r2=588454&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java Thu Oct 25 17:40:57 2007
@@ -1,549 +1,581 @@
-/*
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.jetspeed.layout.impl;
-
-import java.util.Map;
-import java.util.Iterator;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jetspeed.JetspeedActions;
-import org.apache.jetspeed.ajax.AJAXException;
-import org.apache.jetspeed.ajax.AjaxAction;
-import org.apache.jetspeed.ajax.AjaxBuilder;
-import org.apache.jetspeed.layout.Coordinate;
-import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
-import org.apache.jetspeed.layout.PortletPlacementException;
-import org.apache.jetspeed.layout.PortletPlacementContext;
-import org.apache.jetspeed.om.page.Fragment;
-import org.apache.jetspeed.om.page.Page;
-import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.NodeException;
-import org.apache.jetspeed.request.RequestContext;
-
-/**
- * Move Portlet portlet placement action
- *
- * AJAX Parameters: 
- *    id = the fragment id of the portlet to move
- *    page = (implied in the URL)
- * Additional Absolute Parameters:  
- *    row = the new row to move to
- *    col = the new column to move to
- * Additional Relative Parameters: (move left, right, up, down)
- *    none
- *    
- * @author <a>David Gurney</a>
- * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
- * @version $Id: $
- */
-public class MovePortletAction 
-    extends BasePortletAction 
-    implements AjaxAction, AjaxBuilder, Constants
-{
-    protected static final Log log = LogFactory.getLog(MovePortletAction.class);
-    private int iMoveType = -1;
-    private String sMoveType = null;
-
-    public MovePortletAction(String template, 
-            String errorTemplate, 
-            String sMoveType)
-    throws AJAXException    
-    {
-        this(template, errorTemplate, sMoveType, null, null);
-    }
-    
-    public MovePortletAction(String template, 
-                             String errorTemplate, 
-                             PageManager pageManager,
-                             PortletActionSecurityBehavior securityBehavior)
-    throws AJAXException
-    {
-        this( template, errorTemplate, "moveabs", pageManager, securityBehavior );
-    }
-
-    public MovePortletAction(String template, 
-                             String errorTemplate, 
-                             String sMoveType,
-                             PageManager pageManager,
-                             PortletActionSecurityBehavior securityBehavior)
-    throws AJAXException
-    {
-        super(template, errorTemplate, pageManager, securityBehavior);
-        setMoveType(sMoveType);
-    }
-
-    // Convert the move type into an integer
-    public void setMoveType(String p_sMoveType) throws AJAXException
-    {
-        sMoveType = p_sMoveType;
-
-        if (p_sMoveType.equalsIgnoreCase("moveabs"))
-        {
-            iMoveType = ABS;
-        } 
-        else if (p_sMoveType.equalsIgnoreCase("moveup"))
-        {
-            iMoveType = UP;
-        } 
-        else if (p_sMoveType.equalsIgnoreCase("movedown"))
-        {
-            iMoveType = DOWN;
-        } 
-        else if (p_sMoveType.equalsIgnoreCase("moveleft"))
-        {
-            iMoveType = LEFT;
-        } 
-        else if (p_sMoveType.equalsIgnoreCase("moveright"))
-        {
-            iMoveType = RIGHT;
-        }
-        else if (p_sMoveType.equalsIgnoreCase("move"))
-        {
-            iMoveType = CARTESIAN;
-        }
-        else
-        {
-            throw new AJAXException("invalid move type of:" + p_sMoveType);
-        }
-    }
-
-    public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
-    {
-        return runAction(requestContext, resultMap, true);
-    }    
-    
-    public boolean run(RequestContext requestContext, Map resultMap)
-            throws AJAXException
-    {
-        return runAction(requestContext, resultMap, false);
-    }
-    
-    protected boolean runAction( RequestContext requestContext, Map resultMap, boolean batch )  throws AJAXException
-    {
-        boolean success = true;
-        String status = "success";
-        try
-        {
-            resultMap.put(ACTION, sMoveType);
-            // Get the necessary parameters off of the request
-            String moveFragmentId = getActionParameter(requestContext, FRAGMENTID);
-            String layoutId = getActionParameter(requestContext, LAYOUTID);
-            if ( moveFragmentId == null ) 
-            {
-                throw new Exception( FRAGMENTID + " not provided; must specify portlet or layout id" ); 
-            }
-            resultMap.put(FRAGMENTID, moveFragmentId);
-            
-            Fragment currentLayoutFragment = null;
-            Fragment moveToLayoutFragment = null;
-            // when layoutId is null we use old behavior, ignoring everything to do with multiple layout fragments
-            if ( layoutId != null && layoutId.length() > 0 && iMoveType != CARTESIAN )
-            {
-                Page page = requestContext.getPage();
-                currentLayoutFragment = page.getFragmentById( layoutId );
-                if ( currentLayoutFragment == null )
-                {
-                    throw new Exception("layout id not found: " + layoutId );
-                }
-                else
-                {
-                    // determine if layoutId parameter refers to the current or the move target layout fragment
-                    moveToLayoutFragment = currentLayoutFragment;
-                    Iterator layoutChildIter = moveToLayoutFragment.getFragments().iterator();
-                    while ( layoutChildIter.hasNext() )
-                    {
-                        Fragment childFrag = (Fragment)layoutChildIter.next();
-                        if ( childFrag != null )
-                        {
-                            if ( moveFragmentId.equals( childFrag.getId() ) )
-                            {
-                                moveToLayoutFragment = null;
-                                break;
-                            }
-                        }
-                    }
-                    if ( moveToLayoutFragment != null )
-                    {
-                        // figure out the current layout fragment - must know to be able to find the portlet
-                        //    fragment by row/col when a new page is created
-                        Fragment root = requestContext.getPage().getRootFragment();
-                        currentLayoutFragment = getParentFragmentById(moveFragmentId, root);
-                    }
-                }
-                if ( currentLayoutFragment == null )
-                {
-                    // report error
-                    throw new Exception("parent layout id not found for portlet id:" + moveFragmentId );
-                }
-            }
-            
-            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
-            {
-                Page page = requestContext.getPage();
-                Fragment fragment = page.getFragmentById(moveFragmentId);
-                if (fragment == null)
-                {
-                    success = false;
-                    resultMap.put(REASON, "Fragment not found");
-                    return success;
-                }
-                
-                // remember current row/column of porlet fragment
-                int column = fragment.getLayoutColumn();
-                int row = fragment.getLayoutRow();
-                
-                // rememeber current row/column of parent layout fragment and move-to layout fragment
-                int layoutColumn = -1, layoutRow = -1;
-                int moveToLayoutColumn = -1, moveToLayoutRow = -1;
-                if ( currentLayoutFragment != null )
-                {
-                    layoutColumn = currentLayoutFragment.getLayoutColumn();
-                    layoutRow = currentLayoutFragment.getLayoutRow();
-                    if ( moveToLayoutFragment != null )
-                    {
-                        moveToLayoutColumn = moveToLayoutFragment.getLayoutColumn();
-                        moveToLayoutRow = moveToLayoutFragment.getLayoutRow();
-                    }
-                }
-                
-                if (!createNewPageOnEdit(requestContext))
-                {
-                    success = false;
-                    resultMap.put(REASON, "Insufficient access to edit page");
-                    return success;
-                }
-                status = "refresh";
-                
-                // translate old portlet id to new portlet id
-                Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
-                if (newFragment == null)
-                {
-                    success = false;
-                    resultMap.put( REASON, "Failed to find new fragment for portlet id: " + moveFragmentId );
-                    return success;                    
-                }
-                moveFragmentId = newFragment.getId();
-                
-                if ( currentLayoutFragment != null )
-                {
-                    newFragment = getFragmentIdFromLocation(layoutRow, layoutColumn, requestContext.getPage());
-                    if (newFragment == null)
-                    {
-                        success = false;
-                        resultMap.put( REASON, "Failed to find new parent layout fragment id: " + currentLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
-                        return success;
-                    }
-                    currentLayoutFragment = newFragment;
-                    if ( moveToLayoutFragment != null )
-                    {
-                        newFragment = getFragmentIdFromLocation(moveToLayoutRow, moveToLayoutColumn, requestContext.getPage());
-                        if (newFragment == null)
-                        {
-                            success = false;
-                            resultMap.put( REASON, "Failed to find new move-to layout fragment id: " + moveToLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
-                            return success;
-                        }
-                        moveToLayoutFragment = newFragment;
-                    }
-                }
-            }
-            
-            if ( moveToLayoutFragment != null )
-            {
-                success = moveFragment( requestContext,
-                                        pageManager,
-                                        batch,
-                                        resultMap,
-                                        moveFragmentId,
-                                        moveToLayoutFragment,
-                                        currentLayoutFragment ) ;
-            }
-            else
-            {
-                PortletPlacementContext placement = null;
-                if ( currentLayoutFragment != null )
-                    placement = new PortletPlacementContextImpl(requestContext, currentLayoutFragment, 1);
-                else
-                {
-                    placement = new PortletPlacementContextImpl(requestContext);
-                }
-                Fragment fragment = placement.getFragmentById(moveFragmentId);
-                if (fragment == null)
-                {
-                    success = false;
-                    resultMap.put(REASON, "Failed to find fragment for portlet id: " + moveFragmentId );
-                    return success;
-                }
-                Coordinate returnCoordinate = null;
-                float oldX = 0f, oldY = 0f, oldZ = 0f, oldWidth = 0f, oldHeight = 0f;
-                float x = -1f, y = -1f, z = -1f, width = -1f, height = -1f;
-                boolean absHeightChanged = false;
-                
-                String posExtended = getActionParameter(requestContext, DESKTOP_EXTENDED);
-                if ( posExtended != null )
-                {
-                    Map fragmentProperties = fragment.getProperties();
-                    if ( fragmentProperties == null )
-                    {
-                        success = false;
-                        resultMap.put(REASON, "Failed to acquire fragment properties map for portlet id: " + moveFragmentId );
-                        return success;
-                    }
-                    String oldDeskExt = (String)fragmentProperties.get( DESKTOP_EXTENDED );
-                    resultMap.put( OLD_DESKTOP_EXTENDED, ( (oldDeskExt != null) ? oldDeskExt : "" ) );
-                    fragmentProperties.put( DESKTOP_EXTENDED, posExtended );
-                }
-                
-                // Only required for moveabs
-                if (iMoveType == ABS)
-                {
-                    Coordinate a_oCoordinate = getCoordinateFromParams(requestContext);
-                    returnCoordinate = placement.moveAbsolute(fragment, a_oCoordinate);
-                    String sHeight = getActionParameter(requestContext, HEIGHT);
-                    if ( sHeight != null && sHeight.length() > 0 )
-                    {
-                        oldHeight = fragment.getLayoutHeight();
-                        height = Float.parseFloat(sHeight);
-                        fragment.setLayoutHeight(height);
-                        absHeightChanged = true;
-                    }
-                } 
-                else if (iMoveType == LEFT)
-                {
-                    returnCoordinate = placement.moveLeft(fragment);
-                } 
-                else if (iMoveType == RIGHT)
-                {
-                    returnCoordinate = placement.moveRight(fragment);
-                } 
-                else if (iMoveType == UP)
-                {
-                    returnCoordinate = placement.moveUp(fragment);
-                } 
-                else if (iMoveType == DOWN)
-                {
-                    returnCoordinate = placement.moveDown(fragment);
-                }
-                else if (iMoveType == CARTESIAN)
-                {
-                    String sx = getActionParameter(requestContext, X);
-                    String sy = getActionParameter(requestContext, Y);
-                    String sz = getActionParameter(requestContext, Z);
-                    String sWidth = getActionParameter(requestContext, WIDTH);
-                    String sHeight = getActionParameter(requestContext, HEIGHT);
-                    if (sx != null)
-                    {
-                        oldX = fragment.getLayoutX();
-                        x = Float.parseFloat(sx); 
-                        fragment.setLayoutX(x);
-                    }
-                    if (sy != null)
-                    {
-                        oldY = fragment.getLayoutY();                    
-                        y = Float.parseFloat(sy); 
-                        fragment.setLayoutY(y);
-                    }                
-                    if (sz != null)
-                    {
-                        oldZ = fragment.getLayoutZ();                    
-                        z = Float.parseFloat(sz); 
-                        fragment.setLayoutZ(z);
-                    }                
-                    if (sWidth != null)
-                    {
-                        oldWidth = fragment.getLayoutWidth();                    
-                        width = Float.parseFloat(sWidth); 
-                        fragment.setLayoutWidth(width);
-                    }
-                    if (sHeight != null)
-                    {
-                        oldHeight = fragment.getLayoutHeight();                    
-                        height = Float.parseFloat(sHeight); 
-                        fragment.setLayoutHeight(height);
-                    }
-                }
-                // synchronize back to the page layout root fragment
-                Page page = placement.syncPageFragments();
-            
-                if (pageManager != null && !batch)
-                {
-                    pageManager.updatePage(page);
-                }
-                
-                if (iMoveType == CARTESIAN)
-                {
-                    putCartesianResult(resultMap, x, oldX, X, OLD_X);
-                    putCartesianResult(resultMap, y, oldY, Y, OLD_Y);                
-                    putCartesianResult(resultMap, z, oldZ, Z, OLD_Z);
-                    putCartesianResult(resultMap, width, oldWidth, WIDTH, OLD_WIDTH);
-                    putCartesianResult(resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT);
-                }
-                else
-                {
-                    // Need to determine what the old col and row were
-                    resultMap.put(OLDCOL, String.valueOf(returnCoordinate
-                            .getOldCol()));
-                    resultMap.put(OLDROW, String.valueOf(returnCoordinate
-                            .getOldRow()));
-                    // Need to determine what the new col and row were
-                    resultMap.put(NEWCOL, String.valueOf(returnCoordinate
-                            .getNewCol()));
-                    resultMap.put(NEWROW, String.valueOf(returnCoordinate
-                            .getNewRow()));
-                    if ( absHeightChanged )
-                    {
-                        putCartesianResult(resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT);
-                    }
-                }
-            }
-            resultMap.put(STATUS, status);
-            resultMap.put(FRAGMENTID, moveFragmentId);
-        } 
-        catch (Exception e)
-        {
-            // Log the exception
-            log.error("exception while moving a portlet", e);
-            resultMap.put(REASON, e.toString());
-            // Return a failure indicator
-            success = false;
-        }
-
-        return success;
-    }
-
-    protected boolean moveFragment( RequestContext requestContext,
-                                    PageManager pageManager,
-                                    boolean batch,
-                                    Map resultMap,
-                                    String moveFragmentId,
-                                    Fragment moveToLayoutFragment,
-                                    Fragment removeFromLayoutFragment )
-        throws PortletPlacementException, NodeException
-    {
-        boolean success = true;
-        Fragment placeFragment = null;
-        if ( removeFromLayoutFragment != null )
-        {
-            PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, removeFromLayoutFragment, 1 );
-        
-            placeFragment = placement.getFragmentById( moveFragmentId );
-            if ( placeFragment == null )
-            {
-                success = false;
-                resultMap.put( REASON, "Failed to find fragment to move to another layout for fragment id: " + moveFragmentId );
-                return success;
-            }
-            placement.remove( placeFragment );
-            Page page = placement.syncPageFragments();
-            page.removeFragmentById( moveFragmentId );
-        }
-        if ( placeFragment != null )
-        {
-            return placeFragment( requestContext,
-                                  pageManager,
-                                  batch,
-                                  resultMap,
-                                  placeFragment,
-                                  moveToLayoutFragment );
-        }
-        return success;
-    }
-
-    protected boolean placeFragment( RequestContext requestContext,
-                                     PageManager pageManager,
-                                     boolean batch,
-                                     Map resultMap,
-                                     Fragment placeFragment,
-                                     Fragment placeInLayoutFragment )
-        throws PortletPlacementException, NodeException
-    {
-        boolean success = true;
-        if ( placeFragment == null )
-        {
-            success = false;
-            return success;
-        }
-
-        // desktop extended
-        String posExtended = getActionParameter(requestContext, DESKTOP_EXTENDED);
-        if ( posExtended != null )
-        {
-            Map fragmentProperties = placeFragment.getProperties();
-            if ( fragmentProperties == null )
-            {
-                success = false;
-                resultMap.put(REASON, "Failed to acquire fragment properties map for fragment id: " + placeFragment.getId() );
-                return success;
-            }
-            String oldDeskExt = (String)fragmentProperties.get( DESKTOP_EXTENDED );
-            resultMap.put( OLD_DESKTOP_EXTENDED, ( (oldDeskExt != null) ? oldDeskExt : "" ) );
-            fragmentProperties.put( DESKTOP_EXTENDED, posExtended );
-        }
-                
-        // add fragment
-        PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, placeInLayoutFragment, 1 );
-        Coordinate returnCoordinate = placement.add( placeFragment, getCoordinateFromParams( requestContext ) );
-        Page page = placement.syncPageFragments();
-
-        placeInLayoutFragment.getFragments().add( placeFragment );
-        if ( pageManager != null && ! batch )
-        {
-            pageManager.updatePage( page );
-        }
-
-        // Need to determine what the old col and row were
-        resultMap.put( OLDCOL, String.valueOf( returnCoordinate.getOldCol() ) );
-        resultMap.put( OLDROW, String.valueOf( returnCoordinate.getOldRow() ) );
-        // Need to determine what the new col and row were
-        resultMap.put( NEWCOL, String.valueOf( returnCoordinate.getNewCol() ) );
-        resultMap.put( NEWROW, String.valueOf( returnCoordinate.getNewRow() ) );
-
-        return success;
-    }
-    
-    protected Coordinate getCoordinateFromParams(RequestContext requestContext)
-    {
-        String a_sCol = getActionParameter( requestContext, COL );
-        String a_sRow = getActionParameter( requestContext, ROW );
-
-        int a_iCol = 0;
-        int a_iRow = 0;
-
-        // Convert the col and row into integers
-        if ( a_sCol != null )
-        {
-            a_iCol = Integer.parseInt( a_sCol );
-        }
-        if ( a_sRow != null )
-        {
-            a_iRow = Integer.parseInt( a_sRow );
-        }
-
-        Coordinate a_oCoordinate = new CoordinateImpl( 0, 0, a_iCol, a_iRow );
-        return a_oCoordinate;
-    }
-
-    protected void putCartesianResult(Map resultMap, float value, float oldValue, String name, String oldName)
-    {    
-        if (value != -1F)
-        {
-            resultMap.put(oldName, new Float(oldValue));
-            resultMap.put(name, new Float(value));
-        }
-    }
-}
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.layout.impl;
+
+import java.security.Principal;
+import java.util.Map;
+import java.util.Iterator;
+
+import javax.security.auth.Subject;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.administration.PortalConfiguration;
+import org.apache.jetspeed.ajax.AJAXException;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.layout.Coordinate;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.layout.PortletPlacementException;
+import org.apache.jetspeed.layout.PortletPlacementContext;
+import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.page.document.NodeException;
+import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.security.RolePrincipal;
+import org.apache.jetspeed.security.impl.RolePrincipalImpl;
+import org.apache.jetspeed.Jetspeed;
+
+/**
+ * Move Portlet portlet placement action
+ *
+ * AJAX Parameters: 
+ *    id = the fragment id of the portlet to move
+ *    page = (implied in the URL)
+ * Additional Absolute Parameters:  
+ *    row = the new row to move to
+ *    col = the new column to move to
+ * Additional Relative Parameters: (move left, right, up, down)
+ *    none
+ *    
+ * @author <a>David Gurney</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class MovePortletAction 
+    extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    protected static final Log log = LogFactory.getLog(MovePortletAction.class);
+    private int iMoveType = -1;
+    private String sMoveType = null;
+
+    public MovePortletAction(String template, 
+            String errorTemplate, 
+            String sMoveType)
+    throws AJAXException    
+    {
+        this(template, errorTemplate, sMoveType, null, null);
+    }
+    
+    public MovePortletAction(String template, 
+                             String errorTemplate, 
+                             PageManager pageManager,
+                             PortletActionSecurityBehavior securityBehavior)
+    throws AJAXException
+    {
+        this( template, errorTemplate, "moveabs", pageManager, securityBehavior );
+    }
+
+    public MovePortletAction(String template, 
+                             String errorTemplate, 
+                             String sMoveType,
+                             PageManager pageManager,
+                             PortletActionSecurityBehavior securityBehavior)
+    throws AJAXException
+    {
+        super(template, errorTemplate, pageManager, securityBehavior);
+        setMoveType(sMoveType);
+    }
+
+    // Convert the move type into an integer
+    public void setMoveType(String p_sMoveType) throws AJAXException
+    {
+        sMoveType = p_sMoveType;
+
+        if (p_sMoveType.equalsIgnoreCase("moveabs"))
+        {
+            iMoveType = ABS;
+        } 
+        else if (p_sMoveType.equalsIgnoreCase("moveup"))
+        {
+            iMoveType = UP;
+        } 
+        else if (p_sMoveType.equalsIgnoreCase("movedown"))
+        {
+            iMoveType = DOWN;
+        } 
+        else if (p_sMoveType.equalsIgnoreCase("moveleft"))
+        {
+            iMoveType = LEFT;
+        } 
+        else if (p_sMoveType.equalsIgnoreCase("moveright"))
+        {
+            iMoveType = RIGHT;
+        }
+        else if (p_sMoveType.equalsIgnoreCase("move"))
+        {
+            iMoveType = CARTESIAN;
+        }
+        else
+        {
+            throw new AJAXException("invalid move type of:" + p_sMoveType);
+        }
+    }
+
+    public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
+    {
+        return runAction(requestContext, resultMap, true);
+    }    
+    
+    public boolean run(RequestContext requestContext, Map resultMap)
+            throws AJAXException
+    {
+        return runAction(requestContext, resultMap, false);
+    }
+    
+    protected void getRoles( RequestContext requestContext )
+    {
+    	Subject currentSubject = requestContext.getSubject();
+    	Principal principal = requestContext.getRequest().getUserPrincipal();
+        String userName = null; // this.guest;
+        if ( principal != null )
+            userName = principal.getName();
+        else
+        {
+        	PortalConfiguration config = Jetspeed.getConfiguration();
+            if ( config != null )
+            {
+            	userName = config.getString("default.user.principal");
+            }
+        }
+        
+        Iterator roles = currentSubject.getPrincipals(RolePrincipalImpl.class).iterator();
+        StringBuffer rolesBuff = new StringBuffer();
+        int count = 0;
+        while (roles.hasNext())
+        {
+            RolePrincipal role = (RolePrincipal)roles.next();
+            if (count > 0)
+            {
+                rolesBuff.append(";");
+            }
+            rolesBuff.append(role.getName());
+            count++;                        
+        }
+        log.info( "roles for '" + userName + "': " + rolesBuff.toString() );
+    }
+    
+    protected boolean runAction( RequestContext requestContext, Map resultMap, boolean batch )  throws AJAXException
+    {
+        boolean success = true;
+        String status = "success";
+        try
+        {
+            resultMap.put(ACTION, sMoveType);
+            // Get the necessary parameters off of the request
+            String moveFragmentId = getActionParameter(requestContext, FRAGMENTID);
+            String layoutId = getActionParameter(requestContext, LAYOUTID);
+            if ( moveFragmentId == null ) 
+            {
+                throw new Exception( FRAGMENTID + " not provided; must specify portlet or layout id" ); 
+            }
+            resultMap.put(FRAGMENTID, moveFragmentId);
+            
+            getRoles( requestContext );
+            
+            Fragment currentLayoutFragment = null;
+            Fragment moveToLayoutFragment = null;
+            // when layoutId is null we use old behavior, ignoring everything to do with multiple layout fragments
+            if ( layoutId != null && layoutId.length() > 0 && iMoveType != CARTESIAN )
+            {
+                Page page = requestContext.getPage();
+                currentLayoutFragment = page.getFragmentById( layoutId );
+                if ( currentLayoutFragment == null )
+                {
+                    throw new Exception("layout id not found: " + layoutId );
+                }
+                else
+                {
+                    // determine if layoutId parameter refers to the current or the move target layout fragment
+                    moveToLayoutFragment = currentLayoutFragment;
+                    Iterator layoutChildIter = moveToLayoutFragment.getFragments().iterator();
+                    while ( layoutChildIter.hasNext() )
+                    {
+                        Fragment childFrag = (Fragment)layoutChildIter.next();
+                        if ( childFrag != null )
+                        {
+                            if ( moveFragmentId.equals( childFrag.getId() ) )
+                            {
+                                moveToLayoutFragment = null;
+                                break;
+                            }
+                        }
+                    }
+                    if ( moveToLayoutFragment != null )
+                    {
+                        // figure out the current layout fragment - must know to be able to find the portlet
+                        //    fragment by row/col when a new page is created
+                        Fragment root = requestContext.getPage().getRootFragment();
+                        currentLayoutFragment = getParentFragmentById(moveFragmentId, root);
+                    }
+                }
+                if ( currentLayoutFragment == null )
+                {
+                    // report error
+                    throw new Exception("parent layout id not found for portlet id:" + moveFragmentId );
+                }
+            }
+            
+            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
+            {
+                Page page = requestContext.getPage();
+                Fragment fragment = page.getFragmentById(moveFragmentId);
+                if (fragment == null)
+                {
+                    success = false;
+                    resultMap.put(REASON, "Fragment not found");
+                    return success;
+                }
+                
+                // remember current row/column of porlet fragment
+                int column = fragment.getLayoutColumn();
+                int row = fragment.getLayoutRow();
+                
+                // rememeber current row/column of parent layout fragment and move-to layout fragment
+                int layoutColumn = -1, layoutRow = -1;
+                int moveToLayoutColumn = -1, moveToLayoutRow = -1;
+                if ( currentLayoutFragment != null )
+                {
+                    layoutColumn = currentLayoutFragment.getLayoutColumn();
+                    layoutRow = currentLayoutFragment.getLayoutRow();
+                    if ( moveToLayoutFragment != null )
+                    {
+                        moveToLayoutColumn = moveToLayoutFragment.getLayoutColumn();
+                        moveToLayoutRow = moveToLayoutFragment.getLayoutRow();
+                    }
+                }
+                
+                if (!createNewPageOnEdit(requestContext))
+                {
+                    success = false;
+                    resultMap.put(REASON, "Insufficient access to edit page");
+                    return success;
+                }
+                status = "refresh";
+                
+                // translate old portlet id to new portlet id
+                Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
+                if (newFragment == null)
+                {
+                    success = false;
+                    resultMap.put( REASON, "Failed to find new fragment for portlet id: " + moveFragmentId );
+                    return success;                    
+                }
+                moveFragmentId = newFragment.getId();
+                
+                if ( currentLayoutFragment != null )
+                {
+                    newFragment = getFragmentIdFromLocation(layoutRow, layoutColumn, requestContext.getPage());
+                    if (newFragment == null)
+                    {
+                        success = false;
+                        resultMap.put( REASON, "Failed to find new parent layout fragment id: " + currentLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
+                        return success;
+                    }
+                    currentLayoutFragment = newFragment;
+                    if ( moveToLayoutFragment != null )
+                    {
+                        newFragment = getFragmentIdFromLocation(moveToLayoutRow, moveToLayoutColumn, requestContext.getPage());
+                        if (newFragment == null)
+                        {
+                            success = false;
+                            resultMap.put( REASON, "Failed to find new move-to layout fragment id: " + moveToLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
+                            return success;
+                        }
+                        moveToLayoutFragment = newFragment;
+                    }
+                }
+            }
+            
+            if ( moveToLayoutFragment != null )
+            {
+                success = moveToOtherLayoutFragment( requestContext,
+                                        			 batch,
+                                        			 resultMap,
+                                        			 moveFragmentId,
+                                        			 moveToLayoutFragment,
+                                        			 currentLayoutFragment ) ;
+            }
+            else
+            {
+            	PortletPlacementContext placement = null;
+            	
+            	if ( currentLayoutFragment == null )
+            		currentLayoutFragment = getParentFragmentById( moveFragmentId, requestContext.getPage().getRootFragment() );
+            	
+                if ( currentLayoutFragment != null )
+                    placement = new PortletPlacementContextImpl( requestContext, currentLayoutFragment );
+                else
+                    placement = new PortletPlacementContextImpl( requestContext );
+                
+                Fragment fragment = placement.getFragmentById(moveFragmentId);
+                if ( fragment == null )
+                {
+                    success = false;
+                    resultMap.put( REASON, "Failed to find fragment for portlet id: " + moveFragmentId );
+                    return success;
+                }
+                
+                success = moveInFragment( requestContext, placement, fragment, null, resultMap, batch );
+            }
+            if ( success )
+            {
+            	resultMap.put( STATUS, status );
+            }
+        }
+        catch ( Exception e )
+        {
+            // Log the exception
+            log.error( "exception while moving a portlet", e );
+            resultMap.put( REASON, e.toString() );
+            // Return a failure indicator
+            success = false;
+        }
+
+        return success;
+    }
+    
+    protected boolean moveInFragment( RequestContext requestContext, PortletPlacementContext placement, Fragment fragment, Fragment placeInLayoutFragment, Map resultMap, boolean batch )
+        throws PortletPlacementException, NodeException, AJAXException
+    {
+    	boolean success = true;
+
+    	String moveFragmentId = fragment.getId();
+    	boolean addFragment = (placeInLayoutFragment != null);
+        Coordinate returnCoordinate = null;
+        float oldX = 0f, oldY = 0f, oldZ = 0f, oldWidth = 0f, oldHeight = 0f;
+        float x = -1f, y = -1f, z = -1f, width = -1f, height = -1f;
+        boolean absHeightChanged = false;
+
+        // desktop extended
+        String posExtended = getActionParameter( requestContext, DESKTOP_EXTENDED );
+        if ( posExtended != null )
+        {
+            Map fragmentProperties = fragment.getProperties();
+            if ( fragmentProperties == null )
+            {
+                success = false;
+                resultMap.put(REASON, "Failed to acquire fragment properties map for portlet id: " + moveFragmentId );
+                return success;
+            }
+            String oldDeskExt = (String)fragmentProperties.get( DESKTOP_EXTENDED );
+            resultMap.put( OLD_DESKTOP_EXTENDED, ( (oldDeskExt != null) ? oldDeskExt : "" ) );
+            fragmentProperties.put( DESKTOP_EXTENDED, posExtended );
+        }
+                
+        // only required for moveabs
+        if ( iMoveType == ABS )
+        {
+            Coordinate newCoordinate = getCoordinateFromParams( requestContext );
+            returnCoordinate = placement.moveAbsolute( fragment, newCoordinate, addFragment );
+            String sHeight = getActionParameter( requestContext, HEIGHT );
+            if ( sHeight != null && sHeight.length() > 0 )
+            {
+                oldHeight = fragment.getLayoutHeight();
+                height = Float.parseFloat( sHeight );
+                fragment.setLayoutHeight( height );
+                absHeightChanged = true;
+            }
+        } 
+        else if ( iMoveType == LEFT )
+        {
+            returnCoordinate = placement.moveLeft( fragment );
+        } 
+        else if ( iMoveType == RIGHT )
+        {
+            returnCoordinate = placement.moveRight( fragment );
+        } 
+        else if ( iMoveType == UP )
+        {
+            returnCoordinate = placement.moveUp( fragment );
+        } 
+        else if ( iMoveType == DOWN )
+        {
+            returnCoordinate = placement.moveDown( fragment );
+        }
+        else if ( iMoveType == CARTESIAN )
+        {
+            String sx = getActionParameter( requestContext, X );
+            String sy = getActionParameter( requestContext, Y );
+            String sz = getActionParameter( requestContext, Z );
+            String sWidth = getActionParameter( requestContext, WIDTH );
+            String sHeight = getActionParameter( requestContext, HEIGHT );
+            if ( sx != null )
+            {
+                oldX = fragment.getLayoutX();
+                x = Float.parseFloat( sx ); 
+                fragment.setLayoutX( x );
+            }
+            if ( sy != null )
+            {
+                oldY = fragment.getLayoutY();                    
+                y = Float.parseFloat( sy ); 
+                fragment.setLayoutY( y );
+            }                
+            if ( sz != null )
+            {
+                oldZ = fragment.getLayoutZ();                    
+                z = Float.parseFloat( sz ); 
+                fragment.setLayoutZ( z );
+            }                
+            if ( sWidth != null )
+            {
+                oldWidth = fragment.getLayoutWidth();                    
+                width = Float.parseFloat( sWidth ); 
+                fragment.setLayoutWidth( width );
+            }
+            if ( sHeight != null )
+            {
+                oldHeight = fragment.getLayoutHeight();                    
+                height = Float.parseFloat( sHeight ); 
+                fragment.setLayoutHeight( height );
+            }
+        }
+        
+        // synchronize back to the page layout root fragment
+        Page page = placement.syncPageFragments();
+    
+        if ( placeInLayoutFragment != null )
+        {
+            placeInLayoutFragment.getFragments().add( fragment );
+        }
+        
+        if ( pageManager != null && ! batch )
+        {
+            pageManager.updatePage( page );
+        }
+        
+        if ( iMoveType == CARTESIAN )
+        {
+            putCartesianResult( resultMap, x, oldX, X, OLD_X );
+            putCartesianResult( resultMap, y, oldY, Y, OLD_Y );                
+            putCartesianResult( resultMap, z, oldZ, Z, OLD_Z );
+            putCartesianResult( resultMap, width, oldWidth, WIDTH, OLD_WIDTH );
+            putCartesianResult( resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT );
+        }
+        else
+        {
+            // Need to determine what the old col and row were
+            resultMap.put( OLDCOL, String.valueOf( returnCoordinate.getOldCol() ) );
+            resultMap.put( OLDROW, String.valueOf( returnCoordinate.getOldRow() ) );
+            // Need to determine what the new col and row were
+            resultMap.put( NEWCOL, String.valueOf( returnCoordinate.getNewCol() ) );
+            resultMap.put( NEWROW, String.valueOf( returnCoordinate.getNewRow() ) );
+            if ( absHeightChanged )
+            {
+                putCartesianResult( resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT );
+            }
+        }
+        
+        resultMap.put( FRAGMENTID, moveFragmentId );
+        
+        return success;
+    }
+
+    protected boolean moveToOtherLayoutFragment( RequestContext requestContext,
+                                                 boolean batch,
+                                                 Map resultMap,
+                                                 String moveFragmentId,
+                                                 Fragment moveToLayoutFragment,
+                                                 Fragment removeFromLayoutFragment )
+        throws PortletPlacementException, NodeException, AJAXException
+    {
+        boolean success = true;
+        Fragment placeFragment = null;
+        if ( removeFromLayoutFragment != null )
+        {
+            PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, removeFromLayoutFragment );
+        
+            placeFragment = placement.getFragmentById( moveFragmentId );
+            if ( placeFragment == null )
+            {
+                success = false;
+                resultMap.put( REASON, "Failed to find fragment to move to another layout for fragment id: " + moveFragmentId );
+                return success;
+            }
+            placement.remove( placeFragment );
+            Page page = placement.syncPageFragments();
+            page.removeFragmentById( moveFragmentId );
+        }
+        if ( placeFragment != null )
+        {
+            return placeFragment( requestContext,
+                                  batch,
+                                  resultMap,
+                                  placeFragment,
+                                  moveToLayoutFragment );
+        }
+        return success;
+    }
+
+    protected boolean placeFragment( RequestContext requestContext,
+                                     boolean batch,
+                                     Map resultMap,
+                                     Fragment placeFragment,
+                                     Fragment placeInLayoutFragment )
+        throws PortletPlacementException, NodeException, AJAXException
+    {
+        boolean success = true;
+        if ( placeFragment == null )
+        {
+            success = false;
+            return success;
+        }
+        
+        // add fragment
+        PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, placeInLayoutFragment );
+        //placement.add( placeFragment, getCoordinateFromParams( requestContext ) );
+        
+        success = moveInFragment( requestContext, placement, placeFragment, placeInLayoutFragment, resultMap, batch );
+
+        return success;
+    }
+    
+    protected Coordinate getCoordinateFromParams(RequestContext requestContext)
+    {
+        String a_sCol = getActionParameter( requestContext, COL );
+        String a_sRow = getActionParameter( requestContext, ROW );
+
+        int a_iCol = 0;
+        int a_iRow = 0;
+
+        // Convert the col and row into integers
+        if ( a_sCol != null )
+        {
+            a_iCol = Integer.parseInt( a_sCol );
+        }
+        if ( a_sRow != null )
+        {
+            a_iRow = Integer.parseInt( a_sRow );
+        }
+
+        Coordinate a_oCoordinate = new CoordinateImpl( 0, 0, a_iCol, a_iRow );
+        return a_oCoordinate;
+    }
+
+    protected void putCartesianResult(Map resultMap, float value, float oldValue, String name, String oldName)
+    {    
+        if (value != -1F)
+        {
+            resultMap.put(oldName, new Float(oldValue));
+            resultMap.put(name, new Float(value));
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org