You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/02/03 14:25:20 UTC

svn commit: r1781554 - in /myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: internal/config/TobagoConfigBuilder.java webapp/TobagoServletContextListener.java

Author: deki
Date: Fri Feb  3 14:25:19 2017
New Revision: 1781554

URL: http://svn.apache.org/viewvc?rev=1781554&view=rev
Log:
TOBAGO-1674: Allow programmatic configuration in addition to tobago-config.xml

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java?rev=1781554&r1=1781553&r2=1781554&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java Fri Feb  3 14:25:19 2017
@@ -34,37 +34,30 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
-public final class TobagoConfigBuilder {
+public class TobagoConfigBuilder {
 
   private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigBuilder.class);
 
   private static final String WEB_INF_TOBAGO_CONFIG_XML = "WEB-INF/tobago-config.xml";
   private static final String META_INF_TOBAGO_CONFIG_XML = "META-INF/tobago-config.xml";
 
-  private List<TobagoConfigFragment> list;
+  private List<TobagoConfigFragment> configFragmentList;
+  private ServletContext servletContext;
 
-  private TobagoConfigBuilder(final ServletContext servletContext)
-      throws ServletException, IOException, SAXException, ParserConfigurationException, URISyntaxException {
-    list = new ArrayList<TobagoConfigFragment>();
-    configFromClasspath();
-    configFromWebInf(servletContext);
-    final TobagoConfigSorter sorter = new TobagoConfigSorter(list);
-    sorter.sort();
-    final TobagoConfigImpl tobagoConfig = sorter.merge();
-
-    // prepare themes
-    tobagoConfig.resolveThemes();
-
-    tobagoConfig.initDefaultValidatorInfo();
-
-    tobagoConfig.lock();
+  public TobagoConfigBuilder(final ServletContext servletContext) {
+    this.servletContext = servletContext;
+    this.configFragmentList = new ArrayList<TobagoConfigFragment>();
+  }
 
-    servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
+  public TobagoConfigBuilder(ServletContext servletContext, List<TobagoConfigFragment> configFragmentList) {
+    this(servletContext);
+    this.configFragmentList.addAll(configFragmentList);
   }
 
   public static void init(final ServletContext servletContext) {
     try {
       final TobagoConfigBuilder builder = new TobagoConfigBuilder(servletContext);
+      builder.build();
     } catch (final Throwable e) {
       if (LOG.isErrorEnabled()) {
         final String error = "Error while deploy process. Tobago can't be initialized! Application will not run!";
@@ -74,12 +67,33 @@ public final class TobagoConfigBuilder {
     }
   }
 
-  private void configFromWebInf(final ServletContext servletContext)
+  public TobagoConfig build() throws URISyntaxException, SAXException,
+     ParserConfigurationException, ServletException, IOException {
+    final TobagoConfigImpl tobagoConfig = initializeConfigFromFiles();
+    // prepare themes
+    tobagoConfig.resolveThemes();
+    tobagoConfig.initDefaultValidatorInfo();
+    tobagoConfig.lock();
+
+    servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
+    return tobagoConfig;
+  }
+
+  protected TobagoConfigImpl initializeConfigFromFiles()
+     throws ServletException, IOException, SAXException, ParserConfigurationException, URISyntaxException {
+    configFromClasspath();
+    configFromWebInf();
+    final TobagoConfigSorter sorter = new TobagoConfigSorter(configFragmentList);
+    sorter.sort();
+    return sorter.merge();
+  }
+
+  private void configFromWebInf()
       throws IOException, SAXException, ParserConfigurationException, URISyntaxException {
 
     final URL url = servletContext.getResource("/" + WEB_INF_TOBAGO_CONFIG_XML);
     if (url != null) {
-      list.add(new TobagoConfigParser().parse(url));
+      configFragmentList.add(new TobagoConfigParser().parse(url));
     }
   }
 
@@ -97,7 +111,7 @@ public final class TobagoConfigBuilder {
         try {
           final TobagoConfigFragment fragment = new TobagoConfigParser().parse(themeUrl);
           fragment.setUrl(themeUrl);
-          list.add(fragment);
+          configFragmentList.add(fragment);
 
           // tomcat uses jar
           // weblogic uses zip

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java?rev=1781554&r1=1781553&r2=1781554&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java Fri Feb  3 14:25:19 2017
@@ -45,10 +45,10 @@ public class TobagoServletContextListene
 
     if (servletContext.getAttribute(TobagoConfig.TOBAGO_CONFIG) != null) {
       LOG.warn("Tobago has been already initialized. Do nothing.");
-      return;
+    } else {
+      TobagoConfigBuilder.init(servletContext);
     }
-
-    TobagoConfigBuilder.init(servletContext);
+    
     if (LOG.isInfoEnabled()) {
       final TobagoConfig tobagoConfig = TobagoConfig.getInstance(servletContext);
       LOG.info("TobagoConfig: " + tobagoConfig);