You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/01/22 00:03:14 UTC
svn commit: r901912 - in
/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad:
resource/ResourceLoader.java webapp/ResourceServlet.java
Author: arobinson74
Date: Thu Jan 21 23:03:14 2010
New Revision: 901912
URL: http://svn.apache.org/viewvc?rev=901912&view=rev
Log:
TRINIDAD-1690
Modified:
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java?rev=901912&r1=901911&r2=901912&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java Thu Jan 21 23:03:14 2010
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,11 +21,11 @@
import java.io.IOException;
import java.net.URL;
-
import java.net.URLConnection;
+
/**
- * Base class for resource loaders. Resource loaders can lookup resources
+ * Base class for resource loaders. Resource loaders can lookup resources
* as URLs from arbitrary locations, including JAR files.
*
*/
@@ -33,14 +33,14 @@
{
/**
* Returns the shared resource loader that always returns null.
- *
+ *
* @return null for any resource path
*/
public static ResourceLoader getNullResourceLoader()
{
return _NULL_RESOURCE_LOADER;
}
-
+
/**
* Finds the resource with the given name. A resource is some data
* (images, audio, text, etc) that can be accessed by class code in a way
@@ -50,7 +50,7 @@
* identifies the resource.
*
* <p> This method will first search the this resource loader for the
- * resource. That failing, this method will invoke
+ * resource. That failing, this method will invoke
* {@link #findResource(String)} to on the parent resource loader to
* find the resource. </p>
*
@@ -65,22 +65,22 @@
) throws IOException
{
URL url = findResource(name);
-
- if (url == null && _parent != null)
+
+ if (url == null && _parent != null)
{
url = _parent.getResource(name);
}
-
+
return url;
}
-
+
/**
* Returns whether a resource is cachable.
* @return
*/
public boolean isCachable()
{
- return _parent == null || _parent.isCachable();
+ return _parent == null || _parent.isCachable();
}
/**
@@ -99,32 +99,46 @@
{
return null;
}
-
+
+ /**
+ * Called by the {@link org.apache.myfaces.trinidad.webapp.ResourceServlet} to get the content type for
+ * the given connection.
+ *
+ * @param loader the loader that provided the URL for the URL connection
+ * @param conn the URL connection
+ * @return the content type for this URL connection
+ */
+ public static String getContentType(
+ ResourceLoader loader,
+ URLConnection conn)
+ {
+ return loader.getContentType(conn);
+ }
+
/**
* Returns the content type of this URL connection.
- *
- * @return the content type
+ * @return the content type
*/
protected String getContentType(
URLConnection conn)
{
return conn.getContentType();
}
-
+
/**
- * Returns the parent resource loader, or null if this is a root
+ * Returns the parent resource loader, or null if this is a root
* resource loader.
- *
+ *
* @return the parent resource loader
*/
protected ResourceLoader getParent()
{
return _parent;
}
-
+
/**
* Constructs a new resource loader with specified parent resource loader.
- *
+ *
* @param parent the parent resource loader
*/
protected ResourceLoader(
@@ -141,7 +155,7 @@
this(null);
}
- private static final ResourceLoader _NULL_RESOURCE_LOADER =
+ private static final ResourceLoader _NULL_RESOURCE_LOADER =
new ResourceLoader();
private final ResourceLoader _parent;
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java?rev=901912&r1=901911&r2=901912&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java Thu Jan 21 23:03:14 2010
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -26,11 +26,14 @@
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.Reader;
+
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
+
import java.net.SocketException;
import java.net.URL;
import java.net.URLConnection;
+
import java.util.HashMap;
import java.util.Map;
@@ -40,6 +43,7 @@
import javax.faces.context.FacesContextFactory;
import javax.faces.event.PhaseListener;
import javax.faces.lifecycle.Lifecycle;
+
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -57,6 +61,7 @@
import org.apache.myfaces.trinidad.resource.ServletContextResourceLoader;
import org.apache.myfaces.trinidad.util.URLUtils;
+
/**
* A Servlet which serves up web application resources (images, style sheets,
* JavaScript libraries) by delegating to a ResourceLoader.
@@ -78,10 +83,10 @@
public class ResourceServlet extends HttpServlet
{
/**
- *
+ *
*/
private static final long serialVersionUID = 4547362994406585148L;
-
+
/**
* Override of Servlet.destroy();
*/
@@ -94,7 +99,7 @@
super.destroy();
}
-
+
/**
* Override of Servlet.init();
*/
@@ -150,7 +155,7 @@
else
{
Configurator.disableConfiguratorServices(request);
-
+
//=-= Scott O'Bryan =-=
// Be careful. This can be wrapped by other things even though it's meant to be a
// Trinidad only resource call.
@@ -204,7 +209,7 @@
connection.setDoInput(true);
connection.setDoOutput(false);
- _setHeaders(connection, response);
+ _setHeaders(connection, response, loader);
InputStream in = connection.getInputStream();
OutputStream out = response.getOutputStream();
@@ -416,11 +421,12 @@
*/
private void _setHeaders(
URLConnection connection,
- HttpServletResponse response)
+ HttpServletResponse response,
+ ResourceLoader loader)
{
String resourcePath;
URL url;
- String contentType = connection.getContentType();
+ String contentType = ResourceLoader.getContentType(loader, connection);
if (contentType == null || "content/unknown".equals(contentType))
{
@@ -437,26 +443,26 @@
else
contentType = getServletContext().getMimeType(resourcePath);
- // The resource has an file extension we have not
+ // The resource has an file extension we have not
// included in the case statement above
if (contentType == null)
{
- _LOG.warning("ResourceServlet._setHeaders(): " +
+ _LOG.warning("ResourceServlet._setHeaders(): " +
"Content type for {0} is NULL!\n" +
"Cause: Unknown file extension",
resourcePath);
}
}
-
+
if (contentType != null)
{
- response.setContentType(contentType);
+ response.setContentType(contentType);
int contentLength = connection.getContentLength();
if (contentLength >= 0)
response.setContentLength(contentLength);
}
-
+
long lastModified;
try
{
@@ -556,7 +562,7 @@
// cutting back just to be safe.)
public static final long ONE_YEAR_MILLIS = 31363200000L;
-
+
private static final Class[] _DECORATOR_SIGNATURE =
new Class[]{ResourceLoader.class};