jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From unc...@apache.org
Subject svn commit: r170365 - /incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java
Date Mon, 16 May 2005 11:38:27 GMT
Author: uncled
Date: Mon May 16 04:38:27 2005
New Revision: 170365

URL: http://svn.apache.org/viewcvs?rev=170365&view=rev
Log:
improved mime-type support for fs import

Modified:
    incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java

Modified: incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java?rev=170365&r1=170364&r2=170365&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java
(original)
+++ incubator/jackrabbit/trunk/contrib/examples/src/java/org/apache/jackrabbit/examples/FSImport.java
Mon May 16 04:38:27 2005
@@ -22,14 +22,15 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import java.io.FileInputStream;
-import java.io.InputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.Hashtable;
 import java.util.Calendar;
 
+import sun.net.www.MimeTable;
+
 /**
- * The File System import example class.
+ * The First Steps example class.
  */
 public class FSImport {
 
@@ -85,13 +86,14 @@
      *
      * @param parentnode Parent Repository Node
      * @param file File to be imported
-     * @throws RepositoryException, IOException on errors
+     * @throws RepositoryException on repository errors, IOException on io errors
      */
 
     public static void importFile(Node parentnode, File file) throws RepositoryException,
IOException {
 
-        // add some other means to extract mime type from filename
-        String mimeType = "application/octet-stream";
+        MimeTable mt = MimeTable.getDefaultTable();
+        String mimeType = mt.getContentTypeFor(file.getName());
+        if (mimeType==null) mimeType="application/octet-stream";
 
         Node fileNode = parentnode.addNode(file.getName(), "nt:file");
         Node resNode = fileNode.addNode("jcr:content", "nt:resource");
@@ -110,11 +112,11 @@
      *
      * @param parentnode Parent Repository Node
      * @param directory Directory to be traversed
-     * @throws RepositoryException, IOException on errors
+     * @throws RepositoryException on repository errors, IOException on io errors
      */
 
     private static void importFolder(Node parentnode, File directory) throws RepositoryException,
IOException  {
-        File[] direntries =directory.listFiles();
+        File[] direntries = directory.listFiles();
         System.out.println(parentnode.getPath());
         for (int i=0; i<direntries.length; i++) {
             File direntry = direntries[i];
@@ -165,5 +167,4 @@
             dump(child);
         }
     }
-
 }



Mime
View raw message