cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [11/15] git commit: CB-5407: Move getmetadata methods into FS modules
Date Fri, 13 Dec 2013 16:18:07 GMT
CB-5407: Move getmetadata methods into FS modules


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/836c6733
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/836c6733
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/836c6733

Branch: refs/heads/android-file
Commit: 836c67338c4be8e66d340f1e5c9f119285ee5d35
Parents: 03fcd12
Author: Ian Clelland <iclelland@chromium.org>
Authored: Wed Nov 27 14:36:19 2013 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Wed Dec 11 09:57:57 2013 -0500

----------------------------------------------------------------------
 src/android/ContentFilesystem.java |  5 ++++
 src/android/FileUtils.java         | 50 +++++++++++----------------------
 src/android/Filesystem.java        |  3 ++
 src/android/LocalFilesystem.java   | 22 +++++++++++++++
 4 files changed, 46 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index 8fef685..17fddcb 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -71,5 +71,10 @@ public class ContentFilesystem implements Filesystem {
 		// TODO Auto-generated method stub
 		return null;
 	}
+	@Override
+	public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException
{
+		// TODO Auto-generated method stub
+		return null;
+	}
 
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 01ce90b..8e050c5 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -242,15 +242,16 @@ public class FileUtils extends CordovaPlugin {
         else if (action.equals("getMetadata")) {
             final String fname=args.getString(0);
             threadhelper( new FileOp( ){
-                public void run() throws FileNotFoundException, JSONException {
-                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
getMetadata(fname)));
+                public void run() throws FileNotFoundException, JSONException, MalformedURLException
{
+                    JSONObject obj = getFileMetadata(fname);
+                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK,
obj.getLong("lastModifiedDate")));
                 }
             }, callbackContext);
         }
         else if (action.equals("getFileMetadata")) {
             final String fname=args.getString(0);
             threadhelper( new FileOp( ){
-                public void run() throws FileNotFoundException, JSONException {
+                public void run() throws FileNotFoundException, JSONException, MalformedURLException
{
                     JSONObject obj = getFileMetadata(fname);
                     callbackContext.success(obj);
                 }
@@ -891,45 +892,26 @@ public class FileUtils extends CordovaPlugin {
     }
 
     /**
-     * Look up metadata about this entry.
-     *
-     * @param filePath to entry
-     * @return a long
-     * @throws FileNotFoundException
-     */
-    private long getMetadata(String filePath) throws FileNotFoundException {
-        File file = createFileObject(filePath);
-
-        if (!file.exists()) {
-            throw new FileNotFoundException("Failed to find file in getMetadata");
-        }
-
-        return file.lastModified();
-    }
-
-    /**
      * Returns a File that represents the current state of the file that this FileEntry represents.
      *
      * @param filePath to entry
      * @return returns a JSONObject represent a W3C File object
      * @throws FileNotFoundException
      * @throws JSONException
+     * @throws MalformedURLException 
      */
-    private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException
{
-        File file = createFileObject(filePath);
-
-        if (!file.exists()) {
-            throw new FileNotFoundException("File: " + filePath + " does not exist.");
+    private JSONObject getFileMetadata(String baseURLstr) throws FileNotFoundException, JSONException,
MalformedURLException {
+        try {
+        	LocalFilesystemURL inputURL = new LocalFilesystemURL(baseURLstr);
+        	Filesystem fs = this.filesystemForURL(inputURL);
+        	if (fs == null) {
+        		throw new MalformedURLException("No installed handlers for this URL");
+        	}
+        	return fs.getFileMetadataForLocalURL(inputURL);
+        
+        } catch (IllegalArgumentException e) {
+        	throw new MalformedURLException("Unrecognized filesystem URL");
         }
-
-        JSONObject metadata = new JSONObject();
-        metadata.put("size", file.length());
-        metadata.put("type", FileHelper.getMimeType(filePath, cordova));
-        metadata.put("name", file.getName());
-        metadata.put("fullPath", filePath);
-        metadata.put("lastModifiedDate", file.lastModified());
-
-        return metadata;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 4abd403..d627d10 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -3,6 +3,7 @@ package org.apache.cordova.file;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import org.apache.cordova.CordovaInterface;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -20,4 +21,6 @@ public interface Filesystem {
 
 	JSONArray readEntriesAtLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
 
+	JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException;
+
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/836c6733/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 7d3aacb..3d11cf2 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -4,6 +4,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 
+import org.apache.cordova.CordovaInterface;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -214,4 +215,25 @@ public class LocalFilesystem implements Filesystem {
 		return null;
 	}
 
+	@Override
+	public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException
{
+        File file = new File(filesystemPathForURL(inputURL));
+
+        if (!file.exists()) {
+            throw new FileNotFoundException("File at " + inputURL.URL + " does not exist.");
+        }
+
+        JSONObject metadata = new JSONObject();
+        try {
+        	metadata.put("size", file.length());
+        	metadata.put("type", FileHelper.getMimeType(file.getAbsolutePath(), cordova));
+        	metadata.put("name", file.getName());
+        	metadata.put("fullPath", inputURL.fullPath);
+        	metadata.put("lastModifiedDate", file.lastModified());
+        } catch (JSONException e) {
+        	return null;
+        }
+        return metadata;
+	}
+
 }


Mime
View raw message