incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r739956 - in /incubator/sling/trunk/scripting/core: pom.xml src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
Date Mon, 02 Feb 2009 10:28:42 GMT
Author: fmeschbe
Date: Mon Feb  2 10:28:41 2009
New Revision: 739956

URL: http://svn.apache.org/viewvc?rev=739956&view=rev
Log:
SLING-847 Implement the MimeTypeProvider interface to support mapping
extensions and MIME types of registered ScriptEngineFactories to some
MIME types and extensions

Modified:
    incubator/sling/trunk/scripting/core/pom.xml
    incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java

Modified: incubator/sling/trunk/scripting/core/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/core/pom.xml?rev=739956&r1=739955&r2=739956&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/core/pom.xml (original)
+++ incubator/sling/trunk/scripting/core/pom.xml Mon Feb  2 10:28:41 2009
@@ -133,6 +133,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.mime</artifactId>
+            <version>2.0.2-incubator</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.jcr.api</artifactId>
             <version>2.0.2-incubator</version>
         </dependency>

Modified: incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java?rev=739956&r1=739955&r2=739956&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
(original)
+++ incubator/sling/trunk/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/SlingScriptAdapterFactory.java
Mon Feb  2 10:28:41 2009
@@ -33,6 +33,7 @@
 
 import org.apache.sling.api.adapter.AdapterFactory;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.mime.MimeTypeProvider;
 import org.apache.sling.scripting.core.impl.helper.SlingScriptEngineManager;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -55,12 +56,13 @@
  *               values.0="org.apache.sling.api.scripting.SlingScript"
  *               values.1="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.api.adapter.AdapterFactory"
+ * @scr.service interface="org.apache.sling.commons.mime.MimeTypeProvider"
  * @scr.reference name="ScriptEngineFactory"
  *                interface="javax.script.ScriptEngineFactory"
  *                cardinality="0..n" policy="dynamic"
  */
 public class SlingScriptAdapterFactory implements AdapterFactory,
-        BundleListener {
+        MimeTypeProvider, BundleListener {
 
     private static final Logger log = LoggerFactory.getLogger(SlingScriptAdapterFactory.class);
 
@@ -205,6 +207,54 @@
         }
     }
 
+    // ---------- MimeTypeProvider
+
+    /**
+     * Returns the first MIME type entry of the supported MIME types of a
+     * ScriptEngineFactory which is registered for the extension of the given
+     * name. If no ScriptEngineFactory is registered for the given extension or
+     * the registered ScriptEngineFactory is not registered for a MIME type,
+     * this method returns <code>null</code>.
+     * 
+     * @param name The name whose extension is to be mapped to a MIME type. The
+     *            extension is the string after the last dot in the name. If the
+     *            name contains no dot, the entire name is considered the
+     *            extension.
+     */
+    public String getMimeType(String name) {
+        name = name.substring(name.lastIndexOf('.') + 1);
+        ScriptEngine se = getScriptEngineManager().getEngineByExtension(name);
+        if (se != null) {
+            List<?> mimeTypes = se.getFactory().getMimeTypes();
+            if (mimeTypes != null && mimeTypes.size() > 0) {
+                return String.valueOf(mimeTypes.get(0));
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns the first extension entry of the supported extensions of a
+     * ScriptEngineFactory which is registered for the given MIME type. If no
+     * ScriptEngineFactory is registered for the given MIME type or the
+     * registered ScriptEngineFactory is not registered for an extensions, this
+     * method returns <code>null</code>.
+     * 
+     * @param mimeType The MIME type to be mapped to an extension.
+     */
+    public String getExtension(String mimeType) {
+        ScriptEngine se = getScriptEngineManager().getEngineByMimeType(mimeType);
+        if (se != null) {
+            List<?> extensions = se.getFactory().getExtensions();
+            if (extensions != null && extensions.size() > 0) {
+                return String.valueOf(extensions.get(0));
+            }
+        }
+
+        return null;
+    }
+
     // ---------- SCR integration ----------------------------------------------
 
     protected void activate(ComponentContext context) {



Mime
View raw message