From 9fe1f21c9fbcbafa14d222652c5e65e8c00207d6 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 16 Feb 2012 18:17:25 -0800 Subject: [PATCH] Use strings not objects --- .../src/org/apache/cordova/FileUtils.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 73a14863..c1489679 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -185,11 +185,11 @@ public class FileUtils extends Plugin { } } else if (action.equals("moveTo")) { - JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), true); + JSONObject entry = transferTo(args.getString(0), args.getString(1), args.getString(2), true); return new PluginResult(status, entry); } else if (action.equals("copyTo")) { - JSONObject entry = transferTo(args.getString(0), args.getJSONObject(1), args.optString(2), false); + JSONObject entry = transferTo(args.getString(0), args.getString(1), args.getString(2), false); return new PluginResult(status, entry); } else if (action.equals("readEntries")) { @@ -281,6 +281,10 @@ public class FileUtils extends Plugin { * @throws JSONException */ private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException { + if (fileName.startsWith("file://")) { + fileName = fileName.substring(7); + } + File fp = new File(fileName); if (!fp.exists()) { @@ -314,7 +318,15 @@ public class FileUtils extends Plugin { * @throws EncodingException * @throws JSONException */ - private JSONObject transferTo(String fileName, JSONObject newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException { + private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException { + if (fileName.startsWith("file://")) { + fileName = fileName.substring(7); + } + if (newParent.startsWith("file://")) { + newParent = newParent.substring(7); + } + + // Check for invalid file name if (newName != null && newName.contains(":")) { throw new EncodingException("Bad file name"); @@ -327,7 +339,7 @@ public class FileUtils extends Plugin { throw new FileNotFoundException("The source does not exist"); } - File destinationDir = new File(newParent.getString("fullPath")); + File destinationDir = new File(newParent); if (!destinationDir.exists()) { // The destination does not exist so we should fail. throw new FileNotFoundException("The source does not exist");