portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r393017 - in /portals/jetspeed-2/trunk: components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/ components/portal/src/java/org/apache/jetspeed/layout/impl/ src/webapp/WEB-INF/assembly/
Date Mon, 10 Apr 2006 18:21:01 GMT
Author: rwatler
Date: Mon Apr 10 11:20:58 2006
New Revision: 393017

URL: http://svn.apache.org/viewcvs?rev=393017&view=rev
Log:
Added PortalSite component generated menus to AJAX APIs, example request urls:

http://localhost:8080/jetspeed/ajaxapi/default_page.psml?action=getmenus
http://localhost:8080/jetspeed/ajaxapi/default_page.psml?action=getmenu&name=pages


Added:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
  (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm
  (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java
  (with props)
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
  (with props)
Modified:
    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/src/webapp/WEB-INF/assembly/ajax-layout.xml

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm?rev=393017&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
Mon Apr 10 11:20:58 2006
@@ -0,0 +1,84 @@
+#macro (serializeMenu $_menu $_context $_locale $_indent)
+${_indent}<menu>
+#if("$!_menu.getName()" != "")
+${_indent}    <name>$_menu.getName()</name>
+#end
+#if("$!_locale" != "")
+${_indent}    <title>$_menu.getTitle($_locale)</title>
+${_indent}    <short-title>$_menu.getShortTitle($_locale)</short-title>
+#else
+${_indent}    <title>$_menu.getTitle()</title>
+${_indent}    <short-title>$_menu.getShortTitle()</short-title>
+#end
+#if("$!_menu.getSkin()" != "")
+${_indent}    <skin>$_menu.getSkin()</skin>
+#end
+#if("$!_menu.getUrl()" != "")
+${_indent}    <url>$_menu.getUrl()</url>
+#end
+${_indent}    <hidden>$menu.isHidden()</hidden>
+#if("$!_context" != "")
+${_indent}    <selected>$menu.isSelected($_context)</selected>
+#else
+${_indent}    <selected>false</selected>
+#end
+#foreach($element in $_menu.elements.iterator())
+#if($element.elementType == "option")
+${_indent}    <option>
+${_indent}        <type>$element.getType()</type>
+#if("$!_locale" != "")
+${_indent}        <title>$element.getTitle($_locale)</title>
+${_indent}        <short-title>$element.getShortTitle($_locale)</short-title>
+#else
+${_indent}        <title>$element.getTitle()</title>
+${_indent}        <short-title>$element.getShortTitle()</short-title>
+#end
+#if("$!element.getSkin()" != "")
+${_indent}        <skin>$element.getSkin()</skin>
+#end
+#if("$!element.getUrl()" != "")
+${_indent}        <url>$element.getUrl()</url>
+#end
+#if("$!element.getTarget()" != "")
+${_indent}        <target>$element.getTarget()</target>
+#end
+${_indent}        <hidden>$element.isHidden()</hidden>
+#if("$!_context" != "")
+${_indent}        <selected>$element.isSelected($_context)</selected>
+#else
+${_indent}        <selected>false</selected>
+#end
+${_indent}    </option>
+#elseif($element.elementType == "separator")
+${_indent}    <separator>
+#if("$!_locale" != "")
+#if("$!element.getTitle($_locale)" != "")
+${_indent}        <title>$element.getTitle($_locale)</title>
+#end
+#if("$!element.getText($_locale)" != "")
+${_indent}        <text>$element.getText($_locale)</text>
+#end
+#else
+#if("$!element.getTitle()" != "")
+${_indent}        <title>$element.getTitle()</title>
+#end
+#if("$!element.getText()" != "")
+${_indent}        <text>$element.getText()</text>
+#end
+#end
+#if("$!element.getSkin()" != "")
+${_indent}        <skin>$element.getSkin()</skin>
+#end
+${_indent}    </separator>
+#elseif($element.elementType == "menu")
+#serializeMenu($element $_context $_locale "${_indent}    ")
+#end
+#end
+${_indent}</menu>
+#end
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    
+#serializeMenu($menu $menuContext $menuLocale "    ")
+</js>

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
------------------------------------------------------------------------------
    svn:eol-style = native

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm?rev=393017&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm
Mon Apr 10 11:20:58 2006
@@ -0,0 +1,14 @@
+<js>
+    <status>$status</status>
+    <action>$action</action>
+    
+    <menus>
+#foreach ($menu in $standardMenus)    
+        <menu type="standard">${menu}</menu>
+#end        
+#foreach ($menu in $customMenus)    
+        <menu type="custom">${menu}</menu>
+#end        
+    </menus>
+    
+</js>

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menus.vm
------------------------------------------------------------------------------
    svn:eol-style = native

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=393017&r1=393016&r2=393017&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
Mon Apr 10 11:20:58 2006
@@ -46,13 +46,20 @@
     
     public BasePortletAction(String template, 
                              String errorTemplate, 
-                             PageManager pageManager,
                              PortletActionSecurityBehavior securityBehavior)
     {
         this.template = template;
         this.errorTemplate = errorTemplate;
-        this.pageManager = pageManager;
         this.securityBehavior = securityBehavior;
+    }
+
+    public BasePortletAction(String template, 
+                             String errorTemplate, 
+                             PageManager pageManager,
+                             PortletActionSecurityBehavior securityBehavior)
+    {
+        this(template, errorTemplate, securityBehavior);
+        this.pageManager = pageManager;
     }
 
     public boolean buildContext(RequestContext requestContext, Map responseContext)

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=393017&r1=393016&r2=393017&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 Apr 10 11:20:58 2006
@@ -55,6 +55,13 @@
     public static final String PAGE = "page";
     public static final String FOLDER = "folder";
 
+    public static final String STANDARD_MENUS = "standardMenus";
+    public static final String CUSTOM_MENUS = "customMenus";
+    public static final String MENU = "menu";
+    public static final String MENU_NAME = "name";
+    public static final String MENU_CONTEXT = "menuContext";
+    public static final String MENU_LOCALE = "menuLocale";
+
 	// Move types
 	public static final int ABS = 1;
 	public static final int UP = 2;

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java?rev=393017&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java
Mon Apr 10 11:20:58 2006
@@ -0,0 +1,122 @@
+/*
+ * 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.Locale;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.page.document.NodeNotFoundException;
+import org.apache.jetspeed.portalsite.Menu;
+import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
+import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Get menu action retrieves a menu defined for the addressed page.
+ *
+ * AJAX Parameters: 
+ *    menu = the name of the menu definition to retrieve 
+ *    
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class GetMenuAction extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    protected Log log = LogFactory.getLog(GetMenusAction.class);
+    
+    public GetMenuAction(String template,
+                         String errorTemplate,
+                         PortletActionSecurityBehavior securityBehavior)
+    {
+        super(template, errorTemplate, securityBehavior);
+    }
+
+    public boolean run(RequestContext requestContext, Map resultMap)
+    {
+        boolean success = true;
+        String status = "success";
+        try
+        {
+            // generate action result
+            resultMap.put(ACTION, "getmenu");
+
+            // check permission to use ajax api
+            if (!checkAccess(requestContext, JetspeedActions.VIEW))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to get menu");
+                return success;
+            }
+
+            // get action parameter
+            String menuName = requestContext.getRequestParameter(MENU_NAME);
+            if (menuName == null)
+            {
+                success = false;
+                resultMap.put(REASON, "Missing required '" + MENU_NAME + "' parameter");
+                return success;
+            }
+
+            // get request context
+            PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
+            if (siteRequestContext == null)
+            {
+                success = false;
+                resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
+                return success;
+            }
+
+            // get request locale
+            Locale locale = requestContext.getLocale();
+
+            // get menu definition
+            Menu menuDefinition = null;
+            try
+            {
+                menuDefinition = siteRequestContext.getMenu(menuName);
+            }
+            catch (NodeNotFoundException nnfe)
+            {
+            }
+            if (menuDefinition == null)
+            {
+                success = false;
+                resultMap.put(REASON, "Unable to lookup specified menu for page");
+                return success;
+            }
+
+            // return menu definition action results
+            resultMap.put(MENU, menuDefinition);
+            resultMap.put(MENU_CONTEXT, siteRequestContext);
+            resultMap.put(MENU_LOCALE, locale);
+            resultMap.put(STATUS, status);
+        }
+        catch (Exception e)
+        {
+            log.error("Exception while getting page menus info", e);
+            success = false;
+        }
+
+        return success;
+	}
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenuAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java?rev=393017&view=auto
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
(added)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
Mon Apr 10 11:20:58 2006
@@ -0,0 +1,103 @@
+/*
+ * 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 java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.JetspeedActions;
+import org.apache.jetspeed.ajax.AjaxAction;
+import org.apache.jetspeed.ajax.AjaxBuilder;
+import org.apache.jetspeed.layout.PortletActionSecurityBehavior;
+import org.apache.jetspeed.page.document.NodeNotFoundException;
+import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
+import org.apache.jetspeed.profiler.impl.ProfilerValveImpl;
+import org.apache.jetspeed.request.RequestContext;
+
+/**
+ * Get menus action retrieves all menu names defined for the addressed page.
+ *
+ * AJAX Parameters: 
+ *    none
+ *    
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class GetMenusAction extends BasePortletAction 
+    implements AjaxAction, AjaxBuilder, Constants
+{
+    protected Log log = LogFactory.getLog(GetMenusAction.class);
+    
+    public GetMenusAction(String template,
+                          String errorTemplate,
+                          PortletActionSecurityBehavior securityBehavior)
+    {
+        super(template, errorTemplate, securityBehavior);
+    }
+
+    public boolean run(RequestContext requestContext, Map resultMap)
+    {
+        boolean success = true;
+        String status = "success";
+        try
+        {
+            // generate action result
+            resultMap.put(ACTION, "getmenus");
+
+            // check permission to use ajax api
+            if (!checkAccess(requestContext, JetspeedActions.VIEW))
+            {
+                success = false;
+                resultMap.put(REASON, "Insufficient access to get menus");
+                return success;
+            }
+
+            // get request context
+            PortalSiteRequestContext siteRequestContext = (PortalSiteRequestContext)requestContext.getAttribute(ProfilerValveImpl.PORTAL_SITE_REQUEST_CONTEXT_ATTR_KEY);
+            if (siteRequestContext == null)
+            {
+                success = false;
+                resultMap.put(REASON, "Missing portal site request context from ProfilerValve");
+                return success;
+            }
+
+            // get menu names
+            Set standardMenuNames = siteRequestContext.getStandardMenuNames();
+            Set customMenuNames = null;
+            try
+            {
+                customMenuNames = siteRequestContext.getCustomMenuNames();
+            }
+            catch (NodeNotFoundException nnfe)
+            {
+            }
+
+            // return menu names action results
+            resultMap.put(STANDARD_MENUS, standardMenuNames);
+            resultMap.put(CUSTOM_MENUS, customMenuNames);
+            resultMap.put(STATUS, status);
+        }
+        catch (Exception e)
+        {
+            log.error("Exception while getting page menus info", e);
+            success = false;
+        }
+
+        return success;
+	}
+}

Propchange: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/src/webapp/WEB-INF/assembly/ajax-layout.xml?rev=393017&r1=393016&r2=393017&view=diff
==============================================================================
--- 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 Mon Apr 10 11:20:58
2006
@@ -245,7 +245,33 @@
         <ref bean="PortalContextProvider"/>        
     </constructor-arg>    	        
 </bean>
-        	
+
+<bean id="AjaxGetMenus"
+    class="org.apache.jetspeed.layout.impl.GetMenusAction">
+    <constructor-arg index="0">
+        <value>org/apache/jetspeed/layout/ajax-xml/menus.vm</value>
+    </constructor-arg>
+    <constructor-arg index="1">
+        <value>org/apache/jetspeed/layout/ajax-xml/error.vm</value>
+    </constructor-arg>
+    <constructor-arg index='2'>
+        <ref bean="PortletActionSecurityBehavior"/>        
+    </constructor-arg>    	
+</bean>
+
+<bean id="AjaxGetMenu"
+    class="org.apache.jetspeed.layout.impl.GetMenuAction">
+    <constructor-arg index="0">
+        <value>org/apache/jetspeed/layout/ajax-xml/menu.vm</value>
+    </constructor-arg>
+    <constructor-arg index="1">
+        <value>org/apache/jetspeed/layout/ajax-xml/error.vm</value>
+    </constructor-arg>
+    <constructor-arg index='2'>
+        <ref bean="PortletActionSecurityBehavior"/>        
+    </constructor-arg>    	
+</bean>
+
 <bean id="AjaxRequestService" class="org.apache.jetspeed.ajax.AjaxRequestServiceImpl">
     <constructor-arg index="0">
         <map>
@@ -285,6 +311,12 @@
             <entry key="window">
                 <ref bean="AjaxChangeWindow"/>
             </entry>			            
+            <entry key="getmenus">
+                <ref bean="AjaxGetMenus"/>
+            </entry>			            
+            <entry key="getmenu">
+                <ref bean="AjaxGetMenu"/>
+            </entry>			            
         </map>
     </constructor-arg>
     <constructor-arg index="1">
@@ -311,4 +343,4 @@
 		</constructor-arg>
 	</bean>
   
-</beans>
\ No newline at end of file
+</beans>



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