This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.jcr.webdav-2.1.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-webdav.git
commit c5338ab4151ac521774f18a8b3257b5c6351a07d Author: Justin Edelson <jus...@apache.org> AuthorDate: Thu Feb 18 15:08:43 2010 +0000 SLING-1212 - upgrading to Jackrabbit 2. Also includes re-revert of SLING-1363 and implementation of SLING-1330. Thanks to Felix for getting this started. git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/webdav@911430 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 8 +- .../jcr/webdav/impl/helper/SlingMimeResolver.java | 41 ---------- .../webdav/impl/helper/SlingResourceConfig.java | 14 +--- .../jcr/webdav/impl/helper/SlingTikaDetector.java | 88 ++++++++++++++++++++++ 4 files changed, 98 insertions(+), 53 deletions(-) diff --git a/pom.xml b/pom.xml index 584335c..b2a4d81 100644 --- a/pom.xml +++ b/pom.xml @@ -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.0</version> <scope>compile</scope> </dependency> diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingMimeResolver.java b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingMimeResolver.java deleted file mode 100644 index a01ee22..0000000 --- a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingMimeResolver.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.sling.jcr.webdav.impl.helper; - -import org.apache.jackrabbit.server.io.MimeResolver; -import org.apache.sling.commons.mime.MimeTypeService; - -public class SlingMimeResolver extends MimeResolver { - - private final MimeTypeService mimeTypeService; - - public SlingMimeResolver(MimeTypeService mimeTypeService) { - this.mimeTypeService = mimeTypeService; - } - - @Override - public String getMimeType(String filename) { - String type = mimeTypeService.getMimeType(filename); - if (type == null) { - type = getDefaultMimeType(); - } - return type; - } - -} diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java index 270c416..0612a7f 100644 --- a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java +++ b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingResourceConfig.java @@ -30,7 +30,6 @@ import org.apache.jackrabbit.server.io.DefaultHandler; 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 @@ import org.apache.sling.jcr.webdav.impl.servlets.SlingWebDavServlet; public class SlingResourceConfig extends ResourceConfig { - private final MimeResolver mimeResolver; - private final String[] collectionTypes; private final ItemFilter itemFilter; @@ -57,9 +54,9 @@ public class SlingResourceConfig extends ResourceConfig { 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 @@ public class SlingResourceConfig extends ResourceConfig { 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 @@ public class SlingResourceConfig extends ResourceConfig { } @Override - public MimeResolver getMimeResolver() { - return mimeResolver; - } - - @Override public PropertyManager getPropertyManager() { return propertyManager; } diff --git a/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java new file mode 100644 index 0000000..69f2828 --- /dev/null +++ b/src/main/java/org/apache/sling/jcr/webdav/impl/helper/SlingTikaDetector.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +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; + } + +} -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.