portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r351664 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed: ajax/ layout/ajax-xml/ layout/impl/
Date Fri, 02 Dec 2005 10:36:59 GMT
Author: taylor
Date: Fri Dec  2 02:36:53 2005
New Revision: 351664

URL: http://svn.apache.org/viewcvs?rev=351664&view=rev
Log:
implemented a few more ajax xml apis:
* getPortlets (returns filtered (secure) list of portlets, supports filters)
* getPage (returns full psml page as xml, should make this default pipeline action)
* addPortlet (not yet complete)
* removePortlet is broken, get that next

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/add.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
      - copied, changed from r350273, portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlet.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/psml.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPageAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletInfo.java
Removed:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlet.vm
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AjaxRequestServiceImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/error.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.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/GetPortletsAction.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/PortletPlacementContextImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AjaxRequestServiceImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AjaxRequestServiceImpl.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AjaxRequestServiceImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/ajax/AjaxRequestServiceImpl.java
Fri Dec  2 02:36:53 2005
@@ -28,6 +28,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.layout.impl.Constants;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
@@ -230,7 +231,8 @@
         } catch (Exception e)
         {
             log.error("builder failed", e);
-
+            inputMap.put(Constants.REASON, e.toString());
+            
             buildError(requestContext);
         }
     }

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/add.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/add.vm?rev=351664&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/add.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/add.vm
Fri Dec  2 02:36:53 2005
@@ -0,0 +1,6 @@
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    <id>$id</id> 
+    <new_position><col>$newcol</col><row>$newrow</row></new_position>
+</js>
\ No newline at end of file

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/error.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/error.vm?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/error.vm
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/error.vm
Fri Dec  2 02:36:53 2005
@@ -1,5 +1,6 @@
 <js>
     <status>$status</status>
     <action>$action</action>
+	<reason>$reason</reason>
     <id>$id</id>
 </js>

Copied: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
(from r350273, portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlet.vm)
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm?p2=portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm&p1=portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlet.vm&r1=350273&r2=351664&rev=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlet.vm
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getportlets.vm
Fri Dec  2 02:36:53 2005
@@ -3,17 +3,16 @@
     <action>getportlets</action>
     
     <portlets>
-    
-        <portlet name=“myPortlet” id=“1234”>
-            <position><col>0</col><row>1</row></position>
-            <parameters>
-                <param>
-                    <name>moveable</name>
-                    <value>true</value>
-                </param>
-            </parameters>
+#foreach ($portlet in $portlets)    
+        <portlet name="$portlet.Name" displayName="$portlet.DisplayName" description="$portlet.Description">
+##           <position column="$portlet.Column" row="$portlet.Row"/>
+##           <parameters>
+###foreach ($param in $portlet.Parameters)
+##                <param name="$param.Name" value="$param.Value"/>
+###end
+##           </parameters>
         </portlet>
-        
+#end        
     </portlets>
     
 </js>

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/psml.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/psml.vm?rev=351664&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/psml.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/psml.vm
Fri Dec  2 02:36:53 2005
@@ -0,0 +1,43 @@
+#macro (traverseFragments $f)
+    <fragment id="$f.Id" type="$f.Type" name="$f.Name" decorator="$!f.Decorator">
+    #foreach ($prop in $f.getProperties().entrySet())
+      <property name="$prop.Key" value="$prop.Value" />
+	#end
+	#foreach ($pref in $f.Preferences)
+		<preference name="$pref.Name" readOnly='$pref.isReadOnly()'>		
+		  #foreach ($value in $pref.ValueList)
+		    <value>$value</value>
+		  #end
+		</preference>
+	#end
+    #if($f.Type == "layout")
+		#foreach($subf in $f.Fragments)
+        #traverseFragments($subf)
+		#end
+	#end
+    </fragment>                                		
+#end
+
+<js>
+    <status>$status</status>
+    <action>getportlets</action>
+    
+<page hidden='$page.Hidden'>
+  <defaults
+     layout-decorator='$page.getDefaultDecorator("layout")'
+     portlet-decorator='$page.getDefaultDecorator("portlet")'
+  />
+  <name>$page.Name</name>
+  <path>$page.Path</path>
+  <title>$page.Title</title>
+  <short-title>$page.ShortTitle</short-title>
+  
+  #foreach ($meta in $page.Metadata.Fields)
+	<metadata name="$meta.Name" xml:lang="$meta.Locale.Language">$meta.Value</metadata>
+  #end
+    
+  #traverseFragments($page.RootFragment)
+  
+</page>    
+
+</js>

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
Fri Dec  2 02:36:53 2005
@@ -24,6 +24,7 @@
 import org.apache.jetspeed.ajax.AjaxBuilder;
 import org.apache.jetspeed.layout.Coordinate;
 import org.apache.jetspeed.layout.PortletPlacementContext;
+import org.apache.jetspeed.om.common.SecuredResource;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.PageManager;
@@ -32,6 +33,13 @@
 /**
  * Add Portlet portlet placement action
  * 
+ * AJAX Parameters: 
+ *    id = portlet full name (pa::portletName) to be added
+ *    page = (implied in the URL)
+ * Optional Parameters:  
+ *    row = the new row to move to
+ *    col = the new column to move to
+ *    
  * @author <a>David Gurney </a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
  * @version $Id: $
@@ -50,7 +58,9 @@
         this(template, errorTemplate, null);
     }
 
-    public AddPortletAction(String template, String errorTemplate, PageManager pageManager)
+    public AddPortletAction(String template, 
+                            String errorTemplate, 
+                            PageManager pageManager)
     {
         super(template, errorTemplate);
         this.pageManager = pageManager;
@@ -73,6 +83,13 @@
             }
             resultMap.put(PORTLETID, portletId);
 
+            if (false == checkAccess(requestContext, SecuredResource.EDIT_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to edit page");              
 
+                return success;
+            }
+            
             // These are optional parameters
             String col = requestContext.getRequestParameter(COL);
             String row = requestContext.getRequestParameter(ROW);
@@ -95,11 +112,16 @@
 
             // Use the Portlet Placement Manager to accomplish the removal
             PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
-            Fragment fragment = placement.getFragmentById(portletId);
+            Fragment fragment = pageManager.newFragment();
+            fragment.setType(Fragment.PORTLET);
+            fragment.setName(portletId);
+            // TODO: this does not handle nested layouts            
+            Fragment root = requestContext.getPage().getRootFragment();
+            root.getFragments().add(fragment);
             
-            Coordinate coordinate = placement.add(portletId, new CoordinateImpl(iCol, iRow));
+            Coordinate coordinate = placement.add(fragment, new CoordinateImpl(iCol, iRow,
iCol, iRow));
+            Page page = placement.syncPageFragments();                                  
             
             
-            Page page = placement.syncPageFragments();
             if (pageManager != null)
                 pageManager.updatePage(page);
 
@@ -109,6 +131,7 @@
         {
             // Log the exception
             log.error("exception while adding a portlet", e);
+            resultMap.put(REASON, e.toString());
 
             // Return a failure indicator
             success = false;

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/BasePortletAction.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- 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
Fri Dec  2 02:36:53 2005
@@ -19,6 +19,8 @@
 
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.om.common.SecuredResource;
+import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.request.RequestContext;
 
 /**
@@ -75,4 +77,19 @@
         return template;
     }
 
+    public boolean checkAccess(RequestContext context, String action)
+    {
+        Page page = context.getPage();
+        try
+        {
+            page.checkAccess(action);
+            
+        }
+        catch (SecurityException e)
+        {
+            return false;
+        }     
+        return true;
+    }
+    
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- 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
Fri Dec  2 02:36:53 2005
@@ -22,16 +22,21 @@
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: $
  */
-public interface Constants {
+public interface Constants 
+{
 	public static final String STATUS = "status";
 	public static final String ACTION = "action";
-	public static final String PORTLETID = "id";
+    public static final String REASON = "reason";
+	public static final String PORTLETID = "id";    
 	public static final String OLDCOL = "oldcol";
 	public static final String OLDROW = "oldrow";
 	public static final String NEWCOL = "newcol";
 	public static final String NEWROW = "newrow";
 	public static final String COL = "col";
 	public static final String ROW = "row";
+    public static final String FILTER = "filter";
+    public static final String PORTLETS = "portlets";
+    public static final String PAGE = "page";
 
 	// Move types
 	public static final int ABS = 1;

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPageAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPageAction.java?rev=351664&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPageAction.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPageAction.java
Fri Dec  2 02:36:53 2005
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.layout.impl;
+
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.om.common.SecuredResource;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Get Page retrieves a page from the Page Manager store and PSML format
+ *
+ * AJAX Parameters: 
+ *    page = the path and name of the page ("/_user/ronaldino/goals.psml")
+ *    
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class GetPageAction 
+    extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    /** Logger */
+    protected Log log = LogFactory.getLog(GetPortletsAction.class);
+
+    private PageManager pageManager = null;
+    
+    public GetPageAction(String template, 
+            String errorTemplate, 
+            PageManager pageManager)
+    {
+        super(template, errorTemplate);
+        this.pageManager = pageManager;
+    }
+
+    public boolean run(RequestContext requestContext, Map resultMap)
+    {
+        boolean success = true;
+
+        try
+        {
+            resultMap.put(ACTION, "getpage");
+
+            if (false == checkAccess(requestContext, SecuredResource.VIEW_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to view page");
+                return success;
+            }
+            
+            String filter = requestContext.getRequestParameter(FILTER);            
+                        
+            Page page = requestContext.getPage();
+            
+            resultMap.put(STATUS, "success");
+
+            resultMap.put(PAGE, page);
+
+        } 
+        catch (Exception e)
+        {
+            // Log the exception
+            log.error("exception while getting page", e);
+
+            // Return a failure indicator
+            success = false;
+        }
+
+        return success;
+	}
+    
+        
+}

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPortletsAction.java
Fri Dec  2 02:36:53 2005
@@ -15,33 +15,66 @@
  */
 package org.apache.jetspeed.layout.impl;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
+import javax.security.auth.Subject;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jetspeed.ajax.AjaxAction;
 import org.apache.jetspeed.ajax.AjaxBuilder;
-import org.apache.jetspeed.om.page.ContentPage;
-import org.apache.jetspeed.om.page.Fragment;
+import org.apache.jetspeed.components.portletregistry.PortletRegistry;
+import org.apache.jetspeed.om.common.SecuredResource;
+import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
+import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
+import org.apache.jetspeed.page.PageManager;
 import org.apache.jetspeed.request.RequestContext;
+import org.apache.jetspeed.search.ParsedObject;
+import org.apache.jetspeed.search.SearchEngine;
+import org.apache.jetspeed.security.PermissionManager;
+import org.apache.jetspeed.security.PortletPermission;
 
 /**
- * Get Portlet portlet placement action
+ * Get Portlets retrieves the portlet list available to the current subject
  *
+ * AJAX Parameters: 
+ *    filter = (optional)filter to lookup portlets using fulltext search
+ *    
  * @author <a>David Gurney</a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: $
  */
 public class GetPortletsAction 
     extends BasePortletAction 
-    implements AjaxAction, AjaxBuilder, Constants 
+    implements AjaxAction, AjaxBuilder, Constants, Comparator
 {
     /** Logger */
     protected Log log = LogFactory.getLog(GetPortletsAction.class);
 
-    public GetPortletsAction(String template, String errorTemplate)
+    private PageManager pageManager = null;
+    private PortletRegistry registry = null;
+    private SearchEngine searchEngine = null;
+    private PermissionManager permissionManager = null;
+    
+    public GetPortletsAction(String template, 
+                             String errorTemplate,
+                             PageManager pageManager,
+                             PortletRegistry registry,
+                             SearchEngine searchEngine,
+                             PermissionManager permissionManager)
     {
         super(template, errorTemplate);
+        this.pageManager = pageManager;
+        this.registry = registry;
+        this.searchEngine = searchEngine;
+        this.permissionManager = permissionManager;
     }
 
     public boolean run(RequestContext requestContext, Map resultMap)
@@ -52,17 +85,20 @@
         {
             resultMap.put(ACTION, "getportlets");
 
-            // Get the fragment information from the page
-            ContentPage a_oPage = requestContext.getPage();
-
-            // David Taylor is working on a method like this
-            // page.getFragmentByEntitlement();
-
-            Fragment a_oRootFragment = a_oPage.getRootFragment();
-
+            if (false == checkAccess(requestContext, SecuredResource.EDIT_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to edit page");
+                return success;
+            }
+            
+            String filter = requestContext.getRequestParameter(FILTER);            
+                        
+            List portlets = retrievePortlets(requestContext, filter);
+            
             resultMap.put(STATUS, "success");
 
-            // resultMap.put(FRAGMENTS, a_oFragments);
+            resultMap.put(PORTLETS, portlets);
 
         } 
         catch (Exception e)
@@ -76,4 +112,109 @@
 
         return success;
 	}
+    
+    protected List retrievePortlets(RequestContext requestContext, String filter)
+    {
+        Iterator portlets = null;
+        List list = new ArrayList();
+        Locale locale = requestContext.getLocale();
+        
+        if (filter == null)
+            portlets = registry.getAllPortletDefinitions().iterator();
+        else
+            portlets = searchEngine.search(filter).getResults().iterator();
+        
+        Subject subject = requestContext.getSubject();
+        
+        while (portlets.hasNext())
+        {
+            PortletDefinitionComposite portlet = null;
+            if (filter == null)
+                portlet = (PortletDefinitionComposite)portlets.next();
+            else
+                portlet = this.getPortletFromParsedObject((ParsedObject)portlets.next());
+            
+            if (portlet == null)
+                continue;
+            
+            MutablePortletApplication muta = 
+                (MutablePortletApplication)portlet.getPortletApplicationDefinition();
+            String appName = muta.getName();
+            if (appName != null && appName.equals("jetspeed-layouts"))
+                continue;                
+            
+            // SECURITY filtering
+            String uniqueName = appName + "::" + portlet.getName();
+            if (subject != null)
+            {
+                if (permissionManager.checkPermission(subject, 
+                    new PortletPermission(portlet.getUniqueName(), 
+                    SecuredResource.VIEW_ACTION, subject )))
+                {
+                    list.add(new PortletInfo(uniqueName, portlet.getDisplayNameText(locale),
portlet.getDescriptionText(locale)));
+                }
+            }
+        }            
+        Collections.sort(list, this);
+        return list;
+    }
+    
+    protected PortletDefinitionComposite getPortletFromParsedObject(ParsedObject po)
+    {
+        boolean found = false;
+        String name = "";
+        Map fields = po.getFields();
+        if(fields != null)
+        {
+            Object id = fields.get("ID");
+    
+            if(id != null)
+            {
+                if(id instanceof Collection)
+                {
+                    Collection coll = (Collection)id;
+                    name = (String) coll.iterator().next();
+                }
+                else
+                {
+                    name = (String)id;
+                }
+            }
+            
+            if(po.getType().equals("portlet"))
+            {
+                Object pa = fields.get("portlet_application");
+                String paName = "";
+                if(pa != null)
+                {
+                    if(id instanceof Collection)
+                    {
+                        Collection coll = (Collection)pa;
+                        paName = (String) coll.iterator().next();
+                    }
+                    else
+                    {
+                        paName = (String)pa;
+                    }
+                }
+                name = paName + "::" + name;
+                found = true;
+            }
+        }
+        if (found == false)
+            return null;
+        
+        return registry.getPortletDefinitionByUniqueName(name);
+    }
+    
+    public int compare(Object obj1, Object obj2)
+    {
+        PortletInfo portlet1 = (PortletInfo)obj1;
+        PortletInfo portlet2 = (PortletInfo)obj2;
+        String name1 = portlet1.getName();
+        String name2 = portlet2.getName();
+        name1 = (name1 == null) ? "unknown" : name1;
+        name2 = (name2 == null) ? "unknown" : name2;
+        return name1.compareTo(name2);
+    }
 }

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- 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
Fri Dec  2 02:36:53 2005
@@ -24,6 +24,7 @@
 import org.apache.jetspeed.ajax.AjaxBuilder;
 import org.apache.jetspeed.layout.Coordinate;
 import org.apache.jetspeed.layout.PortletPlacementContext;
+import org.apache.jetspeed.om.common.SecuredResource;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.PageManager;
@@ -32,6 +33,15 @@
 /**
  * Move Portlet portlet placement action
  *
+ * AJAX Parameters: 
+ *    id = the fragment id of the portlet to move
+ *    page = (implied in the URL)
+ * Additional Absolute Parameters:  
+ *    row = the new row to move to
+ *    col = the new column to move to
+ * Additional Relative Parameters: (move left, right, up, down)
+ *    none
+ *    
  * @author <a>David Gurney</a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
  * @version $Id: $
@@ -109,9 +119,16 @@
             { 
                 throw new Exception("portlet id not provided"); 
             }
-
+            
             resultMap.put(PORTLETID, portletId);
 
+            if (false == checkAccess(requestContext, SecuredResource.EDIT_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to edit page");
+                return success;
+            }
+            
             PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
             Fragment fragment = placement.getFragmentById(portletId);
             Coordinate returnCoordinate = null;
@@ -149,6 +166,7 @@
 
             // synchronize back to the page layout root fragment
             Page page = placement.syncPageFragments();
+            
             if (pageManager != null)
                 pageManager.updatePage(page);
             
@@ -173,11 +191,12 @@
         {
             // Log the exception
             log.error("exception while adding a portlet", e);
-
+            resultMap.put(REASON, e.toString());
             // Return a failure indicator
             success = false;
         }
 
         return success;
     }
+    
 }

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletInfo.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletInfo.java?rev=351664&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletInfo.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletInfo.java
Fri Dec  2 02:36:53 2005
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.layout.impl;
+
+/**
+ * Portlet Info populated into AJAX XML response per portlet
+ *
+ * @author <a>David Gurney</a>
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class PortletInfo 
+{
+    private String name;
+    private String displayName;
+    private String description;
+    
+    public PortletInfo(String name, String displayName, String description)
+    {
+        this.name = name;
+        this.displayName = displayName;
+        this.description = description;
+    }
+    /**
+     * @return Returns the description.
+     */
+    public String getDescription()
+    {
+        return description;
+    }
+    /**
+     * @return Returns the displayName.
+     */
+    public String getDisplayName()
+    {
+        return displayName;
+    }
+    /**
+     * @return Returns the name.
+     */
+    public String getName()
+    {
+        return name;
+    }
+}

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
Fri Dec  2 02:36:53 2005
@@ -323,27 +323,9 @@
 		return column;
 	}
 	
-	public Coordinate add(String portletDefinitionID, Coordinate coordinate) throws PortletPlacementException

+	public Coordinate add(Fragment fragment, Coordinate coordinate) throws PortletPlacementException

     {
-//        try
-//        {
-//            Fragment fragment = pageManager.newFragment();
-//            fragment.setType(Fragment.PORTLET);
-//            fragment.setId(generator.getNextPeid());
-//            fragment.setName(portletId);
-//            
-//            Page page = pageManager.getContentPage(pageId);
-//            // WARNING: under construction
-//            // this is prototype and very dependent on a single depth fragment structure
           
-//            Fragment root = page.getRootFragment();
-//            root.getFragments().add(fragment);
-//            pageManager.updatePage(page);            
-//        }
-//        catch (Exception e)
-//        {
-//            log.error("failed to add portlet " + portletId + " to page: " + pageId);
-//        }
-		return null;
+        return addInternal(fragment, coordinate);
 	}
 	
 	// Adds an existing fragment to the coordinate position

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java?rev=351664&r1=351663&r2=351664&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
Fri Dec  2 02:36:53 2005
@@ -23,6 +23,7 @@
 import org.apache.jetspeed.ajax.AjaxBuilder;
 import org.apache.jetspeed.layout.Coordinate;
 import org.apache.jetspeed.layout.PortletPlacementContext;
+import org.apache.jetspeed.om.common.SecuredResource;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.page.PageManager;
@@ -33,6 +34,10 @@
 /**
  * Remove Portlet portlet placement action
  * 
+ * AJAX Parameters: 
+ *    id = the fragment id of the portlet to remove
+ *    page = (implied in the URL)
+ *    
  * @author <a>David Gurney </a>
  * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
  * @version $Id: $
@@ -76,6 +81,13 @@
 
             resultMap.put(PORTLETID, portletId);
 
+            if (false == checkAccess(requestContext, SecuredResource.EDIT_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to edit page");
+                return success;
+            }
+            
             // Use the Portlet Placement Manager to accomplish the removal
             PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
             Fragment fragment = placement.getFragmentById(portletId);
@@ -94,7 +106,7 @@
         {
             // Log the exception
             log.error("exception while adding a portlet", e);
-
+            resultMap.put(REASON, e.toString());
             // Return a failure indicator
             success = false;
         }



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