Merge pull request #16 from wtlucy/MYFACES-3629_webFragments

MYFACES-3629 add context attr for case when faces servlet is found by SCI
diff --git a/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java b/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
index 668c1cf..4853361 100644
--- a/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/ee/MyFacesContainerInitializer.java
@@ -115,6 +115,12 @@
      * is stored under this key in the ServletContext.
      */
     public static final String FACES_SERVLET_ADDED_ATTRIBUTE = "org.apache.myfaces.DYNAMICALLY_ADDED_FACES_SERVLET";
+
+    /**
+     * If the servlet mapping for the FacesServlet is found on the ServletContext, Boolean.TRUE 
+     * is stored under this key in the ServletContext.
+     */
+    public static final String FACES_SERVLET_FOUND = "org.apache.myfaces.FACES_SERVLET_FOUND";
     
     private static final String INITIALIZE_ALWAYS_STANDALONE = "org.apache.myfaces.INITIALIZE_ALWAYS_STANDALONE";
     
@@ -183,7 +189,8 @@
                 if (FACES_SERVLET_CLASS.getName().equals(className)
                         || isDelegatedFacesServlet(className))
                 {
-                    // we found a FacesServlet, so we have nothing to do!
+                    // we found a FacesServlet; set an attribute for use during initialization
+                    servletContext.setAttribute(FACES_SERVLET_FOUND, Boolean.TRUE);                    
                     return;
                 }
             }
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index 0838fba..4731154 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -161,17 +161,25 @@
 
                 if (webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
                 {
-                    // check if the FacesServlet has been added dynamically
-                    // in a Servlet 3.0 environment by MyFacesContainerInitializer
+                    // check to see if the FacesServlet was found by MyFacesContainerInitializer
                     Boolean mappingAdded = (Boolean) servletContext.getAttribute(
-                                                        MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+                        MyFacesContainerInitializer.FACES_SERVLET_FOUND);
+
                     if (mappingAdded == null || !mappingAdded)
                     {
-                        if (log.isLoggable(Level.WARNING))
+                        // check if the FacesServlet has been added dynamically
+                        // in a Servlet 3.0 environment by MyFacesContainerInitializer
+                        mappingAdded = (Boolean) servletContext.getAttribute(
+                            MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+
+                        if (mappingAdded == null || !mappingAdded)
                         {
-                            log.warning("No mappings of FacesServlet found. Abort initializing MyFaces.");
+                            if (log.isLoggable(Level.WARNING))
+                            {
+                                log.warning("No mappings of FacesServlet found. Abort initializing MyFaces.");
+                            }
+                            return;
                         }
-                        return;
                     }
                 }
             }
@@ -374,17 +382,25 @@
 
             if (webConfigProvider.getFacesServletMappings(facesContext.getExternalContext()).isEmpty())
             {
-                // check if the FacesServlet has been added dynamically
-                // in a Servlet 3.0 environment by MyFacesContainerInitializer
+                // check to see if the FacesServlet was found by MyFacesContainerInitializer
                 Boolean mappingAdded = (Boolean) servletContext.getAttribute(
-                                                    MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+                    MyFacesContainerInitializer.FACES_SERVLET_FOUND);
+
                 if (mappingAdded == null || !mappingAdded)
                 {
-                    if (log.isLoggable(Level.WARNING))
+                    // check if the FacesServlet has been added dynamically
+                    // in a Servlet 3.0 environment by MyFacesContainerInitializer
+                    mappingAdded = (Boolean) servletContext.getAttribute(
+                        MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
+
+                    if (mappingAdded == null || !mappingAdded)
                     {
-                        log.warning("No mappings of FacesServlet found. Abort destroy MyFaces.");
+                        if (log.isLoggable(Level.WARNING))
+                        {
+                            log.warning("No mappings of FacesServlet found. Abort destroy MyFaces.");
+                        }
+                        return;
                     }
-                    return;
                 }
             }
         }