mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 12:03:28 +08:00
no more silly json strings in there
This commit is contained in:
parent
56f0e8e087
commit
ae800455b1
@ -17,10 +17,7 @@ import com.phonegap.DroidGap;
|
|||||||
* @author davejohnson
|
* @author davejohnson
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class CommandManager {
|
public final class CommandManager {
|
||||||
private static final String EXCEPTION_PREFIX = "[PhoneGap] *ERROR* Exception executing command [";
|
|
||||||
private static final String EXCEPTION_SUFFIX = "]: ";
|
|
||||||
|
|
||||||
private Command[] commands;
|
private Command[] commands;
|
||||||
|
|
||||||
private final Context ctx;
|
private final Context ctx;
|
||||||
@ -86,23 +83,19 @@ public final class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
cr = new CommandResult(CommandResult.Status.CLASSNOTFOUNDEXCEPTION,
|
cr = new CommandResult(CommandResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
||||||
"{ message: 'ClassNotFoundException', status: "+CommandResult.Status.CLASSNOTFOUNDEXCEPTION.ordinal()+" }");
|
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
cr = new CommandResult(CommandResult.Status.ILLEGALACCESSEXCEPTION,
|
cr = new CommandResult(CommandResult.Status.ILLEGAL_ACCESS_EXCEPTION);
|
||||||
"{ message: 'IllegalAccessException', status: "+CommandResult.Status.ILLEGALACCESSEXCEPTION.ordinal()+" }");
|
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException e) {
|
||||||
cr = new CommandResult(CommandResult.Status.INSTANTIATIONEXCEPTION,
|
cr = new CommandResult(CommandResult.Status.INSTANTIATION_EXCEPTION);
|
||||||
"{ message: 'InstantiationException', status: "+CommandResult.Status.INSTANTIATIONEXCEPTION.ordinal()+" }");
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
cr = new CommandResult(CommandResult.Status.JSONEXCEPTION,
|
cr = new CommandResult(CommandResult.Status.JSON_EXCEPTION);
|
||||||
"{ message: 'JSONException', status: "+CommandResult.Status.JSONEXCEPTION.ordinal()+" }");
|
|
||||||
}
|
}
|
||||||
// if async we have already returned at this point unless there was an error...
|
// if async we have already returned at this point unless there was an error...
|
||||||
if (async) {
|
if (async) {
|
||||||
app.loadUrl(cr.toErrorCallbackString(callbackId));
|
app.loadUrl(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
return ( cr != null ? cr.getResult() : "{ status: 0, message: 'all good' }" );
|
return ( cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,38 +1,60 @@
|
|||||||
package com.phonegap.api;
|
package com.phonegap.api;
|
||||||
|
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
public class CommandResult {
|
public class CommandResult {
|
||||||
private final int status;
|
private final int status;
|
||||||
private final String result;
|
private final String message;
|
||||||
|
|
||||||
public CommandResult(Status status, String result) {
|
public CommandResult(Status status) {
|
||||||
this.status = status.ordinal();
|
this.status = status.ordinal();
|
||||||
this.result = result;
|
this.message = CommandResult.StatusMessages[this.status];
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandResult(Status status, String message) {
|
||||||
|
this.status = status.ordinal();
|
||||||
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStatus() {
|
public int getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getResult() {
|
public String getMessage() {
|
||||||
return result;
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJSONString() {
|
||||||
|
return "{ status: " + this.getStatus() + ", message: '" + URLEncoder.encode(this.getMessage()) + "' }";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toSuccessCallbackString(String callbackId) {
|
public String toSuccessCallbackString(String callbackId) {
|
||||||
return "javascript:PhoneGap.callbackSuccess('"+callbackId+"', " + this.getResult()+ ");";
|
return "javascript:PhoneGap.callbackSuccess('"+callbackId+"', " + this.getJSONString() + " );";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toErrorCallbackString(String callbackId) {
|
public String toErrorCallbackString(String callbackId) {
|
||||||
return "javascript:PhoneGap.callbackError('"+callbackId+"', " + this.getResult()+ ");";
|
return "javascript:PhoneGap.callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String[] StatusMessages = new String[] {
|
||||||
|
"OK",
|
||||||
|
"Class not found",
|
||||||
|
"Illegal access",
|
||||||
|
"Instantiation error",
|
||||||
|
"Malformed url",
|
||||||
|
"IO error",
|
||||||
|
"Invalid action",
|
||||||
|
"JSON error"
|
||||||
|
};
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
OK,
|
OK,
|
||||||
CLASSNOTFOUNDEXCEPTION,
|
CLASS_NOT_FOUND_EXCEPTION,
|
||||||
ILLEGALACCESSEXCEPTION,
|
ILLEGAL_ACCESS_EXCEPTION,
|
||||||
INSTANTIATIONEXCEPTION,
|
INSTANTIATION_EXCEPTION,
|
||||||
MALFORMEDURLEXCEPTION,
|
MALFORMED_URL_EXCEPTION,
|
||||||
IOEXCEPTION,
|
IO_EXCEPTION,
|
||||||
INVALIDACTION,
|
INVALID_ACTION,
|
||||||
JSONEXCEPTION
|
JSON_EXCEPTION
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user