incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r711770 - in /incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp: JspScriptEngineFactory.java SlingIOProvider.java
Date Thu, 06 Nov 2008 04:29:05 GMT
Author: fmeschbe
Date: Wed Nov  5 20:29:05 2008
New Revision: 711770

URL: http://svn.apache.org/viewvc?rev=711770&view=rev
Log:
Sling-720 Try to assign a well-known MIME type derived from the filename extension

Modified:
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=711770&r1=711769&r2=711770&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Wed Nov  5 20:29:05 2008
@@ -190,7 +190,7 @@
             // prepare some classes
             prepareJasperClasses();
 
-            ioProvider = new SlingIOProvider(repository);
+            ioProvider = new SlingIOProvider(repository, slingServletContext);
 
             tldLocationsCache = new SlingTldLocationsCache(slingServletContext,
                 componentContext.getBundleContext());

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=711770&r1=711769&r2=711770&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
(original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
Wed Nov  5 20:29:05 2008
@@ -32,6 +32,7 @@
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
+import javax.servlet.ServletContext;
 
 import org.apache.sling.api.SlingException;
 import org.apache.sling.api.resource.Resource;
@@ -52,15 +53,19 @@
 
     private final SlingRepository repository;
 
-    private ThreadLocal<ResourceResolver> requestResourceResolver;
+    private final ThreadLocal<ResourceResolver> requestResourceResolver;
 
     // private session for write access
-    private ThreadLocal<Session> privateSession;
+    private final ThreadLocal<Session> privateSession;
+    
+    // used to find out about the mime type for created files
+    private final ServletContext servletContext;
 
-    SlingIOProvider(SlingRepository repository) {
+    SlingIOProvider(SlingRepository repository, ServletContext servletContext) {
         this.repository = repository;
         this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
         this.privateSession = new ThreadLocal<Session>();
+        this.servletContext = servletContext;
     }
 
     void setRequestResourceResolver(ResourceResolver resolver) {
@@ -80,6 +85,10 @@
         }
     }
 
+    ServletContext getServletContext() {
+        return servletContext;
+    }
+    
     // ---------- IOProvider interface -----------------------------------------
 
     /**
@@ -377,12 +386,17 @@
                     contentNode = fileNode.addNode("jcr:content", "nt:resource");
                 }
 
+                String mimeType = repositoryOutputProvider.getServletContext().getMimeType(
+                    fileName);
+                if (mimeType == null) {
+                    mimeType = "application/octet-stream";
+                }
+                
                 contentNode.setProperty("jcr:lastModified",
                     System.currentTimeMillis());
                 contentNode.setProperty("jcr:data", new ByteArrayInputStream(
                     buf, 0, size()));
-                contentNode.setProperty("jcr:mimeType",
-                    "application/octet-stream");
+                contentNode.setProperty("jcr:mimeType", mimeType);
 
                 parentNode.save();
             } catch (RepositoryException re) {



Mime
View raw message