You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/11/30 12:54:55 UTC

[myfaces] branch master updated: removed unused code

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 098d55d  removed unused code
098d55d is described below

commit 098d55d4ee55afeb52da71cef790747c8aaaf69d
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Fri Nov 30 13:54:19 2018 +0100

    removed unused code
---
 .../lifecycle/DefaultRestoreViewSupport.java       | 356 +--------------------
 .../myfaces/lifecycle/RestoreViewSupport.java      |  14 -
 .../lifecycle/DefaultRestoreViewSupport2Test.java  |  61 +---
 3 files changed, 10 insertions(+), 421 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java b/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
index cd11261..288170f 100644
--- a/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
+++ b/impl/src/main/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport.java
@@ -44,11 +44,8 @@ import javax.faces.render.ResponseStateManager;
 import javax.faces.view.ViewDeclarationLanguage;
 
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-import org.apache.myfaces.shared.application.FacesServletMapping;
-import org.apache.myfaces.shared.application.InvalidViewIdException;
 import org.apache.myfaces.shared.util.Assert;
 import org.apache.myfaces.shared.util.ConcurrentLRUCache;
-import org.apache.myfaces.shared.util.ExternalContextUtils;
 import org.apache.myfaces.shared.util.WebConfigParamUtils;
 
 /**
@@ -66,9 +63,6 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
      * define if the current request is a portlet request or not.
      */
     private static final String PORTLET_LIFECYCLE_PHASE = "javax.portlet.faces.phase";
-    
-    private static final String CACHED_SERVLET_MAPPING =
-        DefaultRestoreViewSupport.class.getName() + ".CACHED_SERVLET_MAPPING";
 
     private final Logger log = Logger.getLogger(DefaultRestoreViewSupport.class.getName());
 
@@ -103,28 +97,17 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
     
     private RenderKitFactory _renderKitFactory = null;
     private VisitContextFactory _visitContextFactory = null;
-    
-    private final String[] _faceletsViewMappings;
-    private final String[] _contextSuffixes;
-    private final String _faceletsContextSufix;
-    private final boolean _initialized;
+
     
     public DefaultRestoreViewSupport()
     {
-        _faceletsViewMappings = null;
-        _contextSuffixes = null;
-        _faceletsContextSufix = null;
-        _initialized = false;
     }
     
     public DefaultRestoreViewSupport(FacesContext facesContext)
     {
-        _faceletsViewMappings = getFaceletsViewMappings(facesContext);
-        _contextSuffixes = getContextSuffix(facesContext);
-        _faceletsContextSufix = getFaceletsContextSuffix(facesContext);
-        _initialized = true;
     }
 
+    @Override
     public void processComponentBinding(FacesContext facesContext, UIComponent component)
     {
         // JSF 2.0: Old hack related to t:aliasBean was fixed defining a event that traverse
@@ -147,29 +130,9 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
             // but lifecycle can continue, if custom exception handler swallows the exception
             facesContext.getAttributes().remove(SKIP_ITERATION_HINT);
         }
-        
-        
-        /*
-        ValueExpression binding = component.getValueExpression("binding");
-        if (binding != null)
-        {
-            binding.setValue(facesContext.getELContext(), component);
-        }
-
-        // This part is for make compatibility with t:aliasBean, because
-        // this components has its own code before and after binding is
-        // set for child components.
-        RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(facesContext, component);
-
-        // The required behavior for the spec is call recursively this method
-        // for walk the component tree.
-        // for (Iterator<UIComponent> iter = component.getFacetsAndChildren(); iter.hasNext();)
-        // {
-        // processComponentBinding(facesContext, iter.next());
-        // }
-         */
     }
 
+    @Override
     public String calculateViewId(FacesContext facesContext)
     {
         Assert.notNull(facesContext);
@@ -231,6 +194,7 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
         return viewId;
     }
 
+    @Override
     public boolean isPostback(FacesContext facesContext)
     {
         ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
@@ -262,6 +226,7 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
     {
         private PostRestoreStateEvent event;
 
+        @Override
         public VisitResult visit(VisitContext context, UIComponent target)
         {
             if (event == null)
@@ -281,252 +246,14 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
             return VisitResult.ACCEPT;
         }
     }
-    
-    @Deprecated
-    public String deriveViewId(FacesContext context, String viewId)
-    {
-        //If no viewId found, don't try to derive it, just continue.
-        if (viewId == null)
-        {
-            return null;
-        }
 
-        FacesServletMapping mapping = getFacesServletMapping(context);
-        if (mapping == null || mapping.isExtensionMapping())
-        {
-            viewId = handleSuffixMapping(context, viewId);
-        }
-        else if (mapping.isExactMapping())
-        {
-            if (viewId.equals(mapping.getExact()))
-            {
-                viewId = handleSuffixMapping(context, viewId + ".jsf");
-            }
-        }
-        else if(mapping.isPrefixMapping())
-        {
-            viewId = handlePrefixMapping(viewId, mapping.getPrefix());
-            
-            // A viewId that is equals to the prefix mapping on servlet mode is
-            // considered invalid, because jsp vdl will use RequestDispatcher and cause
-            // a loop that ends in a exception. Note in portlet mode the view
-            // could be encoded as a query param, so the viewId could be valid.
-            if (viewId != null && viewId.equals(mapping.getPrefix()) &&
-                !ExternalContextUtils.isPortlet(context.getExternalContext()))
-            {
-                throw new InvalidViewIdException();
-            }
-        }
-        else if (mapping.getUrlPattern().startsWith(viewId))
-        {
-            throw new InvalidViewIdException(viewId);
-        }
-
-        return viewId; // return null if no physical resource exists
-    }
-    
-    protected String[] getContextSuffix(FacesContext context)
-    {
-        String defaultSuffix = context.getExternalContext().getInitParameter(ViewHandler.DEFAULT_SUFFIX_PARAM_NAME);
-        if (defaultSuffix == null)
-        {
-            defaultSuffix = ViewHandler.DEFAULT_SUFFIX;
-        }
-        return defaultSuffix.split(" ");
-    }
-    
-    protected String getFaceletsContextSuffix(FacesContext context)
-    {
-        String defaultSuffix = context.getExternalContext().getInitParameter(ViewHandler.FACELETS_SUFFIX_PARAM_NAME);
-        if (defaultSuffix == null)
-        {
-            defaultSuffix = ViewHandler.DEFAULT_FACELETS_SUFFIX;
-        }
-        return defaultSuffix;
-    }
-    
-    
-    
-    protected String[] getFaceletsViewMappings(FacesContext context)
-    {
-        String faceletsViewMappings
-                = context.getExternalContext().getInitParameter(ViewHandler.FACELETS_VIEW_MAPPINGS_PARAM_NAME);
-        if(faceletsViewMappings == null)    //consider alias facelets.VIEW_MAPPINGS
-        {
-            faceletsViewMappings= context.getExternalContext().getInitParameter("facelets.VIEW_MAPPINGS");
-        }
-        
-        return faceletsViewMappings == null ? null : faceletsViewMappings.split(";");
-    }
-    
-    /**
-     * Return the normalized viewId according to the algorithm specified in 7.5.2 
-     * by stripping off any number of occurrences of the prefix mapping from the viewId.
-     * <p>
-     * For example, both /faces/view.xhtml and /faces/faces/faces/view.xhtml would both return view.xhtml
-     * </p>
-     */
-    protected String handlePrefixMapping(String viewId, String prefix)
-    {
-        /*  If prefix mapping (such as "/faces/*") is used for FacesServlet,
-        normalize the viewId according to the following
-            algorithm, or its semantic equivalent, and return it.
-               
-            Remove any number of occurrences of the prefix mapping from the viewId. For example, if the incoming value
-            was /faces/faces/faces/view.xhtml the result would be simply view.xhtml.
-         */
-        String uri = viewId;
-        if ( "".equals(prefix) )
-        {
-            // if prefix is an empty string, we let it be "//"
-            // in order to prevent an infinite loop in uri.startsWith(-emptyString-).
-            // Furthermore a prefix of "//" is just another double slash prevention.
-            prefix = "//";
-        }
-        else
-        {
-            //need to make sure its really /faces/* and not /facesPage.xhtml
-            prefix = prefix + '/';  
-        }
-        while (uri.startsWith(prefix) || uri.startsWith("//")) 
-        {
-            if(uri.startsWith(prefix))
-            {
-                //cut off only /faces, leave the trailing '/' char for the next iteration
-                uri = uri.substring(prefix.length() - 1);
-            }
-            else //uri starts with '//'
-            {
-                //cut off the leading slash, leaving the second slash to compare for the next iteration
-                uri = uri.substring(1);
-            }
-        }
-        //now delete any remaining leading '/'
-        // TODO: CJH: I don't think this is correct, considering that getActionURL() expects everything to
-        // start with '/', and in the suffix case we only mess with the suffix and leave leading
-        // slashes alone.  Please review...
-        /*if(uri.startsWith("/"))
-        {
-            uri = uri.substring(1);
-        }*/
-        
-        return uri;
-    }
-    
-    /**
-     * Return the viewId with any non-standard suffix stripped off and replaced with
-     * the default suffix configured for the specified context.
-     * <p>
-     * For example, an input parameter of "/foo.jsf" may return "/foo.jsp".
-     * </p>
-     */
-    protected String handleSuffixMapping(FacesContext context, String requestViewId)
-    {
-        String[] faceletsViewMappings = _initialized ? _faceletsViewMappings : getFaceletsViewMappings(context);
-        String[] jspDefaultSuffixes = _initialized ? _contextSuffixes : getContextSuffix(context);
-        
-        int slashPos = requestViewId.lastIndexOf('/');
-        int extensionPos = requestViewId.lastIndexOf('.');
-        
-        //Try to locate any resource that match with the expected id
-        for (String defaultSuffix : jspDefaultSuffixes)
-        {
-            StringBuilder builder = new StringBuilder(requestViewId);
-           
-            if (extensionPos > -1 && extensionPos > slashPos)
-            {
-                builder.replace(extensionPos, requestViewId.length(), defaultSuffix);
-            }
-            else
-            {
-                builder.append(defaultSuffix);
-            }
-            String candidateViewId = builder.toString();
-            
-            if( faceletsViewMappings != null && faceletsViewMappings.length > 0 )
-            {
-                for (String mapping : faceletsViewMappings)
-                {
-                    if(mapping.startsWith("/"))
-                    {
-                        continue;   //skip this entry, its a prefix mapping
-                    }
-                    if(mapping.equals(candidateViewId))
-                    {
-                        return candidateViewId;
-                    }
-                    if(mapping.startsWith(".")) //this is a wildcard entry
-                    {
-                        builder.setLength(0); //reset/reuse the builder object 
-                        builder.append(candidateViewId); 
-                        builder.replace(candidateViewId.lastIndexOf('.'), candidateViewId.length(), mapping);
-                        String tempViewId = builder.toString();
-                        if(checkResourceExists(context,tempViewId))
-                        {
-                            return tempViewId;
-                        }
-                    }
-                }
-            }
-
-            // forced facelets mappings did not match or there were no entries in faceletsViewMappings array
-            if(checkResourceExists(context,candidateViewId))
-            {
-                return candidateViewId;
-            }
-        
-        }
-        
-        //jsp suffixes didn't match, try facelets suffix
-        String faceletsDefaultSuffix = _initialized ? _faceletsContextSufix : this.getFaceletsContextSuffix(context);
-        if (faceletsDefaultSuffix != null)
-        {
-            for (String defaultSuffix : jspDefaultSuffixes)
-            {
-                if (faceletsDefaultSuffix.equals(defaultSuffix))
-                {
-                    faceletsDefaultSuffix = null;
-                    break;
-                }
-            }
-        }
-        if (faceletsDefaultSuffix != null)
-        {
-            StringBuilder builder = new StringBuilder(requestViewId);
-            
-            if (extensionPos > -1 && extensionPos > slashPos)
-            {
-                builder.replace(extensionPos, requestViewId.length(), faceletsDefaultSuffix);
-            }
-            else
-            {
-                builder.append(faceletsDefaultSuffix);
-            }
-            
-            String candidateViewId = builder.toString();
-            if(checkResourceExists(context,candidateViewId))
-            {
-                return candidateViewId;
-            }
-        }
-
-        // Otherwise, if a physical resource exists with the name requestViewId let that value be viewId.
-        if(checkResourceExists(context,requestViewId))
-        {
-            return requestViewId;
-        }
-        
-        //Otherwise return null.
-        return null;
-    }
     protected boolean checkResourceExists(FacesContext context, String viewId)
     {
         try
         {
             if (isCheckedViewIdCachingEnabled(context))
             {
-                Boolean resourceExists = getCheckedViewIDMap(context).get(
-                        viewId);
+                Boolean resourceExists = getCheckedViewIDMap(context).get(viewId);
                 if (resourceExists == null)
                 {
                     ViewDeclarationLanguage vdl = context.getApplication().getViewHandler()
@@ -538,8 +265,7 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
                     else
                     {
                         // Fallback to default strategy
-                        resourceExists = context.getExternalContext().getResource(
-                                viewId) != null;
+                        resourceExists = context.getExternalContext().getResource(viewId) != null;
                     }
                     getCheckedViewIDMap(context).put(viewId, resourceExists);
                 }
@@ -566,83 +292,19 @@ public class DefaultRestoreViewSupport implements RestoreViewSupport
                 }
             }
         }
-        catch(MalformedURLException e)
+        catch (MalformedURLException e)
         {
             //ignore and move on
         }     
         return false;
     }
 
+    @Override
     public boolean checkViewExists(FacesContext facesContext, String viewId)
     {
         return checkResourceExists(facesContext, viewId);
     }
 
-    /**
-     * Read the web.xml file that is in the classpath and parse its internals to
-     * figure out how the FacesServlet is mapped for the current webapp.
-     */
-    protected FacesServletMapping getFacesServletMapping(FacesContext context)
-    {
-        Map<Object, Object> attributes = context.getAttributes();
-
-        // Has the mapping already been determined during this request?
-        FacesServletMapping mapping = (FacesServletMapping) attributes.get(CACHED_SERVLET_MAPPING);
-        if (mapping == null)
-        {
-            ExternalContext externalContext = context.getExternalContext();
-            mapping = calculateFacesServletMapping(externalContext.getRequestServletPath(),
-                    externalContext.getRequestPathInfo());
-
-            attributes.put(CACHED_SERVLET_MAPPING, mapping);
-        }
-        return mapping;
-    }
-
-    /**
-     * Determines the mapping of the FacesServlet in the web.xml configuration
-     * file. However, there is no need to actually parse this configuration file
-     * as runtime information is sufficient.
-     *
-     * @param servletPath The servletPath of the current request
-     * @param pathInfo    The pathInfo of the current request
-     * @return the mapping of the FacesServlet in the web.xml configuration file
-     */
-    protected static FacesServletMapping calculateFacesServletMapping(
-        String servletPath, String pathInfo)
-    {
-        if (pathInfo != null)
-        {
-            // If there is a "extra path", it's definitely no extension mapping.
-            // Now we just have to determine the path which has been specified
-            // in the url-pattern, but that's easy as it's the same as the
-            // current servletPath. It doesn't even matter if "/*" has been used
-            // as in this case the servletPath is just an empty string according
-            // to the Servlet Specification (SRV 4.4).
-            return FacesServletMapping.createPrefixMapping(servletPath);
-        }
-        else
-        {
-            // In the case of extension mapping, no "extra path" is available.
-            // Still it's possible that prefix-based mapping has been used.
-            // Actually, if there was an exact match no "extra path"
-            // is available (e.g. if the url-pattern is "/faces/*"
-            // and the request-uri is "/context/faces").
-            int slashPos = servletPath.lastIndexOf('/');
-            int extensionPos = servletPath.lastIndexOf('.');
-            if (extensionPos > -1 && extensionPos > slashPos)
-            {
-                String extension = servletPath.substring(extensionPos);
-                return FacesServletMapping.createExtensionMapping(extension);
-            }
-            else
-            {
-                // There is no extension in the given servletPath and therefore
-                // we assume that it's an exact match using prefix-based mapping.
-                return FacesServletMapping.createPrefixMapping(servletPath);
-            }
-        }
-    }
     
     private ConcurrentLRUCache<String, Boolean> getCheckedViewIDMap(FacesContext context)
     {
diff --git a/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewSupport.java b/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewSupport.java
index 939c433..4453f1e 100644
--- a/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewSupport.java
+++ b/impl/src/main/java/org/apache/myfaces/lifecycle/RestoreViewSupport.java
@@ -42,20 +42,6 @@ public interface RestoreViewSupport
      * </ul>
      */
     String calculateViewId(FacesContext facesContext);
-    
-    /**
-     *  Derive a view id retrieved from calling calculateViewId(FacesContext), but
-     * do not check if a resource with this name exists. This method is useful
-     * to retrieve a VDL instance, but note there are some cases (TCK test) where
-     * it is expected in Restore View algorithm a null or dummy viewId is passed. 
-     * 
-     * @deprecated Use ViewHandler.deriveLogicalViewId
-     * @param context
-     * @param viewId
-     * @return
-     */
-    @Deprecated
-    String deriveViewId(FacesContext context, String viewId);
 
     /**
      * Processes the component tree. For each component (including the given one) in the tree determine if a value
diff --git a/impl/src/test/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport2Test.java b/impl/src/test/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport2Test.java
index 2208354..e28d9fb 100644
--- a/impl/src/test/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport2Test.java
+++ b/impl/src/test/java/org/apache/myfaces/lifecycle/DefaultRestoreViewSupport2Test.java
@@ -68,64 +68,5 @@ public class DefaultRestoreViewSupport2Test extends AbstractJsfTestCase
         }
     }
     
-    @Test
-    public void testDeriveViewId1() throws Exception
-    {
-        request.setPathElements("/testwebapp", "/view1.jsf", null , null);
-
-        DefaultRestoreViewSupport support = new DefaultRestoreViewSupport();
-        
-        String derivedViewId = support.deriveViewId(facesContext, "/view1.jsf");
-        
-        Assert.assertNotNull(derivedViewId);
-    }
-    
-    @Test
-    public void testDeriveViewId2() throws Exception
-    {
-        DefaultRestoreViewSupport support = new DefaultRestoreViewSupport();
-        
-        request.setPathElements("/testwebapp", "/faces", "/view1.jsp" , null);
-        
-        String derivedViewId = support.deriveViewId(facesContext, "/view1.jsp");
-        
-        Assert.assertNotNull(derivedViewId);
-    }
-    
-    @Test
-    public void testDeriveViewId3() throws Exception
-    {
-        DefaultRestoreViewSupport support = new DefaultRestoreViewSupport();
-        
-        request.setPathElements("/testwebapp", "/view2.jsf", null , null);
-        
-        String derivedViewId = support.deriveViewId(facesContext, "/view2.jsf");
-        
-        Assert.assertNotNull(derivedViewId);
-    }
-    
-    @Test
-    public void testDeriveViewId4() throws Exception
-    {
-        DefaultRestoreViewSupport support = new DefaultRestoreViewSupport();
-        
-        request.setPathElements("/testwebapp", "/faces", "/view2.xhtml" , null);
-        
-        String derivedViewId = support.deriveViewId(facesContext, "/view2.xhtml");
-        
-        Assert.assertNotNull(derivedViewId);
-    }
-
-
-    @Test
-    public void testDeriveViewId5() throws Exception
-    {
-        request.setPathElements("/testwebapp", "/noview1.jsf", null , null);
-
-        DefaultRestoreViewSupport support = new DefaultRestoreViewSupport();
-        
-        String derivedViewId = support.deriveViewId(facesContext, "/noview1.jsf");
-        
-        Assert.assertNull(derivedViewId);
-    }
+ 
 }