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/02/10 00:26:44 UTC

svn commit: r376486 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/context/ tobago-example/tobago-example-demo/ tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/ tobago-theme/tobago-theme-richmond/src/main/r...

Author: lofwyr
Date: Thu Feb  9 15:26:40 2006
New Revision: 376486

URL: http://svn.apache.org/viewcvs?rev=376486&view=rev
Log:
Working on MYFACES-1106: Simplify the Theme Handling

Added:
    incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/
    incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/
    incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml
    incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/
    incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/
    incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml
Modified:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
    incubator/tobago/trunk/tobago-example/tobago-example-demo/pom.xml
    incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
    incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml

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=376486&r1=376485&r2=376486&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 Thu Feb  9 15:26:40 2006
@@ -39,6 +39,12 @@
   public static final String RESOURCE_MANAGER
       = "org.apache.myfaces.tobago.context.ResourceManager";
 
+  // todo: Test for new theme build mechanism still under development
+  // http://issues.apache.org/jira/browse/MYFACES-1106
+  // to activate you have to do:
+  // 1. set USE_JAR_THEME_RESOURCE = true, of course
+  // 2. add resource-path in tobago-config.xml
+  // 3. add ResourceServlet in web.xml
   public static final boolean USE_JAR_THEME_RESOURCE = false;
 
   private ResourceManagerFactory() {
@@ -62,10 +68,7 @@
       throws ServletException {
     assert !initialized;
     ResourceManagerImpl resources = new ResourceManagerImpl();
-    locateResources(servletContext, resources, "/");
-    if (USE_JAR_THEME_RESOURCE) {
-      locateResources2(servletContext, resources);
-    }
+    locateResourcesInWar(servletContext, resources, "/");
     for (String dir : tobagoConfig.getResourceDirs()) {
       if (LOG.isDebugEnabled()) {
         LOG.debug("Locating resources in dir: " + dir);
@@ -78,75 +81,90 @@
     initialized = true;
   }
 
-  private static void locateResources2(
-      ServletContext servletContext, ResourceManagerImpl resources)
+  private static void locateResourcesInLib(
+      ServletContext servletContext, ResourceManagerImpl resources, String jarPath)
       throws ServletException {
-    String path = "/WEB-INF/lib/";
-    String resourcePrefix = "/tobago-theme-resources/";
-    LOG.info("childPath = '" + path + "'");
-    Set<String> resourcePaths = servletContext.getResourcePaths(path);
-    for (String childPath : resourcePaths) {
-      LOG.info("childPath = '" + childPath + "'");
-      if (childPath.equals(path)) {
-        continue;
-      }
-      if (childPath.startsWith(path + "tobago-theme-")
-          && childPath.endsWith(".jar")) {
 
-        InputStream stream = null;
-        try {
-          stream = servletContext.getResourceAsStream(childPath);
-          ZipInputStream zip = new ZipInputStream(stream);
-          while (zip.available() > 0) {
-            ZipEntry nextEntry = zip.getNextEntry();
-            if (nextEntry == null || nextEntry.isDirectory()) {
-              continue;
-            }
-            String name = nextEntry.getName();
-            LOG.info("name = '" + name + "'");
-            String prefix = "org/apache/myfaces/tobago/renderkit/";
-            if (name.startsWith(prefix)) {
-              if (name.endsWith(".gif")
-                  || name.endsWith(".jpg")
-                  || name.endsWith(".png")
-                  || name.endsWith(".js")
-                  || name.endsWith(".css")) {
-//                String resourceKey = resourcePrefix + name.substring(prefix.length());
-                LOG.info("*  /" + name);
-                resources.add("/" + name);
-              } else if (name.endsWith(".properties")) {
-//                String resourceKey = resourcePrefix + name.substring(prefix.length());
-                LOG.info("** " + name);
-                addProperties2(resources, name, prefix, resourcePrefix, false);
-              } else if (name.endsWith(".properties.xml")) {
-//                String resourceKey = resourcePrefix + name.substring(prefix.length());
-                LOG.info("** " + name);
-                addProperties2(resources, name, prefix, resourcePrefix, true);
-              }
-            }
+    InputStream stream = null;
+    try {
+      if (findThemeDescriptor(servletContext, jarPath)) {
+
+        ClassLoader classLoader = ResourceManagerFactory.class.getClassLoader();
+
+        stream = servletContext.getResourceAsStream(jarPath);
+        ZipInputStream zip = new ZipInputStream(stream);
+        while (zip.available() > 0) {
+          ZipEntry nextEntry = zip.getNextEntry();
+          if (nextEntry == null || nextEntry.isDirectory()) {
+            continue;
           }
-        } catch (IOException e) {
-          String msg = "while loading " + childPath;
-          if (LOG.isErrorEnabled()) {
-            LOG.error(msg, e);
+          String name = "/" + nextEntry.getName();
+          LOG.info("name = '" + name + "'");
+          String prefix = "/org/apache/myfaces/tobago/renderkit/";
+          if (name.startsWith(prefix)) {
+            if (name.endsWith(".class")) {
+              // ignore the class files
+            } else if (name.endsWith(".properties")) {
+              LOG.info("** " + name.substring(1));
+              InputStream inputStream = classLoader.getResourceAsStream(name.substring(1));
+              addProperties(inputStream, resources, name, false);
+            } else if (name.endsWith(".properties.xml")) {
+              LOG.info("** " + name.substring(1));
+              InputStream inputStream = classLoader.getResourceAsStream(name.substring(1));
+              LOG.info(inputStream);
+              addProperties(inputStream, resources, name, true);
+            } else {
+              resources.add(name);
+            }
           }
-          throw new ServletException(msg, e);
-        } finally {
-          IOUtils.closeQuietly(stream);
         }
       }
+    } catch (IOException e) {
+      String msg = "while loading " + jarPath;
+      if (LOG.isErrorEnabled()) {
+        LOG.error(msg, e);
+      }
+      throw new ServletException(msg, e);
+    } finally {
+      IOUtils.closeQuietly(stream);
     }
   }
 
+  private static boolean findThemeDescriptor(
+      ServletContext servletContext, String jarPath) throws IOException {
+    InputStream stream = servletContext.getResourceAsStream(jarPath);
+    ZipInputStream zip = new ZipInputStream(stream);
+    while (zip.available() > 0) {
+      ZipEntry nextEntry = zip.getNextEntry();
+      if (nextEntry == null || nextEntry.isDirectory()) {
+        continue;
+      }
+      String name = nextEntry.getName();
+      if (name.equals("META-INF/tobago-theme.xml")) {
+        return true;
+      }
+    }
+    return false;
+  }
 
-  private static void locateResources(
+  private static void locateResourcesInWar(
       ServletContext servletContext, ResourceManagerImpl resources, String path)
       throws ServletException {
 
+    if (path.equals("/WEB-INF/") || path.equals("/WEB-INF/lib/")) {
+      if (USE_JAR_THEME_RESOURCE) {
+        // continue
+      } else {
+        return; // ignore
+      }
+    } else if (path.startsWith("/WEB-INF/")) {
+      return; // ignore
+    }
+
     Set<String> resourcePaths = servletContext.getResourcePaths(path);
     if (resourcePaths == null || resourcePaths.isEmpty()) {
       if (LOG.isErrorEnabled()) {
-        LOG.error("ResourcePath empty! Please check the web.xml file!"
+        LOG.error("ResourcePath empty! Please check the tobago-config.xml file!"
             + " path='" + path + "'");
       }
       return;
@@ -155,15 +173,21 @@
       if (childPath.endsWith("/")) {
         // ignore, because weblogic puts the path directory itself in the Set
         if (!childPath.equals(path)) {
-          //Log.debug("dir      " + childPath);
-          locateResources(servletContext, resources, childPath);
+          LOG.info("childPath dir " + childPath);
+          locateResourcesInWar(servletContext, resources, childPath);
         }
       } else {
         //Log.debug("add resc " + childPath);
         if (childPath.endsWith(".properties")) {
-          addProperties(servletContext, resources, childPath, false);
+          InputStream inputStream = servletContext.getResourceAsStream(childPath);
+          addProperties(inputStream, resources, childPath, false);
         } else if (childPath.endsWith(".properties.xml")) {
-          addProperties(servletContext, resources, childPath, true);
+          InputStream inputStream = servletContext.getResourceAsStream(childPath);
+          addProperties(inputStream, resources, childPath, true);
+        } else if (childPath.startsWith("/WEB-INF/lib/") && childPath.endsWith(".jar")) {
+          if (USE_JAR_THEME_RESOURCE) {
+            locateResourcesInLib(servletContext, resources, childPath);
+          }
         } else {
           resources.add(childPath);
           //Log.debug(childPath);
@@ -173,7 +197,7 @@
   }
 
   private static void addProperties(
-      ServletContext servletContext, ResourceManagerImpl resources,
+      InputStream stream, ResourceManagerImpl resources,
       String childPath, boolean xml)
       throws ServletException {
 
@@ -198,9 +222,7 @@
 
 
     Properties temp = new Properties();
-    InputStream stream = null;
     try {
-      stream = servletContext.getResourceAsStream(childPath);
       if (xml) {
         temp.loadFromXML(stream);
         if (LOG.isDebugEnabled()) {
@@ -229,71 +251,6 @@
       resources.add(directory + '/' + locale + '/' + key, temp.getProperty(key));
       if (LOG.isDebugEnabled()) {
         LOG.debug(directory + '/' + locale + '/' + key + "=" + temp.getProperty(key));
-      }
-    }
-  }
-
-  private static void addProperties2(
-      ResourceManagerImpl resources,
-      String childPath, String prefix, String resourcePrefix, boolean xml)
-      throws ServletException {
-
-//    resourcePrefix = "/tobago/"; // fixme
-
-    String directory = childPath.substring(0, childPath.lastIndexOf('/'));
-    String filename = childPath.substring(childPath.lastIndexOf('/') + 1);
-
-    int begin = filename.indexOf('_') + 1;
-    int end = filename.lastIndexOf('.');
-    if (xml) {
-      end = filename.lastIndexOf('.', end - 1);
-    }
-
-    String locale;
-/*
-    if (begin > 0) {
-      locale = filename.substring(begin, end);
-    } else {
-      locale = "default";
-    }
-*/
-    locale = filename.substring(0, end);
-
-
-    Properties temp = new Properties();
-    InputStream stream = null;
-    try {
-      stream = ResourceManagerFactory.class.getClassLoader().getResourceAsStream(childPath);
-      if (xml) {
-        temp.loadFromXML(stream);
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(childPath);
-          LOG.debug("xml properties: " + temp.size());
-        }
-      } else {
-        temp.load(stream);
-        if (LOG.isDebugEnabled()) {
-          LOG.debug(childPath);
-          LOG.debug("    properties: " + temp.size());
-        }
-      }
-    } catch (IOException e) {
-      String msg = "while loading " + childPath;
-      if (LOG.isErrorEnabled()) {
-        LOG.error(msg, e);
-      }
-      throw new ServletException(msg, e);
-    } finally {
-      IOUtils.closeQuietly(stream);
-    }
-
-    for (Enumeration e = temp.propertyNames(); e.hasMoreElements();) {
-      String key = (String) e.nextElement();
-//      String prepath = resourcePrefix + directory.substring(prefix.length());
-      String prepath = directory;
-      resources.add('/' + prepath + '/' + locale + '/' + key, temp.getProperty(key));
-      if (LOG.isDebugEnabled()) {
-        LOG.debug('/' + prepath + '/' + locale + '/' + key + "=" + temp.getProperty(key));
       }
     }
   }

Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/pom.xml?rev=376486&r1=376485&r2=376486&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/pom.xml (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/pom.xml Thu Feb  9 15:26:40 2006
@@ -31,6 +31,7 @@
   <build>
     <finalName>tobago-example-demo</finalName>
     <plugins>
+      <!--may be removed after solving http://issues.apache.org/jira/browse/MYFACES-1106-->
       <plugin>
         <groupId>org.apache.myfaces.tobago</groupId>
         <artifactId>maven-theme-plugin</artifactId>

Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml?rev=376486&r1=376485&r2=376486&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/tobago-config.xml Thu Feb  9 15:26:40 2006
@@ -30,8 +30,12 @@
   <resource-dir>tobago-resource</resource-dir>
   <resource-dir>tobago</resource-dir>
 
-  <!--test for new theme build mechanism-->
+  <!--
+    todo: Test for new theme build mechanism still under development
+    http://issues.apache.org/jira/browse/MYFACES-1106
+  -->
   <!--<resource-dir>org/apache/myfaces/tobago/renderkit</resource-dir>-->
+  <!--this may not necessary, if there is a META-INF/theme-config.xml in a later version -->
 
   <ajax-enabled>false</ajax-enabled>
 </tobago-config>

Modified: incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml?rev=376486&r1=376485&r2=376486&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml (original)
+++ incubator/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/web.xml Thu Feb  9 15:26:40 2006
@@ -58,7 +58,10 @@
     <load-on-startup>2</load-on-startup>
   </servlet>
 
-  <!--test for the theme mechandism-->
+  <!--
+    todo: Test still under development
+    http://issues.apache.org/jira/browse/MYFACES-1106
+  -->
 <!--
   <servlet>
     <servlet-name>ResourceServlet</servlet-name>
@@ -68,7 +71,10 @@
 
   <!-- servlet-mapping -->
 
-  <!--test for the theme mechandism-->
+  <!--
+    todo: Test still under development
+    http://issues.apache.org/jira/browse/MYFACES-1106
+  -->
 <!--
   <servlet-mapping>
     <servlet-name>ResourceServlet</servlet-name>

Added: incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml?rev=376486&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml (added)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml Thu Feb  9 15:26:40 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Copyright 2002-2005 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.
+-->
+
+<!--
+  todo: Test still under development
+  http://issues.apache.org/jira/browse/MYFACES-1106
+-->
+<tobago-theme>
+  <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+</tobago-theme>

Added: incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml?rev=376486&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml (added)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml Thu Feb  9 15:26:40 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Copyright 2002-2005 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.
+-->
+
+<!--
+  todo: Test still under development
+  http://issues.apache.org/jira/browse/MYFACES-1106
+-->
+<tobago-theme>
+  <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+</tobago-theme>

Added: incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml?rev=376486&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml (added)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml Thu Feb  9 15:26:40 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Copyright 2002-2005 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.
+-->
+
+<!--
+  todo: Test still under development
+  http://issues.apache.org/jira/browse/MYFACES-1106
+-->
+<tobago-theme>
+  <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+</tobago-theme>

Added: incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml?rev=376486&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml (added)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml Thu Feb  9 15:26:40 2006
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Copyright 2002-2005 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.
+-->
+
+<!--
+  todo: Test still under development
+  http://issues.apache.org/jira/browse/MYFACES-1106
+-->
+<tobago-theme>
+  <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+</tobago-theme>