portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r893240 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main: java/org/apache/jetspeed/portlets/spaces/PageNavigator.java webapp/WEB-INF/view/spaces/page-navigator.jsp
Date Tue, 22 Dec 2009 17:26:21 GMT
Author: woonsan
Date: Tue Dec 22 17:26:20 2009
New Revision: 893240

URL: http://svn.apache.org/viewvc?rev=893240&view=rev
Log:
JS2-1057: Adding space links menu support in the portlet side.

Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/PageNavigator.java
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/PageNavigator.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/PageNavigator.java?rev=893240&r1=893239&r2=893240&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/PageNavigator.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/PageNavigator.java
Tue Dec 22 17:26:20 2009
@@ -40,7 +40,6 @@
 import org.apache.jetspeed.om.page.Page;
 import org.apache.jetspeed.om.portlet.LocalizedField;
 import org.apache.jetspeed.page.PageManager;
-import org.apache.jetspeed.page.document.NodeNotFoundException;
 import org.apache.jetspeed.portalsite.Menu;
 import org.apache.jetspeed.portalsite.MenuElement;
 import org.apache.jetspeed.portalsite.PortalSiteRequestContext;
@@ -62,7 +61,9 @@
 {
     
     public static final String DEFAULT_PAGES_MENU = "pages";
+    public static final String DEFAULT_LINKS_MENU = "links";
     public static final String DEFAULT_SPACE_NAVS_MENU = "space-navigations";
+    public static final String DEFAULT_SPACE_LINKS_MENU = "space-links";
     
     private static Logger log = LoggerFactory.getLogger(PageNavigator.class);
     
@@ -71,6 +72,7 @@
     protected PageManager pageManager;
     private BasePortalURL baseUrlAccess = null;
     private String defaultMenu = DEFAULT_SPACE_NAVS_MENU;
+    private String defaultLinksMenu = DEFAULT_SPACE_LINKS_MENU;
 
     public void init(PortletConfig config) throws PortletException
     {
@@ -140,6 +142,7 @@
         request.setAttribute("pageNavigator", this);
         
         request.setAttribute("spaceMenuElements", getSpaceMenuElements(space, request));
+        request.setAttribute("spaceLinkElements", getSpaceLinkMenuElements(space, request));
         
         super.doView(request, response);
     }
@@ -229,47 +232,115 @@
             {
                 spaceMenu = psrc.getMenu(menuName);
             }
-            catch (NodeNotFoundException e)
+            catch (Exception e)
+            {
+                log.error("Failed to retrieve menu.", e);
+            }
+            
+            if (spaceMenu == null)
             {
                 if (!DEFAULT_PAGES_MENU.equals(menuName))
                 {
                     spaceMenu = psrc.getMenu(DEFAULT_PAGES_MENU);
-                    defaultMenu = DEFAULT_PAGES_MENU;
+                    
+                    if (spaceMenu != null)
+                    {
+                        defaultMenu = DEFAULT_PAGES_MENU;
+                    }
                 }
             }
             
-            for (MenuElement element : (List<MenuElement>)spaceMenu.getElements())
+            if (spaceMenu != null)
             {
-                String type = element.getElementType();
-                
-                if (MenuElement.MENU_ELEMENT_TYPE.equals(type))
+                for (MenuElement element : (List<MenuElement>) spaceMenu.getElements())
                 {
-                    Menu folderMenu = (Menu) element;
+                    String type = element.getElementType();
                     
-                    if (!isRootSpace)
+                    if (MenuElement.MENU_ELEMENT_TYPE.equals(type))
                     {
-                        spaceMenuElements.add(element);
-                    }
-                    else
-                    {
-                        // TODO: folder menu's url is same to path?
-                        String folderPath = folderMenu.getUrl();
+                        Menu folderMenu = (Menu) element;
                         
-                        if (pageManager.folderExists(folderPath))
+                        if (!isRootSpace)
                         {
-                            Folder folder = pageManager.getFolder(folderPath);
-                            Collection<LocalizedField> fields = folder.getMetadata().getFields("space-owner");
+                            spaceMenuElements.add(element);
+                        }
+                        else
+                        {
+                            // TODO: folder menu's url is same to path?
+                            String folderPath = folderMenu.getUrl();
                             
-                            if (fields == null || fields.isEmpty())
+                            if (pageManager.folderExists(folderPath))
                             {
-                                spaceMenuElements.add(element);
+                                Folder folder = pageManager.getFolder(folderPath);
+                                Collection<LocalizedField> fields = folder.getMetadata().getFields("space-owner");
+                                
+                                if (fields == null || fields.isEmpty())
+                                {
+                                    spaceMenuElements.add(element);
+                                }
                             }
                         }
                     }
+                    else if (MenuElement.OPTION_ELEMENT_TYPE.equals(type))
+                    {
+                        spaceMenuElements.add(element);
+                    }
                 }
-                else if (MenuElement.OPTION_ELEMENT_TYPE.equals(type))
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to retrieve space menu elements.", e);
+        }
+        
+        return spaceMenuElements;
+    }
+    
+    private List<MenuElement> getSpaceLinkMenuElements(Space space, PortletRequest
request)
+    {
+        ArrayList<MenuElement> spaceLinkMenuElements = new ArrayList<MenuElement>();
+        
+        try
+        {
+            RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
+            PortalSiteRequestContext psrc = (PortalSiteRequestContext) rc.getAttribute("org.apache.jetspeed.portalsite.PortalSiteRequestContext");
+
+            Menu spaceLinksMenu = null;
+            
+            String linksMenuName = request.getPreferences().getValue("LinkMenu", defaultLinksMenu);
+            
+            try
+            {
+                spaceLinksMenu = psrc.getMenu(linksMenuName);
+            }
+            catch (Exception e)
+            {
+                log.error("Failed to retrieve menu.", e);
+            }
+            
+            if (spaceLinksMenu == null)
+            {
+                if (!DEFAULT_LINKS_MENU.equals(linksMenuName))
                 {
-                    spaceMenuElements.add(element);
+                    spaceLinksMenu = psrc.getMenu(DEFAULT_LINKS_MENU);
+                    
+                    if (spaceLinksMenu != null)
+                    {
+                        defaultLinksMenu = DEFAULT_LINKS_MENU;
+                    }
+                }
+            }
+            
+            if (spaceLinksMenu != null)
+            {
+                for (MenuElement element : (List<MenuElement>) spaceLinksMenu.getElements())
+                {
+                    String type = element.getElementType();
+                    
+                    if (MenuElement.OPTION_ELEMENT_TYPE.equals(type))
+                    {
+                        spaceLinkMenuElements.add(element);
+                    }
                 }
             }
         }
@@ -278,6 +349,6 @@
             log.error("Failed to retrieve space menu elements.", e);
         }
         
-        return spaceMenuElements;
+        return spaceLinkMenuElements;
     }
 }
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp?rev=893240&r1=893239&r2=893240&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/view/spaces/page-navigator.jsp
Tue Dec 22 17:26:20 2009
@@ -37,11 +37,11 @@
 <portlet:defineObjects/>
 <%
 RequestContext rc = (RequestContext)request.getAttribute(RequestContext.REQUEST_PORTALENV);
-PortalSiteRequestContext psrc = (PortalSiteRequestContext)rc.getAttribute("org.apache.jetspeed.portalsite.PortalSiteRequestContext");
 Space space = (Space)renderRequest.getAttribute("space");
 Locale locale = renderRequest.getLocale();
 PageNavigator pageNavigator = (PageNavigator)renderRequest.getAttribute("pageNavigator");
 List<MenuElement> menuElements = (List<MenuElement>) renderRequest.getAttribute("spaceMenuElements");
+List<MenuElement> linkElements = (List<MenuElement>) renderRequest.getAttribute("spaceLinkElements");
 %>
 <table>
 	<tr><td class="portlet-section-body"><b><%=space.getName() %> Space</b></td>
</tr>
@@ -80,33 +80,30 @@
         <th class="portlet-section-header" colspan="1"></th>
     </tr>
 <%
-Menu linksMenu = psrc.getMenu("additional-links");
-for (MenuElement element : (List<MenuElement>)linksMenu.getElements())
+if (!linkElements.isEmpty())
 {
-	if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE))
+	for (MenuElement element : linkElements)
 	{
-		MenuOption option = (MenuOption)element;
-		String url = pageNavigator.getAbsoluteUrl(option.getUrl(), renderResponse, rc);	
+		if (element.getElementType().equals(MenuElement.OPTION_ELEMENT_TYPE))
+		{
+			MenuOption option = (MenuOption)element;
+			String url = pageNavigator.getAbsoluteUrl(option.getUrl(), renderResponse, rc);	
 %>     
      <tr>
        <td class="portlet-section-body"><a href="<%=url%>"><%=element.getTitle(locale)
%></a></td>
      </tr>
 <%
+		}
 	}
-	else
-	{
-%>
-     <tr>
-       <td class="portlet-section-body">---</td>
-     </tr>
-<%
-	}
-}
 %>
     <tr>
         <th class="portlet-section-header" colspan="1"></th>
     </tr>
 <%
+}
+%>
+
+<%
 Object princ2 = renderRequest.getUserPrincipal();
 if (princ2 != null) {
 %>



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