本文整理汇总了Java中org.mozilla.gecko.sync.ExtendedJSONObject.getString方法的典型用法代码示例。如果您正苦于以下问题:Java ExtendedJSONObject.getString方法的具体用法?Java ExtendedJSONObject.getString怎么用?Java ExtendedJSONObject.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.gecko.sync.ExtendedJSONObject
的用法示例。
在下文中一共展示了ExtendedJSONObject.getString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateResponse
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
/**
* Intepret a response from the auth server.
* <p>
* Throw an appropriate exception on errors; otherwise, return the response's
* status code.
*
* @return response's HTTP status code.
* @throws FxAccountClientException
*/
public static int validateResponse(HttpResponse response) throws FxAccountClientRemoteException {
final int status = response.getStatusLine().getStatusCode();
if (status == 200) {
return status;
}
int code;
int errno;
String error;
String message;
String info;
ExtendedJSONObject body;
try {
body = new SyncStorageResponse(response).jsonObjectBody();
body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
code = body.getLong(JSON_KEY_CODE).intValue();
errno = body.getLong(JSON_KEY_ERRNO).intValue();
error = body.getString(JSON_KEY_ERROR);
message = body.getString(JSON_KEY_MESSAGE);
info = body.getString(JSON_KEY_INFO);
} catch (Exception e) {
throw new FxAccountClientMalformedResponseException(response);
}
throw new FxAccountClientRemoteException(response, code, errno, error, message, info, body);
}
示例2: unbundleBody
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
protected void unbundleBody(ExtendedJSONObject body, byte[] requestKey, byte[] ctxInfo, byte[]... rest) throws Exception {
int length = 0;
for (byte[] array : rest) {
length += array.length;
}
if (body == null) {
throw new FxAccountClientException("body must be non-null");
}
String bundle = body.getString("bundle");
if (bundle == null) {
throw new FxAccountClientException("bundle must be a non-null string");
}
byte[] bundleBytes = Utils.hex2Byte(bundle);
final byte[] respHMACKey = new byte[32];
final byte[] respXORKey = new byte[length];
HKDF.deriveMany(requestKey, new byte[0], ctxInfo, respHMACKey, respXORKey);
unbundleBytes(bundleBytes, respHMACKey, respXORKey, rest);
}
示例3: fromJSONObjectV2
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
/**
* Exactly the same as {@link fromJSONObjectV1}, except that all key pairs are DSA key pairs.
*/
protected static State fromJSONObjectV2(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
switch (stateLabel) {
case Cohabiting:
return new Cohabiting(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")));
case Married:
return new Married(
o.getString("email"),
o.getString("uid"),
Utils.hex2Byte(o.getString("sessionToken")),
Utils.hex2Byte(o.getString("kA")),
Utils.hex2Byte(o.getString("kB")),
keyPairFromJSONObjectV2(o.getObject("keyPair")),
o.getString("certificate"));
default:
return fromJSONObjectV1(stateLabel, o);
}
}
示例4: onConflict
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
@Override
public void onConflict(ClientReadingListRecord up, ReadingListResponse response) {
ExtendedJSONObject body;
try {
body = response.jsonObjectBody();
String conflicting = body.getString("id");
Logger.warn(LOG_TAG, "Conflict detected: remote ID is " + conflicting);
// TODO: When an operation implies that a server record is a replacement
// of what we uploaded, we should ensure that we have a local copy of
// that server record!
} catch (IllegalStateException | NonObjectJSONException | IOException |
ParseException e) {
// Oops.
// But our workaround is the same either way.
}
// Either the record exists locally, in which case we need to merge,
// or it doesn't, and we'll download it shortly.
// The simplest thing to do in both cases is to simply delete the local
// record we tried to upload. Yes, we might lose some annotations, but
// we can leave doing better to a follow-up.
// Issues here are so unlikely that we don't do anything sophisticated
// (like moving the record to a holding area) -- just delete it ASAP.
acc.addDeletion(up);
}
示例5: validateResponse
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
/**
* Intepret a response from the auth server.
* <p>
* Throw an appropriate exception on errors; otherwise, return the response's
* status code.
*
* @return response's HTTP status code.
* @throws FxAccountClientException
*/
public static int validateResponse(HttpResponse response) throws FxAccountAbstractClientRemoteException {
final int status = response.getStatusLine().getStatusCode();
if (status == 200) {
return status;
}
int code;
int errno;
String error;
String message;
ExtendedJSONObject body;
try {
body = new SyncStorageResponse(response).jsonObjectBody();
body.throwIfFieldsMissingOrMisTyped(requiredErrorStringFields, String.class);
body.throwIfFieldsMissingOrMisTyped(requiredErrorLongFields, Long.class);
code = body.getLong(JSON_KEY_CODE).intValue();
errno = body.getLong(JSON_KEY_ERRNO).intValue();
error = body.getString(JSON_KEY_ERROR);
message = body.getString(JSON_KEY_MESSAGE);
} catch (Exception e) {
throw new FxAccountAbstractClientMalformedResponseException(response);
}
throw new FxAccountAbstractClientRemoteException(response, code, errno, error, message, body);
}
示例6: tabFromJSONObject
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
public static Tab tabFromJSONObject(JSONObject o) throws NonArrayJSONException {
ExtendedJSONObject obj = new ExtendedJSONObject(o);
String title = obj.getString("title");
String icon = obj.getString("icon");
JSONArray history = obj.getArray("urlHistory");
// Last used is inexplicably a string in seconds. Most of the time.
long lastUsed = 0;
Object lU = obj.get("lastUsed");
if (lU instanceof Number) {
lastUsed = ((Long) lU) * 1000L;
} else if (lU instanceof String) {
try {
lastUsed = Long.parseLong((String) lU, 10) * 1000L;
} catch (NumberFormatException e) {
Logger.debug(TabsRecord.LOG_TAG, "Invalid number format in lastUsed: " + lU);
}
}
return new Tab(title, icon, history, lastUsed);
}
示例7: unpickleV1
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
private void unpickleV1(final ExtendedJSONObject json)
throws NonObjectJSONException, NoSuchAlgorithmException, InvalidKeySpecException {
this.accountVersion = json.getIntegerSafely(KEY_ACCOUNT_VERSION);
this.email = json.getString(KEY_EMAIL);
this.profile = json.getString(KEY_PROFILE);
this.authServerURI = json.getString(KEY_IDP_SERVER_URI);
this.tokenServerURI = json.getString(KEY_TOKEN_SERVER_URI);
this.profileServerURI = json.getString(KEY_PROFILE_SERVER_URI);
// Fallback to default value when profile server URI was not pickled.
if (this.profileServerURI == null) {
this.profileServerURI = FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT.equals(this.authServerURI)
? FxAccountConstants.DEFAULT_PROFILE_SERVER_ENDPOINT
: FxAccountConstants.STAGE_PROFILE_SERVER_ENDPOINT;
}
// We get the default value for everything except syncing browser data.
this.authoritiesToSyncAutomaticallyMap.put(BrowserContract.AUTHORITY, json.getBoolean(KEY_IS_SYNCING_ENABLED));
this.bundle = json.getObject(KEY_BUNDLE);
if (bundle == null) {
throw new IllegalStateException("Pickle bundle is null.");
}
this.state = getState(bundle);
}
示例8: getState
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
private State getState(final ExtendedJSONObject bundle) throws InvalidKeySpecException,
NonObjectJSONException, NoSuchAlgorithmException {
// TODO: Should copy-pasta BUNDLE_KEY_STATE & LABEL to this file to ensure we maintain
// old versions?
final StateLabel stateLabelString = StateLabel.valueOf(
bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE_LABEL));
final String stateString = bundle.getString(AndroidFxAccount.BUNDLE_KEY_STATE);
if (stateLabelString == null || stateString == null) {
throw new IllegalStateException("stateLabel and stateString must not be null, but: " +
"(stateLabel == null) = " + (stateLabelString == null) +
" and (stateString == null) = " + (stateString == null));
}
try {
return StateFactory.fromJSONObject(stateLabelString, new ExtendedJSONObject(stateString));
} catch (Exception e) {
throw new IllegalStateException("could not get state", e);
}
}
示例9: createPrivateKey
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
public static SigningPrivateKey createPrivateKey(ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException {
String algorithm = o.getString("algorithm");
if (!"DS".equals(algorithm)) {
throw new InvalidKeySpecException("algorithm must equal DS, was " + algorithm);
}
try {
BigInteger x = new BigInteger(o.getString("x"), SERIALIZATION_BASE);
BigInteger p = new BigInteger(o.getString("p"), SERIALIZATION_BASE);
BigInteger q = new BigInteger(o.getString("q"), SERIALIZATION_BASE);
BigInteger g = new BigInteger(o.getString("g"), SERIALIZATION_BASE);
return createPrivateKey(x, p, q, g);
} catch (NullPointerException | NumberFormatException e) {
throw new InvalidKeySpecException("x, p, q, and g must be integers encoded as strings, base " + SERIALIZATION_BASE);
}
}
示例10: createPublicKey
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
public static VerifyingPublicKey createPublicKey(ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException {
String algorithm = o.getString("algorithm");
if (!"DS".equals(algorithm)) {
throw new InvalidKeySpecException("algorithm must equal DS, was " + algorithm);
}
try {
BigInteger y = new BigInteger(o.getString("y"), SERIALIZATION_BASE);
BigInteger p = new BigInteger(o.getString("p"), SERIALIZATION_BASE);
BigInteger q = new BigInteger(o.getString("q"), SERIALIZATION_BASE);
BigInteger g = new BigInteger(o.getString("g"), SERIALIZATION_BASE);
return createPublicKey(y, p, q, g);
} catch (NullPointerException | NumberFormatException e) {
throw new InvalidKeySpecException("y, p, q, and g must be integers encoded as strings, base " + SERIALIZATION_BASE);
}
}
示例11: createPrivateKey
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
public static SigningPrivateKey createPrivateKey(ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException {
String algorithm = o.getString("algorithm");
if (!"RS".equals(algorithm)) {
throw new InvalidKeySpecException("algorithm must equal RS, was " + algorithm);
}
try {
BigInteger n = new BigInteger(o.getString("n"), SERIALIZATION_BASE);
BigInteger d = new BigInteger(o.getString("d"), SERIALIZATION_BASE);
return createPrivateKey(n, d);
} catch (NullPointerException | NumberFormatException e) {
throw new InvalidKeySpecException("n and d must be integers encoded as strings, base " + SERIALIZATION_BASE);
}
}
示例12: fromJSONObjectV3
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
/**
* Exactly the same as {@link fromJSONObjectV2}, except that there's a new
* MigratedFromSyncV11 state.
*/
protected static State fromJSONObjectV3(StateLabel stateLabel, ExtendedJSONObject o) throws InvalidKeySpecException, NoSuchAlgorithmException, NonObjectJSONException {
switch (stateLabel) {
case MigratedFromSync11:
return new MigratedFromSync11(
o.getString("email"),
o.getString("uid"),
o.getBoolean("verified"),
o.getString("password"));
default:
return fromJSONObjectV2(stateLabel, o);
}
}
示例13: initFromPayload
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
@Override
public void initFromPayload(ExtendedJSONObject payload) {
this.hostname = payload.getString(PAYLOAD_HOSTNAME);
this.formSubmitURL = payload.getString(PAYLOAD_FORM_SUBMIT_URL);
this.httpRealm = payload.getString(PAYLOAD_HTTP_REALM);
this.encryptedUsername = payload.getString(PAYLOAD_USERNAME);
this.encryptedPassword = payload.getString(PAYLOAD_PASSWORD);
this.usernameField = payload.getString(PAYLOAD_USERNAME_FIELD);
this.passwordField = payload.getString(PAYLOAD_PASSWORD_FIELD);
}
示例14: handleHttpResponse
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
@Override
public void handleHttpResponse(HttpResponse response) {
SyncResponse res = new SyncResponse(response);
int statusCode = res.getStatusCode();
Logger.debug(LOG_TAG, "Got response with status code " + statusCode + ".");
if (statusCode != 200) {
delegate.handleError(new BrowserIDVerifierErrorResponseException("Expected status code 200."));
return;
}
ExtendedJSONObject o = null;
try {
o = res.jsonObjectBody();
} catch (Exception e) {
delegate.handleError(new BrowserIDVerifierMalformedResponseException(e));
return;
}
String status = o.getString("status");
if ("failure".equals(status)) {
delegate.handleFailure(o);
return;
}
if (!("okay".equals(status))) {
delegate.handleError(new BrowserIDVerifierMalformedResponseException("Expected status okay, got '" + status + "'."));
return;
}
delegate.handleSuccess(o);
}
示例15: updateProfileInformation
import org.mozilla.gecko.sync.ExtendedJSONObject; //导入方法依赖的package包/类
/**
* Update profile information from json on UI thread.
*
* @param profileJSON json fetched from server.
*/
protected void updateProfileInformation(final ExtendedJSONObject profileJSON) {
// View changes must always be done on UI thread.
ThreadUtils.assertOnUiThread();
FxAccountUtils.pii(LOG_TAG, "Profile JSON is: " + profileJSON.toJSONString());
final String userName = profileJSON.getString(FxAccountConstants.KEY_PROFILE_JSON_USERNAME);
// Update the profile username and email if available.
if (!TextUtils.isEmpty(userName)) {
profilePreference.setTitle(userName);
profilePreference.setSummary(fxAccount.getEmail());
} else {
profilePreference.setTitle(fxAccount.getEmail());
}
// Icon update from java is not supported prior to API 11, skip the avatar image fetch and update for older device.
if (!AppConstants.Versions.feature11Plus) {
Logger.info(LOG_TAG, "Skipping profile image fetch for older pre-API 11 devices.");
return;
}
// Avatar URI empty, skip profile image fetch.
final String avatarURI = profileJSON.getString(FxAccountConstants.KEY_PROFILE_JSON_AVATAR);
if (TextUtils.isEmpty(avatarURI)) {
Logger.info(LOG_TAG, "AvatarURI is empty, skipping profile image fetch.");
return;
}
// Using noPlaceholder would avoid a pop of the default image, but it's not available in the version of Picasso
// we ship in the tree.
Picasso
.with(getActivity())
.load(avatarURI)
.centerInside()
.resizeDimen(R.dimen.fxaccount_profile_image_width, R.dimen.fxaccount_profile_image_height)
.placeholder(R.drawable.sync_avatar_default)
.error(R.drawable.sync_avatar_default)
.into(profileAvatarTarget);
}