Merge pull request #152 from owncloud/oauth_login
[pub/Android/ownCloud.git] / src / eu / alefzero / webdav / WebdavEntry.java
index f4fbda4..46923c6 100644 (file)
@@ -2,9 +2,8 @@
  *   Copyright (C) 2012  ownCloud
  *
  *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
+ *   it under the terms of the GNU General Public License version 2,
+ *   as published by the Free Software Foundation.
  *
  *   This program is distributed in the hope that it will be useful,
  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,7 +23,9 @@ import org.apache.jackrabbit.webdav.property.DavProperty;
 import org.apache.jackrabbit.webdav.property.DavPropertyName;
 import org.apache.jackrabbit.webdav.property.DavPropertySet;
 
-import android.util.Log;
+import com.owncloud.android.Log_OC;
+
+import android.net.Uri;
 
 public class WebdavEntry {
     private String mName, mPath, mUri, mContentType;
@@ -49,6 +50,8 @@ public class WebdavEntry {
                     mName = tmp[tmp.length - 1];
             }
 
+            // use unknown mimetype as default behavior
+            mContentType = "application/octet-stream";
             prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
             if (prop != null) {
                 mContentType = (String) prop.getValue();
@@ -56,13 +59,15 @@ public class WebdavEntry {
                 if (mContentType.indexOf(";") >= 0) {
                     mContentType = mContentType.substring(0, mContentType.indexOf(";"));
                 }
-            } else {
-                mContentType = "DIR";
-                /*
-                 * prop = propSet.get(DavPropertyName.ISCOLLECTION); if (prop !=
-                 * null && Boolean.parseBoolean((String) prop.getValue()))
-                 * mContentType = "DIR";
-                 */
+            }
+            
+            // check if it's a folder in the standard way: see RFC2518 12.2 . RFC4918 14.3 
+            prop = propSet.get(DavPropertyName.RESOURCETYPE);
+            if (prop!= null) {
+                Object value = prop.getValue();
+                if (value != null) {
+                    mContentType = "DIR";   // a specific attribute would be better, but this is enough; unless while we have no reason to distinguish MIME types for folders
+                }
             }
 
             prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
@@ -84,7 +89,7 @@ public class WebdavEntry {
             }
 
         } else {
-            Log.e("WebdavEntry",
+            Log_OC.e("WebdavEntry",
                     "General fuckup, no status for webdav response");
         }
     }
@@ -92,6 +97,10 @@ public class WebdavEntry {
     public String path() {
         return mPath;
     }
+    
+    public String decodedPath() {
+        return Uri.decode(mPath);
+    }
 
     public String name() {
         return mName;
@@ -117,7 +126,7 @@ public class WebdavEntry {
         return mCreateTimestamp;
     }
 
-    public long modifiedTimesamp() {
+    public long modifiedTimestamp() {
         return mModifiedTimestamp;
     }