manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1434701 - in /manifoldcf/branches/release-1.1-branch: ./ connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/ connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/s...
Date Thu, 17 Jan 2013 14:49:32 GMT
Author: kwright
Date: Thu Jan 17 14:49:32 2013
New Revision: 1434701

URL: http://svn.apache.org/viewvc?rev=1434701&view=rev
Log:
Second part of CONNECTORS-613.

Modified:
    manifoldcf/branches/release-1.1-branch/   (props changed)
    manifoldcf/branches/release-1.1-branch/connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/FileConnector.java
    manifoldcf/branches/release-1.1-branch/connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharedrive/SharedDriveConnector.java

Propchange: manifoldcf/branches/release-1.1-branch/
------------------------------------------------------------------------------
  Merged /manifoldcf/trunk:r1434697

Modified: manifoldcf/branches/release-1.1-branch/connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/FileConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/release-1.1-branch/connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/FileConnector.java?rev=1434701&r1=1434700&r2=1434701&view=diff
==============================================================================
--- manifoldcf/branches/release-1.1-branch/connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/FileConnector.java
(original)
+++ manifoldcf/branches/release-1.1-branch/connectors/filesystem/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/filesystem/FileConnector.java
Thu Jan 17 14:49:32 2013
@@ -279,6 +279,7 @@ public class FileConnector extends org.a
                     RepositoryDocument data = new RepositoryDocument();
                     data.setBinary(is,fileBytes);
                     data.setFileName(file.getName());
+                    data.setMimeType(mapExtensionToMimeType(file.getName()));
                     data.addField("uri",file.toString());
                     // MHL for other metadata
                     activities.ingestDocument(documentIdentifier,version,convertToURI(documentIdentifier),data);
@@ -308,6 +309,31 @@ public class FileConnector extends org.a
     }
   }
 
+  protected final static Map<String,String> mimeMap;
+  static {
+    mimeMap = new HashMap<String,String>();
+    mimeMap.put("txt","text/plain");
+    mimeMap.put(".pdf","application/pdf");
+    mimeMap.put(".doc","application/msword");
+    mimeMap.put(".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+    mimeMap.put(".ppt","application/vnd.ms-powerpoint");
+    mimeMap.put(".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation");
+    mimeMap.put(".xls","application/vnd.ms-excel");
+    mimeMap.put(".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+  }
+  
+  /** Map an extension to a mime type */
+  protected static String mapExtensionToMimeType(String fileName)
+  {
+    int slashIndex = fileName.lastIndexOf("/");
+    if (slashIndex != -1)
+      fileName = fileName.substring(slashIndex+1);
+    int dotIndex = fileName.lastIndexOf(".");
+    if (dotIndex == -1)
+      return null;
+    return mimeMap.get(fileName.substring(dotIndex+1).toLowerCase(java.util.Locale.ROOT));
+  }
+
   // UI support methods.
   //
   // These support methods come in two varieties.  The first bunch is involved in setting
up connection configuration information.  The second bunch

Modified: manifoldcf/branches/release-1.1-branch/connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharedrive/SharedDriveConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/release-1.1-branch/connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharedrive/SharedDriveConnector.java?rev=1434701&r1=1434700&r2=1434701&view=diff
==============================================================================
--- manifoldcf/branches/release-1.1-branch/connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharedrive/SharedDriveConnector.java
(original)
+++ manifoldcf/branches/release-1.1-branch/connectors/jcifs/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharedrive/SharedDriveConnector.java
Thu Jan 17 14:49:32 2013
@@ -778,6 +778,9 @@ public class SharedDriveConnector extend
                         RepositoryDocument rd = new RepositoryDocument();
                         rd.setBinary(inputStream, tempFile.length());
                         rd.setFileName(file.getName());
+                        String contentType = mapExtensionToMimeType(file.getName());
+                        if (contentType != null)
+                          rd.setMimeType(contentType);
                         rd.addField("lastModified", new Date(file.lastModified()).toString());
                         int index = 0;
                         index = setDocumentSecurity(rd,version,index);
@@ -832,6 +835,9 @@ public class SharedDriveConnector extend
                     RepositoryDocument rd = new RepositoryDocument();
                     rd.setBinary(inputStream, fileLength(file));
                     rd.setFileName(file.getName());
+                    String contentType = mapExtensionToMimeType(file.getName());
+                    if (contentType != null)
+                      rd.setMimeType(contentType);
                     rd.addField("lastModified", new Date(file.lastModified()).toString());
                     int index = 0;
                     index = setDocumentSecurity(rd,version,index);
@@ -976,8 +982,31 @@ public class SharedDriveConnector extend
 
   }
 
-
-
+  protected final static Map<String,String> mimeMap;
+  static {
+    mimeMap = new HashMap<String,String>();
+    mimeMap.put("txt","text/plain");
+    mimeMap.put(".pdf","application/pdf");
+    mimeMap.put(".doc","application/msword");
+    mimeMap.put(".docx","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+    mimeMap.put(".ppt","application/vnd.ms-powerpoint");
+    mimeMap.put(".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation");
+    mimeMap.put(".xls","application/vnd.ms-excel");
+    mimeMap.put(".xlsx","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+  }
+  
+  /** Map an extension to a mime type */
+  protected static String mapExtensionToMimeType(String fileName)
+  {
+    int slashIndex = fileName.lastIndexOf("/");
+    if (slashIndex != -1)
+      fileName = fileName.substring(slashIndex+1);
+    int dotIndex = fileName.lastIndexOf(".");
+    if (dotIndex == -1)
+      return null;
+    return mimeMap.get(fileName.substring(dotIndex+1).toLowerCase(java.util.Locale.ROOT));
+  }
+  
   /** This method calculates an ACL string based on whether there are forced acls and also
based on
   * the acls in place for a file.
   */



Mime
View raw message