portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r483372 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/aggregator/impl/ components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/ components/portal/src/java/org/apache/jetspeed/layout/impl/ src/webapp/W...
Date Thu, 07 Dec 2006 08:31:49 GMT
Author: taylor
Date: Thu Dec  7 00:31:48 2006
New Revision: 483372

URL: http://svn.apache.org/viewvc?view=rev&rev=483372
Log:
ajax apis to support desktop edit mode for:
* update fragment
* add fragment
* remove fragment


Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/update.vm
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/UpdatePageAction.java
    portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/aggregator/impl/PortletRendererImpl.java
Thu Dec  7 00:31:48 2006
@@ -15,8 +15,8 @@
  */
 package org.apache.jetspeed.aggregator.impl;
 
-import java.util.Map;
 import java.util.HashMap;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -41,9 +41,7 @@
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.services.title.DynamicTitleService;
 import org.apache.jetspeed.statistics.PortalStatistics;
-import org.apache.jetspeed.util.JetspeedObjectID;
 import org.apache.pluto.PortletContainer;
-import org.apache.pluto.om.common.ObjectID;
 import org.apache.pluto.om.entity.PortletEntity;
 import org.apache.pluto.om.window.PortletWindow;
 
@@ -238,9 +236,7 @@
 
     protected PortletWindow getPortletWindow( ContentFragment fragment ) throws FailedToRetrievePortletWindow,
PortletEntityNotStoredException
     {
-
-            ObjectID oid = JetspeedObjectID.createFromString(fragment.getId());
-
+            // ObjectID oid = JetspeedObjectID.createFromString(fragment.getId());
             PortletWindow portletWindow = windowAccessor.getPortletWindow(fragment);
             if (portletWindow == null)
             {

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/update.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/update.vm?view=auto&rev=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/update.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/update.vm
Thu Dec  7 00:31:48 2006
@@ -0,0 +1,7 @@
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    <method>$method</method>    
+    <count>$count</count>       
+    <id>$!id</id> 
+</js>
\ No newline at end of file

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java
Thu Dec  7 00:31:48 2006
@@ -16,6 +16,7 @@
 package org.apache.jetspeed.layout.impl;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -158,4 +159,46 @@
         }
         return parameter;
     }
+    
+    public Fragment getParentFragmentById(String id, Fragment root)
+    {
+        if ( id == null )
+        {
+            return null;
+        }
+        return searchForParentFragmentById( id, root );
+    }
+    
+    protected Fragment searchForParentFragmentById( String id, Fragment parent )
+    {   
+        // find fragment by id, tracking fragment parent
+        Fragment matchedParent = null;
+        if( parent != null ) 
+        {
+            // process the children
+            List children = parent.getFragments();
+            for( int i = 0, cSize = children.size() ; i < cSize ; i++) 
+            {
+                Fragment childFrag = (Fragment)children.get( i );
+                if ( childFrag != null ) 
+                {
+                    if ( id.equals( childFrag.getId() ) )
+                    {
+                        matchedParent = parent;
+                        break;
+                    }
+                    else
+                    {
+                        matchedParent = searchForParentFragmentById( id, childFrag );
+                        if ( matchedParent != null )
+                        {
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        return matchedParent;
+    }
+    
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
Thu Dec  7 00:31:48 2006
@@ -71,7 +71,11 @@
     public static final String PAGE_DECORATIONS = "pageDecorations";
     public static final String PORTLET_DECORATIONS = "portletDecorations";
     public static final String LAYOUTS = "layouts";
+    public static final String LAYOUT = "layout";
+    public static final String DEFAULT_LAYOUT = "defaultLayout";
     public static final String DESKTOP_THEMES = "desktopThemes";
+    public static final String TITLE = "title";
+    public static final String SHORT_TITLE = "short-title";    
     public static final String LINK = "link";
     public static final String LINKS = "links";
     public static final String FRAGMENTS = "fragments";

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
Thu Dec  7 00:31:48 2006
@@ -170,7 +170,8 @@
                     {
                         // 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
-                        currentLayoutFragment = getParentFragmentById( portletId, requestContext
);
+                        Fragment root = requestContext.getPage().getRootFragment();
+                        currentLayoutFragment = getParentFragmentById(portletId, root);
                     }
                 }
                 if ( currentLayoutFragment == null )
@@ -477,46 +478,5 @@
             resultMap.put(oldName, new Float(oldValue));
             resultMap.put(name, new Float(value));
         }
-    }
-    public Fragment getParentFragmentById( String id, RequestContext requestContext )
-    {
-        if ( id == null )
-        {
-            return null;
-        }
-        Fragment root = requestContext.getPage().getRootFragment();
-        return searchForParentFragmentById( id, root );
-    }
-    
-    protected Fragment searchForParentFragmentById( String id, Fragment parent )
-    {   
-        // find fragment by id, tracking fragment parent
-        Fragment matchedParent = null;
-        if( parent != null ) 
-        {
-            // process the children
-            List children = parent.getFragments();
-            for( int i = 0, cSize = children.size() ; i < cSize ; i++) 
-            {
-                Fragment childFrag = (Fragment)children.get( i );
-                if ( childFrag != null ) 
-                {
-                    if ( id.equals( childFrag.getId() ) )
-                    {
-                        matchedParent = parent;
-                        break;
-                    }
-                    else
-                    {
-                        matchedParent = searchForParentFragmentById( id, childFrag );
-                        if ( matchedParent != null )
-                        {
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        return matchedParent;
     }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/UpdatePageAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/UpdatePageAction.java?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/UpdatePageAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/UpdatePageAction.java
Thu Dec  7 00:31:48 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.jetspeed.layout.impl;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -23,11 +24,18 @@
 import org.apache.jetspeed.ajax.AJAXException;
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
+import org.apache.jetspeed.components.portletentity.PortletEntityNotStoredException;
+import org.apache.jetspeed.container.window.FailedToRetrievePortletWindow;
+import org.apache.jetspeed.container.window.PortletWindowAccessor;
+import org.apache.jetspeed.om.page.ContentFragment;
+import org.apache.jetspeed.om.page.ContentFragmentImpl;
 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.Node;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.pluto.om.window.PortletWindow;
 
 /**
  * Update Page action -- updates various parts of the PSML page
@@ -42,6 +50,10 @@
  *    | add-meta | update-meta | remove-meta
  *    Security methods:
  *    | add-secref | remove-secref
+ *    Fragment methods:
+ *    | update-fragment | add-fragment | remove-fragment
+ *    
+ *    update-fragment params: id, layout(name), sizes, layoutid (add)
  *    
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
  * @version $Id: $
@@ -51,12 +63,19 @@
     implements AjaxAction, AjaxBuilder, Constants
 {
     protected Log log = LogFactory.getLog(UpdatePageAction.class);
-
+    protected PortletWindowAccessor windowAccess;
+    protected PortletEntityAccessComponent entityAccess;
+    
     public UpdatePageAction(String template, 
                             String errorTemplate, 
-                            PageManager pm)
+                            PageManager pm,
+                            PortletWindowAccessor windowAccess,
+                            PortletEntityAccessComponent entityAccess)
+                            
     {
-        super(template, errorTemplate, pm); 
+        super(template, errorTemplate, pm);
+        this.windowAccess = windowAccess;
+        this.entityAccess = entityAccess;
     }
     
     public boolean run(RequestContext requestContext, Map resultMap)
@@ -81,23 +100,28 @@
                 return success;
             }           
             int count = 0;
+            Page page = null;            
             String path = getActionParameter(requestContext, "path");
             if (path == null)
-                throw new AJAXException("Missing 'path' parameter");
-            Page page = null; 
-            if (!method.equals("add"))
             {
-                page = pageManager.getPage(path);
+                page = requestContext.getPage();
             }
             else
             {
-                if (pageManager.pageExists(path))
+                if (!method.equals("add"))
+                {
+                    page = pageManager.getPage(path);
+                }
+                else
                 {
-                    success = false;
-                    resultMap.put(REASON, "Can't create: Page already exists: " + path);
               
-                    return success;                
+                    if (pageManager.pageExists(path))
+                    {
+                        success = false;
+                        resultMap.put(REASON, "Can't create: Page already exists: " + path);
               
+                        return success;                
+                    }
                 }
-            }                
+            }
             if (method.equals("info"))
             {
                 count = updateInformation(requestContext, resultMap, page, path);
@@ -133,16 +157,48 @@
             else if (method.equals("add"))
             {
                 page = pageManager.newPage(path);
-                page.setTitle(getActionParameter(requestContext, "title"));
-                String s = getActionParameter(requestContext, "short-title");
+                page.setTitle(getActionParameter(requestContext, TITLE));
+                String s = getActionParameter(requestContext, SHORT_TITLE );
                 if (!isBlank(s))
                     page.setShortTitle(s);                
-                page.getRootFragment().setName(getActionParameter(requestContext, "defaultLayout"));
+                page.getRootFragment().setName(getActionParameter(requestContext, DEFAULT_LAYOUT));
                 count++;                
             }
             else if (method.equals("remove"))
             {
                 pageManager.removePage(page);
+            }
+            else if (method.equals("update-fragment"))
+            {
+                String fragmentId = getActionParameter(requestContext, PORTLETID);
+                String layout = getActionParameter(requestContext, LAYOUT);             
  
+                if (isBlank(fragmentId) || isBlank(layout))
+                {
+                    resultMap.put(REASON, "Missing parameter to update fragment");      
         
+                    return false;                    
+                }                
+                count = updateFragment(requestContext, resultMap, page, fragmentId, layout);
+            }
+            else if (method.equals("add-fragment"))
+            {
+                String parentId = getActionParameter(requestContext, LAYOUTID);
+                String layout = getActionParameter(requestContext, LAYOUT);             
  
+                if (isBlank(parentId) || isBlank(layout))
+                {
+                    resultMap.put(REASON, "Missing parameter to add fragment");         
      
+                    return false;                    
+                }                
+                count = addFragment(requestContext, resultMap, page, parentId, layout);
+            }
+            else if (method.equals("remove-fragment"))
+            {
+                String fragmentId = getActionParameter(requestContext, PORTLETID);
+                if (isBlank(fragmentId))
+                {
+                    resultMap.put(REASON, "Missing parameter to remove fragment");      
         
+                    return false;                    
+                }                
+                count = removeFragment(requestContext, resultMap, page, fragmentId);    
           
             }            
             else
             {
@@ -166,6 +222,70 @@
         return success;
     }
     
+    protected int updateFragment(RequestContext requestContext, Map resultMap, Page page,
String fragmentId, String layout)
+    throws PortletEntityNotStoredException, FailedToRetrievePortletWindow
+    {
+        int count = 0;
+        String sizes = getActionParameter(requestContext, SIZES);
+        Fragment fragment = page.getFragmentById(fragmentId);
+        if (fragment != null)
+        {                
+            if (!layout.equals(fragment.getName()))
+            {
+                fragment.setName(layout);
+                ContentFragment contentFragment = new ContentFragmentImpl(fragment, new HashMap());
                   
+                PortletWindow window = windowAccess.getPortletWindow(contentFragment);
+                if (window != null)
+                {
+                    entityAccess.updatePortletEntity(window.getPortletEntity(), contentFragment);
+                    entityAccess.storePortletEntity(window.getPortletEntity());
+                    windowAccess.createPortletWindow(window.getPortletEntity(), contentFragment.getId());
+                    count++;
+                }
+            }
+            if (!isBlank(sizes))
+            {
+                fragment.setLayoutSizes(sizes);
+                count++;
+            }
+        }
+        return count;
+    }
+
+    protected int addFragment(RequestContext requestContext, Map resultMap, Page page, String
parentFragmentId, String layout)
+    {
+        int count = 0;
+        String sizes = getActionParameter(requestContext, SIZES);
+        Fragment fragment = page.getFragmentById(parentFragmentId);
+        if (fragment != null)
+        {
+            Fragment newFragment = pageManager.newFragment();
+            newFragment.setType(Fragment.LAYOUT);            
+            newFragment.setName(layout);
+            fragment.getFragments().add(newFragment);            
+            resultMap.put(PORTLETID, newFragment.getId());                        
+            count++;
+            if (!isBlank(sizes))
+            {
+                newFragment.setLayoutSizes(sizes);
+                count++;
+            }
+        }
+        return count;
+    }
+
+    protected int removeFragment(RequestContext requestContext, Map resultMap, Page page,
String fragmentId)
+    {
+        int count = 0;
+        Fragment fragment = page.getFragmentById(fragmentId);
+        if (fragment != null)
+        {
+            page.removeFragmentById(fragment.getId());
+            count++;
+        }
+        return count;
+    }    
+        
     protected int updateInformation(RequestContext requestContext, Map resultMap, Node node,
String path)
     throws AJAXException    
     {

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml?view=diff&rev=483372&r1=483371&r2=483372
==============================================================================
--- portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml (original)
+++ portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml Thu Dec  7 00:31:48
2006
@@ -436,7 +436,7 @@
 <bean id="AjaxUpdateFolder"
     class="org.apache.jetspeed.layout.impl.UpdateFolderAction">
     <constructor-arg index="0">
-        <value>org/apache/jetspeed/layout/ajax-xml/constraints.vm</value>
+        <value>org/apache/jetspeed/layout/ajax-xml/update.vm</value>
     </constructor-arg>
     <constructor-arg index="1">
         <value>org/apache/jetspeed/layout/ajax-xml/error.vm</value>
@@ -449,7 +449,7 @@
 <bean id="AjaxUpdatePage"
     class="org.apache.jetspeed.layout.impl.UpdatePageAction">
     <constructor-arg index="0">
-        <value>org/apache/jetspeed/layout/ajax-xml/constraints.vm</value>
+        <value>org/apache/jetspeed/layout/ajax-xml/update.vm</value>
     </constructor-arg>
     <constructor-arg index="1">
         <value>org/apache/jetspeed/layout/ajax-xml/error.vm</value>
@@ -457,12 +457,18 @@
     <constructor-arg index='2'>    
         <ref bean="org.apache.jetspeed.page.PageManager"/>        
     </constructor-arg>    
+    <constructor-arg index='3'>
+        <ref bean="org.apache.jetspeed.container.window.PortletWindowAccessor"/>
+    </constructor-arg>  
+    <constructor-arg index='4'>
+        <ref bean="org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent"
/>
+    </constructor-arg>      
 </bean>
                 
 <bean id="AjaxUpdateLink"
     class="org.apache.jetspeed.layout.impl.UpdateLinkAction">
     <constructor-arg index="0">
-        <value>org/apache/jetspeed/layout/ajax-xml/constraints.vm</value>
+        <value>org/apache/jetspeed/layout/ajax-xml/update.vm</value>
     </constructor-arg>
     <constructor-arg index="1">
         <value>org/apache/jetspeed/layout/ajax-xml/error.vm</value>



---------------------------------------------------------------------
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