package main.java.filemanager;

import java.io.File;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by mac on 03/05/15.
 */
public class DirItem {
    enum Type {
        image,
        text,
        zip,
        folder,
        unknown
    }
    //String mimeType;
    String name;
    Type type;
    private static Map<String,Type> types = new HashMap<String, Type>();
    static {
        types.put("image/",Type.image);
        types.put("text/",Type.text);
        types.put("application/zip",Type.zip);
    }
    protected Type determineType(File file) {
        if (file.isDirectory()) {
            return Type.folder;
        }
        String mimeType = URLConnection.guessContentTypeFromName(name);
        int i = mimeType.indexOf('/');
        if (i > 0) {
            Type t = types.get(mimeType.substring(0, i));
            if (t!=null) {
                return t;
            }
        }
        Type t = types.get(mimeType);
        if (t!=null) {
            return t;
        }
        return Type.unknown;
    }
    String getName() {
        return name;
    }
    DirItem(File file) {
        this.name = file.getAbsolutePath();
        this.type=determineType(file);
    }
}

@@ -746,24 +746,60 @@
 Name(name);%0A
+        if (mimeType != null) %7B%0A    
         int 
@@ -825,16 +825,20 @@
 f('/');%0A
+    
         
@@ -854,32 +854,36 @@
 ) %7B%0A            
+    
 Type t = types.g
@@ -916,39 +916,45 @@
 ));%0A            
+ 
+   
 if (t
+ 
 !=
+ 
 null) %7B%0A        
@@ -953,32 +953,36 @@
                 
+ 
+   
 return t;%0A      
@@ -979,34 +979,42 @@
  t;%0A            
+   
+ 
 %7D%0A
+    
         %7D%0A      
@@ -999,32 +999,36 @@
 %7D%0A            %7D%0A
+    
         Type t =
@@ -1061,15 +1061,21 @@
     
+  
+  
 if (t
+ 
 !=
+ 
 null
@@ -1082,32 +1082,36 @@
 ) %7B%0A            
+  
+  
 return t;%0A      
@@ -1096,32 +1096,46 @@
       return t;%0A
+            %7D%0A
         %7D%0A      

test api.jsp