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/01/11 17:12:43 UTC
svn commit: r368051 - in /incubator/tobago/trunk:
tobago-core/src/main/java/org/apache/myfaces/tobago/context/
tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/
tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/
Author: lofwyr
Date: Wed Jan 11 08:12:34 2006
New Revision: 368051
URL: http://svn.apache.org/viewcvs?rev=368051&view=rev
Log:
begin of the development of a theme mechanism which only need one jar file (is swiched off by default)
Added:
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
Modified:
incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ResourceManagerFactory.java
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=368051&r1=368050&r2=368051&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 Wed Jan 11 08:12:34 2006
@@ -32,6 +32,8 @@
import java.util.Enumeration;
import java.util.Properties;
import java.util.Set;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
public class ResourceManagerFactory {
@@ -40,6 +42,8 @@
public static final String RESOURCE_MANAGER
= "org.apache.myfaces.tobago.context.ResourceManager";
+ public static final boolean USE_JAR_THEME_RESOURCE = false;
+
private ResourceManagerFactory() {
}
@@ -62,6 +66,9 @@
assert !initialized;
ResourceManagerImpl resources = new ResourceManagerImpl();
locateResources(servletContext, resources, "/");
+ if (USE_JAR_THEME_RESOURCE) {
+ locateResources2(servletContext, resources);
+ }
for (String dir : tobagoConfig.getResourceDirs()) {
if (LOG.isDebugEnabled()) {
LOG.debug("Locating resources in dir: " + dir);
@@ -74,6 +81,67 @@
initialized = true;
}
+ private static void locateResources2(
+ ServletContext servletContext, ResourceManagerImpl resources)
+ 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);
+ }
+ }
+ }
+ } catch (IOException e) {
+ String msg = "while loading " + childPath;
+ if (LOG.isErrorEnabled()) {
+ LOG.error(msg, e);
+ }
+ throw new ServletException(msg, e);
+ } finally {
+ IOUtils.closeQuietly(stream);
+ }
+ }
+ }
+ }
+
+
private static void locateResources(
ServletContext servletContext, ResourceManagerImpl resources, String path)
throws ServletException {
@@ -169,6 +237,70 @@
}
}
+ 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));
+ }
+ }
+ }
public static void release(ServletContext servletContext) {
assert initialized;
Added: incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
URL: http://svn.apache.org/viewcvs/incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java?rev=368051&view=auto
==============================================================================
--- incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java (added)
+++ incubator/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java Wed Jan 11 08:12:34 2006
@@ -0,0 +1,61 @@
+package org.apache.myfaces.tobago.servlet;
+
+import org.apache.myfaces.tobago.context.Theme;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+
+/**
+ * User: lofwyr
+ * Date: 10.11.2005 21:36:20
+ *
+ * XXX This class is in development. Please don't use it in
+ * production environment!
+ */
+public class ResourceServlet extends HttpServlet {
+
+ private static final Log LOG = LogFactory.getLog(ResourceServlet.class);
+
+ protected void service(
+ HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ LOG.info("C " + request.getContextPath());
+ LOG.info("Q " + request.getQueryString());
+ String requestURI = request.getRequestURI();
+ LOG.info("R " + requestURI);
+
+ String resource = requestURI.substring(
+ request.getContextPath().length() + 1); // todo: make it "stable"
+
+ LOG.info("L " + resource);
+
+ InputStream is
+ = Theme.class.getClassLoader().getResourceAsStream(resource);
+
+ if (requestURI.endsWith(".gif")) {
+ response.setContentType("image/gif");
+ } else if (requestURI.endsWith(".png")) {
+ response.setContentType("image/png");
+ } else if (requestURI.endsWith(".jpg")) {
+ response.setContentType("image/jpeg");
+ } else if (requestURI.endsWith(".js")) {
+ response.setContentType("text/javascript");
+ } else if (requestURI.endsWith(".css")) {
+ response.setContentType("text/css");
+ }
+
+ int c;
+ while (-1 != (c = is.read())) {
+ response.getOutputStream().write(c);
+ }
+ }
+}
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=368051&r1=368050&r2=368051&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 Wed Jan 11 08:12:34 2006
@@ -30,5 +30,8 @@
<resource-dir>tobago-resource</resource-dir>
<resource-dir>tobago</resource-dir>
+ <!--test for new theme build mechanism-->
+ <!--<resource-dir>org/apache/myfaces/tobago/renderkit</resource-dir>-->
+
<enable-ajax>false</enable-ajax>
</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=368051&r1=368050&r2=368051&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 Wed Jan 11 08:12:34 2006
@@ -58,8 +58,24 @@
<load-on-startup>2</load-on-startup>
</servlet>
+ <!--test for the theme mechandism-->
+<!--
+ <servlet>
+ <servlet-name>ResourceServlet</servlet-name>
+ <servlet-class>org.apache.myfaces.tobago.servlet.ResourceServlet</servlet-class>
+ </servlet>
+-->
+
<!-- servlet-mapping -->
+ <!--test for the theme mechandism-->
+<!--
+ <servlet-mapping>
+ <servlet-name>ResourceServlet</servlet-name>
+ <url-pattern>/org/apache/myfaces/tobago/renderkit/*</url-pattern>
+ </servlet-mapping>
+-->
+
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
@@ -81,13 +97,8 @@
</mime-mapping>
<!-- The Usual Welcome File List -->
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-
- <error-page>
- <exception-type>java.lang.Throwable</exception-type>
- <location>/errorPage.jsp</location>
- </error-page>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
</web-app>