You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2012/06/01 21:51:35 UTC
svn commit: r1345322 - in /myfaces/tobago/trunk/tobago-core/src:
main/java/org/apache/myfaces/tobago/context/
main/java/org/apache/myfaces/tobago/internal/config/
main/java/org/apache/myfaces/tobago/internal/context/
main/java/org/apache/myfaces/tobago...
Author: bommel
Date: Fri Jun 1 19:51:35 2012
New Revision: 1345322
URL: http://svn.apache.org/viewvc?rev=1345322&view=rev
Log:
(TOBAGO-945)
Add the version of Tobago to the resources URL to avoid caching when updating Tobago
Added:
myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd
- copied, changed from r1344021, myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceManagerImpl.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockTheme.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/Theme.java Fri Jun 1 19:51:35 2012
@@ -42,4 +42,6 @@ public interface Theme {
String[] getStyleResources(boolean production);
+ String getVersion();
+
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java Fri Jun 1 19:51:35 2012
@@ -62,6 +62,9 @@ public class ThemeImpl implements Theme,
private String[] styles;
+ private boolean versioned;
+
+ private String version;
public String getName() {
return name;
@@ -269,4 +272,20 @@ public class ThemeImpl implements Theme,
}
return styles;
}
+
+ public boolean isVersioned() {
+ return versioned;
+ }
+
+ public void setVersioned(boolean versioned) {
+ this.versioned = versioned;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
}
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/config/TobagoConfigParser.java Fri Jun 1 19:51:35 2012
@@ -41,6 +41,7 @@ public class TobagoConfigParser {
private static final String TOBAGO_CONFIG_DTD_1_0_30 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.30.dtd";
private static final String TOBAGO_CONFIG_DTD_1_0_34 = "/org/apache/myfaces/tobago/config/tobago-config-1.0.34.dtd";
private static final String TOBAGO_CONFIG_XSD_1_5 = "/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd";
+ private static final String TOBAGO_CONFIG_XSD_1_6 = "/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd";
private Digester digester;
@@ -74,7 +75,7 @@ public class TobagoConfigParser {
// 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) {
+ if (xml.indexOf("tobago-config-1.5.xsd") > 0 || xml.indexOf("tobago-config-1.6.xsd") > 0) {
digester.setValidating(false);
return;
}
@@ -127,6 +128,8 @@ public class TobagoConfigParser {
digester.addCallMethod("tobago-config/theme-definitions/theme-definition/display-name", "setDisplayName", 0);
digester.addCallMethod("tobago-config/theme-definitions/theme-definition/resource-path", "setResourcePath", 0);
digester.addCallMethod("tobago-config/theme-definitions/theme-definition/fallback", "setFallbackName", 0);
+ digester.addBeanPropertySetter("tobago-config/theme-definitions/theme-definition/versioned",
+ "versioned");
digester.addObjectCreate("tobago-config/theme-definitions/theme-definition/renderers", RenderersConfigImpl.class);
digester.addSetNext("tobago-config/theme-definitions/theme-definition/renderers", "setRenderersConfig");
digester.addObjectCreate(
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceLocator.java Fri Jun 1 19:51:35 2012
@@ -149,6 +149,19 @@ class ResourceLocator {
if (themeUrl.toString().endsWith(META_INF_TOBAGO_CONFIG_XML)) {
TobagoConfigFragment tobagoConfig = new TobagoConfigParser().parse(themeUrl);
for (ThemeImpl theme : tobagoConfig.getThemeDefinitions()) {
+ if (theme.isVersioned()) {
+ String themeUrlStr = themeUrl.toString();
+ int index = themeUrlStr.indexOf(META_INF_TOBAGO_CONFIG_XML);
+ String metaInf = themeUrlStr.substring(0, index) + "META-INF/MANIFEST.MF";
+ Properties properties = new Properties();
+ InputStream inputStream = new URL(metaInf).openStream();
+ try {
+ properties.load(inputStream);
+ theme.setVersion(properties.getProperty("Implementation-Version"));
+ } finally {
+ IOUtils.closeQuietly(inputStream);
+ }
+ }
addThemeResources(resources, themeUrl, theme);
}
} else {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceManagerImpl.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceManagerImpl.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/context/ResourceManagerImpl.java Fri Jun 1 19:51:35 2012
@@ -303,26 +303,24 @@ public class ResourceManagerImpl impleme
UserAgent browser = clientkey.getUserAgent();
List<String> locales = LocaleUtils.getLocaleSuffixList(clientkey.getLocale());
- String path;
-
// check first the local web application directory
for (String localeSuffix : locales) {
if (production) {
- path = makePath(name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
- boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
+ boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ name, MINIMIZE_SUFFIX, localeSuffix, suffix, key);
if (found && (single || !returnStrings)) {
return matches;
}
if (!found) {
- path = makePath(name, null, localeSuffix, suffix, key);
- found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
+ found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ name, null, localeSuffix, suffix, key);
if (found && (single || !returnStrings)) {
return matches;
}
}
} else {
- path = makePath(name, null, localeSuffix, suffix, key);
- boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
+ boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ name, null, localeSuffix, suffix, key);
if (found && (single || !returnStrings)) {
return matches;
}
@@ -331,29 +329,29 @@ public class ResourceManagerImpl impleme
// after that check the whole resources tree
// e.g. 1. application, 2. library or renderkit
- for (Theme themeName : theme.getFallbackList()) { // theme loop
+ for (Theme currentTheme : theme.getFallbackList()) {// theme loop
for (String resourceDirectory : tobagoConfig.getResourceDirs()) {
for (String browserType : browser.getFallbackList()) { // browser loop
for (String localeSuffix : locales) { // locale loop
if (production) {
- path = makePath(resourceDirectory, contentType, themeName, browserType, subDir, name, MINIMIZE_SUFFIX,
+ boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ resourceDirectory, contentType, currentTheme, browserType, subDir, name, MINIMIZE_SUFFIX,
localeSuffix, suffix, key);
- boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
if (found && (single || !returnStrings)) {
return matches;
}
if (!found) {
- path = makePath(resourceDirectory, contentType, themeName, browserType, subDir, name, null,
- localeSuffix, suffix, key);
- found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
+ found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
+ localeSuffix, suffix, key);
if (found && (single || !returnStrings)) {
return matches;
}
}
} else {
- path = makePath(resourceDirectory, contentType, themeName, browserType, subDir, name, null,
+ boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches,
+ resourceDirectory, contentType, currentTheme, browserType, subDir, name, null,
localeSuffix, suffix, key);
- boolean found = checkPath(prefix, reverseOrder, returnKey, returnStrings, matches, path);
if (found && (single || !returnStrings)) {
return matches;
}
@@ -384,7 +382,8 @@ public class ResourceManagerImpl impleme
private boolean checkPath(
String prefix, boolean reverseOrder, boolean returnKey, boolean returnStrings,
- List matches, String path) {
+ List matches, String name, String minimizeSuffix, String localeSuffix, String extension, String key) {
+ String path = makePath(name, minimizeSuffix, localeSuffix, extension, key);
if (returnStrings && resourceList.containsKey(path)) {
String result =
returnKey
@@ -424,13 +423,65 @@ public class ResourceManagerImpl impleme
return false;
}
+ private boolean checkPath(
+ String prefix, boolean reverseOrder, boolean returnKey, boolean returnStrings,
+ List matches, String resourceDirectory, String contentType, Theme currentTheme, String browserType,
+ String subDir, String name, String minimizeSuffix, String localeSuffix, String suffix, String key) {
+ String path = makePath(resourceDirectory, contentType, currentTheme, browserType, subDir, name, minimizeSuffix,
+ localeSuffix, suffix, key, null);
+ if (returnStrings && resourceList.containsKey(path)) {
+ String result;
+ if (prefix.length() == 0 && returnKey && resourceDirectory.equals(currentTheme.getResourcePath())) {
+ result = makePath(resourceDirectory, contentType, currentTheme, browserType, subDir, name, minimizeSuffix,
+ localeSuffix, suffix, key, currentTheme.getVersion());
+ } else {
+ result = returnKey
+ ? prefix + path : prefix + resourceList.get(path);
+ }
+ if (reverseOrder) {
+ matches.add(0, result);
+ } else {
+ matches.add(result);
+ }
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("testing path: {} *", path); // match
+ }
+
+ return true;
+ } else if (!returnStrings) {
+ try {
+ path = path.substring(1).replace('/', '.');
+ Class clazz = Class.forName(path);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("testing path: " + path + " *"); // match
+ }
+ matches.add(clazz);
+ return true;
+ } catch (ClassNotFoundException e) {
+ // not found
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("testing path: " + path); // no match
+ }
+ }
+ } else {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("testing path: " + path); // no match
+ }
+ }
+ return false;
+ }
+
private String makePath(
- String project, String language, Theme theme, String browser,
- String subDir, String name, String minimizeSuffix, String localeSuffix, String extension, String key) {
+ String project, String language, Theme theme, String browser, String subDir,
+ String name, String minimizeSuffix, String localeSuffix, String extension, String key, String version) {
StringBuilder searchtext = new StringBuilder(64);
searchtext.append('/');
searchtext.append(project);
+ if (version != null) {
+ searchtext.append('/');
+ searchtext.append(version);
+ }
searchtext.append('/');
searchtext.append(language);
searchtext.append('/');
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/servlet/ResourceServlet.java Fri Jun 1 19:51:35 2012
@@ -20,6 +20,7 @@ package org.apache.myfaces.tobago.servle
import org.apache.commons.io.IOUtils;
import org.apache.myfaces.tobago.application.ProjectStage;
import org.apache.myfaces.tobago.config.TobagoConfig;
+import org.apache.myfaces.tobago.context.Theme;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.myfaces.tobago.internal.util.MimeTypeUtils;
@@ -32,6 +33,8 @@ import javax.servlet.http.HttpServletRes
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
/**
* <p><pre>
@@ -67,6 +70,7 @@ public class ResourceServlet extends Htt
private Long expires;
private int bufferSize;
+ private Set<String> resourceDirs = new HashSet<String>();
@Override
public void init(ServletConfig servletConfig) throws ServletException {
@@ -75,6 +79,14 @@ public class ResourceServlet extends Htt
if (tobagoConfig != null && tobagoConfig.getProjectStage() == ProjectStage.Production) {
expires = 24 * 60 * 60 * 1000L;
}
+ for (Theme theme : tobagoConfig.getSupportedThemes()) {
+ String dir = theme.getResourcePath();
+ if (dir.startsWith("/")) {
+ resourceDirs.add(dir.substring(1));
+ } else {
+ resourceDirs.add(dir);
+ }
+ }
String expiresString = servletConfig.getInitParameter("expires");
if (expiresString != null) {
try {
@@ -101,7 +113,14 @@ public class ResourceServlet extends Htt
String requestURI = request.getRequestURI();
String resource = requestURI.substring(request.getContextPath().length() + 1);
-
+ for (String resourceDir : resourceDirs) {
+ if (resource.startsWith(resourceDir)) {
+ if (Character.isDigit(resource.charAt(resourceDir.length()+1))) {
+ resource = resourceDir + resource.substring(resource.indexOf('/', resourceDir.length() + 1));
+ break;
+ }
+ }
+ }
if (expires != null) {
response.setDateHeader("Last-Modified", 0);
response.setHeader("Cache-Control", "Public, max-age=" + expires);
Copied: myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd (from r1344021, myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd?p2=myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd&p1=myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd&r1=1344021&r2=1345322&rev=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.5.xsd (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/resources/org/apache/myfaces/tobago/config/tobago-config-1.6.xsd Fri Jun 1 19:51:35 2012
@@ -4,10 +4,9 @@
targetNamespace="http://myfaces.apache.org/tobago/tobago-config"
xmlns:tobago="http://myfaces.apache.org/tobago/tobago-config"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:xml="http://www.w3.org/XML/1998/namespace"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
- version="1.5">
+ version="1.6">
<xs:annotation>
<xs:documentation>
@@ -33,15 +32,15 @@
<xs:annotation>
<xs:documentation>
<![CDATA[
- This is the XML schema for the tobago configuration files version 1.5.
+ This is the XML schema for the tobago configuration files version 1.6.
Use the following definition:
<tobago-config
xmlns="http://myfaces.apache.org/tobago/tobago-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://myfaces.apache.org/tobago/tobago-config http://myfaces.apache.org/tobago/tobago-config-1.5.xsd"
- version="1.5">
+ xsi:schemaLocation="http://myfaces.apache.org/tobago/tobago-config http://myfaces.apache.org/tobago/tobago-config-1.6.xsd"
+ version="1.6">
...
</tobago-config>
]]>
@@ -68,7 +67,7 @@
<xs:simpleType name="tobago-config-version-type">
<xs:restriction base="xs:token">
- <xs:enumeration value="1.5"/>
+ <xs:enumeration value="1.6"/>
</xs:restriction>
</xs:simpleType>
@@ -124,6 +123,7 @@
<xs:element name="deprecated-name" type="xs:string" minOccurs="0"/>
<xs:element name="resource-path" type="xs:string"/>
<xs:element name="fallback" type="xs:string" minOccurs="0"/>
+ <xs:element name="versioned" type="xs:boolean" minOccurs="0" default="false"/>
<xs:element name="renderers" type="tobago:renderers-type" minOccurs="0"/>
<xs:element name="resources" type="tobago:resources-type" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockTheme.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockTheme.java?rev=1345322&r1=1345321&r2=1345322&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockTheme.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/mock/faces/MockTheme.java Fri Jun 1 19:51:35 2012
@@ -32,6 +32,10 @@ public class MockTheme implements Theme
private RenderersConfig config = new MockRenderersConfig();
+ private boolean versioned;
+
+ private String version;
+
public MockTheme(String name, String displayName, List<Theme> fallbackThemeList) {
this.name = name;
this.displayName = displayName;
@@ -65,4 +69,20 @@ public class MockTheme implements Theme
public String[] getStyleResources(boolean production) {
return new String[0];
}
+
+ public boolean isVersioned() {
+ return versioned;
+ }
+
+ public void setVersioned(boolean versioned) {
+ this.versioned = versioned;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
}