portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r904286 - in /portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces: PageNavigator.java SpaceChangeContext.java SpaceNavigator.java
Date Thu, 28 Jan 2010 22:42:50 GMT
Author: taylor
Date: Thu Jan 28 22:42:50 2010
New Revision: 904286

URL: http://svn.apache.org/viewvc?rev=904286&view=rev
Log:
refine space context change detection

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
  (with props)
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/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java

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=904286&r1=904285&r2=904286&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
Thu Jan 28 22:42:50 2010
@@ -138,60 +138,12 @@
             request.getPortletSession().removeAttribute("links");
             request.getPortletSession().removeAttribute("space");
         }
-        List<SpaceBean> spaces = (List<SpaceBean>)request.getPortletSession().getAttribute("spaces");
-        if (spaces == null)
-        {
-            // TODO: use environment
-            List<Space> sl = spacesService.listSpaces();
-            spaces = new LinkedList<SpaceBean>();
-            for (Space s : sl)
-            {
-            	spaces.add(new SpaceBean(s));
-            }
-        }              
-        request.getPortletSession().setAttribute("spaces", spaces);        
-        SpaceBean space = (SpaceBean) request.getPortletSession().getAttribute("space");
       
-        if (space != null)
-        {
-            // check if this space matches the current portal page path.
-            RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
-            String portalPagePath = rc.getPortalURL().getPath();
-            
-            if (portalPagePath == null || "".equals(portalPagePath))
-            {
-                portalPagePath = "/";
-            }
-            
-            if (!portalPagePath.startsWith(space.getPath()))
-            {
-                space = null;
-            }
-        }
-        
-        if (space == null)
-        {                
-            space = spaces.get(0);
-            
-            if (newSpace != null)
-            {
-                for (SpaceBean sp : spaces)
-                {
-                    if (sp.getName().equals(newSpace))
-                    {
-                        space = sp;
-                        break;
-                    }
-                }
-            }
-            
-            request.getPortletSession().setAttribute("space", space);        
-        }                    
-        request.setAttribute("space", space);
-        request.setAttribute("pageNavigator", this);
-        
-        request.setAttribute("spaceMenuElements", getSpaceMenuElements(space, request));
-        request.setAttribute("spaceLinkElements", getSpaceLinkMenuElements(space, request));
-        
+        SpaceChangeContext scc = SpaceNavigator.changeSpace(request, spacesService, newSpace);
     
+        request.setAttribute("space", scc.getSpace());
+        request.setAttribute("spaces", scc.getSpaces());        
+        request.setAttribute("pageNavigator", this);        
+        request.setAttribute("spaceMenuElements", getSpaceMenuElements(scc.getSpace(), request));
+        request.setAttribute("spaceLinkElements", getSpaceLinkMenuElements(scc.getSpace(),
request));        
         super.doView(request, response);
     }
     

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java?rev=904286&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
(added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
Thu Jan 28 22:42:50 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.portlets.spaces;
+
+import java.util.List;
+
+public class SpaceChangeContext
+{
+	private SpaceBean space;
+	private List<SpaceBean> spaces;
+
+	public SpaceChangeContext(SpaceBean space, List<SpaceBean> spaces)
+	{
+		this.space = space;
+		this.spaces = spaces;
+	}
+
+	public SpaceBean getSpace() {
+		return space;
+	}
+
+	public void setSpace(SpaceBean space) {
+		this.space = space;
+	}
+
+	public List<SpaceBean> getSpaces() {
+		return spaces;
+	}
+
+	public void setSpaces(List<SpaceBean> spaces) {
+		this.spaces = spaces;
+	}
+}

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceChangeContext.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java?rev=904286&r1=904285&r2=904286&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
(original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/spaces/SpaceNavigator.java
Thu Jan 28 22:42:50 2010
@@ -30,6 +30,7 @@
 
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.administration.PortalAdministration;
+import org.apache.jetspeed.om.folder.Folder;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.spaces.Space;
 import org.apache.jetspeed.spaces.Spaces;
@@ -74,49 +75,12 @@
             request.getPortletSession().removeAttribute("spaces");
             request.getPortletSession().removeAttribute("space");
         }
-        List<SpaceBean> spaces = (List<SpaceBean>)request.getPortletSession().getAttribute("spaces");
-        if (spaces == null)
-        {
-            // TODO: use environment
-            List<Space> sl = spacesService.listSpaces();
-            spaces = new LinkedList<SpaceBean>();
-            for (Space s : sl)
-            {
-            	spaces.add(new SpaceBean(s));
-            }
-            request.getPortletSession().setAttribute("spaces", spaces);        
-        }        
-        boolean changed = false;
-        SpaceBean space = (SpaceBean)request.getPortletSession().getAttribute("space"); 
              
-        if (space == null && spaceName != null)
-        {
-        	space = findSpace(spaces, spaceName);
-        	changed = true;
-        }
-        // check if this space matches the current portal page path.
-        RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
-        String portalPagePath = rc.getPortalURL().getPath();
-        if (portalPagePath == null || "".equals(portalPagePath))
-        {
-            portalPagePath = "/";
-        }
-        if (space == null || !portalPagePath.startsWith(space.getPath()))
-        {
-        	space = findSpaceByPath(spaces, portalPagePath);
-        	changed = true;        	
-        }        
-        if (space== null)
-        {
-            space = spaces.get(0);
-        	changed = true;            
-        }
-        if (changed)
-            request.getPortletSession().setAttribute("space", space);        	
-        request.setAttribute("space", space);        
-        request.setAttribute("spaces", spaces);
+        SpaceChangeContext scc = changeSpace(request, spacesService, spaceName);
+        request.setAttribute("space", scc.getSpace());
+        request.setAttribute("spaces", scc.getSpaces());
         super.doView(request, response);
     }
-    
+        
     public void processAction(ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException,
     IOException
     {
@@ -160,7 +124,7 @@
         return space;
     }
  
-    protected SpaceBean findSpace(List<SpaceBean> spaces, String spaceName)
+    protected static SpaceBean findSpace(List<SpaceBean> spaces, String spaceName)
     {
         for (SpaceBean s : spaces)
         {
@@ -172,15 +136,80 @@
         return null;
     }
     
-    protected SpaceBean findSpaceByPath(List<SpaceBean> spaces, String spacePath)
+    protected static SpaceBean findSpaceByPath(List<SpaceBean> spaces, String spacePath)
     {
         for (SpaceBean s : spaces)
         {
-        	if (s.getPath().equals(spacePath))
+        	if (pathsEqual(s.getPath(), spacePath))
         	{
         		return s;
         	}
         }            	
         return null;
-    }    
+    }
+    
+    protected static SpaceChangeContext changeSpace(RenderRequest request, Spaces spacesService,
String spaceName )
+    {
+        List<SpaceBean> spaces = (List<SpaceBean>)request.getPortletSession().getAttribute("spaces");
+        if (spaces == null)
+        {
+            // TODO: use environment
+            List<Space> sl = spacesService.listSpaces();
+            spaces = new LinkedList<SpaceBean>();
+            for (Space s : sl)
+            {
+            	spaces.add(new SpaceBean(s));
+            }
+            request.getPortletSession().setAttribute("spaces", spaces);        
+        }        
+        boolean changed = false;
+        SpaceBean space = (SpaceBean)request.getPortletSession().getAttribute("space"); 
              
+        if (space == null && spaceName != null)
+        {
+        	space = findSpace(spaces, spaceName);
+        	changed = true;
+        }
+        // check if this space matches the current portal page path.
+        RequestContext rc = (RequestContext) request.getAttribute(RequestContext.REQUEST_PORTALENV);
+        String portalPagePath = rc.getPortalURL().getPath();
+        if (portalPagePath == null || "".equals(portalPagePath))
+        {
+            portalPagePath = Folder.PATH_SEPARATOR;
+        }
+        if (space == null || !pathsEqual(portalPagePath, space.getPath()))
+        {
+        	space = findSpaceByPath(spaces, portalPagePath);
+        	changed = true;        	
+        }        
+        if (space== null)
+        {
+            space = spaces.get(0);
+        	changed = true;            
+        }
+        if (changed)
+            request.getPortletSession().setAttribute("space", space);
+    	return new SpaceChangeContext(space, spaces);
+    }
+    
+    protected static boolean pathsEqual(String p1, String p2)
+    {
+    	String s1 = new String (p1);
+    	String s2 = new String (p2);
+    	if (s1 == null || s2 == null)
+    		return false;
+    	int start = s1.indexOf(Folder.PATH_SEPARATOR);
+    	int end = s1.lastIndexOf(Folder.PATH_SEPARATOR);
+    	if (end > start)
+    		s1 = s1.substring(start, end);
+    	start = s2.indexOf(Folder.PATH_SEPARATOR);
+     	end = s2.lastIndexOf(Folder.PATH_SEPARATOR);
+     	if (end > start)
+     		s2 = s2.substring(start, end);    	
+    	if (!s1.endsWith(Folder.PATH_SEPARATOR))
+    		s1 = s1 + Folder.PATH_SEPARATOR;
+    	if (!s2.endsWith(Folder.PATH_SEPARATOR))
+    		s2 = s2 + Folder.PATH_SEPARATOR;
+    	return s1.equals(s2);
+    }
+    
 }
\ No newline at end of file



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