List of usage examples for com.facebook.react.bridge ReadableMap getString
@Nullable String getString(@NonNull String name);
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void download(final ReadableMap options, final Promise promise) { if (!options.hasKey(REQUESTID)) { throw new IllegalArgumentException("requestid is not supplied"); }/* w ww . j a v a 2 s . co m*/ final String requestID = options.getString(REQUESTID); final Map<String, Object> map = requestMap.get(requestID); if (map == null) { throw new IllegalArgumentException("requestid is invalid"); } final TransferObserver observer; try { observer = transferUtility.download((String) map.get(BUCKET), (String) map.get(KEY), new File((String) map.get(PATH))); } catch (final AmazonServiceException e) { promise.reject(e.getErrorCode(), e.getErrorMessage(), e); return; } catch (final AmazonClientException e) { promise.reject("", e.getMessage(), e); return; } transferIDMap.put(observer.getId(), requestID); map.put(TRANSFERID, observer.getId()); if ((Boolean) map.get(SUBSCRIBE)) { this.subscribe(observer); } promise.resolve("success"); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void createUploadRequest(final ReadableMap options, final Callback callback) { if (requestMap == null) { callback.invoke("Error: AWSS3TransferUtility is not initialized", null); return;/* w w w .j a va2 s .co m*/ } final String[] params = { BUCKET, KEY, PATH, SUBSCRIBE, COMPLETIONHANDLER }; for (int i = 0; i < params.length; i++) { if (!options.hasKey(params[i])) { callback.invoke(params[i] + " is not supplied", null); return; } } final Map<String, Object> map = new ConcurrentHashMap<>(); map.put(BUCKET, options.getString(BUCKET)); map.put(KEY, options.getString(KEY)); map.put(PATH, options.getString(PATH)); map.put(SUBSCRIBE, options.getBoolean(SUBSCRIBE)); map.put(COMPLETIONHANDLER, options.getBoolean(COMPLETIONHANDLER)); map.put(TYPE, UPLOAD); final UUID uuid = UUID.randomUUID(); requestMap.put(uuid.toString(), map); callback.invoke(null, uuid.toString()); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void upload(final ReadableMap options, final Promise promise) { if (!options.hasKey(REQUESTID)) { throw new IllegalArgumentException("requestid is not supplied"); }/*from w ww .j a v a 2 s .c o m*/ final String requestID = options.getString(REQUESTID); final Map<String, Object> map = requestMap.get(requestID); if (map == null) { throw new IllegalArgumentException("requestid is invalid"); } final TransferObserver observer; try { observer = transferUtility.upload((String) map.get(BUCKET), (String) map.get(KEY), new File((String) map.get(PATH))); } catch (final AmazonServiceException e) { promise.reject(e.getErrorCode(), e.getErrorMessage(), e); return; } catch (final AmazonClientException e) { promise.reject("", e.getMessage(), e); return; } transferIDMap.put(observer.getId(), requestID); map.put(TRANSFERID, observer.getId()); if ((Boolean) map.get(SUBSCRIBE)) { this.subscribe(observer); } promise.resolve("success"); }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
@ReactMethod public void editRequest(final ReadableMap options) { if (!options.hasKey(CONFIG)) { throw new IllegalArgumentException("config not supplied"); }// ww w. j av a2 s . co m final String config = options.getString(CONFIG); String option = null; if (options.hasKey(OPTION)) { option = options.getString(OPTION); } String request = null; if (options.hasKey(REQUEST)) { request = options.getString(REQUEST); } if (option == null && request == null) { throw new IllegalArgumentException("request and option not supplied. Please supply one"); } if (option != null && request != null) { throw new IllegalArgumentException("request and option are both supplied. Please only supply one"); } if (config.contentEquals(PAUSE)) { this.pause(request, option); } else if (config.contentEquals(RESUME)) { this.resume(request, option); } else if (config.contentEquals(CANCEL)) { this.cancel(request, option); } }
From source file:com.amazonaws.reactnative.sns.AWSRNSNSClient.java
License:Open Source License
@ReactMethod public void initWithOptions(final ReadableMap options) { if (!options.hasKey("region")) { throw new IllegalArgumentException("expected region key"); }/*from www.j a v a 2 s .com*/ final AWSRNCognitoCredentials credentials = this.getReactApplicationContext() .getNativeModule(AWSRNCognitoCredentials.class); if (credentials.getCredentialsProvider() == null) { throw new IllegalArgumentException("AWSCognitoCredentials is not initialized"); } gson = new GsonBuilder().setFieldNamingStrategy(FieldNamingPolicy.UPPER_CAMEL_CASE) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getSerializer()) .registerTypeAdapter(ByteBuffer.class, AWSRNClientMarshaller.getDeserializer()).create(); snsClient = new AmazonSNSClient(credentials.getCredentialsProvider(), new AWSRNClientConfiguration().withUserAgent("SNS")); snsClient.setRegion(Region.getRegion(Regions.fromName(options.getString("region")))); }
From source file:com.auth0.lock.react.bridge.InitOptions.java
License:Open Source License
public InitOptions(@Nullable ReadableMap options) { if (options == null) { return;/*ww w .j a v a 2 s . co m*/ } if (options.hasKey(CLIENT_ID_KEY)) { this.clientId = options.getString(CLIENT_ID_KEY); } if (options.hasKey(DOMAIN_KEY)) { this.domain = options.getString(DOMAIN_KEY); } if (options.hasKey(CONFIGURATION_DOMAIN_KEY)) { this.configurationDomain = options.getString(CONFIGURATION_DOMAIN_KEY); } this.libraryVersion = options.hasKey(LIBRARY_VERSION_KEY) ? options.getString(LIBRARY_VERSION_KEY) : "0.0.0"; }
From source file:com.blockablewebview.BlockableWebViewManager.java
License:Open Source License
@ReactProp(name = "source") public void setSource(WebView view, @Nullable ReadableMap source) { if (source != null) { if (source.hasKey("html")) { String html = source.getString("html"); if (source.hasKey("baseUrl")) { view.loadDataWithBaseURL(source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);/*from w ww . j a v a 2 s. c om*/ } else { view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING); } return; } if (source.hasKey("uri")) { String url = source.getString("uri"); String previousUrl = view.getUrl(); if (previousUrl != null && previousUrl.equals(url)) { return; } if (source.hasKey("method")) { String method = source.getString("method"); if (method.equals(HTTP_METHOD_POST)) { byte[] postData = null; if (source.hasKey("body")) { String body = source.getString("body"); try { postData = body.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { postData = body.getBytes(); } } if (postData == null) { postData = new byte[0]; } view.postUrl(url, postData); return; } } HashMap<String, String> headerMap = new HashMap<>(); if (source.hasKey("headers")) { ReadableMap headers = source.getMap("headers"); ReadableMapKeySetIterator iter = headers.keySetIterator(); while (iter.hasNextKey()) { String key = iter.nextKey(); headerMap.put(key, headers.getString(key)); } } view.loadUrl(url, headerMap); return; } } view.loadUrl(BLANK_URL); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
/** * Handles a message sent from Javascript. Expects the message envelope to look like: * <code>{"type":<String>,"payload":<JSON Object>}</code> * * @param message message from javascript */// w ww .j av a 2 s.c om @ReactMethod public void handler(final ReadableMap message) { if (message == null) { Log.w(LOG_TAG, "data message was null or undefined"); return; } Log.d(LOG_TAG, "JS --> sdk " + message.toString()); String responseId = message.hasKey("responseId") ? message.getString("responseId") : null; final String type = !TextUtils.isEmpty(responseId) ? responseId : message.getString("type"); Subscriber<Object> subscriber = new Subscriber<Object>() { @Override public void onNext(Object object) { WritableMap newAction = Arguments.createMap(); newAction.putString("type", message.getString("type")); writePayloadToMap(newAction, object); sendEvent(newAction, SCBridgeStatus.NEXT, type); } @Override public void onError(Throwable e) { WritableMap newAction = Arguments.createMap(); newAction.putString("type", message.getString("type")); newAction.putString("payload", e.getLocalizedMessage()); sendEvent(newAction, SCBridgeStatus.ERROR, type); } @Override public void onCompleted() { WritableMap completed = Arguments.createMap(); completed.putString("type", message.getString("type")); sendEvent(completed, SCBridgeStatus.COMPLETED, type); } }; mBridgeAPI.parseJSAction(convertMapToHashMap(message), subscriber); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private HashMap<String, Object> convertMapToHashMap(ReadableMap readableMap) { HashMap<String, Object> json = new HashMap<>(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: json.put(key, null);/* w ww. j a va 2s . c o m*/ break; case Boolean: json.put(key, readableMap.getBoolean(key)); break; case Number: json.put(key, readableMap.getDouble(key)); break; case String: json.put(key, readableMap.getString(key)); break; case Map: json.put(key, convertMapToHashMap(readableMap.getMap(key))); break; case Array: json.put(key, convertArrayToArrayList(readableMap.getArray(key))); break; } } return json; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
/** * Handles the {@link BridgeCommand#DATASERVICE_DELETEFEATURE} command. * * @param message//from w ww.j av a 2 s .com */ private void handleDeleteFeature(ReadableMap message) { Log.d(LOG_TAG, "Handling DELETEFEATURE message :" + message.toString()); try { SCKeyTuple featureKey = new SCKeyTuple(message.getString("payload")); sc.getDataService().getStoreById(featureKey.getStoreId()).delete(featureKey) .subscribeOn(Schedulers.io()).subscribe(new Subscriber<Boolean>() { @Override public void onCompleted() { Log.d(LOG_TAG, "delete completed"); } @Override public void onError(Throwable e) { Log.e(LOG_TAG, "onError()\n" + e.getLocalizedMessage()); } @Override public void onNext(Boolean deleted) { //TODO: send this over some "deleted" stream Log.d(LOG_TAG, "feature deleted!"); } }); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }