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/15 01:06:08 UTC

svn commit: r377902 - in /incubator/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/config/ tobago-core/src/main/java/org/apache/myfaces/tobago/context/ tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/ tobago-theme/toba...

Author: lofwyr
Date: Tue Feb 14 16:06:06 2006
New Revision: 377902

URL: http://svn.apache.org/viewcvs?rev=377902&view=rev
Log:
parsing the theme descriptor file to the the resource-path, when "load-themes-from-classpath" is active

Added:
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
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/ResourceLocator.java
    incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
    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/tobago-theme.xml
    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/tobago-theme.xml

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=377902&r1=377901&r2=377902&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 Feb 14 16:06:06 2006
@@ -60,6 +60,7 @@
 
   public void setDefaultThemeClass(String name) {
     try {
+      
       defaultTheme = (Theme) Class.forName(name).newInstance();
     } catch (Exception e) {
       String error = "Cannot create Theme from name: '" + name + "'";

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=377902&r1=377901&r2=377902&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 Feb 14 16:06:06 2006
@@ -107,7 +107,7 @@
   private void locateResourcesInLib(ResourceManagerImpl resources)
       throws ServletException {
 
-//    ThemeParser parser = new ThemeParser(tobagoConfig);
+    ThemeParser parser = new ThemeParser();
     InputStream stream = null;
     try {
       LOG.error("Loading tobago-theme.xml");
@@ -116,7 +116,8 @@
       while (urls.hasMoreElements()) {
         URL themeUrl = urls.nextElement();
 
-//        parser.parse(themeUrl.openStream());
+        Theme theme = parser.parse(themeUrl);
+        String prefix = ensureSlash(theme.getResourcePath());
 
         // TODO other protocols
         if ("jar".equals(themeUrl.getProtocol())) {
@@ -132,8 +133,6 @@
                 continue;
               }
               String name = "/" + nextEntry.getName();
-              //LOG.error("name = '" + name + "'");
-              String prefix = "/org/apache/myfaces/tobago/renderkit/";
               if (name.startsWith(prefix)) {
                 if (name.endsWith(".class")) {
                   // ignore the class files
@@ -165,6 +164,16 @@
       }
       throw new ServletException(msg, e);
     }
+  }
+
+  private String ensureSlash(String resourcePath) {
+    if (!resourcePath.startsWith("/")) {
+      resourcePath = '/' + resourcePath;
+    }
+    if (!resourcePath.endsWith("/")) {
+      resourcePath = resourcePath + '/';
+    }
+    return resourcePath;
   }
 
   private void addProperties(

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=377902&r1=377901&r2=377902&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 Feb 14 16:06:06 2006
@@ -21,13 +21,17 @@
 import java.util.Collections;
 import java.util.List;
 
-public abstract class Theme implements Serializable {
+public class Theme implements Serializable {
 
   private String name;
+  private String resourcePath;
   private String displayName;
   private Theme fallback;
   private List<Theme> fallbackList;
 
+  public Theme() {
+  }
+
   protected Theme(String name, String displayName, Theme fallback) {
     this.name = name;
     this.displayName = displayName;
@@ -56,6 +60,18 @@
     return name;
   }
 
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public String getResourcePath() {
+    return resourcePath;
+  }
+
+  public void setResourcePath(String resourcePath) {
+    this.resourcePath = resourcePath;
+  }
+
   public String toString() {
     return name;
   }
@@ -86,5 +102,7 @@
     result = 29 * result + (fallback != null ? fallback.hashCode() : 0);
     return result;
   }
+
+
 }
 

Added: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java?rev=377902&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java (added)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeParser.java Tue Feb 14 16:06:06 2006
@@ -0,0 +1,59 @@
+package org.apache.myfaces.tobago.context;
+
+import org.apache.commons.digester.Digester;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.xml.sax.SAXException;
+
+import javax.faces.FacesException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * User: lofwyr
+ * Date: 14.02.2006 20:34:41
+ *
+ * @since 1.0.7
+ */
+class ThemeParser {
+
+  private static final Log LOG = LogFactory.getLog(ThemeParser.class);
+
+  private Digester digester;
+
+  public ThemeParser() {
+    digester = new Digester();
+    configure();
+  }
+
+  private Digester configure() {
+
+// todo   digester.setValidating(true);
+    digester.setValidating(false);
+
+    digester.addCallMethod("tobago-theme/resource-path", "setResourcePath", 0);
+    digester.addCallMethod("tobago-theme/name", "setName", 0);
+
+    return digester;
+  }
+
+  public Theme parse(URL url)
+      throws IOException, SAXException, FacesException {
+
+    InputStream inputStream = null;
+    try {
+      inputStream = url.openStream();
+      Theme theme = new Theme();
+      digester.push(theme);
+      digester.parse(inputStream);
+      LOG.info("Found theme: '" + theme + "'");
+      return theme;
+    } finally {
+      IOUtils.closeQuietly(inputStream);
+    }
+  }
+
+}

Modified: 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=377902&r1=377901&r2=377902&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-richmond/src/main/resources/META-INF/tobago-theme.xml Tue Feb 14 16:06:06 2006
@@ -21,5 +21,7 @@
   http://issues.apache.org/jira/browse/MYFACES-1106
 -->
 <tobago-theme>
+  <name>org.apache.myfaces.tobago.theme.Richmond</name>
   <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+  <fallback>org.apache.myfaces.tobago.theme.Speyside</fallback>
 </tobago-theme>

Modified: 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=377902&r1=377901&r2=377902&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-scarborough/src/main/resources/META-INF/tobago-theme.xml Tue Feb 14 16:06:06 2006
@@ -21,5 +21,7 @@
   http://issues.apache.org/jira/browse/MYFACES-1106
 -->
 <tobago-theme>
+  <name>org.apache.myfaces.tobago.theme.Scarborough</name>
   <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+  <fallback>org.apache.myfaces.tobago.theme.Standard</fallback>
 </tobago-theme>

Modified: 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=377902&r1=377901&r2=377902&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-speyside/src/main/resources/META-INF/tobago-theme.xml Tue Feb 14 16:06:06 2006
@@ -21,5 +21,7 @@
   http://issues.apache.org/jira/browse/MYFACES-1106
 -->
 <tobago-theme>
+  <name>org.apache.myfaces.tobago.theme.Speyside</name>
   <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
+  <fallback>org.apache.myfaces.tobago.theme.Scarborough</fallback>
 </tobago-theme>

Modified: 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=377902&r1=377901&r2=377902&view=diff
==============================================================================
--- incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml (original)
+++ incubator/tobago/trunk/tobago-theme/tobago-theme-standard/src/main/resources/META-INF/tobago-theme.xml Tue Feb 14 16:06:06 2006
@@ -21,5 +21,6 @@
   http://issues.apache.org/jira/browse/MYFACES-1106
 -->
 <tobago-theme>
+  <name>org.apache.myfaces.tobago.theme.Standard</name>
   <resource-path>org/apache/myfaces/tobago/renderkit</resource-path>
 </tobago-theme>