empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1327115 - /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
Date Tue, 17 Apr 2012 14:45:31 GMT
Author: doebele
Date: Tue Apr 17 14:45:30 2012
New Revision: 1327115

URL: http://svn.apache.org/viewvc?rev=1327115&view=rev
Log:
EMPIREDB-140
bugfix pagephase listener

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java?rev=1327115&r1=1327114&r2=1327115&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pages/PagePhaseListener.java
Tue Apr 17 14:45:30 2012
@@ -25,8 +25,10 @@ import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.beanutils.BeanUtils;
+import org.apache.empire.jsf2.app.FacesUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -51,17 +53,50 @@ public class PagePhaseListener implement
     @Override
     public void beforePhase(PhaseEvent pe)
     {
-        log.trace("Processing Phase ", pe.getPhaseId());
+        PhaseId phaseId = pe.getPhaseId();
+        if (log.isTraceEnabled())
+            log.trace("Processing Phase {}.", phaseId);        
+
         FacesContext fc = pe.getFacesContext();
         UIViewRoot   vr = fc.getViewRoot();
         if (vr == null)
+        {
+            /*
+            PartialViewContext pvc = fc.getPartialViewContext(); 
+            boolean ajax = pvc.isAjaxRequest();
+            boolean part = pvc.isPartialRequest();
+            if (!part && !ajax)
+            {
+                HttpServletRequest req = FacesUtils.getHttpRequest(fc);
+                String reqURI = req.getRequestURI();
+                log.info("No View Root for request to '"+reqURI+"' in Phase "+String.valueOf(phaseId));
+            }
+            */
             return;
+        }    
 
         // Init Page
         String viewId = vr.getViewId();
         PageDefinition pageDef = PageDefinitions.getPageFromViewId(viewId);
         if (pageDef != null)
         {
+            // Check Request context path 
+            if (phaseId==PhaseId.APPLY_REQUEST_VALUES)
+            {
+                HttpServletRequest req = FacesUtils.getHttpRequest(fc);
+                String reqURI = req.getRequestURI();
+                int vix = viewId.lastIndexOf('.');
+                int rix = reqURI.lastIndexOf('.');
+                if (rix<vix || !viewId.regionMatches(true, 0, reqURI, rix-vix, vix))
+                {   // redirect to view page
+                    String ctxPath = fc.getExternalContext().getRequestContextPath();
+                    String pageURI = ctxPath + viewId.substring(0,vix) + ".iface";
+                    log.warn("Invalid RequestURI '" + reqURI + "'. Redirecting to '"+pageURI+"'.");
+                    FacesUtils.redirectDirectly(fc, pageURI);
+                    return;
+                }
+            }
+            // Process page
             String name = pageDef.getPageBeanName();
             Map<String, Object> viewMap = vr.getViewMap();
             Page pageBean = (Page) viewMap.get(name);



Mime
View raw message