CB-6050: Create instance method for returning a FileEntry structure given a device file path
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/af70ff4e Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/af70ff4e Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/af70ff4e Branch: refs/heads/master Commit: af70ff4e65d6a90bfc03ac3b7561624d6552daef Parents: c56b330 Author: Ian Clelland <[email protected]> Authored: Tue Feb 18 15:04:58 2014 -0500 Committer: Ian Clelland <[email protected]> Committed: Tue Feb 18 15:04:58 2014 -0500 ---------------------------------------------------------------------- src/android/FileUtils.java | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/af70ff4e/src/android/FileUtils.java ---------------------------------------------------------------------- diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java index ca643b3..f7eeaae 100644 --- a/src/android/FileUtils.java +++ b/src/android/FileUtils.java @@ -752,6 +752,26 @@ public class FileUtils extends CordovaPlugin { return fs; } + /** + * Returns a JSON object representing the given File. Internal APIs should be modified + * to use URLs instead of raw FS paths wherever possible, when interfacing with this plugin. + * + * @param file the File to convert + * @return a JSON representation of the given File + * @throws JSONException + */ + public JSONObject getEntryForFile(File file) throws JSONException { + JSONObject entry; + + for (Filesystem fs : filesystems) { + entry = fs.makeEntryForFile(file); + if (entry != null) { + return entry; + } + } + return null; + } + /** * Returns a JSON object representing the given File. Deprecated, as this is only used by * FileTransfer, and because it is a static method that should really be an instance method, @@ -764,15 +784,8 @@ public class FileUtils extends CordovaPlugin { */ @Deprecated public static JSONObject getEntry(File file) throws JSONException { - JSONObject entry; - if (getFilePlugin() != null) { - for (Filesystem fs:getFilePlugin().filesystems) { - entry = fs.makeEntryForFile(file); - if (entry != null) { - return entry; - } - } + return getFilePlugin().getEntryForFile(file); } return null; }
