myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfreed...@apache.org
Subject svn commit: r1227359 [2/2] - in /myfaces/portlet-bridge/core/branches/refactored_3.0.x: ./ controller-api/src/main/java/org/apache/myfaces/portlet/faces/bridge/config/ controller-api/src/main/java/org/apache/myfaces/portlet/faces/bridge/context/ contro...
Date Wed, 04 Jan 2012 22:24:39 GMT
Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java?rev=1227359&r1=1227358&r2=1227359&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java
(original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/java/org/apache/myfaces/portlet/faces/util/config/FacesConfigurationProcessor.java
Wed Jan  4 22:24:38 2012
@@ -31,11 +31,26 @@ import java.util.List;
 
 import java.util.Map;
 
-import javax.portlet.PortletContext;
+import javax.faces.context.ExternalContext;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
 
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeConfigFactory;
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeContextFactory;
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeControllerFactory;
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeFactory;
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeFactoryFinder;
+
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeLoggerFactory;
+
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeRequestScopeFactory;
+import org.apache.myfaces.portlet.faces.bridge.factory.BridgeRequestScopeManagerFactory;
+
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
@@ -43,53 +58,61 @@ import org.xml.sax.helpers.DefaultHandle
 
 //TODO: This is probably better under the Bridge package as a package private utility
 //TODO: This is probably better as a static utility class since it's never kept around.
-public class FacesConfigurationProcessor
+public final class FacesConfigurationProcessor implements SystemEventListener
 {
 
   private static final String FACES_CONFIG_METAINF_PATH = "META-INF/faces-config.xml";
   private static final String FACES_CONFIG_WEBINF_PATH = "/WEB-INF/faces-config.xml";
-  private List<String> mExcludedAttributes = null;
-  private Map<String, String> mPublicParameterMappings = null;
-  private String mWriteBehindRenderResponseWrapper = null;
-  private String mWriteBehindResourceResponseWrapper = null;
+  private static List<String> sExcludedAttributes = null;
+  private static Map<String, String> sPublicParameterMappings = null;
+  private static String sWriteBehindRenderResponseWrapper = null;
+  private static String sWriteBehindResourceResponseWrapper = null;
+
 
+  public FacesConfigurationProcessor()
+  {
+
+  } 
+  
+  public boolean isListenerForSource(Object source)
+  {
+    return true;
+  }
+  
   /**
    * <p>
    * When instantiated, the web.xml of the current application will be scanned looking for
a
    * references to the <code>FacesServlet</code>. <code>isFacesServletPresent()</code>
will
    * return the appropriate value based on the scan.
    * </p>
-   * 
-   * @param context
-   *          the <code>ServletContext</code> for the application of interest
    */
-  public FacesConfigurationProcessor(PortletContext context)
+  public void processEvent(SystemEvent event)
+                    throws AbortProcessingException
   {
-    if (context != null)
-    {
-      scanForFacesMappings(context);
-    }
-  } 
+    scanForBridgeExtensions();
+  }
 
-  public List<String> getExcludedAttributes()
+  public static List<String> getExcludedAttributes()
   {
-    return mExcludedAttributes;
+    return sExcludedAttributes;
   } 
   
-  public Map<String,String> getPublicParameterMappings()
+  public static Map<String,String> getPublicParameterMappings()
   {
-    return mPublicParameterMappings;
+    return sPublicParameterMappings;
   }
   
-  public String getWriteBehindRenderResponseWrapperClassName()
+  public static String getWriteBehindRenderResponseWrapperClassName()
   {
-    return mWriteBehindRenderResponseWrapper;
+    return sWriteBehindRenderResponseWrapper;
   }
   
-  public String getWriteBehindResourceResponseWrapperClassName()
+  public static String getWriteBehindResourceResponseWrapperClassName()
   {
-    return mWriteBehindResourceResponseWrapper;
+    return sWriteBehindResourceResponseWrapper;
   }
+  
+
 
   /**
    * <p>
@@ -99,8 +122,11 @@ public class FacesConfigurationProcessor
    * @param context
    *          the ServletContext instance for this application
    */
-  private void scanForFacesMappings(PortletContext context)
+  private void scanForBridgeExtensions()
   {
+    
+    FacesContext ctx = FacesContext.getCurrentInstance();
+    ExternalContext eCtx = ctx.getExternalContext();
 
     SAXParserFactory factory = getSAXFactory();
     try
@@ -110,7 +136,7 @@ public class FacesConfigurationProcessor
       
       // read each faces-config.xml and see if any contain the bridge extension
       // that defines some excluded attributes
-      ClassLoader cl = getCurrentClassLoader(context);
+      ClassLoader cl = getCurrentClassLoader(eCtx.getContext());
       
       for (Enumeration<URL> items = cl.getResources(FACES_CONFIG_METAINF_PATH);
                items.hasMoreElements();) {
@@ -129,7 +155,7 @@ public class FacesConfigurationProcessor
       }
       
       // Now see if the web app has one in its WEB-INF
-      InputStream configStream = context.getResourceAsStream(FACES_CONFIG_WEBINF_PATH);
+      InputStream configStream = eCtx.getResourceAsStream(FACES_CONFIG_WEBINF_PATH);
       if (configStream != null)
       {
         parser.parse(configStream, handler);
@@ -180,6 +206,7 @@ public class FacesConfigurationProcessor
   private class FacesConfigXmlHandler extends DefaultHandler
   {
 
+    // Application extensions
     private static final String APPLICATION_ELEMENT          = "application";
     private static final String APP_EXTENSION_ELEMENT     = "application-extension";
     private static final String EXCLUDED_ATTRIBUTES_ELEMENT    = "excluded-attributes";
@@ -191,6 +218,17 @@ public class FacesConfigurationProcessor
     private static final String WRITE_BEHIND_RESPONSE_WRAPPERS_ELEMENT = "write-behind-response-wrappers";
     private static final String RENDER_RESPONSE_WRAPPER_CLASS_ELEMENT = "render-response-wrapper-class";
     private static final String RESOURCE_RESPONSE_WRAPPER_CLASS_ELEMENT = "resource-response-wrapper-class";
+    
+    // Factory extensions
+    private static final String FACTORY_ELEMENT          = "factory";
+    private static final String FACTORY_EXTENSION_ELEMENT     = "factory-extension";
+    private static final String CONFIG_FACTORY_ELEMENT    = "bridge-config-factory";
+    private static final String CONTEXT_FACTORY_ELEMENT    = "bridge-context-factory";
+    private static final String CONTROLLER_FACTORY_ELEMENT    = "bridge-controller-factory";
+    private static final String LOGGER_FACTORY_ELEMENT    = "bridge-logger-factory";
+    private static final String REQUEST_SCOPE_FACTORY_ELEMENT    = "bridge-request-scope-factory";
+    private static final String REQUEST_SCOPE_MGR_FACTORY_ELEMENT    = "bridge-request-scope-manager-factory";
+
 
 
 
@@ -202,6 +240,10 @@ public class FacesConfigurationProcessor
     private boolean             mInParameter = false;
     private boolean             mInModelEL = false;
     private boolean             mInWriteBehindResponseWrappers = false;
+    
+    private boolean             mInFactoryElement        = false;
+    private boolean             mInFactoryExtensionElement    = false;
+
 
     
    
@@ -214,7 +256,8 @@ public class FacesConfigurationProcessor
     {
       mInApplicationElement = mInApplicationExtensionElement =
         mInExcludedAttributesElement = mInPublicParameterMappings =
-        mInPublicParameterMapping = mInParameter = mInModelEL = false;
+        mInPublicParameterMapping = mInParameter = mInModelEL = 
+        mInFactoryElement = mInFactoryExtensionElement = false;
     }
 
     @Override
@@ -279,6 +322,23 @@ public class FacesConfigurationProcessor
           mContent = new StringBuilder();
         }
       }
+      else if (FACTORY_ELEMENT.equals(localName))
+      {
+          mInFactoryElement = true;
+      }
+      else if (FACTORY_EXTENSION_ELEMENT.equals(localName))
+      {
+          mInFactoryExtensionElement = true;
+      }
+      else if (CONFIG_FACTORY_ELEMENT.equals(localName) || CONTEXT_FACTORY_ELEMENT.equals(localName)
||
+        CONTROLLER_FACTORY_ELEMENT.equals(localName) || LOGGER_FACTORY_ELEMENT.equals(localName)
||
+        REQUEST_SCOPE_FACTORY_ELEMENT.equals(localName) || REQUEST_SCOPE_MGR_FACTORY_ELEMENT.equals(localName))
+      {
+        if (mInFactoryElement && mInFactoryExtensionElement)
+        {
+          mContent = new StringBuilder();
+        }
+      }
       
     } // END startElement
 
@@ -315,14 +375,14 @@ public class FacesConfigurationProcessor
         // add mContent to the attrs list
         String excludedAttribute = mContent.toString().trim();
         
-        if (mExcludedAttributes == null)
+        if (sExcludedAttributes == null)
         {
-          mExcludedAttributes = (List<String> )new ArrayList(5);
+          sExcludedAttributes = (List<String> )new ArrayList(5);
         }
         
-        if (!mExcludedAttributes.contains(excludedAttribute))
+        if (!sExcludedAttributes.contains(excludedAttribute))
         {
-          mExcludedAttributes.add(excludedAttribute);
+          sExcludedAttributes.add(excludedAttribute);
         }
       }
       else if (PUBLIC_PARAMETER_MAPPINGS_ELEMENT.equals(localName))
@@ -333,14 +393,14 @@ public class FacesConfigurationProcessor
       {
         if (mContent1 != null && mContent2 != null)
         {
-          if (mPublicParameterMappings == null)
+          if (sPublicParameterMappings == null)
           {
-            mPublicParameterMappings = (Map<String, String> )new HashMap(5);
+            sPublicParameterMappings = (Map<String, String> )new HashMap(5);
           }
           
-          if (!mPublicParameterMappings.containsKey(mContent1))
+          if (!sPublicParameterMappings.containsKey(mContent1))
           {
-            mPublicParameterMappings.put(mContent1, mContent2);
+            sPublicParameterMappings.put(mContent1, mContent2);
           }
         }
         mContent1 = mContent2 = null;
@@ -367,18 +427,64 @@ public class FacesConfigurationProcessor
         && mContent.length() > 0)
       {
         // hold mContent to add as pair later
-        mWriteBehindRenderResponseWrapper = mContent.toString().trim();
+        sWriteBehindRenderResponseWrapper = mContent.toString().trim();
       }
       else if (RESOURCE_RESPONSE_WRAPPER_CLASS_ELEMENT.equals(localName) && mContent
!= null
         && mContent.length() > 0)
       {
         // hold mContent to add as pair later
-        mWriteBehindResourceResponseWrapper = mContent.toString().trim();
+        sWriteBehindResourceResponseWrapper = mContent.toString().trim();
       }
-
-      mContent = null;
+      else if (FACTORY_ELEMENT.equals(localName))
+      {
+        mInFactoryElement = false;
+      }
+      else if (FACTORY_EXTENSION_ELEMENT.equals(localName))
+      {
+        mInFactoryExtensionElement = false;
+      }
+      else if (CONFIG_FACTORY_ELEMENT.equals(localName) && mContent != null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeConfigFactory.class);
+      }
+      else if (CONTEXT_FACTORY_ELEMENT.equals(localName) && mContent != null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeContextFactory.class);
+      }
+      else if (CONTROLLER_FACTORY_ELEMENT.equals(localName) && mContent != null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeControllerFactory.class);
+      }
+      else if (LOGGER_FACTORY_ELEMENT.equals(localName) && mContent != null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeLoggerFactory.class);
+      }
+      else if (REQUEST_SCOPE_MGR_FACTORY_ELEMENT.equals(localName) && mContent !=
null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeRequestScopeManagerFactory.class);
+      }
+      else if (REQUEST_SCOPE_FACTORY_ELEMENT.equals(localName) && mContent != null
+        && mContent.length() > 0)
+      {
+        endBridgeFactoryElement(BridgeRequestScopeFactory.class);
+      }     
 
     } // END endElement
+    
+    private void endBridgeFactoryElement(Class<? extends BridgeFactory> type)
+    {
+      // add mContent to the attrs list
+      String factoryClassName = mContent.toString().trim();
+      
+      BridgeFactoryFinder.addFactoryDefinition(type, factoryClassName);
+      
+      mContent = null;
+    }
 
   } // END FacesConfigXmlHandler
 

Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/resources/META-INF/faces-config.xml?rev=1227359&r1=1227358&r2=1227359&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/resources/META-INF/faces-config.xml
(original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/impl/src/main/resources/META-INF/faces-config.xml
Wed Jan  4 22:24:38 2012
@@ -34,21 +34,21 @@
         <el-resolver>org.apache.myfaces.portlet.faces.el.PortletELResolver</el-resolver>
 
     	  <!-- Application is started -->
-<!--        
+       
     	  <system-event-listener>
-		<system-event-listener-class>
-			org.apache.myfaces.portlet.faces.bridge.BridgeImpl
-		</system-event-listener-class>
-		<system-event-class>
-			javax.faces.event.PostConstructApplicationEvent
-		</system-event-class>    					
+          <system-event-listener-class>
+            org.apache.myfaces.portlet.faces.util.config.FacesConfigurationProcessor
+          </system-event-listener-class>
+          <system-event-class>
+            javax.faces.event.PostConstructApplicationEvent
+          </system-event-class>    					
     	  </system-event-listener>
--->        
+     
         
         <application-extension>
           <bridge:excluded-attributes>
             <bridge:excluded-attribute>com.sun.faces.*</bridge:excluded-attribute>
-		<bridge:excluded-attribute>com.sun.faces.util.*</bridge:excluded-attribute>
+            <bridge:excluded-attribute>com.sun.faces.util.*</bridge:excluded-attribute>
             <bridge:excluded-attribute>org.apache.myfaces.application.jsp.JspStateManagerImpl.*</bridge:excluded-attribute>
             <bridge:excluded-attribute>org.apache.myfaces.el.unified.resolver.managedbean.*</bridge:excluded-attribute>
             <bridge:excluded-attribute>org.apache.myfaces.shared_impl.renderkit.RendererUtils.*</bridge:excluded-attribute>
@@ -58,11 +58,19 @@
         </application-extension>
     </application>
     <factory>
-	<application-factory>org.apache.myfaces.portlet.faces.application.PortletApplicationFactoryImpl</application-factory>
-	<faces-context-factory>org.apache.myfaces.portlet.faces.context.PortletFacesContextFactoryImpl</faces-context-factory>
-	<external-context-factory>org.apache.myfaces.portlet.faces.context.PortletExternalContextFactoryImpl</external-context-factory>
+      <application-factory>org.apache.myfaces.portlet.faces.application.PortletApplicationFactoryImpl</application-factory>
+      <faces-context-factory>org.apache.myfaces.portlet.faces.context.PortletFacesContextFactoryImpl</faces-context-factory>
+      <external-context-factory>org.apache.myfaces.portlet.faces.context.PortletExternalContextFactoryImpl</external-context-factory>
       <view-declaration-language-factory>org.apache.myfaces.portlet.faces.application.view.PortletViewDeclarationLanguageFactoryImpl</view-declaration-language-factory>
       <exception-handler-factory>org.apache.myfaces.portlet.faces.context.PortletExceptionHanderFactoryImpl</exception-handler-factory>
       <partial-view-context-factory>org.apache.myfaces.portlet.faces.context.PortletPartialViewContextFactoryImpl</partial-view-context-factory>
+      <factory-extension>
+        <bridge:bridge-config-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeConfigFactoryImpl</bridge:bridge-config-factory>
+        <bridge:bridge-context-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeContextFactoryImpl</bridge:bridge-context-factory>
+        <bridge:bridge-controller-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeControllerFactoryImpl</bridge:bridge-controller-factory>
+        <bridge:bridge-logger-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeLoggerFactoryImpl</bridge:bridge-logger-factory>
+        <bridge:bridge-request-scope-manager-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeRequestScopeManagerFactoryImpl</bridge:bridge-request-scope-manager-factory>
+        <bridge:bridge-request-scope-factory>org.apache.myfaces.portlet.faces.bridge.factory.BridgeRequestScopeFactoryImpl</bridge:bridge-request-scope-factory>
+      </factory-extension>
     </factory>
 </faces-config>

Modified: myfaces/portlet-bridge/core/branches/refactored_3.0.x/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/portlet-bridge/core/branches/refactored_3.0.x/pom.xml?rev=1227359&r1=1227358&r2=1227359&view=diff
==============================================================================
--- myfaces/portlet-bridge/core/branches/refactored_3.0.x/pom.xml (original)
+++ myfaces/portlet-bridge/core/branches/refactored_3.0.x/pom.xml Wed Jan  4 22:24:38 2012
@@ -8,7 +8,7 @@
     "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
+    http://www.apache.org/licenses/LICENSE-2.0pluto
 
     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
@@ -54,6 +54,7 @@
     <myfaces.version>2.0.1</myfaces.version>
     <myfaces.shared.version>4.0.5</myfaces.shared.version>
     <blueprints.version>5</blueprints.version>
+    <slf4j.version>1.6.2</slf4j.version>
   </properties>
   
   <!-- issueManagement is in parent -->
@@ -108,6 +109,13 @@
           <version>5</version>
         </dependency>
 
+	  <!-- Logging -->
+        <dependency>
+           <groupId>org.slf4j</groupId>
+           <artifactId>slf4j-api</artifactId>
+           <version>${slf4j.version}</version>
+	     <scope>compile</scope>
+        </dependency>
 
 
         <!-- Portlet API -->



Mime
View raw message