You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/05/19 12:17:23 UTC

svn commit: r1124660 - in /myfaces/tobago/trunk/tobago-core/src: main/java/org/apache/myfaces/tobago/config/ main/java/org/apache/myfaces/tobago/context/ main/java/org/apache/myfaces/tobago/internal/config/ main/java/org/apache/myfaces/tobago/webapp/ t...

Author: lofwyr
Date: Thu May 19 10:17:22 2011
New Revision: 1124660

URL: http://svn.apache.org/viewvc?rev=1124660&view=rev
Log:
TOBAGO-990 Refactor Tobago configuration
 - split TobagoConfig into 3 parts:
   1. TobagoConfig as simple abstract class (part of the API)
   2. TobagoConfigImpl as the implementation (internal)
   3. TobagoConfigFragment which is used while the library setup, to build one config from multiple tobago-config.xml files. (internal)
 - Ordering of the configurations (similar to JSF 2.0)
 - prevent stacktrace in the current log files at startup (validating schema)

Added:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java   (contents, props changed)
      - copied, changed from r1091388, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
    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/internal/config/TobagoConfigFragment.java
      - copied, changed from r1102563, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java
      - copied, changed from r1102563, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorter.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorterUnitTest.java
Removed:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfigParser.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/context/ThemeParserTest.java
    myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java Thu May 19 10:17:22 2011
@@ -20,111 +20,15 @@ package org.apache.myfaces.tobago.config
 import org.apache.myfaces.tobago.application.ProjectStage;
 import org.apache.myfaces.tobago.context.RenderersConfig;
 import org.apache.myfaces.tobago.context.Theme;
-import org.apache.myfaces.tobago.internal.util.Deprecation;
-import org.apache.myfaces.tobago.internal.util.JndiUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import javax.faces.context.FacesContext;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.servlet.ServletContext;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
-public class TobagoConfig {
-
-  private static final Logger LOG = LoggerFactory.getLogger(TobagoConfig.class);
+public abstract class TobagoConfig {
 
   public static final String TOBAGO_CONFIG = "org.apache.myfaces.tobago.config.TobagoConfig";
 
-  private String name;
-  private List<String> before;
-  private List<String> after;
-  
-  private List<Theme> supportedThemes;
-  private List<String> supportedThemeNames;
-  private Theme defaultTheme;
-  private String defaultThemeName;
-  private List<String> resourceDirs;
-  private Map<String, Theme> availableThemes;
-  private RenderersConfig renderersConfig;
-  private ProjectStage projectStage;
-  private boolean createSessionSecret;
-  private boolean checkSessionSecret;
-  // todo
-  private List<Theme> themeDefinitions;
-
-  public TobagoConfig() {
-    before = new ArrayList<String>();
-    after = new ArrayList<String>();
-    supportedThemeNames = new ArrayList<String>();
-    supportedThemes = new ArrayList<Theme>();
-    resourceDirs = new ArrayList<String>();
-    themeDefinitions = new ArrayList<Theme>();
-    createSessionSecret = true;
-    checkSessionSecret = true;
-  }
-
-  public void addSupportedThemeName(String name) {
-    supportedThemeNames.add(name);
-  }
-  // TODO one init method
-  public void resolveThemes() {
-    if (defaultThemeName != null) {
-      defaultTheme = availableThemes.get(defaultThemeName);
-      checkThemeIsAvailable(defaultThemeName, defaultTheme);
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("name = '{}'", defaultThemeName);
-        LOG.debug("defaultTheme = '{}'", defaultTheme);
-      }
-    } else {
-      int deep = 0;
-      for (Map.Entry<String, Theme> entry : availableThemes.entrySet()) {
-        Theme theme = entry.getValue();
-        if (theme.getFallbackList().size() > deep) {
-          defaultTheme = theme;
-          deep = theme.getFallbackList().size();
-        }
-      }
-      if (defaultTheme == null) {
-        String error = "Did not found any theme! "
-            + "Please ensure you have a tobago-theme.xml file in your "
-            + "theme jar. Please add a theme jar to your WEB-INF/lib";
-        LOG.error(error);
-        throw new RuntimeException(error);
-      } else {
-        if (LOG.isInfoEnabled()) {
-          LOG.info("Using default Theme {}", defaultTheme.getName());
-        }
-      }
-    }
-    if (!supportedThemeNames.isEmpty()) {
-      for (String name : supportedThemeNames) {
-        Theme theme = availableThemes.get(name);
-        checkThemeIsAvailable(name, theme);
-        supportedThemes.add(theme);
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("name = '{}'",  name);
-          LOG.debug("supportedThemes.last() = '{}'", supportedThemes.get(supportedThemes.size() - 1));
-        }
-      }
-    }
-  }
-
-  private void checkThemeIsAvailable(String name, Theme theme) {
-    if (theme == null) {
-      String error = "Theme not found! name: '" + name + "'. "
-          + "Please ensure you have a tobago-theme.xml file in your "
-          + "theme jar. Found the following themes: " + availableThemes.keySet();
-      LOG.error(error);
-      throw new RuntimeException(error);
-    }
-  }
-
   public static TobagoConfig getInstance(FacesContext facesContext) {
     return (TobagoConfig) facesContext.getExternalContext().getApplicationMap().get(TOBAGO_CONFIG);
   }
@@ -133,177 +37,36 @@ public class TobagoConfig {
     return (TobagoConfig) servletContext.getAttribute(TOBAGO_CONFIG);
   }
 
-  public Theme getTheme(String name) {
-    if (name == null) {
-      LOG.debug("searching theme: null");
-      return defaultTheme;
-    }
-    if (defaultTheme.getName().equals(name)) {
-      return defaultTheme;
-    }
-    for (Theme theme : supportedThemes) {
-      if (theme.getName().equals(name)) {
-        return theme;
-      }
-    }
-    LOG.debug("searching theme '{}' not found. Using default: {}", name, defaultTheme);
-    return defaultTheme;
-  }
-
-  public void setDefaultThemeName(String defaultThemeName) {
-    this.defaultThemeName = defaultThemeName;
-  }
+  public abstract Theme getTheme(String name);
 
-  public List<Theme> getSupportedThemes() {
-    return Collections.unmodifiableList(supportedThemes);
-  }
-
-  public void addResourceDir(String resourceDir) {
-    if (!resourceDirs.contains(resourceDir)) {
-      if (LOG.isInfoEnabled()) {
-        LOG.info("adding resourceDir = '{}'", resourceDir);
-      }
-      resourceDirs.add(resourceDir);
-    }
-  }
+  public abstract List<Theme> getSupportedThemes();
 
-  public List<String> getResourceDirs() {
-    return resourceDirs;
-  }
-
-  /** @deprecated since 1.5.0 */
+/*
+  // todo: should this be part of the api?
+  public abstract void addResourceDir(String resourceDir);
+*/
+
+/*
+  // todo: should this be part of the api?
+  public abstract List<String> getResourceDirs();
+*/
+
+  /**
+   * @deprecated since 1.5.0
+   */
   @Deprecated
-  public boolean isAjaxEnabled() {
-    Deprecation.LOG.warn("Ajax is always enabled!");
-    return true;
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setAjaxEnabled(String value) {
-    Deprecation.LOG.error("Ajax is always enabled!");
-  }
-
-  public Theme getDefaultTheme() {
-    return defaultTheme;
-  }
-
-  public void setAvailableThemes(Map<String, Theme> availableThemes) {
-    this.availableThemes = availableThemes;
-    for (Theme theme : this.availableThemes.values()) {
-      addResourceDir(theme.getResourcePath());
-    }
-  }
-
-  public RenderersConfig getRenderersConfig() {
-    return renderersConfig;
-  }
-
-  public void setRenderersConfig(RenderersConfig renderersConfig) {
-    this.renderersConfig = renderersConfig;
-  }
-
-  public ProjectStage getProjectStage() {
-    return projectStage;
-  }
-  // TODO one init method
-  public void initProjectState(ServletContext servletContext) {
-    String stageName = null;
-    try {
-      Context ctx = new InitialContext();
-      Object obj = JndiUtils.getJndiProperty(ctx, "jsf", "ProjectStage");
-      if (obj != null) {
-        if (obj instanceof String) {
-          stageName = (String) obj;
-        } else {
-          LOG.warn("JNDI lookup for key {} should return a java.lang.String value",
-              ProjectStage.PROJECT_STAGE_JNDI_NAME);
-        }
-      }
-    } catch (NamingException e) {
-      // ignore
-    }
-
-    if (stageName == null) {
-      stageName = servletContext.getInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME);
-    }
-
-    if (stageName == null) {
-      stageName = System.getProperty("org.apache.myfaces.PROJECT_STAGE");
-    }
-
-    if (stageName != null) {
-      try {
-        projectStage = ProjectStage.valueOf(stageName);
-      } catch (IllegalArgumentException e) {
-        LOG.error("Couldn't discover the current project stage", e);
-      }
-    }
-    if (projectStage == null) {
-      if (LOG.isInfoEnabled()) {
-        LOG.info("Couldn't discover the current project stage, using {}", ProjectStage.Production);
-      }
-      projectStage = ProjectStage.Production;
-    }
-  }
-
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
+  public abstract boolean isAjaxEnabled();
 
-  public List<String> getBefore() {
-    return before;
-  }
+  public abstract Theme getDefaultTheme();
 
-  public void addBefore(String name) {
-    before.add(name);
-  }
+  public abstract RenderersConfig getRenderersConfig();
 
-  public List<String> getAfter() {
-    return after;
-  }
+  public abstract ProjectStage getProjectStage();
 
-  public void addAfter(String name) {
-    after.add(name);
-  }
+  public abstract List<Theme> getThemeDefinitions();
 
-  public void addThemeDefinition(Theme theme) {
-    themeDefinitions.add(theme);
-  }
+  public abstract boolean isCreateSessionSecret();
 
-  public List<Theme> getThemeDefinitions() {
-    return themeDefinitions;
-  }
+  public abstract boolean isCheckSessionSecret();
 
-  public boolean isCreateSessionSecret() {
-    return createSessionSecret;
-  }
-
-  public void setCreateSessionSecret(String createSessionSecret) {
-    this.createSessionSecret = Boolean.valueOf(createSessionSecret);
-  }
-
-  public boolean isCheckSessionSecret() {
-    return checkSessionSecret;
-  }
-
-  public void setCheckSessionSecret(String checkSessionSecret) {
-    this.checkSessionSecret = Boolean.valueOf(checkSessionSecret);
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setFixResourceOrder(String value) {
-    Deprecation.LOG.error("Config fix-resource-order not longer supported. (Is always activated).");
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setFixLayoutTransparency(String value) {
-    Deprecation.LOG.error("Config fix-layout-transparency not longer supported. (Is always activated).");
-  }
 }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfigParser.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfigParser.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfigParser.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfigParser.java Thu May 19 10:17:22 2011
@@ -26,6 +26,7 @@ import org.apache.myfaces.tobago.context
 import org.apache.myfaces.tobago.context.ThemeResources;
 import org.apache.myfaces.tobago.context.ThemeScript;
 import org.apache.myfaces.tobago.context.ThemeStyle;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigFragment;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -51,21 +52,21 @@ public class TobagoConfigParser {
   public TobagoConfigParser() {
     digester = new Digester();
     digester.setUseContextClassLoader(true);
-    digester.setValidating(true);
     configure();
     registerDtds();
   }
 
-  public TobagoConfig parse(URL url) throws IOException, SAXException, FacesException {
+  public TobagoConfigFragment parse(URL url) throws IOException, SAXException, FacesException {
 
     if (LOG.isInfoEnabled()) {
       LOG.info("Parsing configuration file: '{}'", url);
     }
 
-    TobagoConfig tobagoConfig = new TobagoConfig();
+    TobagoConfigFragment tobagoConfig = new TobagoConfigFragment();
     digester.push(tobagoConfig);
     InputStream inputStream = null;
     try {
+      configureValidation(url);
       inputStream = url.openStream();
       digester.parse(inputStream);
     } finally {
@@ -75,6 +76,20 @@ public class TobagoConfigParser {
     return tobagoConfig;
   }
 
+  private void configureValidation(URL url) {
+    // TODO: validating is turned of in case of a schema
+    try {
+      final String xml = IOUtils.toString(url.openStream());
+      if (xml.indexOf("tobago-config-1.5.xsd") > 0) {
+        digester.setValidating(false);
+        return;
+      }
+    } catch (Exception e) {
+      LOG.warn("Error while checking: '" + url + "'", e);
+    }
+    digester.setValidating(true);
+  }
+
   private Digester configure() {
 
     // ordering

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java Thu May 19 10:17:22 2011
@@ -19,8 +19,9 @@ package org.apache.myfaces.tobago.contex
 
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.io.IOUtils;
-import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.apache.myfaces.tobago.config.TobagoConfigParser;
+import org.apache.myfaces.tobago.internal.config.ThemeParser;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigFragment;
 import org.apache.myfaces.tobago.util.XmlUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -145,7 +146,7 @@ class ResourceLocator {
       for (URL themeUrl : urls) {
         ThemeImpl theme;
         if (themeUrl.toString().endsWith(META_INF_TOBAGO_CONFIG_XML)) {
-          TobagoConfig tobagoConfig = new TobagoConfigParser().parse(themeUrl);
+          TobagoConfigFragment tobagoConfig = new TobagoConfigParser().parse(themeUrl);
           theme = (ThemeImpl) tobagoConfig.getThemeDefinitions().get(0);
         } else {
           // the old way

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java Thu May 19 10:17:22 2011
@@ -17,7 +17,7 @@ package org.apache.myfaces.tobago.contex
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
 
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
@@ -45,7 +45,7 @@ public class ResourceManagerFactory {
   }
 
   public static void init(
-      ServletContext servletContext, TobagoConfig tobagoConfig)
+      ServletContext servletContext, TobagoConfigImpl tobagoConfig)
       throws ServletException {
     assert !initialized;
     ResourceManagerImpl resourceManager= new ResourceManagerImpl(tobagoConfig);

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java Thu May 19 10:17:22 2011
@@ -20,7 +20,7 @@ package org.apache.myfaces.tobago.contex
 import org.apache.myfaces.tobago.application.ProjectStage;
 import org.apache.myfaces.tobago.component.RendererTypes;
 import org.apache.myfaces.tobago.config.Configurable;
-import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
 import org.apache.myfaces.tobago.internal.context.ClientPropertiesKey;
 import org.apache.myfaces.tobago.internal.context.ImageCacheKey;
 import org.apache.myfaces.tobago.internal.context.JspCacheKey;
@@ -68,9 +68,9 @@ public class ResourceManagerImpl impleme
   private final Map<ThemeConfigCacheKey, MeasureValue> themeCache 
       = new ConcurrentHashMap<ThemeConfigCacheKey, MeasureValue>(100, 0.75f, 1);
   
-  private TobagoConfig tobagoConfig;
+  private TobagoConfigImpl tobagoConfig;
 
-  public ResourceManagerImpl(TobagoConfig tobagoConfig) {
+  public ResourceManagerImpl(TobagoConfigImpl tobagoConfig) {
     this.tobagoConfig = tobagoConfig;
     this.production = tobagoConfig.getProjectStage() == ProjectStage.Production;
   }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeBuilder.java Thu May 19 10:17:22 2011
@@ -17,15 +17,15 @@ package org.apache.myfaces.tobago.contex
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /*
  * Date: 25.03.2006 08:21:06
@@ -35,9 +35,9 @@ class ThemeBuilder {
   private static final Logger LOG = LoggerFactory.getLogger(ThemeBuilder.class);
 
   private List<ThemeImpl> availableThemes = new ArrayList<ThemeImpl>();
-  private TobagoConfig tobagoConfig;
+  private TobagoConfigImpl tobagoConfig;
 
-  ThemeBuilder(TobagoConfig tobagoConfig) {
+  ThemeBuilder(TobagoConfigImpl tobagoConfig) {
     this.tobagoConfig = tobagoConfig;
   }
 

Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java (from r1091388, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java&r1=1091388&r2=1124660&rev=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java Thu May 19 10:17:22 2011
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.context;
+package org.apache.myfaces.tobago.internal.config;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -19,6 +19,13 @@ package org.apache.myfaces.tobago.contex
 
 import org.apache.commons.digester.Digester;
 import org.apache.commons.io.IOUtils;
+import org.apache.myfaces.tobago.context.MarkupConfig;
+import org.apache.myfaces.tobago.context.RendererConfig;
+import org.apache.myfaces.tobago.context.RenderersConfigImpl;
+import org.apache.myfaces.tobago.context.ThemeImpl;
+import org.apache.myfaces.tobago.context.ThemeResources;
+import org.apache.myfaces.tobago.context.ThemeScript;
+import org.apache.myfaces.tobago.context.ThemeStyle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.SAXException;
@@ -28,18 +35,17 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 
-/*
- * Date: 14.02.2006 20:34:41
- *
+/**
  * @since 1.0.7
+ * @deprecated since 1.5.0. The grammar is now part of the TobagoConfigParser
  */
-class ThemeParser {
+public class ThemeParser {
 
   private static final Logger LOG = LoggerFactory.getLogger(ThemeParser.class);
 
   private Digester digester;
 
-  ThemeParser() {
+  public ThemeParser() {
     configure();
   }
 

Propchange: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/ThemeParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 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=1124660&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigBuilder.java Thu May 19 10:17:22 2011
@@ -0,0 +1,189 @@
+package org.apache.myfaces.tobago.internal.config;
+
+/*
+ * 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.
+ */
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.config.TobagoConfigParser;
+import org.apache.myfaces.tobago.context.ResourceManagerFactory;
+import org.apache.myfaces.tobago.context.Theme;
+import org.apache.myfaces.tobago.context.ThemeImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.SAXException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+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";
+  /**
+   * @deprecated Since 1.5.0
+   */
+  private static final String META_INF_TOBAGO_THEME_XML = "META-INF/tobago-theme.xml";
+
+  private List<TobagoConfigFragment> list;
+
+  private TobagoConfigBuilder(ServletContext servletContext) throws ServletException, IOException, SAXException {
+    list = new ArrayList<TobagoConfigFragment>();
+    configFromWebInf(servletContext);
+    configFromClasspath();
+    final TobagoConfigImpl tobagoConfig = mergeList();
+
+    // todo: cleanup, use one central TobagoConfig, no singleton ResourceManager
+    // resources
+    tobagoConfig.initProjectState(servletContext);
+    ResourceManagerFactory.init(servletContext, tobagoConfig);
+    // prepare themes
+    tobagoConfig.resolveThemes();
+
+    servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
+  }
+
+  public static void init(ServletContext servletContext) {
+    try {
+      final TobagoConfigBuilder builder = new TobagoConfigBuilder(servletContext);
+    } catch (Throwable e) {
+      if (LOG.isErrorEnabled()) {
+        String error = "Error while deploy process. Tobago can't be initialized! Application will not run!";
+        LOG.error(error, e);
+        throw new RuntimeException(error, e);
+      }
+    }
+  }
+
+  private void configFromWebInf(ServletContext servletContext) throws IOException, SAXException {
+
+    final String configPath = "/WEB-INF/tobago-config.xml";
+    final URL url = servletContext.getResource(configPath);
+    list.add(new TobagoConfigParser().parse(url));
+  }
+
+  private void resolve(ServletContext servletContext) throws ServletException {
+    final TobagoConfigImpl tobagoConfig = mergeList();
+
+    // todo: cleanup, use one central TobagoConfig, no singleton ResourceManager
+    // resources
+    tobagoConfig.initProjectState(servletContext);
+    ResourceManagerFactory.init(servletContext, tobagoConfig);
+    // prepare themes
+    tobagoConfig.resolveThemes();
+
+    servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
+  }
+
+  private TobagoConfigImpl mergeList() {
+// todo
+    LOG.warn("Merge implementation in progress...)");
+
+    TobagoConfigSorter sorter = new TobagoConfigSorter(list);
+    sorter.sort();
+    TobagoConfigImpl result = new TobagoConfigImpl();
+
+    for (TobagoConfigFragment fragment : list) {
+      // default theme
+      final String defaultTheme = fragment.getDefaultThemeName();
+      if (defaultTheme != null) {
+        result.setDefaultThemeName(defaultTheme);
+      }
+
+      // supported themes
+      for (String supported : fragment.getSupportedThemeNames()) {
+        result.addSupportedThemeName(supported);
+      }
+
+      // resource dirs
+      for (String dir : fragment.getResourceDirs()) {
+        result.addResourceDir(dir);
+      }
+
+      // renderers config
+      // TODO: merging not implemented yet!!!
+      result.setRenderersConfig(fragment.getRenderersConfig());
+
+      // session secret
+      if (fragment.getCreateSessionSecret() != null) {
+        result.setCreateSessionSecret(fragment.getCreateSessionSecret());
+      }
+      if (fragment.getCheckSessionSecret() != null) {
+        result.setCheckSessionSecret(fragment.getCheckSessionSecret());
+      }
+
+      // theme definition
+      // todo
+      for (Theme theme : fragment.getThemeDefinitions()) {
+        result.addThemeDefinition(theme);
+      }
+
+      // url
+      // todo???
+
+    }
+    return result;
+  }
+
+  private void configFromClasspath() throws ServletException {
+
+    ThemeParser parser = new ThemeParser();
+    try {
+      if (LOG.isInfoEnabled()) {
+        LOG.info("Searching for '" + META_INF_TOBAGO_THEME_XML + "' and '" + META_INF_TOBAGO_CONFIG_XML + "'");
+      }
+      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+      List<URL> urls = new ArrayList<URL>();
+      CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_CONFIG_XML));
+      CollectionUtils.addAll(urls, classLoader.getResources(META_INF_TOBAGO_THEME_XML));
+
+      for (URL themeUrl : urls) {
+        TobagoConfigFragment tobagoConfig;
+        if (themeUrl.toString().endsWith(META_INF_TOBAGO_CONFIG_XML)) {
+          tobagoConfig = new TobagoConfigParser().parse(themeUrl);
+        } else {
+          // the old way
+          tobagoConfig = new TobagoConfigFragment();
+          final ThemeImpl theme = parser.parse(themeUrl);
+          tobagoConfig.addThemeDefinition(theme);
+        }
+        tobagoConfig.setUrl(themeUrl);
+        String protocol = themeUrl.getProtocol();
+        // tomcat uses jar
+        // weblogic uses zip
+        // IBM WebSphere uses wsjar
+        if (!"jar".equals(protocol) && !"zip".equals(protocol) && !"wsjar".equals(protocol)) {
+          LOG.warn("Unknown protocol '" + themeUrl + "'");
+        }
+
+        list.add(tobagoConfig);
+      }
+    } catch (Exception e) {
+      String msg = "while loading ";
+      LOG.error(msg, e);
+      throw new ServletException(msg, e);
+    }
+  }
+
+
+}

Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java (from r1102563, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java&r1=1102563&r2=1124660&rev=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigFragment.java Thu May 19 10:17:22 2011
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.config;
+package org.apache.myfaces.tobago.internal.config;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,147 +17,58 @@ package org.apache.myfaces.tobago.config
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.application.ProjectStage;
 import org.apache.myfaces.tobago.context.RenderersConfig;
 import org.apache.myfaces.tobago.context.Theme;
 import org.apache.myfaces.tobago.internal.util.Deprecation;
-import org.apache.myfaces.tobago.internal.util.JndiUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.faces.context.FacesContext;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import javax.servlet.ServletContext;
+import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
-import java.util.Map;
 
-public class TobagoConfig {
+public class TobagoConfigFragment {
 
-  private static final Logger LOG = LoggerFactory.getLogger(TobagoConfig.class);
-
-  public static final String TOBAGO_CONFIG = "org.apache.myfaces.tobago.config.TobagoConfig";
+  private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigFragment.class);
 
   private String name;
   private List<String> before;
   private List<String> after;
-  
-  private List<Theme> supportedThemes;
+
   private List<String> supportedThemeNames;
-  private Theme defaultTheme;
   private String defaultThemeName;
   private List<String> resourceDirs;
-  private Map<String, Theme> availableThemes;
   private RenderersConfig renderersConfig;
-  private ProjectStage projectStage;
-  private boolean createSessionSecret;
-  private boolean checkSessionSecret;
+  private Boolean createSessionSecret;
+  private Boolean checkSessionSecret;
   // todo
   private List<Theme> themeDefinitions;
+  private URL url;
 
-  public TobagoConfig() {
+  public TobagoConfigFragment() {
     before = new ArrayList<String>();
     after = new ArrayList<String>();
     supportedThemeNames = new ArrayList<String>();
-    supportedThemes = new ArrayList<Theme>();
     resourceDirs = new ArrayList<String>();
     themeDefinitions = new ArrayList<Theme>();
-    createSessionSecret = true;
-    checkSessionSecret = true;
   }
 
   public void addSupportedThemeName(String name) {
     supportedThemeNames.add(name);
   }
-  // TODO one init method
-  public void resolveThemes() {
-    if (defaultThemeName != null) {
-      defaultTheme = availableThemes.get(defaultThemeName);
-      checkThemeIsAvailable(defaultThemeName, defaultTheme);
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("name = '{}'", defaultThemeName);
-        LOG.debug("defaultTheme = '{}'", defaultTheme);
-      }
-    } else {
-      int deep = 0;
-      for (Map.Entry<String, Theme> entry : availableThemes.entrySet()) {
-        Theme theme = entry.getValue();
-        if (theme.getFallbackList().size() > deep) {
-          defaultTheme = theme;
-          deep = theme.getFallbackList().size();
-        }
-      }
-      if (defaultTheme == null) {
-        String error = "Did not found any theme! "
-            + "Please ensure you have a tobago-theme.xml file in your "
-            + "theme jar. Please add a theme jar to your WEB-INF/lib";
-        LOG.error(error);
-        throw new RuntimeException(error);
-      } else {
-        if (LOG.isInfoEnabled()) {
-          LOG.info("Using default Theme {}", defaultTheme.getName());
-        }
-      }
-    }
-    if (!supportedThemeNames.isEmpty()) {
-      for (String name : supportedThemeNames) {
-        Theme theme = availableThemes.get(name);
-        checkThemeIsAvailable(name, theme);
-        supportedThemes.add(theme);
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("name = '{}'",  name);
-          LOG.debug("supportedThemes.last() = '{}'", supportedThemes.get(supportedThemes.size() - 1));
-        }
-      }
-    }
-  }
-
-  private void checkThemeIsAvailable(String name, Theme theme) {
-    if (theme == null) {
-      String error = "Theme not found! name: '" + name + "'. "
-          + "Please ensure you have a tobago-theme.xml file in your "
-          + "theme jar. Found the following themes: " + availableThemes.keySet();
-      LOG.error(error);
-      throw new RuntimeException(error);
-    }
-  }
 
-  public static TobagoConfig getInstance(FacesContext facesContext) {
-    return (TobagoConfig) facesContext.getExternalContext().getApplicationMap().get(TOBAGO_CONFIG);
+  public List<String> getSupportedThemeNames() {
+    return supportedThemeNames;
   }
 
-  public static TobagoConfig getInstance(ServletContext servletContext) {
-    return (TobagoConfig) servletContext.getAttribute(TOBAGO_CONFIG);
-  }
-
-  public Theme getTheme(String name) {
-    if (name == null) {
-      LOG.debug("searching theme: null");
-      return defaultTheme;
-    }
-    if (defaultTheme.getName().equals(name)) {
-      return defaultTheme;
-    }
-    for (Theme theme : supportedThemes) {
-      if (theme.getName().equals(name)) {
-        return theme;
-      }
-    }
-    LOG.debug("searching theme '{}' not found. Using default: {}", name, defaultTheme);
-    return defaultTheme;
+  public String getDefaultThemeName() {
+    return defaultThemeName;
   }
 
   public void setDefaultThemeName(String defaultThemeName) {
     this.defaultThemeName = defaultThemeName;
   }
 
-  public List<Theme> getSupportedThemes() {
-    return Collections.unmodifiableList(supportedThemes);
-  }
-
   public void addResourceDir(String resourceDir) {
     if (!resourceDirs.contains(resourceDir)) {
       if (LOG.isInfoEnabled()) {
@@ -173,28 +84,10 @@ public class TobagoConfig {
 
   /** @deprecated since 1.5.0 */
   @Deprecated
-  public boolean isAjaxEnabled() {
-    Deprecation.LOG.warn("Ajax is always enabled!");
-    return true;
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
   public void setAjaxEnabled(String value) {
     Deprecation.LOG.error("Ajax is always enabled!");
   }
 
-  public Theme getDefaultTheme() {
-    return defaultTheme;
-  }
-
-  public void setAvailableThemes(Map<String, Theme> availableThemes) {
-    this.availableThemes = availableThemes;
-    for (Theme theme : this.availableThemes.values()) {
-      addResourceDir(theme.getResourcePath());
-    }
-  }
-
   public RenderersConfig getRenderersConfig() {
     return renderersConfig;
   }
@@ -203,50 +96,6 @@ public class TobagoConfig {
     this.renderersConfig = renderersConfig;
   }
 
-  public ProjectStage getProjectStage() {
-    return projectStage;
-  }
-  // TODO one init method
-  public void initProjectState(ServletContext servletContext) {
-    String stageName = null;
-    try {
-      Context ctx = new InitialContext();
-      Object obj = JndiUtils.getJndiProperty(ctx, "jsf", "ProjectStage");
-      if (obj != null) {
-        if (obj instanceof String) {
-          stageName = (String) obj;
-        } else {
-          LOG.warn("JNDI lookup for key {} should return a java.lang.String value",
-              ProjectStage.PROJECT_STAGE_JNDI_NAME);
-        }
-      }
-    } catch (NamingException e) {
-      // ignore
-    }
-
-    if (stageName == null) {
-      stageName = servletContext.getInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME);
-    }
-
-    if (stageName == null) {
-      stageName = System.getProperty("org.apache.myfaces.PROJECT_STAGE");
-    }
-
-    if (stageName != null) {
-      try {
-        projectStage = ProjectStage.valueOf(stageName);
-      } catch (IllegalArgumentException e) {
-        LOG.error("Couldn't discover the current project stage", e);
-      }
-    }
-    if (projectStage == null) {
-      if (LOG.isInfoEnabled()) {
-        LOG.info("Couldn't discover the current project stage, using {}", ProjectStage.Production);
-      }
-      projectStage = ProjectStage.Production;
-    }
-  }
-
   public String getName() {
     return name;
   }
@@ -279,7 +128,7 @@ public class TobagoConfig {
     return themeDefinitions;
   }
 
-  public boolean isCreateSessionSecret() {
+  public Boolean getCreateSessionSecret() {
     return createSessionSecret;
   }
 
@@ -287,7 +136,7 @@ public class TobagoConfig {
     this.createSessionSecret = Boolean.valueOf(createSessionSecret);
   }
 
-  public boolean isCheckSessionSecret() {
+  public Boolean getCheckSessionSecret() {
     return checkSessionSecret;
   }
 
@@ -306,4 +155,17 @@ public class TobagoConfig {
   public void setFixLayoutTransparency(String value) {
     Deprecation.LOG.error("Config fix-layout-transparency not longer supported. (Is always activated).");
   }
+
+  public URL getUrl() {
+    return url;
+  }
+
+  public void setUrl(URL url) {
+    this.url = url;
+  }
+
+  @Override
+  public String toString() {
+    return name != null ? name : "(id=" + System.identityHashCode(this) + ")";
+  }
 }

Copied: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java (from r1102563, myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java?p2=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java&p1=myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java&r1=1102563&r2=1124660&rev=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigImpl.java Thu May 19 10:17:22 2011
@@ -1,4 +1,4 @@
-package org.apache.myfaces.tobago.config;
+package org.apache.myfaces.tobago.internal.config;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -18,6 +18,7 @@ package org.apache.myfaces.tobago.config
  */
 
 import org.apache.myfaces.tobago.application.ProjectStage;
+import org.apache.myfaces.tobago.config.TobagoConfig;
 import org.apache.myfaces.tobago.context.RenderersConfig;
 import org.apache.myfaces.tobago.context.Theme;
 import org.apache.myfaces.tobago.internal.util.Deprecation;
@@ -25,26 +26,22 @@ import org.apache.myfaces.tobago.interna
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.faces.context.FacesContext;
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.servlet.ServletContext;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-public class TobagoConfig {
+public class TobagoConfigImpl extends TobagoConfig {
 
-  private static final Logger LOG = LoggerFactory.getLogger(TobagoConfig.class);
+  private static final Logger LOG = LoggerFactory.getLogger(TobagoConfigImpl.class);
 
   public static final String TOBAGO_CONFIG = "org.apache.myfaces.tobago.config.TobagoConfig";
 
-  private String name;
-  private List<String> before;
-  private List<String> after;
-  
   private List<Theme> supportedThemes;
   private List<String> supportedThemeNames;
   private Theme defaultTheme;
@@ -57,10 +54,9 @@ public class TobagoConfig {
   private boolean checkSessionSecret;
   // todo
   private List<Theme> themeDefinitions;
+  private URL url;
 
-  public TobagoConfig() {
-    before = new ArrayList<String>();
-    after = new ArrayList<String>();
+  public TobagoConfigImpl() {
     supportedThemeNames = new ArrayList<String>();
     supportedThemes = new ArrayList<Theme>();
     resourceDirs = new ArrayList<String>();
@@ -125,14 +121,6 @@ public class TobagoConfig {
     }
   }
 
-  public static TobagoConfig getInstance(FacesContext facesContext) {
-    return (TobagoConfig) facesContext.getExternalContext().getApplicationMap().get(TOBAGO_CONFIG);
-  }
-
-  public static TobagoConfig getInstance(ServletContext servletContext) {
-    return (TobagoConfig) servletContext.getAttribute(TOBAGO_CONFIG);
-  }
-
   public Theme getTheme(String name) {
     if (name == null) {
       LOG.debug("searching theme: null");
@@ -178,12 +166,6 @@ public class TobagoConfig {
     return true;
   }
 
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setAjaxEnabled(String value) {
-    Deprecation.LOG.error("Ajax is always enabled!");
-  }
-
   public Theme getDefaultTheme() {
     return defaultTheme;
   }
@@ -247,30 +229,6 @@ public class TobagoConfig {
     }
   }
 
-  public String getName() {
-    return name;
-  }
-
-  public void setName(String name) {
-    this.name = name;
-  }
-
-  public List<String> getBefore() {
-    return before;
-  }
-
-  public void addBefore(String name) {
-    before.add(name);
-  }
-
-  public List<String> getAfter() {
-    return after;
-  }
-
-  public void addAfter(String name) {
-    after.add(name);
-  }
-
   public void addThemeDefinition(Theme theme) {
     themeDefinitions.add(theme);
   }
@@ -283,27 +241,15 @@ public class TobagoConfig {
     return createSessionSecret;
   }
 
-  public void setCreateSessionSecret(String createSessionSecret) {
-    this.createSessionSecret = Boolean.valueOf(createSessionSecret);
+  public void setCreateSessionSecret(boolean createSessionSecret) {
+    this.createSessionSecret = createSessionSecret;
   }
 
   public boolean isCheckSessionSecret() {
     return checkSessionSecret;
   }
 
-  public void setCheckSessionSecret(String checkSessionSecret) {
-    this.checkSessionSecret = Boolean.valueOf(checkSessionSecret);
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setFixResourceOrder(String value) {
-    Deprecation.LOG.error("Config fix-resource-order not longer supported. (Is always activated).");
-  }
-
-  /** @deprecated since 1.5.0 */
-  @Deprecated
-  public void setFixLayoutTransparency(String value) {
-    Deprecation.LOG.error("Config fix-layout-transparency not longer supported. (Is always activated).");
+  public void setCheckSessionSecret(boolean checkSessionSecret) {
+    this.checkSessionSecret = checkSessionSecret;
   }
 }

Added: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorter.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorter.java?rev=1124660&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorter.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorter.java Thu May 19 10:17:22 2011
@@ -0,0 +1,198 @@
+package org.apache.myfaces.tobago.internal.config;
+
+/*
+ * 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.
+ */
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class TobagoConfigSorter implements Comparator<TobagoConfigFragment> {
+
+  private List<TobagoConfigFragment> list;
+  private List<Pair> pairs;
+
+  public TobagoConfigSorter(List<TobagoConfigFragment> list) {
+    this.list = list;
+  }
+
+  public void sort() {
+
+    createRelevantPairs();
+
+    makeTransitive();
+
+    ensureIrreflexive();
+
+    ensureAntiSymmetric();
+
+    sort0();
+
+  }
+
+  protected void makeTransitive() {
+    // make the half order transitive: a < b && b < c => a < c
+    boolean growing = true;
+    while (growing) {
+      growing = false;
+      for (int i = 0; i < pairs.size(); i++) {
+        for (int j = 0; j < pairs.size(); j++) {
+          if (pairs.get(i).getHigher() == pairs.get(j).getLower()
+              && !isInRelation(pairs.get(i).getLower(), pairs.get(j).getHigher())) {
+            pairs.add(new Pair(pairs.get(i).getLower(), pairs.get(j).getHigher()));
+            growing = true;
+          }
+        }
+      }
+    }
+  }
+
+  protected void ensureIrreflexive() {
+    for (Pair a : pairs) {
+        if (a.getLower() == a.getHigher()) {
+          StringBuffer buffer = new StringBuffer();
+          buffer.append("Ordering problem. There are conflicting order rules. Not irreflexive. " + "'");
+          buffer.append(a.getLower());
+          buffer.append("' < '");
+          buffer.append(a.getHigher());
+          buffer.append("'!\nThe reason may be a cycle.\n");
+          buffer.append("Complete list of rules: \n");
+          for (Pair pair : pairs) {
+            buffer.append("'");
+            buffer.append(pair.getLower());
+            buffer.append("' < '");
+            buffer.append(pair.getHigher());
+            buffer.append("'\n");
+
+          }
+          throw new RuntimeException(buffer.toString());
+        }
+      }
+  }
+
+  protected void ensureAntiSymmetric() {
+    for (Pair a : pairs) {
+      for (Pair b : pairs) {
+        if (a.getLower() == b.getHigher() && a.getHigher() == b.getLower()) {
+          StringBuffer buffer = new StringBuffer();
+          buffer.append("Ordering problem. There are conflicting order rules. Not antisymmetric. " + "'");
+          buffer.append(a.getLower());
+          buffer.append("' < '");
+          buffer.append(a.getHigher());
+          buffer.append("'" + "'");
+          buffer.append(a.getLower());
+          buffer.append("' > '");
+          buffer.append(a.getHigher());
+          buffer.append("'!\nThe reason may be a cycle.\n");
+          buffer.append("Complete list of rules: \n");
+          for (Pair pair : pairs) {
+            buffer.append("'");
+            buffer.append(pair.getLower());
+            buffer.append("' < '");
+            buffer.append(pair.getHigher());
+            buffer.append("'\n");
+
+          }
+          throw new RuntimeException(buffer.toString());
+        }
+      }
+    }
+  }
+
+  public int compare(TobagoConfigFragment a, TobagoConfigFragment b) {
+    if (isInRelation(a, b)) {
+      return -1;
+    }
+    if (isInRelation(b, a)) {
+      return 1;
+    }
+    return 0;
+  }
+
+  protected void createRelevantPairs() {
+
+    pairs = new ArrayList<Pair>();
+
+    // collecting all relations, which are relevant for us. We don't need "before" and "after" of unknown names.
+    for (TobagoConfigFragment tobagoConfig : list) {
+      for (String befores : tobagoConfig.getBefore()) {
+        TobagoConfigFragment before = findByName(befores);
+        if (before != null) {
+          pairs.add(new Pair(tobagoConfig, before));
+        }
+      }
+      for (String afters : tobagoConfig.getAfter()) {
+        TobagoConfigFragment after = findByName(afters);
+        if (after != null) {
+          pairs.add(new Pair(after, tobagoConfig));
+        }
+      }
+    }
+  }
+
+  protected void sort0() {
+    Collections.sort(list, this);
+  }
+
+  private boolean isInRelation(TobagoConfigFragment lower, TobagoConfigFragment higher) {
+    for (Pair p : pairs) {
+      if (p.getLower() == lower && p.getHigher() == higher) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private TobagoConfigFragment findByName(String name) {
+    for (TobagoConfigFragment tobagoConfig : list) {
+      if (name.equals(tobagoConfig.getName())) {
+        return tobagoConfig;
+      }
+    }
+    return null;
+  }
+
+  protected List<Pair> getPairs() {
+    return pairs;
+  }
+
+  private static class Pair {
+
+    private final TobagoConfigFragment lower;
+    private final TobagoConfigFragment higher;
+
+    private Pair(TobagoConfigFragment lower, TobagoConfigFragment higher) {
+      this.lower = lower;
+      this.higher = higher;
+    }
+
+    public TobagoConfigFragment getLower() {
+      return lower;
+    }
+
+    public TobagoConfigFragment getHigher() {
+      return higher;
+    }
+
+    @Override
+    public String toString() {
+      return lower + "<" + higher;
+    }
+  }
+
+}

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=1124660&r1=1124659&r2=1124660&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 Thu May 19 10:17:22 2011
@@ -18,15 +18,14 @@ package org.apache.myfaces.tobago.webapp
  */
 
 import org.apache.myfaces.tobago.config.TobagoConfig;
-import org.apache.myfaces.tobago.config.TobagoConfigParser;
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import java.net.URL;
 
 public class TobagoServletContextListener implements ServletContextListener {
 
@@ -45,30 +44,7 @@ public class TobagoServletContextListene
       return;
     }
 
-    try {
-
-      // tobago-config.xml
-      // TobagoConfig tobagoConfig = new TobagoConfigParser().parse(servletContext);
-      final String configPath = "/WEB-INF/tobago-config.xml";
-      final URL url = servletContext.getResource(configPath);
-      final TobagoConfig tobagoConfig = new TobagoConfigParser().parse(url);
-
-      servletContext.setAttribute(TobagoConfig.TOBAGO_CONFIG, tobagoConfig);
-
-      // todo: cleanup, use one central TobagoConfig, no singleton ResourceManager
-      // resources
-      tobagoConfig.initProjectState(servletContext);
-      ResourceManagerFactory.init(servletContext, tobagoConfig);
-      // prepare themes
-      tobagoConfig.resolveThemes();
-
-    } catch (Throwable e) {
-      if (LOG.isErrorEnabled()) {
-        String error = "Error while deploy process. Tobago can't be initialized! Application will not run!";
-        LOG.error(error, e);
-        throw new RuntimeException(error, e);
-      }
-    }
+    TobagoConfigBuilder.init(servletContext);
   }
 
   public void contextDestroyed(ServletContextEvent event) {

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/context/ThemeParserTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/context/ThemeParserTest.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/context/ThemeParserTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/context/ThemeParserTest.java Thu May 19 10:17:22 2011
@@ -17,7 +17,8 @@ package org.apache.myfaces.tobago.contex
  * limitations under the License.
  */
 
-import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.internal.config.ThemeParser;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
 import org.junit.Assert;
 import org.junit.Test;
 import org.xml.sax.SAXException;
@@ -30,7 +31,7 @@ public class ThemeParserTest {
 
   @Test
   public void test() throws IOException, SAXException {
-    TobagoConfig config = new TobagoConfig();
+    TobagoConfigImpl config = new TobagoConfigImpl();
     ThemeBuilder themeBuilder = new ThemeBuilder(config);
     ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
     Enumeration<URL> urls = classLoader.getResources("theme-config.xml");

Added: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorterUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorterUnitTest.java?rev=1124660&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorterUnitTest.java (added)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/config/TobagoConfigSorterUnitTest.java Thu May 19 10:17:22 2011
@@ -0,0 +1,195 @@
+package org.apache.myfaces.tobago.internal.config;
+
+/*
+ * 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.
+ */
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class TobagoConfigSorterUnitTest {
+
+  @Test
+  public void testCompare() {
+
+    // config + names
+
+    TobagoConfigFragment a = new TobagoConfigFragment();
+    a.setName("a");
+
+    TobagoConfigFragment b = new TobagoConfigFragment();
+    b.setName("b");
+
+    TobagoConfigFragment c = new TobagoConfigFragment();
+    c.setName("c");
+
+    TobagoConfigFragment d = new TobagoConfigFragment();
+    d.setName("d");
+
+    TobagoConfigFragment e = new TobagoConfigFragment();
+    e.setName("e");
+
+    TobagoConfigFragment f = new TobagoConfigFragment();
+    f.setName("f");
+
+    TobagoConfigFragment m = new TobagoConfigFragment();
+    m.setName("m");
+
+    TobagoConfigFragment n = new TobagoConfigFragment();
+    n.setName("n");
+
+    // unnamed
+    TobagoConfigFragment u1 = new TobagoConfigFragment();
+    TobagoConfigFragment u2 = new TobagoConfigFragment();
+    TobagoConfigFragment u3 = new TobagoConfigFragment();
+
+    // before
+    a.getBefore().add("b");
+    b.getBefore().add("c");
+
+    u1.getBefore().add("d");
+    u2.getBefore().add("d");
+
+    u2.getBefore().add("y"); // not relevant
+
+    // after
+    e.getAfter().add("d");
+    f.getAfter().add("e");
+
+    u1.getAfter().add("c");
+    u2.getAfter().add("c");
+
+    u2.getAfter().add("z"); // not relevant
+
+    n.getAfter().add("m");
+
+    List<TobagoConfigFragment> list = new ArrayList<TobagoConfigFragment>();
+    list.add(a);
+    list.add(b);
+    list.add(c);
+    list.add(d);
+    list.add(e);
+    list.add(f);
+    list.add(u1);
+    list.add(u2);
+    list.add(u3);
+    list.add(m);
+    list.add(n);
+
+    TobagoConfigSorter sorter = new TobagoConfigSorter(list);
+    sorter.createRelevantPairs();
+
+    Assert.assertEquals(9, sorter.getPairs().size()); // all but these with "z" and "y"
+
+    sorter.makeTransitive();
+
+    Assert.assertEquals(28, sorter.getPairs().size());
+
+    sorter.ensureIrreflexive();
+
+    sorter.ensureAntiSymmetric();
+
+    sorter.sort0();
+
+    Assert.assertEquals(a, list.get(0));
+    Assert.assertEquals(b, list.get(1));
+    Assert.assertEquals(c, list.get(2));
+    Assert.assertEquals(u1, list.get(3));
+    Assert.assertEquals(u2, list.get(4));
+    Assert.assertEquals(d, list.get(5));
+    Assert.assertEquals(e, list.get(6));
+    Assert.assertEquals(f, list.get(7));
+    Assert.assertEquals(u3, list.get(8));
+    Assert.assertEquals(m, list.get(9));
+    Assert.assertEquals(n, list.get(10));
+  }
+
+  @Test
+  public void testCycle() {
+
+    // config + names
+
+    TobagoConfigFragment a = new TobagoConfigFragment();
+    a.setName("a");
+
+    TobagoConfigFragment b = new TobagoConfigFragment();
+    b.setName("b");
+
+    // before
+    a.getBefore().add("b");
+    b.getBefore().add("a");
+
+    List<TobagoConfigFragment> list = new ArrayList<TobagoConfigFragment>();
+    list.add(a);
+    list.add(b);
+
+    TobagoConfigSorter sorter = new TobagoConfigSorter(list);
+    sorter.createRelevantPairs();
+
+    Assert.assertEquals(2, sorter.getPairs().size()); // all but these with "z" and "y"
+
+    sorter.makeTransitive();
+
+    try {
+      sorter.ensureIrreflexive();
+      sorter.ensureAntiSymmetric();
+
+      Assert.fail("Cycle was not found");
+    } catch (RuntimeException e) {
+      // must find the cycle
+    }
+  }
+
+  @Test
+  public void testCycle2() {
+
+    // config + names
+
+    TobagoConfigFragment a = new TobagoConfigFragment();
+    a.setName("a");
+
+    TobagoConfigFragment b = new TobagoConfigFragment();
+    b.setName("b");
+
+    // before
+    a.getBefore().add("b");
+    // after
+    a.getAfter().add("b");
+
+    List<TobagoConfigFragment> list = new ArrayList<TobagoConfigFragment>();
+    list.add(a);
+    list.add(b);
+
+    TobagoConfigSorter sorter = new TobagoConfigSorter(list);
+    sorter.createRelevantPairs();
+
+    Assert.assertEquals(2, sorter.getPairs().size()); // all but these with "z" and "y"
+
+    sorter.makeTransitive();
+
+    try {
+      sorter.ensureIrreflexive();
+      sorter.ensureAntiSymmetric();
+
+      Assert.fail("Cycle was not found");
+    } catch (RuntimeException e) {
+      // must find the cycle
+    }
+  }
+}

Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java?rev=1124660&r1=1124659&r2=1124660&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/AbstractTobagoTestBase.java Thu May 19 10:17:22 2011
@@ -28,6 +28,7 @@ import org.apache.myfaces.tobago.config.
 import org.apache.myfaces.tobago.context.ClientProperties;
 import org.apache.myfaces.tobago.context.ResourceManagerFactory;
 import org.apache.myfaces.tobago.context.Theme;
+import org.apache.myfaces.tobago.internal.config.TobagoConfigImpl;
 import org.junit.After;
 import org.junit.Before;
 import org.slf4j.Logger;
@@ -63,7 +64,7 @@ public abstract class AbstractTobagoTest
 
     // Tobago specific extensions
 
-    TobagoConfig tobagoConfig = new TobagoConfig();
+    TobagoConfigImpl tobagoConfig = new TobagoConfigImpl();
     Theme theme = new MockTheme("default", "Default Mock Theme", Collections.EMPTY_LIST);
     Theme one = new MockTheme("one", "Mock Theme One", Arrays.asList(theme));
     Map<String, Theme> availableThemes = new HashMap<String, Theme>();