You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/09/17 12:30:32 UTC

[myfaces-trinidad] 09/36: TRINIDAD-1690

This is an automated email from the ASF dual-hosted git repository.

deki pushed a commit to branch 1.2.12.2-branch
in repository https://gitbox.apache.org/repos/asf/myfaces-trinidad.git

commit a5ff7f84e269b7f6355c64d5cc2009d3cef39a51
Author: Andrew Robinson <ar...@apache.org>
AuthorDate: Thu Jan 21 23:03:14 2010 +0000

    TRINIDAD-1690
---
 .../myfaces/trinidad/resource/ResourceLoader.java  | 56 ++++++++++++++--------
 .../myfaces/trinidad/webapp/ResourceServlet.java   | 36 ++++++++------
 2 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java
index d029213..97f64db 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/resource/ResourceLoader.java
@@ -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 @@ package org.apache.myfaces.trinidad.resource;
 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 @@ public class ResourceLoader
 {
   /**
    * 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 @@ public class ResourceLoader
    * 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 @@ public class ResourceLoader
     ) 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 @@ public class ResourceLoader
   {
   	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 @@ public class ResourceLoader
     this(null);
   }
 
-  private static final ResourceLoader _NULL_RESOURCE_LOADER = 
+  private static final ResourceLoader _NULL_RESOURCE_LOADER =
                                                       new ResourceLoader();
 
   private final ResourceLoader _parent;
diff --git a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
index 4f13f52..bfc2636 100644
--- a/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
+++ b/trinidad-api/src/main/java/org/apache/myfaces/trinidad/webapp/ResourceServlet.java
@@ -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.InputStreamReader;
 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.FacesContext;
 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.ResourceLoader;
 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 @@ import org.apache.myfaces.trinidad.util.URLUtils;
 public class ResourceServlet extends HttpServlet
 {
   /**
-   * 
+   *
    */
   private static final long serialVersionUID = 4547362994406585148L;
-  
+
   /**
    * Override of Servlet.destroy();
    */
@@ -94,7 +99,7 @@ public class ResourceServlet extends HttpServlet
 
     super.destroy();
   }
-  
+
   /**
    * Override of Servlet.init();
    */
@@ -150,7 +155,7 @@ public class ResourceServlet extends HttpServlet
     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 @@ public class ResourceServlet extends HttpServlet
     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 @@ public class ResourceServlet extends HttpServlet
    */
   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 @@ public class ResourceServlet extends HttpServlet
       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 @@ public class ResourceServlet extends HttpServlet
   // cutting back just to be safe.)
   public static final long ONE_YEAR_MILLIS = 31363200000L;
 
-  
+
   private static final Class[] _DECORATOR_SIGNATURE =
                                   new Class[]{ResourceLoader.class};
 

-- 
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.