You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2006/01/03 08:28:25 UTC

svn commit: r365560 - in /portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout: ajax-xml/getpages.vm impl/Constants.java impl/GetPagesAction.java

Author: taylor
Date: Mon Jan  2 23:28:23 2006
New Revision: 365560

URL: http://svn.apache.org/viewcvs?rev=365560&view=rev
Log:
added ajax capabilities to customizer
- getPages
- getPage

(this is still early in dev state)

Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getpages.vm
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPagesAction.java
Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getpages.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getpages.vm?rev=365560&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getpages.vm (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/getpages.vm Mon Jan  2 23:28:23 2006
@@ -0,0 +1,12 @@
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    
+    <pages>
+#foreach ($page in $pages)    
+        <page name="$page.Name" title="$page.Title" path="$page.Path">
+        </page>
+#end        
+    </pages>
+    
+</js>

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=365560&r1=365559&r2=365560&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 Mon Jan  2 23:28:23 2006
@@ -36,7 +36,9 @@
 	public static final String ROW = "row";
     public static final String FILTER = "filter";
     public static final String PORTLETS = "portlets";
+    public static final String PAGES = "pages";
     public static final String PAGE = "page";
+    public static final String FOLDER = "folder";
 
 	// Move types
 	public static final int ABS = 1;

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPagesAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPagesAction.java?rev=365560&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPagesAction.java (added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetPagesAction.java Mon Jan  2 23:28:23 2006
@@ -0,0 +1,132 @@
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+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.folder.Folder;
+import org.apache.jetspeed.om.page.Page;
+import org.apache.jetspeed.page.PageManager;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Get Pages retrieves all pages for the given folder
+ *
+ * AJAX Parameters: 
+ *    folder = the path of folder containing the pages 
+ *    
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: $
+ */
+public class GetPagesAction 
+    extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants, Comparator
+{
+    /** Logger */
+    protected Log log = LogFactory.getLog(GetPortletsAction.class);
+
+    private PageManager pageManager = null;
+    
+    public GetPagesAction(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, "getpages");
+
+            if (false == checkAccess(requestContext, SecuredResource.EDIT_ACTION))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to edit page");
+                return success;
+            }
+                                    
+            List pages = retrievePages(requestContext);
+            
+            resultMap.put(STATUS, "success");
+
+            resultMap.put(PAGES, pages);
+
+        } 
+        catch (Exception e)
+        {
+            // Log the exception
+            log.error("exception while getting portlet info", e);
+
+            // Return a failure indicator
+            success = false;
+        }
+
+        return success;
+	}
+    
+    protected List retrievePages(RequestContext requestContext)
+    {        
+        List list = new ArrayList();
+ 
+        String folderName = requestContext.getRequestParameter(FOLDER);
+        if (folderName == null)
+        {
+            return list;
+        }
+        try
+        {
+            Folder folder = pageManager.getFolder(folderName);
+            Iterator it = folder.getPages().iterator();
+            while (it.hasNext())
+            {
+                Page page = (Page)it.next();
+                list.add(page);
+            }
+            Collections.sort(list, this);
+        }
+        catch (Exception e)
+        {            
+        }
+        return list;
+    }
+    
+    
+    public int compare(Object obj1, Object obj2)
+    {
+        Page page1 = (Page)obj1;
+        Page page2 = (Page)obj2;
+        String name1 = page1.getName();
+        String name2 = page2.getName();
+        name1 = (name1 == null) ? "unknown" : name1;
+        name2 = (name2 == null) ? "unknown" : name2;
+        return name1.compareTo(name2);
+    }
+}



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