You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/08/28 21:45:57 UTC
svn commit: r990423 - in /myfaces/core/trunk/impl/src:
main/java/org/apache/myfaces/application/
main/java/org/apache/myfaces/resource/
test/java/org/apache/myfaces/view/facelets/mock/
Author: lu4242
Date: Sat Aug 28 19:45:56 2010
New Revision: 990423
URL: http://svn.apache.org/viewvc?rev=990423&view=rev
Log:
MYFACES-2899 Move Resource Handler selected code to shared
Removed:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerCache.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerSupport.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/AliasResourceMetaImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ClassLoaderResourceLoader.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ExternalContextResourceLoader.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ResourceImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ResourceLoader.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ResourceMeta.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ResourceMetaImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/ResourceUtils.java
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/DefaultResourceHandlerSupport.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/mock/MockResourceHandlerSupport.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/DefaultResourceHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/DefaultResourceHandlerSupport.java?rev=990423&r1=990422&r2=990423&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/DefaultResourceHandlerSupport.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/DefaultResourceHandlerSupport.java Sat Aug 28 19:45:56 2010
@@ -18,18 +18,14 @@
*/
package org.apache.myfaces.application;
-import java.util.Map;
-
import javax.faces.application.ProjectStage;
-import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
-import org.apache.myfaces.resource.ClassLoaderResourceLoader;
-import org.apache.myfaces.resource.ExternalContextResourceLoader;
import org.apache.myfaces.resource.InternalClassLoaderResourceLoader;
-import org.apache.myfaces.resource.ResourceLoader;
-import org.apache.myfaces.shared_impl.application.FacesServletMapping;
+import org.apache.myfaces.shared_impl.resource.BaseResourceHandlerSupport;
+import org.apache.myfaces.shared_impl.resource.ClassLoaderResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ExternalContextResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ResourceLoader;
/**
* A ResourceHandlerSupport implementation for use with standard Java Servlet engines,
@@ -38,80 +34,14 @@ import org.apache.myfaces.shared_impl.ap
* @author Leonardo Uribe (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class DefaultResourceHandlerSupport implements ResourceHandlerSupport
+public class DefaultResourceHandlerSupport extends BaseResourceHandlerSupport
{
- /**
- * Set the max time in miliseconds set on the "Expires" header for a resource.
- * (default to one week in miliseconds or 604800000)
- */
- @JSFWebConfigParam(since="2.0", defaultValue="604800000")
- public static final String RESOURCE_MAX_TIME_EXPIRES = "org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES";
-
- /**
- * Identifies the FacesServlet mapping in the current request map.
- */
- private static final String CACHED_SERVLET_MAPPING =
- DefaultResourceHandlerSupport.class.getName() + ".CACHED_SERVLET_MAPPING";
-
private ResourceLoader[] _resourceLoaders;
- private Long _startupTime;
-
- private Long _maxTimeExpires;
-
public DefaultResourceHandlerSupport()
{
- _startupTime = System.currentTimeMillis();
- }
-
- public String calculateResourceBasePath(FacesContext facesContext)
- {
- FacesServletMapping mapping = getFacesServletMapping(facesContext);
- ExternalContext externalContext = facesContext.getExternalContext();
-
- if (mapping != null)
- {
- String resourceBasePath = null;
- if (mapping.isExtensionMapping())
- {
- // Mapping using a suffix. In this case we have to strip
- // the suffix. If we have a url like:
- // http://localhost:8080/testjsf20/javax.faces.resource/imagen.jpg.jsf?ln=dojo
- //
- // The servlet path is /javax.faces.resource/imagen.jpg.jsf
- //
- // For obtain the resource name we have to remove the .jsf suffix and
- // the prefix ResourceHandler.RESOURCE_IDENTIFIER
- resourceBasePath = externalContext.getRequestServletPath();
- int stripPoint = resourceBasePath.lastIndexOf('.');
- if (stripPoint > 0)
- {
- resourceBasePath = resourceBasePath.substring(0, stripPoint);
- }
- }
- else
- {
- // Mapping using prefix. In this case we have to strip
- // the prefix used for mapping. If we have a url like:
- // http://localhost:8080/testjsf20/faces/javax.faces.resource/imagen.jpg?ln=dojo
- //
- // The servlet path is /faces
- // and the path info is /javax.faces.resource/imagen.jpg
- //
- // For obtain the resource name we have to remove the /faces prefix and
- // then the prefix ResourceHandler.RESOURCE_IDENTIFIER
- resourceBasePath = externalContext.getRequestPathInfo();
- }
- return resourceBasePath;
- }
- else
- {
- //If no mapping is detected, just return the
- //information follows the servlet path but before
- //the query string
- return externalContext.getRequestPathInfo();
- }
+ super();
}
public ResourceLoader[] getResourceLoaders()
@@ -138,131 +68,4 @@ public class DefaultResourceHandlerSuppo
}
return _resourceLoaders;
}
-
- public boolean isExtensionMapping()
- {
- FacesServletMapping mapping = getFacesServletMapping(
- FacesContext.getCurrentInstance());
- if (mapping != null)
- {
- if (mapping.isExtensionMapping())
- {
- return true;
- }
- }
- return false;
- }
-
- public String getMapping()
- {
- FacesServletMapping mapping = getFacesServletMapping(
- FacesContext.getCurrentInstance());
- if (mapping != null)
- {
- if (mapping.isExtensionMapping())
- {
- return mapping.getExtension();
- }
- else
- {
- return mapping.getPrefix();
- }
- }
- return "";
- }
-
- /**
- * Read the web.xml file that is in the classpath and parse its internals to
- * figure out how the FacesServlet is mapped for the current webapp.
- */
- protected FacesServletMapping getFacesServletMapping(FacesContext context)
- {
- Map<Object, Object> attributes = context.getAttributes();
-
- // Has the mapping already been determined during this request?
- FacesServletMapping mapping = (FacesServletMapping) attributes.get(CACHED_SERVLET_MAPPING);
- if (mapping == null)
- {
- ExternalContext externalContext = context.getExternalContext();
- mapping = calculateFacesServletMapping(externalContext.getRequestServletPath(),
- externalContext.getRequestPathInfo());
-
- attributes.put(CACHED_SERVLET_MAPPING, mapping);
- }
- return mapping;
- }
-
- /**
- * Determines the mapping of the FacesServlet in the web.xml configuration
- * file. However, there is no need to actually parse this configuration file
- * as runtime information is sufficient.
- *
- * @param servletPath The servletPath of the current request
- * @param pathInfo The pathInfo of the current request
- * @return the mapping of the FacesServlet in the web.xml configuration file
- */
- protected static FacesServletMapping calculateFacesServletMapping(
- String servletPath, String pathInfo)
- {
- if (pathInfo != null)
- {
- // If there is a "extra path", it's definitely no extension mapping.
- // Now we just have to determine the path which has been specified
- // in the url-pattern, but that's easy as it's the same as the
- // current servletPath. It doesn't even matter if "/*" has been used
- // as in this case the servletPath is just an empty string according
- // to the Servlet Specification (SRV 4.4).
- return FacesServletMapping.createPrefixMapping(servletPath);
- }
- else
- {
- // In the case of extension mapping, no "extra path" is available.
- // Still it's possible that prefix-based mapping has been used.
- // Actually, if there was an exact match no "extra path"
- // is available (e.g. if the url-pattern is "/faces/*"
- // and the request-uri is "/context/faces").
- int slashPos = servletPath.lastIndexOf('/');
- int extensionPos = servletPath.lastIndexOf('.');
- if (extensionPos > -1 && extensionPos > slashPos)
- {
- String extension = servletPath.substring(extensionPos);
- return FacesServletMapping.createExtensionMapping(extension);
- }
- else
- {
- // There is no extension in the given servletPath and therefore
- // we assume that it's an exact match using prefix-based mapping.
- return FacesServletMapping.createPrefixMapping(servletPath);
- }
- }
- }
-
- public long getStartupTime()
- {
- return _startupTime;
- }
-
- public long getMaxTimeExpires()
- {
- if (_maxTimeExpires == null)
- {
- String time = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(RESOURCE_MAX_TIME_EXPIRES);
- if (time != null && time.length() > 0)
- {
- try
- {
- _maxTimeExpires = Long.parseLong(time);
- }
- catch (NumberFormatException e)
- {
- _maxTimeExpires = 604800000L;
- }
- }
- else
- {
- _maxTimeExpires = 604800000L;
- }
- }
- return _maxTimeExpires;
- }
}
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java?rev=990423&r1=990422&r2=990423&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ResourceHandlerImpl.java Sat Aug 28 19:45:56 2010
@@ -35,9 +35,11 @@ import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletResponse;
import org.apache.myfaces.renderkit.ErrorPageWriter;
-import org.apache.myfaces.resource.ResourceImpl;
-import org.apache.myfaces.resource.ResourceLoader;
-import org.apache.myfaces.resource.ResourceMeta;
+import org.apache.myfaces.shared_impl.resource.ResourceHandlerCache;
+import org.apache.myfaces.shared_impl.resource.ResourceHandlerSupport;
+import org.apache.myfaces.shared_impl.resource.ResourceImpl;
+import org.apache.myfaces.shared_impl.resource.ResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ResourceMeta;
import org.apache.myfaces.shared_impl.util.ClassUtils;
import org.apache.myfaces.shared_impl.util.ExternalContextUtils;
import org.apache.myfaces.shared_impl.util.StringUtils;
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java?rev=990423&r1=990422&r2=990423&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/resource/InternalClassLoaderResourceLoader.java Sat Aug 28 19:45:56 2010
@@ -25,6 +25,10 @@ import javax.faces.context.ExternalConte
import javax.faces.context.FacesContext;
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.shared_impl.resource.AliasResourceMetaImpl;
+import org.apache.myfaces.shared_impl.resource.ResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ResourceMeta;
+import org.apache.myfaces.shared_impl.resource.ResourceMetaImpl;
import org.apache.myfaces.shared_impl.util.ClassUtils;
/**
Modified: myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/mock/MockResourceHandlerSupport.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/mock/MockResourceHandlerSupport.java?rev=990423&r1=990422&r2=990423&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/mock/MockResourceHandlerSupport.java (original)
+++ myfaces/core/trunk/impl/src/test/java/org/apache/myfaces/view/facelets/mock/MockResourceHandlerSupport.java Sat Aug 28 19:45:56 2010
@@ -19,9 +19,8 @@
package org.apache.myfaces.view.facelets.mock;
import org.apache.myfaces.application.DefaultResourceHandlerSupport;
-import org.apache.myfaces.resource.ClassLoaderResourceLoader;
-import org.apache.myfaces.resource.ExternalContextResourceLoader;
-import org.apache.myfaces.resource.ResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ClassLoaderResourceLoader;
+import org.apache.myfaces.shared_impl.resource.ResourceLoader;
/**
* Redirect resource request to the directory where the test class is,