You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2006/01/25 08:22:11 UTC

svn commit: r372155 - /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java

Author: matzew
Date: Tue Jan 24 23:22:07 2006
New Revision: 372155

URL: http://svn.apache.org/viewcvs?rev=372155&view=rev
Log:
some refactoring

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java?rev=372155&r1=372154&r2=372155&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/custom/stylesheet/StylesheetRenderer.java Tue Jan 24 23:22:07 2006
@@ -15,17 +15,13 @@
  */
 package org.apache.myfaces.custom.stylesheet;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.renderkit.RendererUtils;
 import org.apache.myfaces.renderkit.html.HtmlRenderer;
 
 /**
@@ -35,8 +31,6 @@
 
 public class StylesheetRenderer extends HtmlRenderer {
 
-	 private static final Log LOG = LogFactory.getLog(StylesheetRenderer.class);
-      
 	 public void encodeEnd(FacesContext context, UIComponent component)
         throws IOException {
 
@@ -56,7 +50,7 @@
             writer.writeAttribute("media", stylesheet.getMedia(), null);
           }          
           //writer.writeText("<!--\n", null);
-          Object text = loadFile(context.getExternalContext().getRequestContextPath(), stylesheet.getPath());
+          Object text = RendererUtils.loadResourceFile(context, stylesheet.getPath());
           if (text != null)
           {
               writer.writeText(text, null);
@@ -83,46 +77,4 @@
         
 
     }
-
-  private Object loadFile(String ctxPath, String file)
-  {
-    
-    String href = ctxPath+file;
-    LOG.debug("loadFile: " + href);
-    
-    File cssFile = new File(href);
-    String content;
-    
-
-
-    if (cssFile.canRead())
-    {
-      FileInputStream in;
-      try {
-        in = new FileInputStream(cssFile);
-        byte[] fileBuffer = new byte[(int) cssFile.length()];
-        in.read(fileBuffer);
-        in.close();
-        content = new String(fileBuffer);
-      }
-      catch (FileNotFoundException e) {
-        // TODO Auto-generated catch block
-        e.printStackTrace();
-        content=null;
-      }
-      catch (IOException e) {
-        // TODO Auto-generated catch block
-        e.printStackTrace();
-        content=null;
-      }
-
-    }
-    else
-    {
-      LOG.error("File not readable: " + href);
-      content=null;
-    }
-    
-    return content;
-  }
 }