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 sm...@apache.org on 2007/05/16 12:07:56 UTC

svn commit: r538512 - 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/

Author: smilek
Date: Wed May 16 03:07:53 2007
New Revision: 538512

URL: http://svn.apache.org/viewvc?view=rev&rev=538512
Log:
added includeMenuDefs query parameter to getmenus ajax-api, which when set to true (i.e. includeMenuDefs=true) causes response to include entire menu definitions rather than just the menu names

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm
    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/GetMenusAction.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/layout/ajax-xml/menu.vm
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm?view=diff&rev=538512&r1=538511&r2=538512
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/ajax-xml/menu.vm Wed May 16 03:07:53 2007
@@ -14,8 +14,12 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 *#
-#macro (serializeMenu $_menu $_context $_locale $_indent)
+#macro (serializeMenu $_menu $_context $_locale $_indent $_menutype)
+#if($_menutype && $_menutype.length()>0)
+${_indent}<menu type="$_menutype">
+#else
 ${_indent}<menu>
+#end
 #if("$!_menu.getName()" != "")
 ${_indent}    <name>$_menu.getName()</name>
 #end
@@ -32,9 +36,9 @@
 #if("$!_menu.getUrl()" != "")
 ${_indent}    <url>$_menu.getUrl()</url>
 #end
-${_indent}    <hidden>$menu.isHidden()</hidden>
+${_indent}    <hidden>$_menu.isHidden()</hidden>
 #if("$!_context" != "")
-${_indent}    <selected>$menu.isSelected($_context)</selected>
+${_indent}    <selected>$_menu.isSelected($_context)</selected>
 #else
 ${_indent}    <selected>false</selected>
 #end
@@ -87,14 +91,36 @@
 #end
 ${_indent}    </separator>
 #elseif($element.elementType == "menu")
-#serializeMenu($element $_context $_locale "${_indent}    ")
+#set($childmenutype="")
+#serializeMenu($element $_context $_locale "${_indent}    " $childmenutype)
 #end
 #end
 ${_indent}</menu>
 #end
 <js>
     <status>$status</status>
-    <action>$action</action>
-    
-#serializeMenu($menu $menuContext $menuLocale "    ")
+    <action>$action</action> 
+#if( $menu )
+#set($menuType="")
+#serializeMenu($menu $menuContext $menuLocale "    " $menuType)
+#else
+    <menus>
+#if($includeMenuDefs)
+#foreach ($menu in $standardMenus)
+#serializeMenu($menuDefinitions.get( $menu ) $menuContext $menuLocale "        " "standard")
+#end
+#foreach ($menu in $customMenus)
+#serializeMenu($menuDefinitions.get( $menu ) $menuContext $menuLocale "        " "custom")
+#end
+#else
+#foreach ($menu in $standardMenus)    
+        <menu type="standard">${menu}</menu>
+#end        
+#foreach ($menu in $customMenus)    
+        <menu type="custom">${menu}</menu>
+#end
+#end 
+    </menus>
+#end
+
 </js>

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=538512&r1=538511&r2=538512
==============================================================================
--- 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 Wed May 16 03:07:53 2007
@@ -77,6 +77,8 @@
     
     public static final String STANDARD_MENUS = "standardMenus";
     public static final String CUSTOM_MENUS = "customMenus";
+    public static final String MENU_DEFINITIONS = "menuDefinitions";
+    public static final String INCLUDE_MENU_DEFS = "includeMenuDefs";
     public static final String MENU = "menu";
     public static final String MENU_NAME = "name";
     public static final String MENU_CONTEXT = "menuContext";

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java?view=diff&rev=538512&r1=538511&r2=538512
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/GetMenusAction.java Wed May 16 03:07:53 2007
@@ -16,8 +16,11 @@
  */
 package org.apache.jetspeed.layout.impl;
 
+import java.util.Locale;
 import java.util.Map;
+import java.util.HashMap;
 import java.util.Set;
+import java.util.Iterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -26,6 +29,7 @@
 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;
@@ -87,10 +91,53 @@
             catch (NodeNotFoundException nnfe)
             {
             }
-
+            
             // return menu names action results
             resultMap.put(STANDARD_MENUS, standardMenuNames);
             resultMap.put(CUSTOM_MENUS, customMenuNames);
+            
+            // get action parameter
+            String includeMenuDefinitions = getActionParameter(requestContext, INCLUDE_MENU_DEFS);
+            if ( includeMenuDefinitions != null && includeMenuDefinitions.toLowerCase().equals( "true" ) )
+            {
+                // get request locale
+                Locale locale = requestContext.getLocale();
+                
+                HashMap menuDefinitionsMap = new HashMap();
+                
+                StringBuffer failReason = new StringBuffer();
+                Iterator menuNamesIter = standardMenuNames.iterator();
+                while ( menuNamesIter.hasNext() )
+                {
+                    String menuName = (String)menuNamesIter.next();
+                    Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason );
+                    if ( menuDefinition != null )
+                        menuDefinitionsMap.put( menuName, menuDefinition );
+                }
+                menuNamesIter = customMenuNames.iterator();
+                while ( menuNamesIter.hasNext() )
+                {
+                    String menuName = (String)menuNamesIter.next();
+                    Menu menuDefinition = getMenuDefinition( menuName, siteRequestContext, failReason );
+                    if ( menuDefinition != null )
+                        menuDefinitionsMap.put( menuName, menuDefinition );
+                }
+                
+                if ( failReason.length() > 0 )
+                {
+                    success = false;
+                    resultMap.put(REASON, failReason.toString() );
+                    return success;
+                }
+                resultMap.put( INCLUDE_MENU_DEFS, new Boolean( true ) );
+                resultMap.put( MENU_DEFINITIONS, menuDefinitionsMap );
+                resultMap.put( MENU_CONTEXT, siteRequestContext );
+                resultMap.put( MENU_LOCALE, locale );
+            }
+            else
+            {
+                resultMap.put( INCLUDE_MENU_DEFS, new Boolean( false ) );
+            }
             resultMap.put(STATUS, status);
         }
         catch (Exception e)
@@ -101,4 +148,25 @@
 
         return success;
 	}
+    
+    private Menu getMenuDefinition( String menuName, PortalSiteRequestContext siteRequestContext, StringBuffer failReason )
+    {
+        // get menu definition
+        Menu menuDefinition = null;
+        try
+        {
+            menuDefinition = siteRequestContext.getMenu( menuName );
+        }
+        catch ( NodeNotFoundException nnfe )
+        {
+        }
+        if ( menuDefinition == null && failReason != null )
+        {
+            if ( failReason.length() == 0 )
+                failReason.append( "Unable to lookup specified menus: " ).append( menuName );
+            else
+                failReason.append( ", " ).append( menuName );
+        }
+        return menuDefinition;
+    }
 }

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=538512&r1=538511&r2=538512
==============================================================================
--- 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 Wed May 16 03:07:53 2007
@@ -384,7 +384,7 @@
 <bean id="AjaxGetMenus"
     class="org.apache.jetspeed.layout.impl.GetMenusAction">
     <constructor-arg index="0">
-        <value>org/apache/jetspeed/layout/ajax-xml/menus.vm</value>
+        <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>



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