portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smi...@apache.org
Subject svn commit: r595431 [2/2] - in /portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed: decoration/ desktop/impl/ layout/ajax-xml/ layout/impl/
Date Thu, 15 Nov 2007 20:21:27 GMT
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=595431&r1=595430&r2=595431&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 Nov 15 12:21:24 2007
@@ -29,6 +29,7 @@
 import org.apache.jetspeed.ajax.AJAXException;
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.layout.Coordinate;
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 import org.apache.jetspeed.layout.PortletPlacementException;
@@ -37,6 +38,8 @@
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.page.document.NodeException;
+import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
+import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.RolePrincipal;
 import org.apache.jetspeed.security.impl.RolePrincipalImpl;
@@ -63,35 +66,42 @@
     implements AjaxAction, AjaxBuilder, Constants
 {
     protected static final Log log = LogFactory.getLog(MovePortletAction.class);
+    protected static final String eol = System.getProperty( "line.separator" );
+    
+    private PortletRegistry registry;
     private int iMoveType = -1;
     private String sMoveType = null;
 
-    public MovePortletAction(String template, 
-            String errorTemplate, 
-            String sMoveType)
-    throws AJAXException    
+    public MovePortletAction( String template, 
+            				  String errorTemplate,
+                              PortletRegistry registry,
+                              String sMoveType )
+        throws AJAXException
     {
-        this(template, errorTemplate, sMoveType, null, null);
+        this( template, errorTemplate, registry, 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);
+    public MovePortletAction( String template, 
+                              String errorTemplate,
+                              PortletRegistry registry,
+                              PageManager pageManager,
+                              PortletActionSecurityBehavior securityBehavior )
+        throws AJAXException
+    {
+        this( template, errorTemplate, registry, "moveabs", pageManager, securityBehavior );
+    }
+
+    public MovePortletAction( String template,
+                              String errorTemplate,
+                              PortletRegistry registry,
+                              String sMoveType,
+                              PageManager pageManager,
+                              PortletActionSecurityBehavior securityBehavior )
+        throws AJAXException
+    {
+        super( template, errorTemplate, pageManager, securityBehavior );
+        setMoveType( sMoveType );
+        this.registry = registry;
     }
 
     // Convert the move type into an integer
@@ -139,39 +149,7 @@
     {
         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;
@@ -187,9 +165,7 @@
                 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
@@ -203,7 +179,7 @@
                 }
                 else
                 {
-                    // determine if layoutId parameter refers to the current or the move target layout fragment
+                    // determine if layoutId parameter refers to the current layout fragment or to some other layout fragment
                     moveToLayoutFragment = currentLayoutFragment;
                     Iterator layoutChildIter = moveToLayoutFragment.getFragments().iterator();
                     while ( layoutChildIter.hasNext() )
@@ -223,7 +199,7 @@
                         // 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);
+                        currentLayoutFragment = getParentFragmentById( moveFragmentId, root );
                     }
                 }
                 if ( currentLayoutFragment == null )
@@ -233,36 +209,45 @@
                 }
             }
             
-            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
+            if ( false == checkAccess( requestContext, JetspeedActions.EDIT ) )
             {
+            	if ( ! isPageQualifiedForCreateNewPageOnEdit( requestContext ) )
+            	{
+            		success = false;
+                    resultMap.put(REASON, "Page is not qualified for create-new-page-on-edit");
+                    return success;
+            	}
+            	
                 Page page = requestContext.getPage();
-                Fragment fragment = page.getFragmentById(moveFragmentId);
-                if (fragment == null)
+                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 )
+                NestedFragmentContext moveFragmentContext = null;
+                NestedFragmentContext moveToFragmentContext = null;
+                try
                 {
-                    layoutColumn = currentLayoutFragment.getLayoutColumn();
-                    layoutRow = currentLayoutFragment.getLayoutRow();
-                    if ( moveToLayoutFragment != null )
-                    {
-                        moveToLayoutColumn = moveToLayoutFragment.getLayoutColumn();
-                        moveToLayoutRow = moveToLayoutFragment.getLayoutRow();
-                    }
+                	moveFragmentContext = new NestedFragmentContext( fragment, page, registry );
+                	//log.info( "moveFragmentContext original : " + eol + moveFragmentContext.toString() );
+                	if ( moveToLayoutFragment != null )
+                	{
+                		moveToFragmentContext = new NestedFragmentContext( moveToLayoutFragment, page, registry );
+                		//log.info( "moveToFragmentContext original : " + eol + moveToFragmentContext.toString() );
+                	}
                 }
-                
-                if (!createNewPageOnEdit(requestContext))
+                catch ( Exception ex )
+                {
+                	log.error( "Failure to construct nested context for fragment " + moveFragmentId, ex );
+                	success = false;
+                    resultMap.put( REASON, "Cannot construct nested context for fragment" );
+                    return success;
+                }
+                                
+                //log.info("before createNewPageOnEdit page-name=" + page.getName() + " page-path=" + page.getPath() + " page-url=" + page.getUrl() );
+                if ( ! createNewPageOnEdit( requestContext ) )
                 {
                     success = false;
                     resultMap.put(REASON, "Insufficient access to edit page");
@@ -270,37 +255,50 @@
                 }
                 status = "refresh";
                 
-                // translate old portlet id to new portlet id
-                Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
-                if (newFragment == null)
+                Page newPage = requestContext.getPage();                
+                //log.info("after createNewPageOnEdit page-name=" + newPage.getName() + " page-path=" + newPage.getPath() + " page-url=" + newPage.getUrl() );
+                Fragment newPageRootFragment = newPage.getRootFragment();
+                
+                // using NestedFragmentContext, find portlet id for copy of target portlet in the new page 
+                Fragment newFragment = null;
+                try
                 {
-                    success = false;
+                	newFragment = moveFragmentContext.getFragmentOnNewPage( newPage, registry );
+                	//log.info( "npe newFragment: " + newFragment.getType() + " " + newFragment.getId() );
+                }
+                catch ( Exception ex )
+                {
+                	log.error( "Failure to locate copy of fragment " + moveFragmentId, ex );
+                	success = false;
                     resultMap.put( REASON, "Failed to find new fragment for portlet id: " + moveFragmentId );
-                    return success;                    
+                    return success;
                 }
-                moveFragmentId = newFragment.getId();
                 
-                if ( currentLayoutFragment != null )
+                moveFragmentId = newFragment.getId();
+                currentLayoutFragment = getParentFragmentById( moveFragmentId, newPageRootFragment );
+                if ( currentLayoutFragment == null )
+                {
+                	success = false;
+                    resultMap.put( REASON, "Failed to find parent layout for copied fragment " + moveFragmentId );
+                    return success;
+                }
+                //log.info( "npe newParentFragment: " + currentLayoutFragment.getType() + " " + currentLayoutFragment.getId() );
+                if ( moveToLayoutFragment != null )
                 {
-                    newFragment = getFragmentIdFromLocation(layoutRow, layoutColumn, requestContext.getPage());
-                    if (newFragment == null)
+                	Fragment newMoveToFragment = null;
+                    try
                     {
-                        success = false;
-                        resultMap.put( REASON, "Failed to find new parent layout fragment id: " + currentLayoutFragment.getId() + " for portlet id: " + moveFragmentId );
-                        return success;
+                    	newMoveToFragment = moveToFragmentContext.getFragmentOnNewPage( newPage, registry );
+                    	//log.info( "npe newMoveToFragment: " + newMoveToFragment.getType() + " " + newMoveToFragment.getId() );
                     }
-                    currentLayoutFragment = newFragment;
-                    if ( moveToLayoutFragment != null )
+                    catch ( Exception ex )
                     {
-                        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;
+                    	log.error( "Failure to locate copy of destination fragment " + moveToLayoutFragment.getId(), ex );
+                    	success = false;
+                        resultMap.put( REASON, "Failed to find copy of destination fragment" );
+                        return success;
                     }
+                    moveToLayoutFragment = newMoveToFragment;
                 }
             }
             
@@ -316,14 +314,15 @@
             else
             {
             	PortletPlacementContext placement = null;
+            	Page page = requestContext.getPage();
             	
             	if ( currentLayoutFragment == null )
-            		currentLayoutFragment = getParentFragmentById( moveFragmentId, requestContext.getPage().getRootFragment() );
+            		currentLayoutFragment = getParentFragmentById( moveFragmentId, page.getRootFragment() );
             	
                 if ( currentLayoutFragment != null )
-                    placement = new PortletPlacementContextImpl( requestContext, currentLayoutFragment );
+                    placement = new PortletPlacementContextImpl( page, registry, currentLayoutFragment );
                 else
-                    placement = new PortletPlacementContextImpl( requestContext );
+                    placement = new PortletPlacementContextImpl( page, registry );
                 
                 Fragment fragment = placement.getFragmentById(moveFragmentId);
                 if ( fragment == null )
@@ -501,7 +500,8 @@
         Fragment placeFragment = null;
         if ( removeFromLayoutFragment != null )
         {
-            PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, removeFromLayoutFragment );
+        	Page page = requestContext.getPage();
+            PortletPlacementContext placement = new PortletPlacementContextImpl( page, registry, removeFromLayoutFragment );
         
             placeFragment = placement.getFragmentById( moveFragmentId );
             if ( placeFragment == null )
@@ -511,7 +511,7 @@
                 return success;
             }
             placement.remove( placeFragment );
-            Page page = placement.syncPageFragments();
+            page = placement.syncPageFragments();
             page.removeFragmentById( moveFragmentId );
         }
         if ( placeFragment != null )
@@ -540,7 +540,8 @@
         }
         
         // add fragment
-        PortletPlacementContext placement = new PortletPlacementContextImpl( requestContext, placeInLayoutFragment );
+        Page page = requestContext.getPage();
+        PortletPlacementContext placement = new PortletPlacementContextImpl( page, registry, placeInLayoutFragment );
         //placement.add( placeFragment, getCoordinateFromParams( requestContext ) );
         
         success = moveInFragment( requestContext, placement, placeFragment, placeInLayoutFragment, resultMap, batch );
@@ -577,5 +578,10 @@
             resultMap.put(oldName, new Float(oldValue));
             resultMap.put(name, new Float(value));
         }
+    }
+    
+    protected PortletRegistry getPortletRegistry()
+    {
+    	return this.registry;
     }
 }

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityConstraintsBehavior.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityConstraintsBehavior.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityConstraintsBehavior.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityConstraintsBehavior.java Thu Nov 15 12:21:24 2007
@@ -42,7 +42,11 @@
     
     public PortletActionSecurityConstraintsBehavior(PageManager pageManager)
     {
-        super(pageManager);
+    	this( pageManager, Boolean.FALSE );
+    }
+    public PortletActionSecurityConstraintsBehavior(PageManager pageManager, Boolean enableCreateUserPagesFromRolesOnEdit )
+    {
+        super( pageManager, enableCreateUserPagesFromRolesOnEdit );
         PortalConfiguration config = Jetspeed.getConfiguration();
         if (config != null)
         {

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathBehavior.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathBehavior.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathBehavior.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathBehavior.java Thu Nov 15 12:21:24 2007
@@ -37,10 +37,16 @@
 {
     protected Log log = LogFactory.getLog(PortletActionSecurityPathBehavior.class);    
     protected PageManager pageManager;
+    private boolean enableCreateUserPagesFromRolesOnEdit;
     
-    public PortletActionSecurityPathBehavior(PageManager pageManager)
+    public PortletActionSecurityPathBehavior(PageManager pageManager )
+    {
+    	this( pageManager, Boolean.FALSE ) ;
+    }
+    public PortletActionSecurityPathBehavior(PageManager pageManager, Boolean enableCreateUserPagesFromRolesOnEdit )
     {
         this.pageManager = pageManager;
+        this.enableCreateUserPagesFromRolesOnEdit = ( enableCreateUserPagesFromRolesOnEdit == null ? false : enableCreateUserPagesFromRolesOnEdit.booleanValue() );
     }
 
     public boolean checkAccess(RequestContext context, String action)
@@ -57,23 +63,43 @@
         }
         return true;
     }
+    
+    public boolean isCreateNewPageOnEditEnabled()
+    {
+    	return enableCreateUserPagesFromRolesOnEdit;
+    }
+    public boolean isPageQualifiedForCreateNewPageOnEdit(RequestContext context)
+    {
+    	if ( ! this.enableCreateUserPagesFromRolesOnEdit || context == null )
+    		return false ;
+    	return isPageQualifiedForCreateNewPageOnEdit( context.getPage().getPath() );
+    }
+    
+    protected boolean isPageQualifiedForCreateNewPageOnEdit( String pagePath )
+    {
+        if (pagePath == null)
+        	return false;
+        // page must be in role directory
+        return (pagePath.indexOf(Folder.ROLE_FOLDER) == 0);
+    }
 
     public boolean createNewPageOnEdit(RequestContext context)
     {
+    	if ( ! this.enableCreateUserPagesFromRolesOnEdit )
+    		return false ;
+
         Page page = context.getPage();        
-        String path = page.getPath();
+        String pagePath = page.getPath();
         try
-        {        
-            if (path == null)
-                return false;
-            // make sure we are not copying from user area
-            if (path.indexOf(Folder.USER_FOLDER) == -1)
+        {
+        	if ( isPageQualifiedForCreateNewPageOnEdit( pagePath ) )
             {
+        		String pageName = page.getName();
                 this.pageManager.createUserHomePagesFromRoles(context.getSubject());
                 page = this.pageManager.getPage(Folder.USER_FOLDER 
                                                 + context.getRequest().getUserPrincipal().getName()
                                                 + Folder.PATH_SEPARATOR 
-                                                + Folder.FALLBACK_DEFAULT_PAGE);                 
+                                                + pageName);   // was Folder.FALLBACK_DEFAULT_PAGE prior to 2007-11-06
                 context.setPage(new ContentPageImpl(page));
                 context.getRequest().getSession().removeAttribute(ProfilerValveImpl.PORTAL_SITE_SESSION_CONTEXT_ATTR_KEY);                
             }            

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathMergeBehavior.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathMergeBehavior.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathMergeBehavior.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletActionSecurityPathMergeBehavior.java Thu Nov 15 12:21:24 2007
@@ -44,12 +44,15 @@
     extends PortletActionSecurityPathBehavior
     implements PortletActionSecurityBehavior
 {
-    protected Log log = LogFactory.getLog(PortletActionSecurityPathMergeBehavior.class);    
-    protected PageManager pageManager;
+    protected Log log = LogFactory.getLog(PortletActionSecurityPathMergeBehavior.class);
     
-    public PortletActionSecurityPathMergeBehavior(PageManager pageManager)
+    public PortletActionSecurityPathMergeBehavior( PageManager pageManager )
     {
-        super(pageManager);
+    	this( pageManager, Boolean.FALSE );
+    }
+    public PortletActionSecurityPathMergeBehavior( PageManager pageManager, Boolean enableCreateUserPagesFromRolesOnEdit )
+    {
+        super( pageManager, enableCreateUserPagesFromRolesOnEdit );
     }
 
     public Subject getSubject(RequestContext context)

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java Thu Nov 15 12:21:24 2007
@@ -19,18 +19,23 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ArrayList;
 import java.util.Set;
-import java.util.Vector;
 import java.util.Map;
+import java.util.Collections;
+import java.util.Comparator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.layout.Coordinate;
 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.request.RequestContext;
+import org.apache.pluto.om.common.Parameter;
+import org.apache.pluto.om.common.ParameterSet;
+import org.apache.pluto.om.portlet.PortletDefinition;
 
 
 /**
@@ -59,143 +64,354 @@
  * 
  * @author <a>David Gurney</a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:smilek@apache.org">Steve Milek</a>
  * @version $Id: $
  */
 public class PortletPlacementContextImpl implements PortletPlacementContext 
 {
-    /** Logger */
-    private Log log = LogFactory.getLog(PortletPlacementContextImpl.class);
+    private static Log log = LogFactory.getLog( PortletPlacementContextImpl.class );
+    protected static final String eol = System.getProperty( "line.separator" );
 
 	// Columns are reference by index, the rows are held
-	// in the array list as shown below:
+	// in the columnsList as shown below:
 	//
 	// [0]        [1]          [2]
 	// ArrayList  ArrayList    ArrayList
+	//  Row0Frag   Row0Frag     Row0Frag
 	//  Row1Frag   Row1Frag     Row1Frag
 	//  Row2Frag   Row2Frag     Row2Frag
-	//  Row3Frag   Row3Frag     Row3Frag
 	//  ...
 	//
-	protected Vector[] columnsList = null;
+	protected ArrayList[] columnsList = null;
 	
 	// Used as a convience when looking up a particular fragment
 	//
-	// Key is Fragment, value is a Coordinate object
+	// key is Fragment id (String), value is a Coordinate object
 	protected Map fragmentCoordinateMap = new HashMap();
 	
 	// Used as a convience when looking up a particular fragment by id
 	//
-	// Key is the Fragment id (String), value is the Fragment
+	// key is the Fragment id (String), value is the Fragment
 	protected Map fragmentMap = new HashMap();
 	
-	// Number of columns found
+	// Number of columns
 	protected int numberOfColumns = -1;
 	
     protected Page page;
+    private PortletRegistry registry;
     protected Fragment layoutContainerFragment;
         
-	public PortletPlacementContextImpl( RequestContext requestContext ) 
+	public PortletPlacementContextImpl( Page page, PortletRegistry registry ) 
         throws PortletPlacementException 
     {
-		init( requestContext, null );
+		this( page, registry, null );
 	}
-    
-    public PortletPlacementContextImpl( RequestContext requestContext, Fragment container ) 
+        
+    public PortletPlacementContextImpl( Page page, PortletRegistry registry, Fragment container ) 
         throws PortletPlacementException 
     {
-        init( requestContext, container );
+    	if ( page == null )
+    		throw new NullPointerException( "PortletPlacementContext cannot be instantiated with a null Page argument" );
+    	if ( registry == null )
+    		throw new NullPointerException( "PortletPlacementContext cannot be instantiated with a null PortletRegistry argument" );
+    	
+    	this.page = page;
+    	this.registry = registry;
+    	
+    	init( container );
     }
 	
-	// Initialize the data structures by getting the fragments
-	// from the page manager
-	protected void init( RequestContext requestContext, Fragment container )
+    protected void init( Fragment container )
         throws PortletPlacementException 
     {
-        this.page = requestContext.getPage();
         if ( container == null )
         {
             container = page.getRootFragment();
+            if ( container == null )
+            	throw new PortletPlacementException( "PortletPlacementContext cannot acquire root layout fragment from page" );
+        }        
+        if ( ! "layout".equals( container.getType() ) )
+        {
+        	throw new PortletPlacementException( "PortletPlacementContext specified container fragment (" + container.getId() + ") is not a layout fragment, but is type: " + container.getType() );
         }
         this.layoutContainerFragment = container;
         
-        processLayoutContainerFragment();
-
-        // The final step is to populate the array with the fragments
-		populateArray();
+        int columnCount = PortletPlacementContextImpl.getColumnCountAndSizes( container, registry, null );
+        if ( columnCount <= 0 )
+        {
+        	throw new PortletPlacementException( "PortletPlacementContext cannot detemine number of columns in layout fragment (" + container.getId() + ")" );
+        }
+        this.numberOfColumns = columnCount;
+        
+        initProcessLayoutContainerFragment();
         
         //debugFragments( "init" );
 	}
 	
-	/**
-	 * For the layout container fragment, evaluate each child fragment and 
-	 * populate the internal data structures
-	 */
-	protected void processLayoutContainerFragment() 
+	private void initProcessLayoutContainerFragment() 
         throws PortletPlacementException 
     {
-        // Process this fragment, then its children
-		if ( this.layoutContainerFragment != null )
+        List fragChildren = this.layoutContainerFragment.getFragments();
+        int fragChildCount = fragChildren.size();
+        
+        int columnCount = this.numberOfColumns;
+        
+        // sort the fragments in the same manner as /portal and /desktop rendering
+        FragmentLinkedListEntry[][] colLinkedLists = new FragmentLinkedListEntry[columnCount][fragChildCount];
+        FragmentLinkedListInfo[] colLinkedListsInfo = new FragmentLinkedListInfo[columnCount];
+        for ( int colIndex = 0 ; colIndex < columnCount ; colIndex++ )
+        {
+        	colLinkedListsInfo[ colIndex ] = new FragmentLinkedListInfo();
+        }
+        for( int fragChildIndex = 0; fragChildIndex < fragChildCount; fragChildIndex++ ) 
         {
-            // Process the child fragments
-            List childFragments = this.layoutContainerFragment.getFragments();
-            int highRow = 0;
-            for( int ix = 0; ix < childFragments.size(); ix++ ) 
+            Fragment fragment = (Fragment)fragChildren.get( fragChildIndex );		
+            if ( fragment != null )
             {
-                Fragment fragment = (Fragment)childFragments.get( ix );
-			
-                if ( fragment != null ) 
-                {
-                	int col = getFragmentCol( fragment );
-    				int row = getFragmentRow( fragment );
-    		        
-    		        if ( row < 0 ) 
-                        row = highRow;
-    		        else if ( row > highRow )
-    		        	highRow = row;
-    		        
-    	        	// Add this fragment to the data structures
-    	        	addFragmentInternal( fragment, col, row );
-                }
+            	int col = getColumnFromFragment( fragment );            	
+            	
+            	FragmentLinkedListEntry[] ll = colLinkedLists[col];
+            	FragmentLinkedListInfo llInfo = colLinkedListsInfo[col];
+            	
+            	Integer rowObj = getRowFromFragment( fragment );
+            	int row;
+            	if ( rowObj != null )
+            		row = rowObj.intValue();
+            	else
+            		row = llInfo.getHigh() + 1;   // fragment with unspecified row property is assigned 
+                                                  //    the value of current fragment in the highest row + 1
+            		                              //    - this is one of the reasons we are not using sort here
+            	
+            	FragmentLinkedListEntry fragLLentry = new FragmentLinkedListEntry( fragChildIndex, row );
+            	int llLen = llInfo.useNextAvailableIndex();
+            	ll[ llLen ] = fragLLentry;
+            	if ( llLen == 0 )
+            	{
+            		llInfo.setHead( 0 );
+            		llInfo.setTail( 0 );
+            		llInfo.setHigh( row );
+            	}
+            	else
+            	{
+            		if ( row > llInfo.getHigh() )
+            		{
+            			ll[ llInfo.getTail() ].setNextEntry( llLen );
+            			llInfo.setHigh( row );
+            			llInfo.setTail( llLen );
+            		}
+            		else
+            		{
+            			int llEntryIndex = llInfo.getHead();
+            			int llPrevEntryIndex = -1;
+            			while ( ll[llEntryIndex].getRow() < row )
+            			{
+            				llPrevEntryIndex = llEntryIndex;
+            				llEntryIndex = ll[llEntryIndex].getNextEntry();
+            			}
+            			if ( ll[llEntryIndex].getRow() == row )
+            			{   // a subsequent fragment (in the document) with a row value equal to that 
+            				//    of a previous fragment is inserted before the previous fragment
+            				//    - this is one of the reasons we are not using sort here
+            				int incrementedRow = row + 1;
+            				ll[llEntryIndex].setRow( incrementedRow );
+            				if ( llInfo.getTail() == llEntryIndex )
+            					llInfo.setHigh( incrementedRow );
+            			}
+            			fragLLentry.setNextEntry( llEntryIndex );
+            			if ( llPrevEntryIndex == -1 )
+            				llInfo.setHead( llLen );
+            			else
+            				ll[llPrevEntryIndex].setNextEntry( llLen );
+            		}
+            	}
             }
-		}
+        }
+
+        ArrayList[] columnFragments = new ArrayList[ columnCount ];
+        for ( int colIndex = 0 ; colIndex < columnCount ; colIndex++ )
+        {
+        	ArrayList fragmentsInColumn = new ArrayList();
+        	columnFragments[ colIndex ] = fragmentsInColumn;
+        	
+        	FragmentLinkedListEntry[] ll = colLinkedLists[colIndex];
+        	FragmentLinkedListInfo llInfo = colLinkedListsInfo[colIndex];
+            
+        	int rowIndex = 0;
+            int nextEntryIndex = llInfo.getHead();
+            while ( nextEntryIndex != -1 )
+            {
+                FragmentLinkedListEntry fragLLentry = ll[nextEntryIndex];
+                Fragment fragment = (Fragment)fragChildren.get( fragLLentry.getFragmentIndex() );
+                
+                fragmentsInColumn.add( fragment );
+                CoordinateImpl coordinate = new CoordinateImpl( colIndex, rowIndex );
+        		this.fragmentCoordinateMap.put( fragment.getId(), coordinate );
+        		this.fragmentMap.put( fragment.getId(), fragment );
+        		
+                nextEntryIndex = fragLLentry.getNextEntry();
+        		rowIndex++;
+            }
+        }
+        this.columnsList = columnFragments;
 	}
 	
-	// Adds the fragment to the internal data structures
-	protected void addFragmentInternal( Fragment fragment, int col, int row ) 
-    {
-		// Create a Coordinate object to hold the row and column
-		CoordinateImpl coordinate = new CoordinateImpl( col, row );
+	private int getColumnFromFragment( Fragment fragment )
+	{
+		// get column value in the same manner as /portal and /desktop rendering
+		
+		// get column from properties to distinguish between null and -1 (fragment.getLayoutColumn() is -1 when column is not specified)
+		String colStr = (String)fragment.getProperties().get( "column" );
+        int columnCount = this.numberOfColumns;
+		int col = columnCount - 1;
+		if ( colStr != null )
+		{
+			try
+    		{
+				col = Integer.parseInt( colStr );
+				if ( col < 0 )
+					col = 0;
+				else if ( col >= columnCount )
+					col = columnCount - 1;
+    		}
+    		catch ( NumberFormatException ex )
+    		{
+    			col = columnCount - 1;
+    		}
+		}
+		return col;
+	}
+	private Integer getRowFromFragment( Fragment fragment )
+	{
+		// get row value in the same manner as /portal and /desktop rendering
+		
+		// get row from properties to distinguish between null and -1 (fragment.getLayoutRow() is -1 when row is not specified)
+		String rowStr = (String)fragment.getProperties().get( "row" );
+		if ( rowStr != null )
+		{
+			try
+    		{
+				int row = Integer.parseInt( rowStr );
+				if ( row < 0 )
+					row = 0;
+				return new Integer( row );
+    		}
+    		catch ( NumberFormatException ex )
+    		{
+    		}
+		}
+		return null;
+	}
+	
+	private int normalizeColumnIndex( int col, ArrayList[] columnFragments, int defaultForUnspecifiedCol )
+	{
+		int columnCount = this.numberOfColumns;
+		if ( col >= columnCount )
+    		col = (columnCount -1);
+    	else if ( col < 0 && defaultForUnspecifiedCol >= 0 && defaultForUnspecifiedCol < columnCount )
+    		col = defaultForUnspecifiedCol;
+    	else if ( col < 0 )
+    		col = 0;
+		return col;
+	}
+
+	class FragmentLinkedListInfo
+	{
+		private int head = -1;
+		private int tail = -1;
+		private int high = -1;
+		private int availableNextIndex = 0;
 		
-		// Save the fragment in the lookup hash
-		this.fragmentCoordinateMap.put( fragment, coordinate );
-		this.fragmentMap.put( fragment.getId(), fragment );
+		FragmentLinkedListInfo()
+		{
+		}
 		
-		// Establish the maximum column number
-		if ( col > this.numberOfColumns ) 
-        {
-			this.numberOfColumns = col + 1;
+		public int getHead()
+		{
+        	return head;
+        }
+		public void setHead( int newOne )
+		{
+        	this.head = newOne;
+        }
+		public int getTail()
+		{
+        	return tail;
+        }
+		public void setTail( int newOne )
+		{
+        	this.tail = newOne;
+        }
+		public int getHigh()
+		{
+        	return high;
+        }
+		public void setHigh( int newOne )
+		{
+        	this.high = newOne;
+        }
+		public int useNextAvailableIndex()
+		{
+			return this.availableNextIndex++;
 		}
 	}
+	
+	class FragmentLinkedListEntry
+	{
+		private int fragmentIndex;
+		private int row;
+		private int nextEntry = -1;
+		
+		FragmentLinkedListEntry( int fragmentIndex, int row )
+		{
+			this.fragmentIndex = fragmentIndex;
+			this.row = row;
+		}
+		
+		public int getFragmentIndex()
+		{
+			return this.fragmentIndex;
+		}
+		public int getRow()
+		{
+			return this.row;
+		}
+		public void setRow( int newOne )
+		{
+			this.row = newOne;
+		}
+		public int getNextEntry()
+		{
+			return this.nextEntry;
+		}
+		public void setNextEntry( int newOne )
+		{
+			this.nextEntry = newOne;
+		}
+	}	
     
-    public Fragment debugFragments(String debug)
+	public String dumpFragments( String debug )
     {       
         StringBuffer out = new StringBuffer();
-        out.append( "PortletPlacementContext - " ).append( debug ).append( " - container: " ).append( layoutContainerFragment == null ? "<null>" : ( layoutContainerFragment.getId() + " / " + layoutContainerFragment.getType() ) ).append( "\n" );
+        out.append( "PortletPlacementContext - " );
+        if ( debug != null )
+        	out.append( debug ).append( " - " );
+        out.append( "container: " ).append( this.layoutContainerFragment == null ? "<null>" : ( this.layoutContainerFragment.getId() + " / " + this.layoutContainerFragment.getType() ) ).append( " column-count=" ).append( this.numberOfColumns ).append( eol );
         for (int ix = 0; ix < this.columnsList.length; ix++)
         {
-            Vector column = this.columnsList[ix];
-            out.append( "   column " ).append( ix ).append( "\n" );
+            ArrayList column = this.columnsList[ix];
+            out.append( "   column " ).append( ix ).append( eol );
             Iterator frags = column.iterator();
             while ( frags.hasNext() )
             {
                 Fragment f = (Fragment)frags.next();
-                out.append( "      frag " ).append( f == null ? "<null>" : f.getId() );
-                if ( f != null )
-                    out.append( " / " ).append( f.getType() ).append( " col=" ).append( f.getLayoutColumn() ).append( " row=" ).append( f.getLayoutRow() );
-                out.append( "\n" );
+                out.append( "      frag " ).append( f == null ? "<null>" : ( f.getId() + " / " + f.getType() ) ).append( eol );
             }
         }
-        log.info( out.toString() );
+        return out.toString();
+    }
+    public Fragment debugFragments( String debug )
+    {
+        log.info( dumpFragments( debug ) );
         return layoutContainerFragment;
     }
 
@@ -206,254 +422,164 @@
      * @return the managed page layout with updated fragment state. 
      */
     public Page syncPageFragments()
-    {        
-        for ( int col = 0; col < this.columnsList.length; col++ )
-        {
-            Vector column = this.columnsList[col];
-            Iterator frags = column.iterator();
-            int row = 0;
-            while ( frags.hasNext() )
-            {
-                Fragment f = (Fragment)frags.next();
-                if ( f == null )
-                    continue;
-                f.setLayoutColumn( col );
-                f.setLayoutRow( row );
-                row++;
-            }
-        }
-        //debugFragments( "syncPageFragments" );
-        return page;
+    {
+    	syncFragments( true, -1 );
+    	//debugFragments( "syncPage" );
+    	return this.page;
     }
     
-	// Helper method
-	// The implementation will probably change to get this information
-	// directly from the fragment via fragment.getFragmentCol()
-	protected int getFragmentRow(Fragment fragment)
+    protected int getLatestColumn( Coordinate coordinate )
     {
-        return fragment.getLayoutRow();
-	}
-	
-	// The implementation will probably change to get this information
-	// directly from the fragment via fragment.getFragmentRow()
-	protected int getFragmentCol(Fragment fragment) 
+    	int col = -1;
+    	if ( coordinate != null )
+    	{
+    		col = coordinate.getNewCol();
+    		if ( col == -1 )
+    			col = coordinate.getOldCol();
+    	}
+    	return col;
+    }
+    protected int getLatestRow( Coordinate coordinate )
     {
-        int col = fragment.getLayoutColumn();
-        if (col < 0)
-            col = 0;
-        return col;
-	}
-		
-	/**
-	 * Now that we know the number of columns, the array can be
-	 * constructed and populated
-	 */
-	protected void populateArray() throws PortletPlacementException 
+    	int row = -1;
+    	if ( coordinate != null )
+    	{
+    		row = coordinate.getNewRow();
+    		if ( row == -1 )
+    			row = coordinate.getOldRow();
+    	}
+    	return row;
+    }
+    
+    protected void syncFragments( boolean updateFragmentObjects, int onlyForColumnIndex )
     {
-		if ( this.numberOfColumns == -1 )
+        for ( int colIndex = 0; colIndex < this.columnsList.length; colIndex++ )
         {
-			//throw new PortletPlacementException("no columns found");
-            this.numberOfColumns = 1; // create a new column
-		}
-		
-		// Allocate the memory for the array of ArrayLists
-		// Add one since it is zero based
-		this.columnsList = new Vector[this.numberOfColumns + 1];
-		
-		// Put an array list into each index
-		for ( int i = 0; i < this.numberOfColumns + 1; i++ )
-        {
-			this.columnsList[i] = new Vector();
-		}
-		
-		// Get all of the fragments from the hashmap
-		Set keys = this.fragmentCoordinateMap.keySet();
-		Iterator keyIterator = keys.iterator();
-		while ( keyIterator.hasNext() ) 
-        {
-			// The key is a Fragment
-			Fragment fragment = (Fragment) keyIterator.next();
-			
-			// Get the Coordinate associated with this fragment
-			Coordinate coordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment );
-			
-			// Make sure we have both
-			if ( fragment != null && coordinate != null )
-            {
-				// Get the array list for the column
-				Vector columnArray = this.columnsList[coordinate.getOldCol()];
-				
-				int row = coordinate.getOldRow();
-				
-				// Before setting the fragment in the array it might
-				// be necessary to add blank rows before this row
-				// An ArrayList can only set an element that already exists
-				prepareList( columnArray, row );
-				
-				// Place the fragment in the array list using the row
-				columnArray.set( row, fragment );
-			}
-		}
-	}
-	
-	// Ensures that the array list has at least row number of rows
-	protected void prepareList(Vector list, int row) 
+        	if ( onlyForColumnIndex == -1 || onlyForColumnIndex == colIndex )
+        	{
+	            ArrayList column = this.columnsList[colIndex];
+	            int colRowCount = column.size();
+	        	for ( int rowIndex= 0; rowIndex < colRowCount; rowIndex++ )
+	        	{
+	        		Fragment fragment = (Fragment)column.get( rowIndex );
+	                Coordinate coordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+	                boolean needsReplacementCoordinate = false;
+	                
+	                if ( getLatestColumn( coordinate ) != colIndex || getLatestRow( coordinate ) != rowIndex )
+	                	needsReplacementCoordinate = true;
+
+	                if ( needsReplacementCoordinate )
+	        		{
+	        			Coordinate replacementCoordinate = new CoordinateImpl( coordinate.getOldCol(), coordinate.getOldRow(), colIndex, rowIndex );
+	        			this.fragmentCoordinateMap.put( fragment.getId(), replacementCoordinate );
+	        		}
+	        		if ( updateFragmentObjects )
+	                {
+	                	fragment.setLayoutColumn( colIndex );
+	                	fragment.setLayoutRow( rowIndex );
+	                }
+	            }
+        	}
+        }
+    }
+    
+    public int getFragmentRow( Fragment fragment )
     {
-		if(list != null) 
-        {
-			int size = list.size();
-			if(row + 1 > size) 
-            {
-				// Add one to the row since it is zero based
-				for(int i = size; i < row + 1; i++) 
-                {
-					list.add(null);
-				}
-			}
-		}
-	}
-		
-    public int addColumns( int col )
-        throws PortletPlacementException 
+    	if ( fragment == null ) return -1;
+		Coordinate coordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+    	
+		if ( coordinate == null )
+			return -1;
+		if ( coordinate.getNewRow() >= 0  )
+			return coordinate.getNewRow();
+		return coordinate.getOldRow();
+    }
+    
+    public int getFragmentCol( Fragment fragment )
     {
-        if ( col > this.numberOfColumns )
-        {            
-            if ( col < 100 ) // arbitrary limit of columns
-            {
-                // expand
-                int prevNumberOfColumns = this.numberOfColumns;
-                this.numberOfColumns = col + 1;
-                
-                Vector [] temp = new Vector[this.numberOfColumns];
-                for (int ix = 0; ix < prevNumberOfColumns; ix++)
-                    temp[ix] = this.columnsList[ix];
-                for (int ix = prevNumberOfColumns; ix < temp.length; ix++)
-                    temp[ix] = new Vector();
-                this.columnsList = temp;
-            }
-            else
-            {
-                throw new PortletPlacementException( "cannot add column - " + col + " is above the limit of columns that this api supports" );
-            }
-        }
-        return col;
+    	if ( fragment == null ) return -1;
+		Coordinate coordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+    	
+		if ( coordinate == null )
+			return -1;
+		if ( coordinate.getNewCol() >= 0  )
+			return coordinate.getNewCol();
+		return coordinate.getOldCol();
     }
-
-	public Fragment getFragment(String fragmentId) throws PortletPlacementException 
+			
+	public Fragment getFragment( String fragmentId ) throws PortletPlacementException 
     {
-		return (Fragment)this.fragmentMap.get(fragmentId);
+		return (Fragment)this.fragmentMap.get( fragmentId );
 	}
 	
-	public Fragment getFragmentAtOldCoordinate(Coordinate coordinate) throws PortletPlacementException 
+	public Fragment getFragmentAtOldCoordinate( Coordinate coordinate ) throws PortletPlacementException 
     {
-		return getFragmentAtCoordinate(coordinate, true);
+		return getFragmentAtCoordinate( coordinate, true, false );
 	}
 
-	public Fragment getFragmentAtNewCoordinate(Coordinate coordinate) throws PortletPlacementException 
+	public Fragment getFragmentAtNewCoordinate( Coordinate coordinate ) throws PortletPlacementException 
     {
-		return getFragmentAtCoordinate(coordinate, false);
+		return getFragmentAtCoordinate( coordinate, false, false );
 	}
 
-	protected Fragment getFragmentAtCoordinate(Coordinate coordinate, boolean isOld) throws PortletPlacementException 
+	protected Fragment getFragmentAtCoordinate( Coordinate coordinate, boolean useOldCoordinateValues, boolean suppressExceptions ) throws PortletPlacementException 
     {
 		int col = -1;
 		int row = -1;
-		if (isOld == true) 
+		if ( useOldCoordinateValues ) 
         {
 			col = coordinate.getOldCol();
 			row = coordinate.getOldRow();
-		} else 
+		}
+		else 
         {
 			col = coordinate.getNewCol();
 			row = coordinate.getNewRow();
 		}
 		
 		// Do some sanity checking about the request
-		if ( col < 0 || col > this.columnsList.length )
+		if ( col < 0 || col >= this.numberOfColumns )
         {
-			throw new PortletPlacementException("requested column is out of bounds");
+			if ( suppressExceptions )
+				return null;
+			throw new PortletPlacementException( "Requested column (" + col + ") is out of bounds (column-count=" + this.numberOfColumns + ")" );
 		}
 		
 		// Get the array list associated with the column
-		Vector columnArray = this.columnsList[col];
-		if ( row < 0 || row > columnArray.size() )
+		ArrayList columnArray = this.columnsList[col];
+		if ( row < 0 || row >= columnArray.size() )
         {
-			throw new PortletPlacementException("requested row is out of bounds");
+			if ( suppressExceptions )
+				return null;
+			throw new PortletPlacementException( "Requested row (" + row + ") is out of bounds (col[" + col + "].row-count=" + columnArray.size() + ")" );
 		}
 		
 		return (Fragment)columnArray.get( row );
 	}
 	
-	public Fragment getFragmentById(String fragmentId) throws PortletPlacementException 
+	public Fragment getFragmentById( String fragmentId ) throws PortletPlacementException 
     {
 		return (Fragment)this.fragmentMap.get( fragmentId );
 	}
 
 	public int getNumberColumns() throws PortletPlacementException 
     {
-        return numberOfColumns;
-		//return this.columnsList.length;
+        return this.numberOfColumns;
 	}
 
-	public int getNumberRows(int col) throws PortletPlacementException 
+	public int getNumberRows( int col ) throws PortletPlacementException 
     {
 		// Sanity check the column
-		if ( col < 0 || col > this.columnsList.length ) 
+		if ( col < 0 || col >= this.numberOfColumns )
         {
-			throw new PortletPlacementException( "column out of bounds" );
+			throw new PortletPlacementException( "Requested column (" + col + ") is out of bounds (column-count=" + this.numberOfColumns + ")" );
 		}
-		
 		return this.columnsList[col].size();
 	}
 	
 	public Coordinate add( Fragment fragment, Coordinate coordinate ) throws PortletPlacementException 
     {
-        int col = coordinate.getNewCol();
-        int row = coordinate.getNewRow();
-        
-        if ( this.numberOfColumns == -1 )
-        {
-            this.numberOfColumns = 1;
-            this.columnsList = new Vector[this.numberOfColumns];
-            col = 0;
-        }        
-        if ( col > this.numberOfColumns )
-        {    
-            col = addColumns( col );
-        }
-        
-        Vector column = this.columnsList[col];
-        if ( column != null )
-        {
-            for ( int ix = 0; ix < column.size(); ix++ )
-            {                
-                Fragment frag = (Fragment)column.get( ix );
-                if (frag == null)
-                    continue;
-                Coordinate c = (Coordinate)this.fragmentCoordinateMap.get( frag );
-                if (c == null)
-                    continue;
-                if ( c.getNewCol() == row )
-                {
-                    row++;
-                }
-            }
-            // Make sure that the column has room to add the row
-            if ( row < 0 || row > column.size() )
-            {
-            	// Add to the end
-            	column.addElement(fragment);
-            	row = column.size()-1;
-            }
-            else
-            {
-            	column.add(row, fragment);
-            }
-            Coordinate newCoord = new CoordinateImpl( col, row, col, row );
-            this.fragmentCoordinateMap.put( fragment, newCoord );
-            return newCoord;
-        }
-        return coordinate;
+		return moveAbsolute( fragment, coordinate, true );
 	}
 
 	public Coordinate moveAbsolute( Fragment fragment, Coordinate newCoordinate )
@@ -461,155 +587,320 @@
     {
 		return moveAbsolute( fragment, newCoordinate, false );
     }
-	public Coordinate moveAbsolute( Fragment fragment, Coordinate newCoordinate, boolean addFragment )
+	public Coordinate moveAbsolute( Fragment fragment, Coordinate newCoordinate, boolean okToAddFragment )
         throws PortletPlacementException 
     {
-		int newCol = newCoordinate.getNewCol();
-		int newRow = newCoordinate.getNewRow();
+		if ( fragment == null )
+    		throw new NullPointerException( "PortletPlacementContext moveAbsolute() cannot accept a null Fragment argument" );
+
+		Coordinate currentCoordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+		int currentCol = getLatestColumn( currentCoordinate );
+		int currentRow = getLatestRow( currentCoordinate );
 		
-		int oldCol = newCol, oldRow = newRow;
-		if ( ! addFragment )
+		int newCol = normalizeColumnIndex( getLatestColumn( newCoordinate ), this.columnsList, currentCol );
+		int newRow = getLatestRow( newCoordinate );
+
+		if ( currentCoordinate == null )
 		{
-			// Find the fragment
-			Coordinate oldCoordinate = (Coordinate)this.fragmentCoordinateMap.get(fragment);
-			if ( oldCoordinate == null ) 
-	        {
-				throw new PortletPlacementException("could not find fragment");
-			}
+			if ( ! okToAddFragment )
+				throw new NullPointerException( "PortletPlacementContext moveAbsolute() cannot add fragment (" + fragment.getId() + ") unless the okToAddFragment argument is set to true" );
 			
-			// Save the old coordinates
-			oldCol = oldCoordinate.getOldCol();
-			oldRow = oldCoordinate.getOldRow();
-
-			List oldRowList = this.columnsList[oldCol];
+			// add fragment
+			ArrayList newColumn = this.columnsList[newCol];
+			if ( newRow < 0 || newRow >= newColumn.size() )
+				newRow = newColumn.size();
+			newColumn.add( newRow, fragment );
 			
-			// Remove the fragment from it's old position
-			oldRowList.remove( oldRow );
-		}
-		
-		// Create a new coordinate object with both the old and new positions
-		
-		// The next two lines must occur after the remove above.  This is
-		// because the new and old columns might be the same and the remove
-		// will change the number of rows
-        if ( newCol > this.numberOfColumns )
-        {    
-            newCol = addColumns( newCol );
-        }
-
-		List newRowList = this.columnsList[newCol];
-		int numRowsNewColumn = newRowList.size();
-		
-		// Decide whether an insert or an add is appropriate
-		if ( newRow > (numRowsNewColumn - 1) ) 
-        {
-			newRow = numRowsNewColumn;
-			// Add a new row
-			newRowList.add(fragment);
-		} 
-        else 
-        {
-			// Insert the fragment at the new position
-			((Vector)newRowList).insertElementAt( fragment, newRow );		
+			CoordinateImpl coordinate = new CoordinateImpl( newCol, newRow );
+        	this.fragmentCoordinateMap.put( fragment.getId(), coordinate );
+			this.fragmentMap.put( fragment.getId(), fragment );
+			syncFragments( false, newCol );
 		}
-
-        //debugFragments( "move absolute [" + fragment.getId() + "] " + ( addFragment ? "(add-fragment) " : "" ) );
-        
-		// New coordinates after moving
-        newCoordinate = new CoordinateImpl( oldCol, oldRow, newCol, newRow );
-		this.fragmentCoordinateMap.put( fragment, newCoordinate );
-		if ( addFragment )
+		else
 		{
-			this.fragmentMap.put( fragment.getId(), fragment );
+			boolean columnChanged = ( currentCol != newCol );
+			boolean rowChanged = ( currentRow != newRow );
+
+			if ( columnChanged || rowChanged )
+			{
+				verifyFragmentAtExpectedCoordinate( currentCol, currentRow, fragment, "moveAbsolute()" );
+				
+				ArrayList currentColumn = this.columnsList[currentCol];
+				currentColumn.remove( currentRow );
+				
+				ArrayList newColumn = currentColumn;
+				if ( columnChanged )
+					newColumn = this.columnsList[newCol];
+
+				if ( newRow < 0 || newRow >= newColumn.size() )
+					newColumn.add( fragment );
+				else
+					newColumn.add( newRow, fragment );
+				
+				this.fragmentMap.put( fragment.getId(), fragment );
+				
+				syncFragments( false, currentCol );
+				if ( columnChanged )
+					syncFragments( false, newCol );
+			}
 		}
-		return newCoordinate;
+		return (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
 	}
 
-	protected Coordinate moveDirection(Fragment fragment, int deltaCol, int deltaRow) 
-    throws PortletPlacementException 
+	protected Coordinate moveDirection( Fragment fragment, int deltaCol, int deltaRow ) 
+        throws PortletPlacementException 
     {
-		// Find the fragment
-		Coordinate foundCoordinate = (Coordinate)this.fragmentCoordinateMap.get(fragment);
-		if(foundCoordinate == null) 
-        {
-			throw new PortletPlacementException("could not find fragment");
-		}
+		if ( fragment == null )
+    		throw new NullPointerException( "PortletPlacementContext moveDirection() cannot accept a null Fragment argument" );
 
-		// Check the coordinates to make sure that there is room to move down
-		int oldCol = foundCoordinate.getOldCol();
-		int oldRow = foundCoordinate.getOldRow();
-		
-		Vector columnArray = this.columnsList[oldCol];
-		
-		// Check the row and column boundaries to make sure there is room
-		// to do the move
-		if((oldRow + deltaRow + 1 > columnArray.size()) || ((oldRow + deltaRow) < 0) ||
-		   (oldCol + deltaCol + 1 > this.columnsList.length) || ((oldCol + deltaCol) < 0)) 
-        {
-			// Out of bounds, don't do the move
-			Coordinate c = new CoordinateImpl(oldCol, oldRow, oldCol, oldRow);
-            //debugFragments("move direction (1)");
-            return c;
+		if ( deltaCol != 0 || deltaRow != 0 )
+		{
+			Coordinate currentCoordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+			if ( currentCoordinate == null )
+				throw new NullPointerException( "PortletPlacementContext moveDirection() cannot locate target fragment (" + fragment.getId() + ")" );
+	
+			int currentCol = getLatestColumn( currentCoordinate );
+			int currentRow = getLatestRow( currentCoordinate );
+			
+			verifyFragmentAtExpectedCoordinate( currentCol, currentRow, fragment, "moveDirection()" );
+			
+			int newCol = currentCol + deltaCol;
+			int newRow = currentRow + deltaRow;
+			if ( newCol >= 0 && newCol < this.numberOfColumns )
+			{
+				ArrayList currentColumn = this.columnsList[currentCol];
+				ArrayList newColumn = currentColumn;
+				if ( newCol != currentCol )
+					newColumn = this.columnsList[newCol];
+				
+				currentColumn.remove( currentRow );
+					
+				if ( newRow < 0 || newRow >= newColumn.size() )
+					newColumn.add( fragment );
+				else
+					newColumn.add( newRow, fragment );
+				
+				this.fragmentMap.put( fragment.getId(), fragment );
+				
+				syncFragments( false, currentCol );
+				if ( newCol != currentCol )
+					syncFragments( false, newCol );
+			}
 		}
-        else 
-        {
-			Coordinate c = moveAbsolute(fragment, new CoordinateImpl(oldCol, oldRow, oldCol + deltaCol, oldRow + deltaRow));
-            //debugFragments("move direction (2)");
-            return c;
-		}        
+		return (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
 	}
 	
-	public Coordinate moveDown(Fragment fragment) throws PortletPlacementException 
+	public Coordinate moveDown( Fragment fragment ) throws PortletPlacementException 
     {
-		return moveDirection(fragment, 0, 1);
+		return moveDirection( fragment, 0, 1 );
 	}
 
-	public Coordinate moveUp(Fragment fragment) throws PortletPlacementException 
+	public Coordinate moveUp( Fragment fragment ) throws PortletPlacementException 
     {
-		return moveDirection(fragment, 0, -1);
+		return moveDirection( fragment, 0, -1 );
 	}
 
-	public Coordinate moveLeft(Fragment fragment) throws PortletPlacementException 
+	public Coordinate moveLeft( Fragment fragment ) throws PortletPlacementException 
     {
-		return moveDirection(fragment, -1, 0);
+		return moveDirection( fragment, -1, 0 );
 	}
 
-	public Coordinate moveRight(Fragment fragment) throws PortletPlacementException 
+	public Coordinate moveRight( Fragment fragment ) throws PortletPlacementException 
     {
-		return moveDirection(fragment, 1, 0);
+		return moveDirection( fragment, 1, 0 );
 	}
 
-	public Coordinate remove(Fragment fragment) throws PortletPlacementException 
+	public Coordinate remove( Fragment fragment ) throws PortletPlacementException 
     {
-		// Locate the fragment
-		Coordinate coordinate = (Coordinate)this.fragmentCoordinateMap.get(fragment);
-		if(coordinate == null) 
-        {
-			throw new PortletPlacementException("fragment not found:" + fragment.getName());
-		}
+		if ( fragment == null )
+    		throw new NullPointerException( "PortletPlacementContext remove() cannot accept a null Fragment argument" );
 		
-		int col = coordinate.getOldCol();
-		int row = coordinate.getOldRow();
+		Coordinate currentCoordinate = (Coordinate)this.fragmentCoordinateMap.get( fragment.getId() );
+		if ( currentCoordinate == null )
+			throw new NullPointerException( "PortletPlacementContext remove() cannot locate target fragment (" + fragment.getId() + ")" );
+
+		int currentCol = getLatestColumn( currentCoordinate );
+		int currentRow = getLatestRow( currentCoordinate );
 		
-		if(col < 0 || col > this.columnsList.length) 
-        {
-			throw new PortletPlacementException("column out of bounds:" + fragment.getName());
-		}
+		verifyFragmentAtExpectedCoordinate( currentCol, currentRow, fragment, "moveDirection()" );
+
+		ArrayList currentColumn = this.columnsList[currentCol];
 		
-		Vector columnArray = this.columnsList[col];
-		if(row < 0 || row > columnArray.size()) 
-        {
-			throw new PortletPlacementException("row out of bounds:" + fragment.getName());
-		}
+		currentColumn.remove( currentRow );
 		
-		// Remove the fragment from the array
-		columnArray.remove(row);
+		this.fragmentCoordinateMap.remove( fragment.getId() );
+		this.fragmentMap.remove( fragment.getId() );
 		
-		// Remove the fragment from the hashmap
-		this.fragmentCoordinateMap.remove(fragment);
-		this.fragmentMap.remove(fragment.getId());
+		syncFragments( false, currentCol );
 		
-		return coordinate;
+		return currentCoordinate;
+	}
+	
+	protected Fragment verifyFragmentAtExpectedCoordinate( int colIndex, int rowIndex, Fragment fragment, String sourceDesc )
+		throws PortletPlacementException
+	{
+		CoordinateImpl coordinate = new CoordinateImpl( colIndex, rowIndex );
+		
+		boolean suppressExceptions = ( fragment != null );
+		Fragment foundFragment = getFragmentAtCoordinate( coordinate, true, suppressExceptions );
+		
+		if ( fragment != null )
+		{
+			if ( foundFragment == null || foundFragment.getId() != fragment.getId() )
+			{
+				sourceDesc = ( sourceDesc == null ? "getFragmentAtExpectedCoordinate" : sourceDesc );
+				
+				ArrayList column = null;
+				int colFragCount = -1;
+				if ( colIndex >= 0 && colIndex < this.numberOfColumns )
+				{
+					column = this.columnsList[colIndex];
+					colFragCount = column.size();
+				}
+				StringBuffer out = new StringBuffer();
+				out.append( "PortletPlacementContext " ).append( sourceDesc ).append( " has encountered unexpected results");
+				out.append( " using the current instance state to locate fragment " ).append( fragment.getId() ).append( " (" );
+				if ( foundFragment == null )
+					out.append( "no fragment" );
+				else
+					out.append( "different fragment" );
+				out.append( " in row " ).append( rowIndex ).append( " of column " ).append( colIndex );
+				if ( column == null )
+				{
+					out.append( " - column is out of bounds, column-count=" ).append( this.numberOfColumns );
+				}
+				else
+				{
+					out.append( " - " );
+					if ( rowIndex < 0 || rowIndex >= colFragCount )
+						out.append( "row is out of bounds, " );
+					out.append( "row-count=" ).append( colFragCount );
+				}
+				out.append( ")" );
+				throw new PortletPlacementException( out.toString() );
+			}
+		}
+		return fragment;
 	}
 
+	static public int getColumnCountAndSizes( Fragment layoutFragment, PortletRegistry registry, Map fragSizes )
+	{
+		return PortletPlacementContextImpl.getColumnCountAndSizes( layoutFragment, registry, fragSizes, false );
+	}
+    static public int getColumnCountAndSizes( Fragment layoutFragment, PortletRegistry registry, Map fragSizes, boolean suppressErrorLogging )
+	{
+    	if ( layoutFragment == null )
+    		throw new NullPointerException( "getColumnCountAndSizes cannot accept a null Fragment argument" );
+    	if ( registry == null )
+    		throw new NullPointerException( "getColumnCountAndSizes cannot accept a null PortletRegistry argument" );
+    	
+		int columnCount = -1;
+		if ( ! "layout".equals( layoutFragment.getType() ) )
+		{
+			if ( ! suppressErrorLogging )
+				log.error( "getColumnCountAndSizes not a layout fragment - " + layoutFragment.getId() + " type=" + layoutFragment.getType() );
+		}
+		else
+    	{   // get layout fragment sizes
+    		String sizesVal = layoutFragment.getProperty( "sizes" );
+    		String layoutName = layoutFragment.getName();
+    		layoutName = ( (layoutName != null && layoutName.length() > 0) ? layoutName : (String)null );
+    		ParameterSet paramSet = null;
+    		PortletDefinition portletDef = null;
+    		if ( sizesVal == null || sizesVal.length() == 0 )
+    		{
+    			if ( layoutName != null )
+    			{
+    				// logic below is copied from org.apache.jetspeed.portlets.MultiColumnPortlet
+    				portletDef = registry.getPortletDefinitionByUniqueName( layoutName );
+                    if ( portletDef != null )
+                    {
+                    	paramSet = portletDef.getInitParameterSet();
+                    	if ( paramSet != null )
+                    	{
+                    		Parameter sizesParam = paramSet.get( "sizes" );
+                    		sizesVal = ( sizesParam == null ) ? null : sizesParam.getValue();
+                    	}
+                    }
+    			}
+    		}
+    		if ( sizesVal != null && sizesVal.length() > 0 )
+    		{
+    			if ( fragSizes != null )
+    				fragSizes.put( layoutFragment.getId(), sizesVal );
+					
+				int sepPos = -1, startPos = 0, sizesLen = sizesVal.length();
+				columnCount = 0;
+				do
+				{
+					sepPos = sizesVal.indexOf( ',', startPos );
+					if ( sepPos != -1 )
+					{
+						if ( sepPos > startPos )
+							columnCount++;
+						startPos = sepPos +1;
+					}
+					else if ( startPos < sizesLen )
+					{
+						columnCount++;
+					}
+				} while ( startPos < sizesLen && sepPos != -1 );
+				if ( ! suppressErrorLogging && columnCount <= 0 )
+					log.error( "getColumnCountAndSizes invalid columnCount - " + layoutFragment.getId() + " / " + layoutName + " count=" + columnCount + " sizes=" + sizesVal );
+			}
+			else if ( paramSet == null )
+			{
+				if ( ! suppressErrorLogging )
+				{
+					if ( layoutName == null )
+						log.error( "getColumnCountAndSizes null sizes, null layoutName - " + layoutFragment.getId() );
+					else if ( portletDef == null )
+						log.error( "getColumnCountAndSizes null sizes, null PortletDefinition - " + layoutFragment.getId() + " / " + layoutName );
+					else
+						log.error( "getColumnCountAndSizes null sizes, null ParameterSet - " + layoutFragment.getId() + " / " + layoutName );
+				}
+			}
+			else
+			{
+				Parameter colsParam = paramSet.get( "columns" );
+				String colsParamVal = ( colsParam == null ) ? null : colsParam.getValue();
+				if ( colsParamVal != null && colsParamVal.length() > 0 )
+				{
+					try
+					{
+						columnCount = Integer.parseInt( colsParamVal );
+					}
+					catch ( NumberFormatException ex )
+					{
+					}
+					if ( columnCount < 1 )
+					{
+						columnCount = 2;
+					}
+					switch ( columnCount )
+					{
+	            		case 1: sizesVal = "100%"; break;
+	            		case 2: sizesVal = "50%,50%"; break;
+	            		case 3: sizesVal = "34%,33%,33%"; break;
+	            		case 4: sizesVal = "25%,25%,25%,25%"; break;
+	            		default: 
+	            		{
+	            			sizesVal = "50%,50%";
+	            			columnCount = 2;
+	            			break;
+	            		}
+					}
+					if ( fragSizes != null )
+						fragSizes.put( layoutFragment.getId(), sizesVal );
+					//log.info( "getColumnCountAndSizes " + layoutFragment.getId() + " count=" + columnCount + " defaulted-sizes=" + sizesParamVal );
+				}
+				else
+				{
+					if ( ! suppressErrorLogging )
+						log.error( "getColumnCountAndSizes null sizes, columns not defined in ParameterSet - " + layoutFragment.getId() + " / " + layoutName );
+				}
+			}
+    	}
+		return columnCount;
+	}	
 }

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java Thu Nov 15 12:21:24 2007
@@ -24,6 +24,7 @@
 import org.apache.jetspeed.ajax.AJAXException;
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
 import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
 import org.apache.jetspeed.layout.PortletPlacementContext;
 import org.apache.jetspeed.om.page.Fragment;
@@ -49,20 +50,24 @@
     implements AjaxAction, AjaxBuilder, Constants
 {
     protected static final Log log = LogFactory.getLog(RemovePortletAction.class);
+    
+    private PortletRegistry registry;
 
-    public RemovePortletAction(String template, String errorTemplate)
-            throws PipelineException
+    public RemovePortletAction( String template, String errorTemplate, PortletRegistry registry )
+        throws PipelineException
     {
-        this(template, errorTemplate, null, null);
+        this( template, errorTemplate, registry, null, null );
     }
 
-    public RemovePortletAction(String template, 
-                               String errorTemplate, 
-                               PageManager pageManager, 
-                               PortletActionSecurityBehavior securityBehavior)
-    throws PipelineException
+    public RemovePortletAction( String template, 
+                                String errorTemplate,
+                                PortletRegistry registry,
+                                PageManager pageManager, 
+                                PortletActionSecurityBehavior securityBehavior )
+        throws PipelineException
     {
-        super(template, errorTemplate, pageManager, securityBehavior);
+        super( template, errorTemplate, pageManager, securityBehavior );
+        this.registry = registry;
     }
     
     public boolean runBatch(RequestContext requestContext, Map resultMap) throws AJAXException
@@ -82,77 +87,98 @@
         String status = "success";
         try
         {
-            resultMap.put(ACTION, "remove");
+            resultMap.put( ACTION, "remove" );
             // Get the necessary parameters off of the request
-            String portletId = getActionParameter(requestContext, PORTLETID);
+            String portletId = getActionParameter( requestContext, PORTLETID );
             if (portletId == null) 
             { 
                 success = false;
-                resultMap.put(REASON, "Portlet ID not provided");
+                resultMap.put( REASON, "Portlet ID not provided" );
                 return success;
             }
-            resultMap.put(PORTLETID, portletId);
-            if (false == checkAccess(requestContext, JetspeedActions.EDIT))
+            resultMap.put( PORTLETID, portletId );
+            if ( false == checkAccess( requestContext, JetspeedActions.EDIT ) )
             {
                 Page page = requestContext.getPage();
-                Fragment fragment = page.getFragmentById(portletId);
-                if (fragment == null)
+                Fragment fragment = page.getFragmentById( portletId );
+                if ( fragment == null )
                 {
                     success = false;
-                    resultMap.put(REASON, "Fragment not found");
+                    resultMap.put( REASON, "Fragment not found" );
                     return success;                    
                 }
-                int column = fragment.getLayoutColumn();
-                int row = fragment.getLayoutRow();
-                if (!createNewPageOnEdit(requestContext))
+                
+                NestedFragmentContext removeFragmentContext = null;
+                try
+                {
+                	removeFragmentContext = new NestedFragmentContext( fragment, page, registry );
+                }
+                catch ( Exception ex )
+                {
+                	log.error( "Failure to construct nested context for fragment " + portletId, ex );
+                	success = false;
+                    resultMap.put( REASON, "Cannot construct nested context for fragment" );
+                    return success;
+                }
+                
+                if ( ! createNewPageOnEdit( requestContext ) )
                 {                
                     success = false;
-                    resultMap.put(REASON, "Insufficient access to edit page");
+                    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)
+                status = "refresh";
+                
+                Page newPage = requestContext.getPage();
+
+                // using NestedFragmentContext, find portlet id for copy of target portlet in the new page 
+                Fragment newFragment = null;
+                try
                 {
-                    success = false;
-                    resultMap.put(REASON, "Failed to find new fragment");
-                    return success;                    
+                	newFragment = removeFragmentContext.getFragmentOnNewPage( newPage, registry );
+                }
+                catch ( Exception ex )
+                {
+                	log.error( "Failure to locate copy of fragment " + portletId, ex );
+                	success = false;
+                    resultMap.put( REASON, "Failed to find new fragment for portlet id: " + portletId );
+                    return success;
                 }
                 portletId = newFragment.getId();
             }
             
             // Use the Portlet Placement Manager to accomplish the removal
-            Fragment root = requestContext.getPage().getRootFragment();
+            Page page = requestContext.getPage();
+            Fragment root = page.getRootFragment();
             Fragment layoutContainerFragment = getParentFragmentById( portletId, root );
             PortletPlacementContext placement = null;
             Fragment fragment = null;
             if ( layoutContainerFragment != null )
             {
-            	placement = new PortletPlacementContextImpl(requestContext, layoutContainerFragment);
-            	fragment = placement.getFragmentById(portletId);
+            	placement = new PortletPlacementContextImpl( page, registry, layoutContainerFragment );
+            	fragment = placement.getFragmentById( portletId );
             }
             if ( fragment == null )
             {
                 success = false;
-                resultMap.put(REASON, "Fragment not found");
+                resultMap.put( REASON, "Fragment not found" );
                 return success;                
             }
             placement.remove(fragment);
-            Page page = placement.syncPageFragments();
-            page.removeFragmentById(fragment.getId());
+            page = placement.syncPageFragments();
+            page.removeFragmentById( fragment.getId() );
             if (!batch)
             {
                 if (pageManager != null)
-                    pageManager.updatePage(page);
+                    pageManager.updatePage( page );
             }
             // Build the results for the response
-            resultMap.put(PORTLETID, portletId);            
-            resultMap.put(STATUS, status);
-            resultMap.put(OLDCOL, String.valueOf(fragment.getLayoutColumn()));
-            resultMap.put(OLDROW, String.valueOf(fragment.getLayoutRow()));
+            resultMap.put( PORTLETID, portletId );            
+            resultMap.put( STATUS, status );
+            resultMap.put( OLDCOL, String.valueOf( fragment.getLayoutColumn() ) );
+            resultMap.put( OLDROW, String.valueOf( fragment.getLayoutRow() ) );
         } 
-        catch (Exception e)
+        catch ( Exception e )
         {
             // Log the exception
             log.error("exception while adding a portlet", e);
@@ -162,5 +188,10 @@
         }
 
         return success;
+    }
+    
+    protected PortletRegistry getPortletRegistry()
+    {
+    	return this.registry;
     }
 }

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RolesSecurityBehavior.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RolesSecurityBehavior.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RolesSecurityBehavior.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/RolesSecurityBehavior.java Thu Nov 15 12:21:24 2007
@@ -51,6 +51,15 @@
         }        
         return false;
     }
+    
+    public boolean isCreateNewPageOnEditEnabled()
+    {
+    	return false;
+    }
+    public boolean isPageQualifiedForCreateNewPageOnEdit(RequestContext context)
+    {
+    	return false ;
+    }
 
     public boolean createNewPageOnEdit(RequestContext context)
     {

Modified: portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java?rev=595431&r1=595430&r2=595431&view=diff
==============================================================================
--- portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java (original)
+++ portals/jetspeed-2/branches/JETSPEED-2.1.3/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java Thu Nov 15 12:21:24 2007
@@ -74,6 +74,7 @@
     public boolean run(RequestContext requestContext, Map resultMap)
             throws AJAXException
     {
+    	System.out.println( "SecurityConstraintsAction run" );
         boolean success = true;
         String status = "success";
         try
@@ -120,10 +121,13 @@
         } 
         catch (Exception e)
         {
+        	System.out.println( "SecurityConstraintsAction run failure caused by " + e.getClass().getName() + " " + e.getMessage() );
+        	e.printStackTrace();
             log.error("exception administering portal permissions", e);
             resultMap.put(REASON, e.toString());
             success = false;
         }
+        System.out.println( "SecurityConstraintsAction complete " + resultMap.toString() );
         return success;
     }
     
@@ -157,6 +161,8 @@
     protected int updateConstraintDefinition(RequestContext requestContext, Map resultMap)
     throws AJAXException
     {
+    	System.out.println( "SecurityConstraintsAction updateConstraintDefinition started" );
+        	
         int count = 0;
         boolean added = false;
         String xml = getActionParameter(requestContext, "xml");
@@ -232,6 +238,9 @@
         }
         catch (Exception e)
         {
+        	System.out.println( "SecurityConstraintsAction updateConstraintDefinition failure caused by " + e.getClass().getName() + " " + e.getMessage() );
+        	e.printStackTrace();
+        	log.error( "SecurityConstraintsAction updateConstraintDefinition failure caused by " + e.getClass().getName() + " " + e.getMessage(), e );
             throw new AJAXException(e);
         }
         return count;



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


Mime
View raw message