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 2006/03/29 01:07:28 UTC

svn commit: r389621 - in /incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago: config/ context/ renderkit/ webapp/

Author: lofwyr
Date: Tue Mar 28 15:07:26 2006
New Revision: 389621

URL: http://svn.apache.org/viewcvs?rev=389621&view=rev
Log:
fix TOBAGO-48 evaluate the resource-path from the tobago-theme.xml

Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ClientProperties.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/config/TobagoConfig.java Tue Mar 28 15:07:26 2006
@@ -26,6 +26,8 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
 
 public class TobagoConfig {
   private static final Log LOG = LogFactory.getLog(TobagoConfig.class);
@@ -37,7 +39,7 @@
   private List<String> supportedThemeNames;
   private Theme defaultTheme;
   private String defaultThemeName;
-  private List<String> resourceDirs;
+  private Set<String> resourceDirs;
   private boolean loadThemesFromClasspath = true;
   private List<MappingRule> mappingRules;
   private boolean ajaxEnabled;
@@ -47,7 +49,7 @@
   public TobagoConfig() {
     supportedThemeNames = new ArrayList<String>();
     supportedThemes = new ArrayList<Theme>();
-    resourceDirs = new ArrayList<String>();
+    resourceDirs = new HashSet<String>();
   }
 
   public void addMappingRule(MappingRule mappingRule) {
@@ -146,11 +148,13 @@
   }
 
   public void addResourceDir(String resourceDir) {
-    LOG.info("resourceDir = '" + resourceDir + "'");
+    if (LOG.isInfoEnabled()) {
+      LOG.info("adding resourceDir = '" + resourceDir + "'");
+    }
     resourceDirs.add(resourceDir);
   }
 
-  public List<String> getResourceDirs() {
+  public Set<String> getResourceDirs() {
     return resourceDirs;
   }
 

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ClientProperties.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ClientProperties.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ClientProperties.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ClientProperties.java Tue Mar 28 15:07:26 2006
@@ -141,7 +141,8 @@
     return client;
   }
 
-  public static List getLocaleList(Locale locale, boolean propertyPathMode) {
+  public static List<String> getLocaleList(
+      Locale locale, boolean propertyPathMode) {
 
     String string = locale.toString();
     String prefix = propertyPathMode ? "" : "_";

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceLocator.java Tue Mar 28 15:07:26 2006
@@ -63,7 +63,7 @@
     this.loadThemesFromClasspath = loadThemesFromClasspath;
   }
 
-  public void init()
+  public void locate()
       throws ServletException {
     locateResourcesInWar(servletContext, resourceManager, "/");
     locateResourcesFromClasspath(resourceManager);

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java Tue Mar 28 15:07:26 2006
@@ -21,6 +21,7 @@
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
+import java.util.Map;
 
 public class ResourceManagerFactory {
 
@@ -43,24 +44,27 @@
     return (ResourceManager) servletContext.getAttribute(RESOURCE_MANAGER);
   }
 
-  public static ResourceManagerImpl init(
+  public static void init(
       ServletContext servletContext, TobagoConfig tobagoConfig)
       throws ServletException {
     assert !initialized;
-    ResourceManagerImpl resourceManager = new ResourceManagerImpl();
+    ResourceManagerImpl resourceManager
+        = new ResourceManagerImpl(tobagoConfig);
 
     ThemeBuilder themeBuilder = new ThemeBuilder();
     ResourceLocator resourceLocator = new ResourceLocator(
         servletContext, resourceManager, themeBuilder,
         tobagoConfig.isLoadThemesFromClasspath());
-    resourceLocator.init();
-    tobagoConfig.setAvailableThemes(themeBuilder.resolveThemes());
+    resourceLocator.locate();
+    Map<String, Theme> availableThemes = themeBuilder.resolveThemes();
+    tobagoConfig.setAvailableThemes(availableThemes);
+    for (Theme theme : availableThemes.values()) {
+      tobagoConfig.addResourceDir(theme.getResourcePath());
+    }
 
     servletContext.setAttribute(RESOURCE_MANAGER, resourceManager);
 
     initialized = true;
-
-    return resourceManager;
   }
 
   public static void release(ServletContext servletContext) {

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerImpl.java Tue Mar 28 15:07:26 2006
@@ -1,7 +1,7 @@
 package org.apache.myfaces.tobago.context;
 
 /*
- * Copyright 2002-2005 The Apache Software Foundation.
+ * Copyright 2002-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,13 +20,11 @@
 import org.apache.commons.logging.LogFactory;
 import static org.apache.myfaces.tobago.TobagoConstants.RENDERER_TYPE_OUT;
 import org.apache.myfaces.tobago.config.TobagoConfig;
-import org.apache.myfaces.tobago.renderkit.TobagoRenderKit;
 
 import javax.faces.component.UIViewRoot;
 import javax.faces.render.Renderer;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
@@ -42,18 +40,12 @@
 
   private final Cache cache;
 
-  private final List<String> resourceDirectories;
-
-  private final List<String> classDirectories;
-
   private TobagoConfig tobagoConfig;
 
-  public ResourceManagerImpl() {
+  public ResourceManagerImpl(TobagoConfig tobagoConfig) {
     resourceList = new Properties();
     cache = new Cache();
-    resourceDirectories = new ArrayList<String>(2);
-    classDirectories = new ArrayList<String>(1);
-    classDirectories.add(TobagoRenderKit.PACKAGE_PREFIX.replace('.', '/'));
+    this.tobagoConfig = tobagoConfig;
   }
 
   public void add(String resourceKey) {
@@ -71,14 +63,6 @@
     resourceList.put(resourceKey, value);
   }
 
-  public void addResourceDirectory(String resourceDirectory) {
-    this.resourceDirectories.add(resourceDirectory);
-    if (LOG.isDebugEnabled()) {
-      LOG.debug(
-          "Adding resourceDirectory '" + resourceDirectory + "' to " + this);
-    }
-  }
-
   public double getCacheCoverage() {
     return cache.found + cache.miss > 0
         ? cache.found / (double) (cache.found + cache.miss) : 0;
@@ -107,7 +91,7 @@
       if (result == null) {
         // TODO: cache null values
         try {
-          List paths = getPaths(clientPropertyId, locale, resourceDirectories, "", null,
+          List paths = getPaths(clientPropertyId, locale, "", null,
               name.substring(0, dot), name.substring(dot), false, true, true, null,
               true, ignoreMissing);
           if (paths != null) {
@@ -146,7 +130,7 @@
         return result;
       }
       try {
-        result = (String) getPaths(clientPropertyId, locale, resourceDirectories, "",
+        result = (String) getPaths(clientPropertyId, locale, "",
             type, name, "", false, true, true, null, true, false).get(0);
         cache.put(key, result);
       } catch (Exception e) {
@@ -177,7 +161,7 @@
       if (result != null) {
         return result;
       }
-      List properties = getPaths(clientPropertyId, locale, resourceDirectories, "", type, bundle,
+      List properties = getPaths(clientPropertyId, locale, "", type, bundle,
           "", false, true, false, propertyKey, true, false);
       if (properties != null) {
         result = (String) properties.get(0);
@@ -204,7 +188,7 @@
     return buffer.toString();
   }
 
-  private List getPaths(String clientProperties, Locale locale, List<String> mainDirectories, String prefix,
+  private List getPaths(String clientProperties, Locale locale, String prefix,
       String subDir, String name, String suffix,
       boolean reverseOrder, boolean single, boolean returnKey,
       String key, boolean returnStrings, boolean ignoreMissing) {
@@ -214,12 +198,12 @@
     String contentType = tokenizer.nextToken();
     Theme theme = tobagoConfig.getTheme(tokenizer.nextToken());
     UserAgent browser = UserAgent.getInstanceForId(tokenizer.nextToken());
-    List locales = ClientProperties.getLocaleList(locale, false);
+    List<String> locales = ClientProperties.getLocaleList(locale, false);
 
     String path;
 
     // e.g. 1. application, 2. library or renderkit
-    for (String resourceDirectory : mainDirectories) {
+    for (String resourceDirectory : tobagoConfig.getResourceDirs()) {
       for (Theme themeName : theme.getFallbackList()) { // theme loop
         for (String browserType : browser.getFallbackList()) { // browser loop
           for (Object locale1 : locales) { // locale loop
@@ -268,9 +252,7 @@
         }
       }
     }
-    Iterator localeIterator = locales.iterator();
-    while (localeIterator.hasNext()) { // locale loop
-      String localeSuffix = (String) localeIterator.next();
+    for (String localeSuffix : locales) { // locale loop
       path = makePath(name, localeSuffix, suffix, key);
       if (LOG.isDebugEnabled()) {
         LOG.debug("testing path: " + path);
@@ -307,7 +289,7 @@
     if (matches.size() == 0) {
       if (!ignoreMissing) {
         LOG.error("Path not found, and no fallback. Using empty string.\n"
-            + "mainDirs = '" + mainDirectories
+            + "resourceDirs = '" + tobagoConfig.getResourceDirs()
             + "' contentType = '" + contentType
             + "' theme = '" + theme
             + "' browser = '" + browser
@@ -407,7 +389,7 @@
 
       try {
         name = getRendererClassName(name);
-        Class clazz = (Class) getPaths(clientPropertyId, locale, classDirectories, "", type, name,
+        Class clazz = (Class) getPaths(clientPropertyId, locale, "", type, name,
             "", false, true, true, null, false, false).get(0);
         renderer = (Renderer) clazz.newInstance();
         cache.put(key, renderer);
@@ -536,7 +518,7 @@
         return result;
       }
       try {
-        List matches = getPaths(clientPropertyId, locale, resourceDirectories, "",
+        List matches = getPaths(clientPropertyId, locale, "",
             type, name.substring(0, dot),
             name.substring(dot), true, false, true, null, true, false);
         result = (String[]) matches.toArray(new String[matches.size()]);
@@ -560,7 +542,7 @@
       if (result != null) {
         return result;
       }
-      List properties = getPaths(clientPropertyId, locale, resourceDirectories, "", type, bundle,
+      List properties = getPaths(clientPropertyId, locale, "", type, bundle,
           "", false, true, false, propertyKey, true, true);
       if (properties != null) {
         result = (String) properties.get(0);
@@ -571,17 +553,6 @@
     }
     return result;
   }
-
-// ------------------------------------------------------------ getter + setter
-
-  public List<String> getResourceDirectories() {
-    return resourceDirectories;
-  }
-
-  public void setTobagoConfig(TobagoConfig tobagoConfig) {
-    this.tobagoConfig = tobagoConfig;
-  }
-
 
   private class Cache extends HashMap {
 

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java Tue Mar 28 15:07:26 2006
@@ -1,5 +1,21 @@
 package org.apache.myfaces.tobago.context;
 
+/*
+ * Copyright 2002-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.List;
 
 /**
@@ -12,4 +28,6 @@
   List<Theme> getFallbackList();
 
   String getDisplayName();
+
+  String getResourcePath();
 }

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java Tue Mar 28 15:07:26 2006
@@ -34,7 +34,6 @@
 
   private String deprecatedName;
 
-  // TODO: is to be implemented
   private String resourcePath;
 
   private ThemeImpl fallback;
@@ -107,7 +106,7 @@
   }
 
   public String toString() {
-    LOG.warn("Should not be called!", new Exception());
+//    LOG.warn("Should not be called!", new Exception());
     return name;
   }
 }

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/TobagoRenderKit.java Tue Mar 28 15:07:26 2006
@@ -37,12 +37,6 @@
 
   public static final String RENDER_KIT_ID = "tobago";
 
-  public static final String PACKAGE_PREFIX
-      = TobagoRenderKit.class.getName().substring(
-          0, TobagoRenderKit.class.getName().lastIndexOf('.'));
-
-  public static final int PACKAGE_PREFIX_LENGTH = PACKAGE_PREFIX.length();
-
   private ResourceManager resources;
 
   // FIXME: use family

Modified: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java?rev=389621&r1=389620&r2=389621&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java (original)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/webapp/TobagoServletContextListener.java Tue Mar 28 15:07:26 2006
@@ -22,8 +22,7 @@
 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.ResourceManager;
-import org.apache.myfaces.tobago.context.ResourceManagerImpl;
+import org.apache.myfaces.tobago.context.Theme;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
@@ -57,15 +56,9 @@
 
       // todo: cleanup, use one central TobagoConfig, no singleton ResourceManager
       // resources
-      ResourceManagerImpl resourceManager
-          = ResourceManagerFactory.init(servletContext, tobagoConfig);
-      resourceManager.setTobagoConfig(tobagoConfig);
-      for (String dir : tobagoConfig.getResourceDirs()) {
-        if (LOG.isDebugEnabled()) {
-          LOG.debug("Locating resources in dir: " + dir);
-        }
-        resourceManager.addResourceDirectory(dir);
-      }
+      ResourceManagerFactory.init(servletContext, tobagoConfig);
+
+      // prepare themes
       tobagoConfig.resoveThemes();
 
       // theme config cache