incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deedu...@apache.org
Subject [15/15] webworks commit: Sync up with cordova-js.
Date Tue, 03 Apr 2012 12:59:31 GMT
Sync up with cordova-js.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/commit/681a9446
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/tree/681a9446
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/diff/681a9446

Branch: refs/heads/master
Commit: 681a94464ec669d68f3fc8757471ac87717e8896
Parents: 74117b4
Author: Drew Walters <deedubbu@apache.org>
Authored: Fri Mar 2 07:37:17 2012 -0600
Committer: Drew Walters <deedubbu@apache.org>
Committed: Fri Mar 2 07:37:17 2012 -0600

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaExtension.java   |    2 +-
 .../src/org/apache/cordova/api/PluginResult.java   |   10 ++-
 .../src/org/apache/cordova/file/FileManager.java   |   61 +++++++++++---
 3 files changed, 57 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/681a9446/framework/ext/src/org/apache/cordova/CordovaExtension.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/CordovaExtension.java b/framework/ext/src/org/apache/cordova/CordovaExtension.java
index 86dad0b..b6e99a5 100644
--- a/framework/ext/src/org/apache/cordova/CordovaExtension.java
+++ b/framework/ext/src/org/apache/cordova/CordovaExtension.java
@@ -113,7 +113,7 @@ public final class CordovaExtension implements WidgetExtension {
             // if this is premature, we at least set the _nativeReady flag to true
             // so that when the JS side is ready, it knows native side is too
             Logger.log(this.getClass().getName() + ": invoking Cordova.onNativeReady.fire()");
-            scriptEngine.executeScript("try {Cordova.onNativeReady.fire();} catch(e) {_nativeReady
= true;}", null);
+            scriptEngine.executeScript("try {require('cordova/channel').onNativeReady.fire();}
catch(e) {_nativeReady = true;}", null);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/681a9446/framework/ext/src/org/apache/cordova/api/PluginResult.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/api/PluginResult.java b/framework/ext/src/org/apache/cordova/api/PluginResult.java
index 2cca7ee..f8a666c 100644
--- a/framework/ext/src/org/apache/cordova/api/PluginResult.java
+++ b/framework/ext/src/org/apache/cordova/api/PluginResult.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cordova.api;
 
+import org.apache.cordova.json4j.JSONArray;
 import org.apache.cordova.json4j.JSONObject;
 
 /**
@@ -40,6 +41,11 @@ public class PluginResult {
         this.message = JSONObject.quote(message);
     }
 
+    public PluginResult(Status status, JSONArray message) {
+        this.status = status.ordinal();
+        this.message = message.toString();
+    }
+
     public PluginResult(Status status, JSONObject message) {
         this.status = status.ordinal();
         this.message = (message != null) ? message.toString(): "null";
@@ -93,7 +99,7 @@ public class PluginResult {
      * @return JavaScript string that invokes the appropriate plugin success callback
      */
     public String toSuccessCallbackString(String callbackId) {
-        return "try { Cordova.callbackSuccess('"+callbackId+"', " + this.getJSONString()
+ "); } catch(e) { alert('error in callbackSuccess:' + e.message); }";
+        return "try { require('cordova').callbackSuccess('"+callbackId+"', " + this.getJSONString()
+ "); } catch(e) { alert('error in callbackSuccess:' + e.message); }";
     }
 
     /**
@@ -104,7 +110,7 @@ public class PluginResult {
      * @return JavaScript string that invokes the appropriate plugin error callback
      */
     public String toErrorCallbackString(String callbackId) {
-        return "try { Cordova.callbackError('"+callbackId+"', " + this.getJSONString() +
"); } catch(e) { alert('error in callbackError:' + e.message); }";
+        return "try { require('cordova').callbackError('"+callbackId+"', " + this.getJSONString()
+ "); } catch(e) { alert('error in callbackError:' + e.message); }";
     }
 
     public String toErrorString() {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-blackberry-webworks/blob/681a9446/framework/ext/src/org/apache/cordova/file/FileManager.java
----------------------------------------------------------------------
diff --git a/framework/ext/src/org/apache/cordova/file/FileManager.java b/framework/ext/src/org/apache/cordova/file/FileManager.java
index b59dfcb..7bf75eb 100644
--- a/framework/ext/src/org/apache/cordova/file/FileManager.java
+++ b/framework/ext/src/org/apache/cordova/file/FileManager.java
@@ -77,6 +77,7 @@ public class FileManager extends Plugin {
     protected static String ACTION_REQUEST_FILE_SYSTEM = "requestFileSystem";
     protected static String ACTION_RESOLVE_FILE_SYSTEM_URI = "resolveLocalFileSystemURI";
     protected static String ACTION_GET_METADATA = "getMetadata";
+    protected static String ACTION_GET_FILE_METADATA = "getFileMetadata";
     protected static String ACTION_LIST_DIRECTORY = "readEntries";
     protected static String ACTION_COPY_TO = "copyTo";
     protected static String ACTION_MOVE_TO = "moveTo";
@@ -219,7 +220,7 @@ public class FileManager extends Plugin {
             }
             return resolveFileSystemURI(uri);
         }
-        else if (ACTION_GET_METADATA.equals(action)) {
+        else if (ACTION_GET_METADATA.equals(action) || ACTION_GET_FILE_METADATA.equals(action))
{
             String path = null;
             try {
                 path = args.getString(0);
@@ -230,7 +231,7 @@ public class FileManager extends Plugin {
                 return new PluginResult(PluginResult.Status.JSON_EXCEPTION,
                         SYNTAX_ERR);
             }
-            return getMetadata(path);
+            return getMetadata(path, ACTION_GET_FILE_METADATA.equals(action));
         }
         else if (ACTION_LIST_DIRECTORY.equals(action)) {
             String path = null;
@@ -529,7 +530,7 @@ public class FileManager extends Plugin {
         }
         catch (JSONException e) {
             return new PluginResult(PluginResult.Status.JSON_EXCEPTION,
-                    "File systen entry JSON conversion failed.");
+                    "File system entry JSON conversion failed.");
         }
 
         return result;
@@ -571,17 +572,30 @@ public class FileManager extends Plugin {
      *
      * @param path
      *            full path name of the file or directory
+     * @param full
+     *            return full or partial meta data.
      * @return PluginResult containing metadata for file system entry or an
      *         error code if unable to retrieve metadata
      */
-    protected static PluginResult getMetadata(String path) {
+    protected static PluginResult getMetadata(String path, boolean full) {
         PluginResult result = null;
         FileConnection fconn = null;
         try {
             fconn = (FileConnection)Connector.open(path);
             if (fconn.exists()) {
-                long lastModified = fconn.lastModified();
-                result = new PluginResult(PluginResult.Status.OK, lastModified);
+                if (full) {
+                    JSONObject metadata = new JSONObject();
+                    metadata.put("size", fconn.fileSize());
+                    metadata.put("type",
+                            MIMETypeAssociations.getMIMEType(fconn.getURL()));
+                    metadata.put("name", fconn.getName());
+                    metadata.put("fullPath", fconn.getURL());
+                    metadata.put("lastModifiedDate", fconn.lastModified());
+                    result = new PluginResult(PluginResult.Status.OK, metadata);
+                } else {
+                    result = new PluginResult(PluginResult.Status.OK,
+                            fconn.lastModified());
+                }
             }
             else {
                 result = new PluginResult(PluginResult.Status.IO_EXCEPTION,
@@ -597,7 +611,11 @@ public class FileManager extends Plugin {
         catch (IOException e) {
             Logger.log(FileUtils.class.getName() + ": " + e);
             result = new PluginResult(PluginResult.Status.IO_EXCEPTION,
-                    e.getMessage());
+                    NOT_READABLE_ERR);
+        }
+        catch (JSONException e) {
+            result = new PluginResult(PluginResult.Status.JSON_EXCEPTION,
+                    "File system entry JSON conversion failed.");
         }
         finally {
             try {
@@ -609,6 +627,18 @@ public class FileManager extends Plugin {
         return result;
     }
 
+    private static JSONObject buildEntry(String dirPath, String filePath) throws JSONException
{
+        JSONObject entry = new JSONObject();
+        boolean isDir = filePath.endsWith(FileUtils.FILE_SEPARATOR);
+
+        entry.put("isFile", !isDir);
+        entry.put("isDirectory", isDir);
+        entry.put("name", isDir ? filePath.substring(0, filePath.length()-1) : filePath);
+        entry.put("fullPath", dirPath + filePath);
+
+        return entry;
+    }
+
     /**
      * Returns a listing of the specified directory contents. Names of both
      * files and directories are returned.
@@ -630,13 +660,18 @@ public class FileManager extends Plugin {
                     NOT_FOUND_ERR);
         }
 
-        // pass directory contents back as an array of Strings (names)
-        JSONArray array = new JSONArray();
-        while (listing.hasMoreElements()) {
-            array.add((String)listing.nextElement());
-        }
+        try {
+            // pass directory contents back as an array of JSONObjects (entries)
+            JSONArray array = new JSONArray();
+            while (listing.hasMoreElements()) {
+                array.add(buildEntry(path, (String) listing.nextElement()));
+            }
 
-        return new PluginResult(PluginResult.Status.OK, array.toString());
+            return new PluginResult(PluginResult.Status.OK, array);
+        } catch (JSONException e) {
+            return new PluginResult(PluginResult.Status.JSON_EXCEPTION,
+                    "File system entry JSON conversion failed.");
+        }
     }
 
     /**


Mime
View raw message