You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by wk...@apache.org on 2011/06/10 13:16:30 UTC
svn commit: r1134280 - in /incubator/stanbol/trunk: contenthub/web/pom.xml
contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java
launchers/full/src/main/bundles/list.xml parent/pom.xml
Author: wkasper
Date: Fri Jun 10 11:16:30 2011
New Revision: 1134280
URL: http://svn.apache.org/viewvc?rev=1134280&view=rev
Log:
Added mime type identifier to contenthub for uploaded files
Modified:
incubator/stanbol/trunk/contenthub/web/pom.xml
incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java
incubator/stanbol/trunk/launchers/full/src/main/bundles/list.xml
incubator/stanbol/trunk/parent/pom.xml
Modified: incubator/stanbol/trunk/contenthub/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/pom.xml?rev=1134280&r1=1134279&r2=1134280&view=diff
==============================================================================
--- incubator/stanbol/trunk/contenthub/web/pom.xml (original)
+++ incubator/stanbol/trunk/contenthub/web/pom.xml Fri Jun 10 11:16:30 2011
@@ -114,6 +114,11 @@
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
+ <dependency>
+ <groupId>eu.medsea.mimeutil</groupId>
+ <artifactId>mime-util</artifactId>
+ </dependency>
+
<!-- OSGi tax -->
<dependency>
Modified: incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java?rev=1134280&r1=1134279&r2=1134280&view=diff
==============================================================================
--- incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java (original)
+++ incubator/stanbol/trunk/contenthub/web/src/main/java/org/apache/stanbol/contenthub/web/resource/ContentHubRootResource.java Fri Jun 10 11:16:30 2011
@@ -22,6 +22,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -74,6 +75,8 @@ import org.slf4j.LoggerFactory;
import com.sun.jersey.api.view.Viewable;
import com.sun.jersey.core.header.FormDataContentDisposition;
+import eu.medsea.mimeutil.MimeUtil2;
+
/**
* Resource to provide a CRU[D] REST API for content items and there related
* enhancements.
@@ -114,6 +117,8 @@ public class ContentHubRootResource exte
protected List<RecentlyEnhanced> recentlyEnhanced;
protected TripleCollection entityCache;
+
+ protected MimeUtil2 mimeIdentifier;
public static class RecentlyEnhanced {
@@ -168,6 +173,10 @@ public class ContentHubRootResource exte
log.error("Missing either store={} or tcManager={}", store, tcManager);
throw new WebApplicationException(404);
}
+ mimeIdentifier = new MimeUtil2();
+ mimeIdentifier.registerMimeDetector("eu.medsea.mimeutil.detector.ExtensionMimeDetector");
+ mimeIdentifier.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
+
this.uriInfo = uriInfo;
this.offset = offset;
this.pageSize = pageSize;
@@ -359,12 +368,8 @@ public class ContentHubRootResource exte
} else if (file != null) {
data = FileUtils.readFileToByteArray(file);
String lowerFilename = disposition.getFileName().toLowerCase();
- // TODO: use a mimetype sniffer lib instead
- if (lowerFilename.matches(".*\\.jpe?g")) {
- mt = MediaType.valueOf("image/jpeg");
- } else {
- mt = APPLICATION_OCTET_STREAM_TYPE;
- }
+ Collection<?> mimeTypes = mimeIdentifier.getMimeTypes(file);
+ mt = MediaType.valueOf(MimeUtil2.getMostSpecificMimeType(mimeTypes).toString());
}
if (data != null && mt != null) {
String uri = makeContentItemUri(data).getUnicodeString();
Modified: incubator/stanbol/trunk/launchers/full/src/main/bundles/list.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/launchers/full/src/main/bundles/list.xml?rev=1134280&r1=1134279&r2=1134280&view=diff
==============================================================================
--- incubator/stanbol/trunk/launchers/full/src/main/bundles/list.xml (original)
+++ incubator/stanbol/trunk/launchers/full/src/main/bundles/list.xml Fri Jun 10 11:16:30 2011
@@ -151,6 +151,11 @@
<artifactId>joda-time</artifactId>
<version>1.6.2</version>
</bundle>
+ <bundle>
+ <groupId>eu.medsea.mimeutil</groupId>
+ <artifactId>mime-util</artifactId>
+ <version>2.1.3</version>
+ </bundle>
</startLevel>
<!-- JAX-RS -->
Modified: incubator/stanbol/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/parent/pom.xml?rev=1134280&r1=1134279&r2=1134280&view=diff
==============================================================================
--- incubator/stanbol/trunk/parent/pom.xml (original)
+++ incubator/stanbol/trunk/parent/pom.xml Fri Jun 10 11:16:30 2011
@@ -563,6 +563,14 @@
<scope>provided</scope>
</dependency>
+ <!-- MimeUtil -->
+ <dependency>
+ <groupId>eu.medsea.mimeutil</groupId>
+ <artifactId>mime-util</artifactId>
+ <version>2.1.3</version>
+ <scope>provided</scope>
+ </dependency>
+
<!-- SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>