Author: nbelaevski
Date: 2008-07-30 21:08:18 -0400 (Wed, 30 Jul 2008)
New Revision: 9834
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/cached/CachedResourceBuilder.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
Log:
https://jira.jboss.org/jira/browse/RF-4063
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2008-07-31
01:08:11 UTC (rev 9833)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceBuilderImpl.java 2008-07-31
01:08:18 UTC (rev 9834)
@@ -308,9 +308,12 @@
.getMessage(Messages.QUERY_STRING_BUILDING_ERROR), e);
}
}
+
+ boolean isGlobal = !resource.isSessionAware();
+
String resourceURL = getWebXml(context).getFacesResourceURL(context,
- uri.toString());//
context.getApplication().getViewHandler().getResourceURL(context,uri.toString());
- if (resource.isSessionAware()) {
+ uri.toString(), isGlobal);//
context.getApplication().getViewHandler().getResourceURL(context,uri.toString());
+ if (!isGlobal) {
resourceURL = context.getExternalContext().encodeResourceURL(
resourceURL);
}
@@ -416,8 +419,8 @@
// return getWebXml(context).getFacesResourceKey(request);
// }
- public String getFacesResourceURL(FacesContext context, String Url) {
- return getWebXml(context).getFacesResourceURL(context, Url);
+ public String getFacesResourceURL(FacesContext context, String Url, boolean isGlobal) {
+ return getWebXml(context).getFacesResourceURL(context, Url, isGlobal);
}
/**
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/cached/CachedResourceBuilder.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/cached/CachedResourceBuilder.java 2008-07-31
01:08:11 UTC (rev 9833)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/cached/CachedResourceBuilder.java 2008-07-31
01:08:18 UTC (rev 9834)
@@ -131,8 +131,11 @@
// Refresh LRU
cache.get(key);
}
- String resourceURL = getFacesResourceURL(facesContext, key);
- if (resource.isSessionAware()) {
+
+ boolean isGlobal = !resource.isSessionAware();
+
+ String resourceURL = getFacesResourceURL(facesContext, key, isGlobal);
+ if (!isGlobal) {
resourceURL = facesContext.getExternalContext().encodeResourceURL(
resourceURL);
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2008-07-31 01:08:11
UTC (rev 9833)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/WebXml.java 2008-07-31 01:08:18
UTC (rev 9834)
@@ -68,25 +68,37 @@
static final String WEB_XML = "/WEB-INF/web.xml";
- public static final String RESOURCE_URI_PREFIX_START = "a4j";
+ public static final String RESOURCE_URI_PREFIX = "a4j";
- public static final String RESOURCE_URI_PREFIX;
+ public static final String GLOBAL_RESOURCE_URI_PREFIX = "a4j/g";
+
+ public static final String SESSION_RESOURCE_URI_PREFIX = "a4j/s";
+ public static final String RESOURCE_URI_PREFIX_VERSIONED;
+
+ public static final String GLOBAL_RESOURCE_URI_PREFIX_VERSIONED;
+
+ public static final String SESSION_RESOURCE_URI_PREFIX_VERSIONED;
+
static {
VersionBean versionBean = new VersionBean();
Version version = versionBean.getVersion();
+ String suffix = "/" + version.getMajor() + "_" + version.getMinor()
+ "_"
+ + version.getRevision();
+
//that's to prevent static compile-time linkage to constant values
- RESOURCE_URI_PREFIX = RESOURCE_URI_PREFIX_START + "/" +
- + version.getMajor() + "_" + version.getMinor() + "_"
- + version.getRevision();
+ RESOURCE_URI_PREFIX_VERSIONED = RESOURCE_URI_PREFIX + suffix;
+ GLOBAL_RESOURCE_URI_PREFIX_VERSIONED = GLOBAL_RESOURCE_URI_PREFIX + suffix;
+ SESSION_RESOURCE_URI_PREFIX_VERSIONED = SESSION_RESOURCE_URI_PREFIX + suffix;
}
- static final String RESOURCE_URI_PREFIX_WITH_SLASH = "/"
- + RESOURCE_URI_PREFIX;
-
public static final String RESOURCE_URI_PREFIX_PARAM =
"org.ajax4jsf.RESOURCE_URI_PREFIX";
+ public static final String GLOBAL_RESOURCE_URI_PREFIX_PARAM =
"org.ajax4jsf.GLOBAL_RESOURCE_URI_PREFIX";
+
+ public static final String SESSION_RESOURCE_URI_PREFIX_PARAM =
"org.ajax4jsf.SESSION_RESOURCE_URI_PREFIX";
+
/**
* Prefix for Resourse-Ajax filter, in common must be same as for
* {@link javax.faces.webapp.FacesServlet}
@@ -114,8 +126,12 @@
/**
* Prefix for resources handled by Chameleon framework.
*/
- private String _resourcePrefix = RESOURCE_URI_PREFIX_WITH_SLASH;
+ private String _resourcePrefix = RESOURCE_URI_PREFIX;
+ private String _globalResourcePrefix;
+
+ private String _sessionResourcePrefix;
+
public static WebXml getInstance() {
return getInstance(FacesContext.getCurrentInstance());
}
@@ -279,9 +295,9 @@
* @param Url
* @return
*/
- public String getFacesResourceURL(FacesContext context, String Url) {
+ public String getFacesResourceURL(FacesContext context, String Url, boolean isGlobal) {
StringBuffer buf = new StringBuffer();
- buf.append(getResourcePrefix()).append(Url);
+ buf.append(isGlobal ? getGlobalResourcePrefix() :
getSessionResourcePrefix()).append(Url);
// Insert suffix mapping
if (isPrefixMapping()) {
buf.insert(0, getFacesFilterPrefix());
@@ -299,6 +315,65 @@
}
+ @Deprecated
+ public String getFacesResourceURL(FacesContext context, String Url) {
+ return getFacesResourceURL(context, Url, false);
+ }
+
+ public String getFacesResourceKey(String resourcePath) {
+ // Remove JSESSIONID - for expired sessions it will merged to path.
+ int jsesionidStart;
+ if ((jsesionidStart = resourcePath.lastIndexOf(";jsessionid")) >= 0) {
+ resourcePath = resourcePath.substring(0, jsesionidStart);
+ }
+ String resourcePrefix = getResourcePrefix();
+ if (isPrefixMapping()) {
+ String facesFilterPrefix = getFacesFilterPrefix();
+
+ if (resourcePath.startsWith(facesFilterPrefix)) {
+ String sessionResourcePrefix = getSessionResourcePrefix();
+ if (resourcePath.startsWith(sessionResourcePrefix, facesFilterPrefix.length())) {
+ return resourcePath.substring(facesFilterPrefix.length()
+ + sessionResourcePrefix.length());
+ } else {
+ String globalResourcePrefix = getGlobalResourcePrefix();
+ if (!sessionResourcePrefix.equals(globalResourcePrefix) &&
+ resourcePath.startsWith(globalResourcePrefix, facesFilterPrefix.length())) {
+
+ return resourcePath.substring(facesFilterPrefix.length()
+ + globalResourcePrefix.length());
+ } else if (!globalResourcePrefix.equals(resourcePrefix) &&
+ resourcePath.startsWith(resourcePrefix, facesFilterPrefix.length())) {
+
+ return resourcePath.substring(facesFilterPrefix.length()
+ + resourcePrefix.length());
+ }
+ }
+ }
+ } else {
+ String sessionResourcePrefix = getSessionResourcePrefix();
+ if (resourcePath.startsWith(sessionResourcePrefix)) {
+ return resourcePath.substring(sessionResourcePrefix.length(),
+ resourcePath.length() - getFacesFilterSuffix().length());
+ } else {
+ String globalResourcePrefix = getGlobalResourcePrefix();
+ if (!sessionResourcePrefix.equals(globalResourcePrefix) &&
+ resourcePath.startsWith(globalResourcePrefix)) {
+
+ return resourcePath.substring(globalResourcePrefix.length(),
+ resourcePath.length() - getFacesFilterSuffix().length());
+ } else if (!globalResourcePrefix.equals(resourcePrefix) &&
+ resourcePath.startsWith(resourcePrefix)) {
+
+ return resourcePath.substring(resourcePrefix.length(),
+ resourcePath.length() - getFacesFilterSuffix().length());
+ }
+ }
+ }
+
+ return null;
+ }
+
/**
* Detect request to resource and extract key from request
*
@@ -309,22 +384,8 @@
public String getFacesResourceKey(HttpServletRequest request) {
String resourcePath = request.getRequestURI().substring(
request.getContextPath().length());//
isPrefixMapping()?request.getPathInfo():request.getServletPath();
- // Remove JSESSIONID - for expired sessions it will merged to path.
- int jsesionidStart;
- if ((jsesionidStart = resourcePath.lastIndexOf(";jsessionid")) >= 0) {
- resourcePath = resourcePath.substring(0, jsesionidStart);
- }
- if (isPrefixMapping()) {
- if (resourcePath.startsWith(getFacesFilterPrefix()
- + getResourcePrefix())) {
- return resourcePath.substring(getFacesFilterPrefix().length()
- + getResourcePrefix().length());
- }
- } else if (resourcePath.startsWith(getResourcePrefix())) {
- return resourcePath.substring(getResourcePrefix().length(),
- resourcePath.length() - getFacesFilterSuffix().length());
- }
- return null;
+
+ return getFacesResourceKey(resourcePath);
}
/**
@@ -380,19 +441,57 @@
/**
* @return Returns the resourcePrefix.
*/
+ @Deprecated
public String getResourcePrefix() {
return _resourcePrefix;
}
/**
+ * @since 3.2.2
+ * @return
+ */
+ public String getGlobalResourcePrefix() {
+ return _globalResourcePrefix;
+ }
+
+ /**
+ * @since 3.2.2
+ * @return
+ */
+ public String getSessionResourcePrefix() {
+ return _sessionResourcePrefix;
+ }
+
+ /**
* @param resourcePrefix
* The resourcePrefix to set.
*/
+ @Deprecated
void setResourcePrefix(String resourcePrefix) {
_resourcePrefix = resourcePrefix;
}
/**
+ * @since 3.2.2
+ * @param resourcePrefix
+ * The resourcePrefix to set.
+ */
+ void setGlobalResourcePrefix(String resourcePrefix) {
+ _globalResourcePrefix = resourcePrefix;
+ }
+
+ /**
+ * @since 3.2.2
+ * @param resourcePrefix
+ * The resourcePrefix to set.
+ *
+ */
+
+ void setSessionResourcePrefix(String resourcePrefix) {
+ _sessionResourcePrefix = resourcePrefix;
+ }
+
+ /**
* @return Returns the filterName.
*/
public String getFilterName() {
@@ -444,21 +543,56 @@
Messages.NO_PREFIX_OR_SUFFIX_IN_FILTER_MAPPING_ERROR,
filterName));
}
+
+ String globalResourcePrefix = (String) context
+ .getInitParameter(GLOBAL_RESOURCE_URI_PREFIX_PARAM);
+
+ String sessionResourcePrefix = (String) context
+ .getInitParameter(SESSION_RESOURCE_URI_PREFIX_PARAM);
+
String resourcePrefix = (String) context
- .getInitParameter(RESOURCE_URI_PREFIX_PARAM);
- if (null == resourcePrefix) {
- resourcePrefix = RESOURCE_URI_PREFIX;
+ .getInitParameter(RESOURCE_URI_PREFIX_PARAM);
+
+ if (null != resourcePrefix) {
+ if (globalResourcePrefix == null) {
+ //TODO overriden
+ globalResourcePrefix = resourcePrefix;
+ }
+
+ if (sessionResourcePrefix == null) {
+ //TODO overriden
+ sessionResourcePrefix = resourcePrefix;
+ }
+ } else {
+ resourcePrefix = RESOURCE_URI_PREFIX_VERSIONED;
}
+
+ if (globalResourcePrefix == null) {
+ //TODO overriden
+ globalResourcePrefix = GLOBAL_RESOURCE_URI_PREFIX_VERSIONED;
+ }
+
+ if (sessionResourcePrefix == null) {
+ //TODO overriden
+ sessionResourcePrefix = SESSION_RESOURCE_URI_PREFIX_VERSIONED;
+ }
+
if (null != _facesFilterPrefix) {
_prefixMapping = true;
if (_facesFilterPrefix.endsWith("/")) {
+ setGlobalResourcePrefix(globalResourcePrefix);
+ setSessionResourcePrefix(sessionResourcePrefix);
setResourcePrefix(resourcePrefix);
} else {
+ setGlobalResourcePrefix("/" + globalResourcePrefix);
+ setSessionResourcePrefix("/" + sessionResourcePrefix);
setResourcePrefix("/" + resourcePrefix);
}
} else if (null != _facesFilterSuffix) {
_prefixMapping = false;
setResourcePrefix("/" + resourcePrefix);
+ setGlobalResourcePrefix("/" + globalResourcePrefix);
+ setSessionResourcePrefix("/" + sessionResourcePrefix);
}
}