geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r899547 - in /geronimo/server/branches/2.2/plugins/console: console-filter/src/main/java/org/apache/geronimo/console/filter/ console-portal-driver/src/main/java/org/apache/geronimo/console/filter/ console-portal-driver/src/main/webapp/WEB-I...
Date Fri, 15 Jan 2010 06:46:16 GMT
Author: genspring
Date: Fri Jan 15 06:46:15 2010
New Revision: 899547

URL: http://svn.apache.org/viewvc?rev=899547&view=rev
Log:
GERONIMO-4994 use hash to keep the page to the latest page viewed after refresh.


Added:
    geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java
  (with props)
Modified:
    geronimo/server/branches/2.2/plugins/console/console-filter/src/main/java/org/apache/geronimo/console/filter/XSRFHandler.java
    geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
    geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-only.jsp
    geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-with-tree.jsp
    geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml

Modified: geronimo/server/branches/2.2/plugins/console/console-filter/src/main/java/org/apache/geronimo/console/filter/XSRFHandler.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-filter/src/main/java/org/apache/geronimo/console/filter/XSRFHandler.java?rev=899547&r1=899546&r2=899547&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-filter/src/main/java/org/apache/geronimo/console/filter/XSRFHandler.java
(original)
+++ geronimo/server/branches/2.2/plugins/console/console-filter/src/main/java/org/apache/geronimo/console/filter/XSRFHandler.java
Fri Jan 15 06:46:15 2010
@@ -49,6 +49,7 @@
     private static final String XSRF_JS_FILENAME = "/XSRF.js";
     private static final String XSRF_JS_UNIQUEID = "<%XSRF_UNIQUEID%>";
     private static final String NOXSS_SHOW_TREE = "noxssShowTree";
+    private static final String NOXSS_HASH_OF_PAGE_TO_REDIRECT = "noxssPage";
 
     private Map<String, String> sessionMap = Collections.synchronizedMap(new HashMap<String,
String>());
     private String xsrfJS;
@@ -87,8 +88,14 @@
 
         if ((hreq.getQueryString() != null) || (hreq.getParameterNames().hasMoreElements()))
{
             
-            if (hreq.getParameterMap().keySet().size() == 1 && hreq.getParameter(NOXSS_SHOW_TREE)
!= null
-                    && hreq.getParameter(NOXSS_SHOW_TREE).equals("true")) {
+            if (hreq.getParameterMap().keySet().size() == 1 && hreq.getParameter(NOXSS_SHOW_TREE)
!= null) {
+
+                return false;
+
+            }
+            
+            if (hreq.getParameterMap().keySet().size() == 2 && hreq.getParameter(NOXSS_SHOW_TREE)
!= null
+                    && hreq.getParameter(NOXSS_HASH_OF_PAGE_TO_REDIRECT)!=null) {
 
                 return false;
 

Added: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java?rev=899547&view=auto
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java
(added)
+++ geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java
Fri Jan 15 06:46:15 2010
@@ -0,0 +1,126 @@
+/**
+ *  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.geronimo.console.filter;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Random;
+import java.util.WeakHashMap;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This filter is used to
+ *   1,Keep a hash-->url mapping
+ *   2,Redirect to certain url based on hash parameter in request* 
+ * 
+ * @version $Rev$ $Date$
+ */
+public class RedirectByHashFilter implements Filter {
+
+    private static final Logger log = LoggerFactory.getLogger(RedirectByHashFilter.class);
+    
+    private static final Random random = new Random(System.currentTimeMillis());
+    
+    private static final Map<String,String> hashToRedirectURL=new WeakHashMap<String,String>();
+    private static final Map<String,String> redirectURLToHash=new WeakHashMap<String,String>();
+    
+    private static final String NOXSS_HASH_OF_PAGE_TO_REDIRECT = "noxssPage";
+    private static final String NOXSS_SHOW_TREE = "noxssShowTree";
+    private static final String HASH_OF_CURRENT_PORTAL_PAGE = "hashOfCurrentPortalPage";
+    
+    public void destroy() {
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
throws IOException,
+            ServletException {
+
+        //Generate hash for pure portlets page but not the index page.
+        if (request instanceof HttpServletRequest && request.getParameter(NOXSS_SHOW_TREE)
== null) {
+
+            HttpServletRequest httpServletRequest = (HttpServletRequest) request;
+
+            String currentRequestURI = httpServletRequest.getServletPath()+httpServletRequest.getPathInfo();
+
+            String hash;
+            
+            if (redirectURLToHash.get(currentRequestURI) == null) {
+
+                    hash = Long.toString(random.nextLong());   
+                    
+                    //ensure the key is unique
+                    while (hashToRedirectURL.keySet().contains(hash)) {
+                        hash = Long.toString(random.nextLong());
+                    }
+                
+                    hashToRedirectURL.put(hash, currentRequestURI);
+                    redirectURLToHash.put(currentRequestURI, hash);
+                
+            } else {       
+                    hash = redirectURLToHash.get(currentRequestURI);     
+            }
+            
+            log.info("Hash value for page:"+currentRequestURI+" is:"+hash);
+            
+            //this attribute will be used to add hash to index page.
+            request.setAttribute(HASH_OF_CURRENT_PORTAL_PAGE,hash);
+
+        }
+        
+        String hashOfPageToRedirect = request.getParameter(NOXSS_HASH_OF_PAGE_TO_REDIRECT);
+        
+        //Redirect index page url that contain noxssPage=xxxxxx to the real destination.
+        if (hashOfPageToRedirect != null && request.getParameter(NOXSS_SHOW_TREE)
!= null) {
+
+            String pageToRedirect = hashToRedirectURL.get(hashOfPageToRedirect) + "?"+NOXSS_SHOW_TREE+"=true";
+            HttpServletResponse httpServletResponse = (HttpServletResponse) response;
+           
+            //log.info("Redirecting to:" + pageToRedirect+" according to hash:"+hashOfPageToRedirect);
+            
+           // pageToRedirect=pageToRedirect.substring("/console".length());
+            log.info("Redirecting to:" + pageToRedirect+" according to hash:"+hashOfPageToRedirect);
+           // request.getParameterMap().remove(NOXSS_HASH_OF_PAGE_TO_REDIRECT);
+            request.getRequestDispatcher(pageToRedirect).forward(request, response);
+            
+            return;
+            //httpServletResponse.sendRedirect(pageToRedirect);
+            
+        } else {
+            
+            log.info("no redirect for:" + ((HttpServletRequest)request).getRequestURL());
+            filterChain.doFilter(request, response);
+        }    
+
+
+    }
+
+    public void init(FilterConfig arg0) throws ServletException {
+        // TODO Auto-generated method stub   
+    }
+
+}

Propchange: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/java/org/apache/geronimo/console/filter/RedirectByHashFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp?rev=899547&r1=899546&r2=899547&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
(original)
+++ geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/navigation.jsp
Fri Jan 15 06:46:15 2010
@@ -158,7 +158,10 @@
            anchorName = anchors[i].innerHTML; 
            if ( anchorName == portalPageName) { 
                displayPortlets(anchors[i]);
-               findAndSelect(portalPageName,navigationTree.rootNode);
+               
+               if(navigationTree){
+                   findAndSelect(portalPageName,navigationTree.rootNode);
+               }
                return;
            }
        }
@@ -166,9 +169,14 @@
    }
 
     function displayPortlets(anchor){
+    
+        var iframeHref = anchor.href;
 
-        document.getElementById('content').style.display = 'none';
-        document.getElementById("portletsFrame").src = anchor.href+"?formId="+formID;
+        if(document.location.href.indexOf(iframeHref)==0){      
+            iframeHref=document.location.href.substring(0,document.location.href.indexOf("?"));
+        }
+    
+        document.getElementById("portletsFrame").src = iframeHref+"?formId="+formID;
         setTimeout('returnToTop()', 30);
      }
      

Modified: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-only.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-only.jsp?rev=899547&r1=899546&r2=899547&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-only.jsp
(original)
+++ geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-only.jsp
Fri Jan 15 06:46:15 2010
@@ -28,5 +28,11 @@
     <jsp:include page="portlet-skin.jsp" />
 </c:forEach>
 </div>
+
+<script type="text/javascript">
+    if(parent){
+        parent.location.hash="#noxssPage=<c:out value="${hashOfCurrentPortalPage}"/>";
+    }
+</script>
 </body>
 

Modified: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-with-tree.jsp
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-with-tree.jsp?rev=899547&r1=899546&r2=899547&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-with-tree.jsp
(original)
+++ geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/themes/portlets-with-tree.jsp
Fri Jan 15 06:46:15 2010
@@ -17,12 +17,29 @@
 limitations under the License.
 --%>
 <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt"%>
 <%@ taglib uri="http://portals.apache.org/pluto" prefix="pluto" %>
+<fmt:setLocale value="<%=request.getLocale()%>" />
+<fmt:setBundle basename="org.apache.geronimo.console.i18n.ConsoleResource"/>
+<%@ page import="org.apache.geronimo.pluto.impl.PageConfig"%>
 
 <body id="admin-console" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"
rightmargin="0">
 
 <script language="JavaScript">
 
+<%-- When there's hash in current page url
+redirect the page with noxxsPage hash as the query string,
+the server side will get the real redirect target page based on the value of noxxsPage--%>
+
+ if(document.location.hash!='') {
+       var href = document.location.href;
+       var newHref = href.substring(0,href.lastIndexOf("#"));
+       if(newHref.indexOf("&noxssPage")>0){
+            newHref = newHref.substring(0,href.indexOf("&noxssPage"));
+       }
+       document.location.href =  newHref + "&noxssPage=" +document.location.hash.substr(11,document.location.hash.length);
+    }
+
 var iframeId;
 
 function delayResize(id){
@@ -96,18 +113,6 @@
                     <!-- Portlet Section -->
                     <td class="Gutter">&nbsp;</td> <!-- Spacer -->
                     <td valign="top">
-
-                <!-- Content block: portlets are divided into two columns/groups -->
-                <!--<div id="body-block" style="height:100%">-->
-                <div id="content">
-                    <pluto:isMaximized var="isMax" />
-
-                    <c:forEach var="portlet" varStatus="status"	items="${currentPage.portletIds}">
-                        <c:set var="portlet" value="${portlet}" scope="request" />
-                        <jsp:include page="portlet-skin.jsp" />
-                    </c:forEach>
-
-                </div>
                 
                     <iframe  src="" id="portletsFrame" width="100%" height="100%" scrolling="no"
frameborder="0" onload="if (window.parent && window.parent.delayResize) {window.parent.delayResize('portletsFrame');}">
                     
@@ -123,4 +128,12 @@
     </tr>
 </table>
 </body>
-
+<script type="text/javascript">
+    <% 
+    PageConfig pc=(PageConfig)request.getAttribute("currentPage");
+    String pageID=pc.getName();
+    String pageName=pageID.substring(pageID.lastIndexOf("/")+1,pageID.length());
+    %>
+    var pageName = "<fmt:message key="<%=pageName%>"/>";
+    quickLaunchPortlets(pageName);
+</script>

Modified: geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml?rev=899547&r1=899546&r2=899547&view=diff
==============================================================================
--- geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml
(original)
+++ geronimo/server/branches/2.2/plugins/console/console-portal-driver/src/main/webapp/WEB-INF/web.xml
Fri Jan 15 06:46:15 2010
@@ -58,13 +58,23 @@
   </filter>
 
   <filter-mapping>
-	<filter-name>PlutoURLRebuildFilter</filter-name>
-	<url-pattern>/portal/*</url-pattern>
+    <filter-name>PlutoURLRebuildFilter</filter-name>
+    <url-pattern>/portal/*</url-pattern>
   </filter-mapping>
 
   <filter-mapping>
-	<filter-name>PlutoURLRebuildFilter</filter-name>
-	<url-pattern>/secure/*</url-pattern>
+    <filter-name>PlutoURLRebuildFilter</filter-name>
+    <url-pattern>/secure/*</url-pattern>
+  </filter-mapping>
+  
+  <filter>
+    <filter-name>RedirectByHashFilter</filter-name>
+    <filter-class>org.apache.geronimo.console.filter.RedirectByHashFilter</filter-class>
+  </filter>
+  
+  <filter-mapping>
+    <filter-name>RedirectByHashFilter</filter-name>
+    <url-pattern>/portal/*</url-pattern>
   </filter-mapping>
   
   <servlet>



Mime
View raw message