[jboss-cvs] jboss-seam/src/main/org/jboss/seam/util ...

Gavin King gavin.king at jboss.com
Thu Jun 21 00:07:16 EDT 2007


  User: gavin   
  Date: 07/06/21 00:07:16

  Modified:    src/main/org/jboss/seam/util    DTDEntityResolver.java
                        Resources.java
  Added:       src/main/org/jboss/seam/util    FacesResources.java
  Log:
  yay, seam finally not dependent upon JSF jar :)
  
  Revision  Changes    Path
  1.7       +4 -4      jboss-seam/src/main/org/jboss/seam/util/DTDEntityResolver.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: DTDEntityResolver.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/util/DTDEntityResolver.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- DTDEntityResolver.java	21 Jun 2007 02:56:17 -0000	1.6
  +++ DTDEntityResolver.java	21 Jun 2007 04:07:15 -0000	1.7
  @@ -1,11 +1,11 @@
  -//$Id: DTDEntityResolver.java,v 1.6 2007/06/21 02:56:17 gavin Exp $
  +//$Id: DTDEntityResolver.java,v 1.7 2007/06/21 04:07:15 gavin Exp $
   //Contributed by Markus Meissner
   package org.jboss.seam.util;
   
   import java.io.InputStream;
   import java.io.Serializable;
   
  -import org.jboss.seam.Seam;
  +import org.jboss.seam.contexts.ServletLifecycle;
   import org.jboss.seam.log.LogProvider;
   import org.jboss.seam.log.Logging;
   import org.xml.sax.EntityResolver;
  @@ -92,9 +92,9 @@
      {
   		try 
         {
  -			return Seam.class.getResourceAsStream(path);
  +			return Resources.getResourceAsStream( path, ServletLifecycle.getServletContext() );
   		}
  -		catch( Throwable t ) 
  +		catch (Throwable t) 
         {
   			return null;
   		}
  
  
  
  1.12      +14 -59    jboss-seam/src/main/org/jboss/seam/util/Resources.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Resources.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/util/Resources.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -b -r1.11 -r1.12
  --- Resources.java	19 Jun 2007 19:02:37 -0000	1.11
  +++ Resources.java	21 Jun 2007 04:07:15 -0000	1.12
  @@ -3,7 +3,6 @@
   import java.io.InputStream;
   import java.net.URL;
   
  -import javax.faces.context.FacesContext;
   import javax.servlet.ServletContext;
   
   import org.jboss.seam.Seam;
  @@ -11,22 +10,21 @@
   public class Resources 
   {
   
  -   public static InputStream getResourceAsStream(String resource) 
  +   public static InputStream getResourceAsStream(String resource, ServletContext servletContext) 
      {
         String stripped = resource.startsWith("/") ? 
               resource.substring(1) : resource;
      
         InputStream stream = null; 
   
  -      try
  +      if (servletContext!=null)
         {
  -         if (FacesContext.getCurrentInstance() != null)
  +         try
            {
  -            stream = FacesContext.getCurrentInstance().getExternalContext()
  -               .getResourceAsStream(resource);
  -         }
  +            stream = servletContext.getResourceAsStream(resource);
         }
         catch (Exception e) {}
  +      }
         
         if (stream==null)
         {
  @@ -36,28 +34,28 @@
         return stream;
      }
   
  -   public static InputStream getResourceAsStream(String resource, ServletContext servletContext) 
  +   public static URL getResource(String resource, ServletContext servletContext) 
      {
         String stripped = resource.startsWith("/") ? 
               resource.substring(1) : resource;
      
  -      InputStream stream = null; 
  +      URL url  = null; 
   
         try
         {
  -         stream = servletContext.getResourceAsStream(resource);
  +         url = servletContext.getResource(resource);
         }
         catch (Exception e) {}
         
  -      if (stream==null)
  +      if (url==null)
         {
  -         stream = getResourceAsStream(resource, stripped);
  +        url = getResource(resource, stripped);
         }
         
  -      return stream;
  +      return url;
      }
   
  -   private static InputStream getResourceAsStream(String resource, String stripped)
  +   static InputStream getResourceAsStream(String resource, String stripped)
      {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
         InputStream stream = null;
  @@ -76,50 +74,7 @@
         return stream;
      }
      
  -   public static URL getResource(String resource) 
  -   {
  -      String stripped = resource.startsWith("/") ? 
  -               resource.substring(1) : resource;
  -      
  -         URL url = null; 
  -
  -         try
  -         {
  -            url = FacesContext.getCurrentInstance().getExternalContext()
  -                  .getResource(resource);
  -         }
  -         catch (Exception e) {}
  -         
  -         if (url==null)
  -         {
  -            url = getResource(resource, stripped);
  -         }
  -         
  -         return url;
  -   }
  -   
  -   public static URL getResource(String resource, ServletContext servletContext) 
  -   {
  -      String stripped = resource.startsWith("/") ? 
  -            resource.substring(1) : resource;
  -   
  -      URL url  = null; 
  -
  -      try
  -      {
  -         url = servletContext.getResource(resource);
  -      }
  -      catch (Exception e) {}
  -      
  -      if (url==null)
  -      {
  -        url = getResource(resource, stripped);
  -      }
  -      
  -      return url;
  -   }
  -   
  -   private static URL getResource(String resource, String stripped)
  +   static URL getResource(String resource, String stripped)
      {
         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
         URL url = null;
  
  
  
  1.1      date: 2007/06/21 04:07:15;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/util/FacesResources.java
  
  Index: FacesResources.java
  ===================================================================
  package org.jboss.seam.util;
  
  import java.io.InputStream;
  import java.net.URL;
  
  import javax.faces.context.ExternalContext;
  
  public class FacesResources 
  {
  
     public static InputStream getResourceAsStream(String resource, ExternalContext context) 
     {
        String stripped = resource.startsWith("/") ? 
              resource.substring(1) : resource;
     
        InputStream stream = null; 
  
        try
        {
           if (context!=null)
           {
              stream = context.getResourceAsStream(resource);
           }
        }
        catch (Exception e) {}
        
        if (stream==null)
        {
           stream = Resources.getResourceAsStream(resource, stripped);
        }
        
        return stream;
     }
  
     public static URL getResource(String resource, ExternalContext context) 
     {
        String stripped = resource.startsWith("/") ? 
                 resource.substring(1) : resource;
        
           URL url = null; 
  
           try
           {
              if (context!=null)
              {
                 url = context.getResource(resource);
              }
           }
           catch (Exception e) {}
           
           if (url==null)
           {
              url = Resources.getResource(resource, stripped);
           }
           
           return url;
     }
     
  }
  
  
  



More information about the jboss-cvs-commits mailing list