myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1436645 - in /myfaces/core/branches/2.2.x: api/src/main/java/javax/faces/ impl/src/main/java/org/apache/myfaces/config/ impl/src/main/java/org/apache/myfaces/config/impl/digester/ impl/src/main/java/org/apache/myfaces/spi/ impl/src/main/ja...
Date Mon, 21 Jan 2013 21:54:03 GMT
Author: lu4242
Date: Mon Jan 21 21:54:03 2013
New Revision: 1436645

URL: http://svn.apache.org/viewvc?rev=1436645&view=rev
Log:
MYFACES-3679 Implement ApplicationConfigurationResourceDocumentPopulator 

Added:
    myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java
  (with props)
Modified:
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigUnmarshaller.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/impl/digester/DigesterFacesConfigUnmarshallerImpl.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProvider.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProviderWrapper.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/ServiceProviderFinder.java
    myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java

Added: myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java?rev=1436645&view=auto
==============================================================================
--- myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java
(added)
+++ myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java
Mon Jan 21 21:54:03 2013
@@ -0,0 +1,31 @@
+/*
+ * 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 javax.faces;
+
+import org.w3c.dom.Document;
+
+/**
+ *
+ * @author Leonardo Uribe
+ */
+public abstract class ApplicationConfigurationResourceDocumentPopulator
+{
+    
+    public abstract void populateApplicationConfigurationResource(Document toPopulate);
+}

Propchange: myfaces/core/branches/2.2.x/api/src/main/java/javax/faces/ApplicationConfigurationResourceDocumentPopulator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationMerger.java
Mon Jan 21 21:54:03 2013
@@ -102,7 +102,10 @@ public class DefaultFacesConfigurationMe
         
         // faces-config.xml files from javax.faces.CONFIG_FILES
         appConfigResources.addAll(facesConfigProvider.getContextSpecifiedFacesConfig(externalContext));
-
+        
+        // JSF 2.2 ApplicationConfigurationResourceDocumentPopulator FacesConfig
+        appConfigResources.addAll(facesConfigProvider.
+            getApplicationConfigurationResourceDocumentPopulatorFacesConfig(externalContext));
 
         // apply the ordering and sorting algorithm 
         orderAndFeedArtifacts(dispenser, appConfigResources, webAppFacesConfig);

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/DefaultFacesConfigurationProvider.java
Mon Jan 21 21:54:03 2013
@@ -35,16 +35,34 @@ import javax.faces.context.ExternalConte
 import javax.faces.webapp.FacesServlet;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringReader;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
+import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import javax.faces.ApplicationConfigurationResourceDocumentPopulator;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.myfaces.shared.util.FastWriter;
+import org.apache.myfaces.spi.ServiceProviderFinder;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
 
 /**
  * 
@@ -406,4 +424,110 @@ public class DefaultFacesConfigurationPr
         }
     }
 
+    @Override
+    public List<FacesConfig> getApplicationConfigurationResourceDocumentPopulatorFacesConfig(ExternalContext
ectx)
+    {
+        ServiceProviderFinder spff = ServiceProviderFinderFactory.getServiceProviderFinder(ectx);
+        ServiceLoader<ApplicationConfigurationResourceDocumentPopulator> instances
= 
+            spff.load(ApplicationConfigurationResourceDocumentPopulator.class);
+        if (instances != null)
+        {
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+            // namespace aware
+            factory.setNamespaceAware(true);
+            // no validation
+            factory.setValidating(false);
+            
+            DocumentBuilder builder = null;
+            DOMImplementation domImpl = null;
+            try
+            {
+                builder = factory.newDocumentBuilder();
+                domImpl = builder.getDOMImplementation();
+            }
+            catch (ParserConfigurationException ex)
+            {
+                log.log(Level.SEVERE, "Cannot create dom document builder, skipping it",
ex);
+            }
+            
+            if (builder != null)
+            {
+                List<FacesConfig> facesConfigList = new ArrayList<FacesConfig>();
+                List<Document> documentList = new ArrayList<Document>();
+                for (ApplicationConfigurationResourceDocumentPopulator populator : instances)
+                {
+                    // Spec says "... For each implementation, create a fresh org.w3c.dom.Document

+                    // instance, configured to be in the XML namespace of the
+                    // application configuration resource format. ..."
+                    Document document = domImpl.createDocument(
+                        "http://java.sun.com/xml/ns/javaee", "faces-config", null);
+                    //Document document = builder.newDocument();
+                    populator.populateApplicationConfigurationResource(document);
+                    documentList.add(document);
+                }
+                
+                // Parse document. This strategy construct the faces-config.xml in a
+                // memory buffer and then loads it using commons digester.
+                // TODO: Find a better way without write the DOM and read it again and without
+                // rewrite commons-digester parser!.
+                Transformer trans = null;
+                try
+                {
+                    trans = TransformerFactory.newInstance().newTransformer();
+                    trans.setOutputProperty(OutputKeys.INDENT, "no");
+                    trans.setOutputProperty(OutputKeys.METHOD, "xml");
+                    trans.setOutputProperty(OutputKeys.VERSION, "1.0");
+                    trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+                }
+                catch (TransformerConfigurationException ex)
+                {
+                    Logger.getLogger(DefaultFacesConfigurationProvider.class.getName()).log(Level.SEVERE,
null, ex);
+                }
+
+                if (trans != null)
+                {
+                    FastWriter xmlAsWriter = new FastWriter();
+                    for (int i = 0; i < documentList.size(); i++)
+                    {
+                        Document document = documentList.get(i);
+                        xmlAsWriter.reset();
+                        try
+                        {
+                            DOMSource source = new DOMSource(document);
+                            StreamResult result = new StreamResult(xmlAsWriter);
+
+                            trans.transform(source, result);
+
+                            StringReader xmlReader = new StringReader(xmlAsWriter.toString());
+                            FacesConfig facesConfig = getUnmarshaller(ectx).getFacesConfig(
+                                xmlReader);
+                            facesConfigList.add(facesConfig);
+                        }
+                        catch (IOException ex)
+                        {
+                            log.log(Level.SEVERE, "Error while reading faces-config from
populator", ex);
+                        }
+                        catch (SAXException ex)
+                        {
+                            log.log(Level.SEVERE, "Error while reading faces-config from
populator", ex);
+                        }
+                        catch (TransformerConfigurationException ex)
+                        {
+                            log.log(Level.SEVERE, "Error while reading faces-config from
populator", ex);
+                        }
+                        catch (TransformerException ex)
+                        {
+                            log.log(Level.SEVERE, "Error while reading faces-config from
populator", ex);
+                        }
+                    }
+                    return facesConfigList;
+                }
+                else
+                {
+                    log.log(Level.SEVERE, "Cannot create xml transformer, skipping it");
+                }
+            }
+        }
+        return Collections.emptyList();
+    }
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigUnmarshaller.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigUnmarshaller.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigUnmarshaller.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/FacesConfigUnmarshaller.java
Mon Jan 21 21:54:03 2013
@@ -20,6 +20,8 @@ package org.apache.myfaces.config;
 
 import java.io.InputStream;
 import java.io.IOException;
+import java.io.Reader;
+import org.apache.myfaces.config.impl.digester.elements.FacesConfig;
 
 import org.xml.sax.SAXException;
 
@@ -33,4 +35,6 @@ import org.xml.sax.SAXException;
 public interface FacesConfigUnmarshaller<T>
 {
     public T getFacesConfig(InputStream in, String systemId) throws IOException, SAXException;
+    
+    public FacesConfig getFacesConfig(Reader r) throws IOException, SAXException;
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/impl/digester/DigesterFacesConfigUnmarshallerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/impl/digester/DigesterFacesConfigUnmarshallerImpl.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/impl/digester/DigesterFacesConfigUnmarshallerImpl.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/config/impl/digester/DigesterFacesConfigUnmarshallerImpl.java
Mon Jan 21 21:54:03 2013
@@ -29,6 +29,7 @@ import org.xml.sax.SAXException;
 import javax.faces.context.ExternalContext;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.Reader;
 
 /**
  * @author <a href="mailto:oliver@rossmueller.com">Oliver Rossmueller</a>
@@ -328,4 +329,27 @@ public class DigesterFacesConfigUnmarsha
 
         return config;
     }
+    
+    public FacesConfig getFacesConfig(Reader r) throws IOException, SAXException
+    {
+        //InputSource is = new InputSource(in);
+        //is.setSystemId(systemId);
+
+        // Fix for http://issues.apache.org/jira/browse/MYFACES-236
+        FacesConfig config = (FacesConfig) digester.parse(r);
+
+        for (org.apache.myfaces.config.element.Application application : config.getApplications())
+        {
+            for (org.apache.myfaces.config.element.LocaleConfig localeConfig : application.getLocaleConfig())
+            {
+                if (!localeConfig.getSupportedLocales().contains(localeConfig.getDefaultLocale()))
+                {
+                    localeConfig.getSupportedLocales().add(localeConfig.getDefaultLocale());
+                }
+            }
+        }
+
+        return config;
+    }
+
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProvider.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProvider.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProvider.java
Mon Jan 21 21:54:03 2013
@@ -93,4 +93,9 @@ public abstract class FacesConfiguration
      */
     public abstract FacesConfig getWebAppFacesConfig(ExternalContext ectx); 
     
+    /**
+     * 
+     */
+    public abstract List<FacesConfig> 
+        getApplicationConfigurationResourceDocumentPopulatorFacesConfig(ExternalContext ectx);
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProviderWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProviderWrapper.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProviderWrapper.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/FacesConfigurationProviderWrapper.java
Mon Jan 21 21:54:03 2013
@@ -73,5 +73,10 @@ public abstract class FacesConfiguration
     {
         return getWrapped().getWebAppFacesConfig(ectx);
     }
+    
+    public List<FacesConfig> getApplicationConfigurationResourceDocumentPopulatorFacesConfig(ExternalContext
ectx)
+    {
+        return getWrapped().getApplicationConfigurationResourceDocumentPopulatorFacesConfig(ectx);
+    }
 
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/ServiceProviderFinder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/ServiceProviderFinder.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/ServiceProviderFinder.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/ServiceProviderFinder.java
Mon Jan 21 21:54:03 2013
@@ -19,6 +19,7 @@
 package org.apache.myfaces.spi;
 
 import java.util.List;
+import java.util.ServiceLoader;
 
 /**
  * This class provides an interface to override SPI handling done by
@@ -43,4 +44,6 @@ public abstract class ServiceProviderFin
      */
     public abstract List<String> getServiceProviderList(String spiClass);
     
+    public abstract <S> ServiceLoader<S> load(Class<S> spiClass);
+    
 }

Modified: myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java?rev=1436645&r1=1436644&r2=1436645&view=diff
==============================================================================
--- myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
(original)
+++ myfaces/core/branches/2.2.x/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultServiceProviderFinder.java
Mon Jan 21 21:54:03 2013
@@ -29,6 +29,7 @@ import java.util.Enumeration;
 import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.ServiceLoader;
 import java.util.Set;
 
 import org.apache.myfaces.shared.util.ClassUtils;
@@ -154,4 +155,9 @@ public class DefaultServiceProviderFinde
         connection.setUseCaches(false);
         return connection.getInputStream();
     }
+    
+    public <S> ServiceLoader<S> load(Class<S> spiClass)
+    {
+        return ServiceLoader.load(spiClass);
+    }
 }



Mime
View raw message