incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r885727 - in /sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav: ./ src/main/java/org/apache/sling/jcr/webdav/impl/helper/
Date Tue, 01 Dec 2009 10:55:45 GMT
Author: fmeschbe
Date: Tue Dec  1 10:55:44 2009
New Revision: 885727

URL: http://svn.apache.org/viewvc?rev=885727&view=rev
Log:
SLING-1212 Upgrade simple WebDAV support to Jackrabbit 2.0-beta3 and replace
old MimeResolver with new SlingTikaDetector

Added:
    sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
  (with props)
Removed:
    sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingMimeResolver.java
Modified:
    sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/pom.xml
    sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java

Modified: sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/pom.xml
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/pom.xml?rev=885727&r1=885726&r2=885727&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/pom.xml (original)
+++ sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/pom.xml Tue Dec  1 10:55:44
2009
@@ -115,9 +115,15 @@
         </dependency>
 
         <dependency>
+            <groupId>javax.jcr</groupId>
+            <artifactId>jcr</artifactId>
+            <version>2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.jackrabbit</groupId>
             <artifactId>jackrabbit-jcr-server</artifactId>
-            <version>1.5.0</version>
+            <version>2.0-beta3</version>
             <scope>compile</scope>
         </dependency>
 

Modified: sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java?rev=885727&r1=885726&r2=885727&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
(original)
+++ sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java
Tue Dec  1 10:55:44 2009
@@ -30,7 +30,6 @@
 import org.apache.jackrabbit.server.io.DirListingExportHandler;
 import org.apache.jackrabbit.server.io.IOManager;
 import org.apache.jackrabbit.server.io.IOManagerImpl;
-import org.apache.jackrabbit.server.io.MimeResolver;
 import org.apache.jackrabbit.server.io.PropertyManager;
 import org.apache.jackrabbit.server.io.PropertyManagerImpl;
 import org.apache.jackrabbit.webdav.simple.DefaultItemFilter;
@@ -43,8 +42,6 @@
 
 public class SlingResourceConfig extends ResourceConfig {
 
-    private final MimeResolver mimeResolver;
-
     private final String[] collectionTypes;
 
     private final ItemFilter itemFilter;
@@ -57,9 +54,9 @@
 
     private final Dictionary<String, String> servletInitParams;
 
-    public SlingResourceConfig(MimeTypeService mimetypService,
+    public SlingResourceConfig(MimeTypeService mimeTypeService,
             Dictionary<?, ?> config) {
-        mimeResolver = new SlingMimeResolver(mimetypService);
+        super(new SlingTikaDetector(mimeTypeService));
         collectionTypes = OsgiUtil.toStringArray(
             config.get(SlingWebDavServlet.COLLECTION_TYPES),
             SlingWebDavServlet.COLLECTION_TYPES_DEFAULT);
@@ -93,7 +90,7 @@
         DirListingExportHandler dirHandler = new DirListingExportHandler();
         DefaultHandler defaultHandler = new DefaultHandler(null, collectionType,
             nonCollectionType, contentType);
-        
+
         ioManager = new IOManagerImpl();
         ioManager.addIOHandler(dirHandler);
         ioManager.addIOHandler(defaultHandler);
@@ -131,11 +128,6 @@
     }
 
     @Override
-    public MimeResolver getMimeResolver() {
-        return mimeResolver;
-    }
-
-    @Override
     public PropertyManager getPropertyManager() {
         return propertyManager;
     }

Added: sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
URL: http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java?rev=885727&view=auto
==============================================================================
--- sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
(added)
+++ sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
Tue Dec  1 10:55:44 2009
@@ -0,0 +1,83 @@
+/*
+ * Copyright 1997-2009 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.jcr.webdav.impl.helper;
+
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.tika.detect.Detector;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.mime.MediaType;
+
+public class SlingTikaDetector implements Detector {
+
+    private final MimeTypeService mimeTypeService;
+
+    public SlingTikaDetector(MimeTypeService mimeTypeService) {
+        this.mimeTypeService = mimeTypeService;
+    }
+
+    public MediaType detect(InputStream rawData, Metadata metadata) {
+
+        // NOTE: This implementation is built after the Tika NameDetector
+        //    implementation which only takes the resource name into
+        //    consideration when trying to detect the MIME type.
+
+        // Look for a resource name in the input metadata
+        String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
+        if (name != null) {
+            // If the name is a URL, skip the trailing query and fragment parts
+            int question = name.indexOf('?');
+            if (question != -1) {
+                name = name.substring(0, question);
+            }
+            int hash = name.indexOf('#');
+            if (hash != -1) {
+                name = name.substring(0, hash);
+            }
+
+            // If the name is a URL or a path, skip all but the last component
+            int slash = name.lastIndexOf('/');
+            if (slash != -1) {
+                name = name.substring(slash + 1);
+            }
+            int backslash = name.lastIndexOf('\\');
+            if (backslash != -1) {
+                name = name.substring(backslash + 1);
+            }
+
+            // Decode any potential URL encoding
+            int percent = name.indexOf('%');
+            if (percent != -1) {
+                try {
+                    name = URLDecoder.decode(name, "UTF-8");
+                } catch (UnsupportedEncodingException e) {
+                    throw new AssertionError("UTF-8 not supported");
+                }
+            }
+
+            // Skip any leading or trailing whitespace
+            name = name.trim();
+            if (name.length() > 0) {
+                // Match the name against the registered patterns
+                String type = mimeTypeService.getMimeType(name);
+                if (type != null) {
+                    return MediaType.parse(type);
+                }
+            }
+        }
+
+        return MediaType.OCTET_STREAM;
+    }
+
+}

Propchange: sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/whiteboard/fmeschbe/jackrabbit2upgrade/bundles/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message