List of usage examples for com.google.gson JsonObject getAsJsonPrimitive
public JsonPrimitive getAsJsonPrimitive(String memberName)
From source file:org.matrix.androidsdk.util.EventDisplay.java
License:Apache License
/** * Stringify the linked event.//from w ww. j a va 2 s . c o m * @param displayNameColor the display name highlighted color. * @return The text or null if it isn't possible. */ public CharSequence getTextualDisplay(Integer displayNameColor) { CharSequence text = null; try { JsonObject jsonEventContent = mEvent.getContentAsJsonObject(); String userDisplayName = getUserDisplayName(mEvent.getSender(), mRoomState); String eventType = mEvent.getType(); if (mEvent.isCallEvent()) { if (Event.EVENT_TYPE_CALL_INVITE.equals(eventType)) { boolean isVideo = false; // detect call type from the sdp try { JsonObject offer = jsonEventContent.get("offer").getAsJsonObject(); JsonElement sdp = offer.get("sdp"); String sdpValue = sdp.getAsString(); isVideo = sdpValue.contains("m=video"); } catch (Exception e) { Log.e(LOG_TAG, "getTextualDisplay : " + e.getLocalizedMessage()); } if (isVideo) { return mContext.getString(R.string.notice_placed_video_call, userDisplayName); } else { return mContext.getString(R.string.notice_placed_voice_call, userDisplayName); } } else if (Event.EVENT_TYPE_CALL_ANSWER.equals(eventType)) { return mContext.getString(R.string.notice_answered_call, userDisplayName); } else if (Event.EVENT_TYPE_CALL_HANGUP.equals(eventType)) { return mContext.getString(R.string.notice_ended_call, userDisplayName); } else { return eventType; } } else if (Event.EVENT_TYPE_STATE_HISTORY_VISIBILITY.equals(eventType)) { CharSequence subpart; String historyVisibility = (null != jsonEventContent.get("history_visibility")) ? jsonEventContent.get("history_visibility").getAsString() : RoomState.HISTORY_VISIBILITY_SHARED; if (TextUtils.equals(historyVisibility, RoomState.HISTORY_VISIBILITY_SHARED)) { subpart = mContext.getString(R.string.notice_room_visibility_shared); } else if (TextUtils.equals(historyVisibility, RoomState.HISTORY_VISIBILITY_INVITED)) { subpart = mContext.getString(R.string.notice_room_visibility_invited); } else if (TextUtils.equals(historyVisibility, RoomState.HISTORY_VISIBILITY_JOINED)) { subpart = mContext.getString(R.string.notice_room_visibility_joined); } else if (TextUtils.equals(historyVisibility, RoomState.HISTORY_VISIBILITY_WORLD_READABLE)) { subpart = mContext.getString(R.string.notice_room_visibility_world_readable); } else { subpart = mContext.getString(R.string.notice_room_visibility_unknown, historyVisibility); } text = mContext.getString(R.string.notice_made_future_room_visibility, userDisplayName, subpart); } else if (Event.EVENT_TYPE_RECEIPT.equals(eventType)) { // the read receipt should not be displayed text = "Read Receipt"; } else if (Event.EVENT_TYPE_MESSAGE.equals(eventType)) { String msgtype = (null != jsonEventContent.get("msgtype")) ? jsonEventContent.get("msgtype").getAsString() : ""; // all m.room.message events should support the 'body' key fallback, so use it. text = jsonEventContent.get("body") == null ? null : jsonEventContent.get("body").getAsString(); // check for html formatting if (jsonEventContent.has("formatted_body") && jsonEventContent.has("format")) { String format = jsonEventContent.getAsJsonPrimitive("format").getAsString(); if (Message.FORMAT_MATRIX_HTML.equals(format)) { String htmlBody = jsonEventContent.getAsJsonPrimitive("formatted_body").getAsString(); // some markers are not supported so fallback on an ascii display until to find the right way to manage them // an issue has been created https://github.com/vector-im/vector-android/issues/38 if (!TextUtils.isEmpty(htmlBody) && !htmlBody.contains("<ol>") && !htmlBody.contains("<li>")) { text = Html .fromHtml(jsonEventContent.getAsJsonPrimitive("formatted_body").getAsString()); } } } // avoid empty image name if (TextUtils.equals(msgtype, Message.MSGTYPE_IMAGE) && TextUtils.isEmpty(text)) { text = mContext.getString(R.string.summary_user_sent_image, userDisplayName); } else if (TextUtils.equals(msgtype, Message.MSGTYPE_EMOTE)) { text = "* " + userDisplayName + " " + text; } else if (TextUtils.isEmpty(text)) { text = ""; } else if (mPrependAuthor) { text = new SpannableStringBuilder( mContext.getString(R.string.summary_message, userDisplayName, text)); if (null != displayNameColor) { ((SpannableStringBuilder) text).setSpan(new ForegroundColorSpan(displayNameColor), 0, userDisplayName.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((SpannableStringBuilder) text).setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, userDisplayName.length() + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } else if (Event.EVENT_TYPE_MESSAGE_ENCRYPTION.equals(eventType)) { text = mContext.getString(R.string.notice_end_to_end, userDisplayName, mEvent.getWireEventContent().algorithm); } else if (Event.EVENT_TYPE_MESSAGE_ENCRYPTED.equals(eventType)) { // don't display if (mEvent.isRedacted()) { String redactedInfo = EventDisplay.getRedactionMessage(mContext, mEvent, mRoomState); if (TextUtils.isEmpty(redactedInfo)) { return null; } else { return redactedInfo; } } else { String message = null; if (null != mEvent.getCryptoError()) { String errorDescription; MXCryptoError error = mEvent.getCryptoError(); if (TextUtils.equals(error.errcode, MXCryptoError.UNKNOWN_INBOUND_SESSION_ID_ERROR_CODE)) { errorDescription = mContext.getResources() .getString(R.string.notice_crypto_error_unkwown_inbound_session_id); } else { errorDescription = error.getLocalizedMessage(); } message = mContext.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription); } if (TextUtils.isEmpty(message)) { message = mContext.getString(R.string.encrypted_message); } SpannableString spannableStr = new SpannableString(message); spannableStr.setSpan(new android.text.style.StyleSpan(Typeface.ITALIC), 0, message.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text = spannableStr; } } else if (Event.EVENT_TYPE_STATE_ROOM_TOPIC.equals(eventType)) { String topic = jsonEventContent.getAsJsonPrimitive("topic").getAsString(); if (mEvent.isRedacted()) { String redactedInfo = EventDisplay.getRedactionMessage(mContext, mEvent, mRoomState); if (TextUtils.isEmpty(redactedInfo)) { return null; } topic = redactedInfo; } if (!TextUtils.isEmpty(topic)) { text = mContext.getString(R.string.notice_topic_changed, userDisplayName, topic); } else { text = mContext.getString(R.string.notice_room_topic_removed, userDisplayName); } } else if (Event.EVENT_TYPE_STATE_ROOM_NAME.equals(eventType)) { String roomName = jsonEventContent.getAsJsonPrimitive("name").getAsString(); if (mEvent.isRedacted()) { String redactedInfo = EventDisplay.getRedactionMessage(mContext, mEvent, mRoomState); if (TextUtils.isEmpty(redactedInfo)) { return null; } roomName = redactedInfo; } if (!TextUtils.isEmpty(roomName)) { text = mContext.getString(R.string.notice_room_name_changed, userDisplayName, roomName); } else { text = mContext.getString(R.string.notice_room_name_removed, userDisplayName); } } else if (Event.EVENT_TYPE_STATE_ROOM_THIRD_PARTY_INVITE.equals(eventType)) { RoomThirdPartyInvite invite = JsonUtils.toRoomThirdPartyInvite(mEvent.getContent()); String displayName = invite.display_name; if (mEvent.isRedacted()) { String redactedInfo = EventDisplay.getRedactionMessage(mContext, mEvent, mRoomState); if (TextUtils.isEmpty(redactedInfo)) { return null; } displayName = redactedInfo; } text = mContext.getString(R.string.notice_room_third_party_invite, userDisplayName, displayName); } else if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(eventType)) { text = getMembershipNotice(mContext, mEvent, mRoomState); } } catch (Exception e) { Log.e(LOG_TAG, "getTextualDisplay() " + e.getLocalizedMessage()); } return text; }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
License:Mozilla Public License
public void updateDisbursementDetails(final JsonCommand command, final Map<String, Object> actualChanges) { List<Long> list = fetchDisbursementIds(); if (command.parameterExists(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .arrayOfParameterNamed(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { String dateFormat = null; Locale locale = null; if (command.parsedJson().isJsonObject()) { JsonObject topLevel = command.parsedJson().getAsJsonObject(); final String dateFormatParameter = "dateFormat"; if (topLevel.has(dateFormatParameter) && topLevel.get(dateFormatParameter).isJsonPrimitive()) { final JsonPrimitive primitive = topLevel.get(dateFormatParameter).getAsJsonPrimitive(); dateFormat = primitive.getAsString(); }/*from w ww . j a va 2s .com*/ final String localeParameter = "locale"; if (topLevel.has(localeParameter) && topLevel.get(localeParameter).isJsonPrimitive()) { final JsonPrimitive primitive = topLevel.get(localeParameter).getAsJsonPrimitive(); String localeString = primitive.getAsString(); locale = JsonParserHelper.localeFromString(localeString); } } int i = 0; do { final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); if (jsonObject.has(LoanApiConstants.disbursementDateParameterName) && jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName)) { Date expectedDisbursementDate = null; BigDecimal principal = null; LocalDate date = null; Long id = null; if (jsonObject.get(LoanApiConstants.disbursementDateParameterName) != null && jsonObject .get(LoanApiConstants.disbursementDateParameterName).isJsonPrimitive()) { final JsonPrimitive primitive = jsonObject .get(LoanApiConstants.disbursementDateParameterName).getAsJsonPrimitive(); final String valueAsString = primitive.getAsString(); if (StringUtils.isNotBlank(valueAsString)) { date = JsonParserHelper.convertFrom(valueAsString, LoanApiConstants.disbursementDateParameterName, dateFormat, locale); } } if (date != null) { expectedDisbursementDate = date.toDate(); } if (jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } if (jsonObject.has(LoanApiConstants.disbursementIdParameterName) && jsonObject.get(LoanApiConstants.disbursementIdParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementIdParameterName).getAsString()))) { id = jsonObject.getAsJsonPrimitive(LoanApiConstants.disbursementIdParameterName) .getAsLong(); } if (id != null) { LoanDisbursementDetails loanDisbursementDetail = fetchLoanDisbursementsById(id); list.remove(id); if (loanDisbursementDetail.actualDisbursementDate() == null) { Date actualDisbursementDate = null; LoanDisbursementDetails disbursementDetails = new LoanDisbursementDetails( expectedDisbursementDate, actualDisbursementDate, principal); if (!loanDisbursementDetail.equals(disbursementDetails)) { loanDisbursementDetail.copy(disbursementDetails); actualChanges.put("disbursementDetailId", id); actualChanges.put("recalculateLoanSchedule", true); } } } else { Date actualDisbursementDate = null; LoanDisbursementDetails disbursementDetails = new LoanDisbursementDetails( expectedDisbursementDate, actualDisbursementDate, principal); disbursementDetails.updateLoan(this); this.disbursementDetails.add(disbursementDetails); actualChanges.put(LoanApiConstants.disbursementDataParameterName, expectedDisbursementDate + "-" + principal); actualChanges.put("recalculateLoanSchedule", true); } } i++; } while (i < disbursementDataArray.size()); for (Long id : list) { this.disbursementDetails.remove(fetchLoanDisbursementsById(id)); actualChanges.put("recalculateLoanSchedule", true); } } } }
From source file:org.mifosplatform.portfolio.loanaccount.loanschedule.service.LoanScheduleAssembler.java
License:Mozilla Public License
private List<DisbursementData> fetchDisbursementData(final JsonObject command) { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command); List<DisbursementData> disbursementDatas = new ArrayList<>(); if (command.has(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .getAsJsonArray(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { int i = 0; do {/*from ww w .ja v a 2 s . c o m*/ final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); LocalDate expectedDisbursementDate = null; BigDecimal principal = null; if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { expectedDisbursementDate = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); } if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } disbursementDatas.add(new DisbursementData(null, expectedDisbursementDate, null, principal)); i++; } while (i < disbursementDataArray.size()); } } return disbursementDatas; }
From source file:org.mifosplatform.portfolio.loanaccount.service.LoanAssembler.java
License:Mozilla Public License
private Set<LoanDisbursementDetails> fetchDisbursementData(final JsonObject command) { final Locale locale = this.fromApiJsonHelper.extractLocaleParameter(command); final String dateFormat = this.fromApiJsonHelper.extractDateFormatParameter(command); Set<LoanDisbursementDetails> disbursementDatas = new HashSet<>(); if (command.has(LoanApiConstants.disbursementDataParameterName)) { final JsonArray disbursementDataArray = command .getAsJsonArray(LoanApiConstants.disbursementDataParameterName); if (disbursementDataArray != null && disbursementDataArray.size() > 0) { int i = 0; do {//from w ww .j a va 2 s . c o m final JsonObject jsonObject = disbursementDataArray.get(i).getAsJsonObject(); Date expectedDisbursementDate = null; Date actualDisbursementDate = null; BigDecimal principal = null; if (jsonObject.has(LoanApiConstants.disbursementDateParameterName)) { LocalDate date = this.fromApiJsonHelper.extractLocalDateNamed( LoanApiConstants.disbursementDateParameterName, jsonObject, dateFormat, locale); if (date != null) { expectedDisbursementDate = date.toDate(); } } if (jsonObject.has(LoanApiConstants.disbursementPrincipalParameterName) && jsonObject.get(LoanApiConstants.disbursementPrincipalParameterName).isJsonPrimitive() && StringUtils.isNotBlank((jsonObject .get(LoanApiConstants.disbursementPrincipalParameterName).getAsString()))) { principal = jsonObject .getAsJsonPrimitive(LoanApiConstants.disbursementPrincipalParameterName) .getAsBigDecimal(); } disbursementDatas.add(new LoanDisbursementDetails(expectedDisbursementDate, actualDisbursementDate, principal)); i++; } while (i < disbursementDataArray.size()); } } return disbursementDatas; }
From source file:org.mobicents.servlet.restcomm.provisioning.number.nexmo.NexmoPhoneNumberProvisioningManager.java
License:Open Source License
@Override public List<PhoneNumber> searchForNumbers(String country, PhoneNumberSearchFilters listFilters) { if (logger.isDebugEnabled()) { logger.debug("searchPattern " + listFilters.getFilterPattern()); }//from ww w. j av a 2 s .com Pattern filterPattern = listFilters.getFilterPattern(); String filterPatternString = null; if (filterPattern != null) { filterPatternString = filterPattern.toString().replaceAll("[^\\d]", ""); } if (logger.isDebugEnabled()) { logger.debug("searchPattern simplified for nexmo " + filterPatternString); } String queryUri = searchURI + country; boolean queryParamAdded = false; if (("US".equalsIgnoreCase(country) || "CA".equalsIgnoreCase(country)) && listFilters.getAreaCode() != null) { // https://github.com/Mobicents/RestComm/issues/551 fixing the search pattern for US when Area Code is selected // https://github.com/Mobicents/RestComm/issues/602 fixing the search pattern for CA when Area Code is selected queryUri = queryUri + "?pattern=1" + listFilters.getAreaCode() + "&search_pattern=0"; queryParamAdded = true; } else if (filterPatternString != null) { queryUri = queryUri + "?pattern=" + filterPatternString + "&search_pattern=1"; queryParamAdded = true; } if (listFilters.getSmsEnabled() != null || listFilters.getVoiceEnabled() != null) { if (!queryParamAdded) { queryUri = queryUri + "?"; queryParamAdded = true; } else { queryUri = queryUri + "&"; } if (listFilters.getSmsEnabled() != null && listFilters.getVoiceEnabled() != null) { queryUri = queryUri + "features=SMS,VOICE"; } else if (listFilters.getSmsEnabled() != null) { queryUri = queryUri + "features=SMS"; } else { queryUri = queryUri + "features=VOICE"; } } if (listFilters.getRangeIndex() != -1) { if (!queryParamAdded) { queryUri = queryUri + "?"; queryParamAdded = true; } else { queryUri = queryUri + "&"; } queryUri = queryUri + "index=" + listFilters.getRangeIndex(); } if (listFilters.getRangeSize() != -1) { if (!queryParamAdded) { queryUri = queryUri + "?"; queryParamAdded = true; } else { queryUri = queryUri + "&"; } queryUri = queryUri + "size=" + listFilters.getRangeSize(); } final HttpGet get = new HttpGet(queryUri); try { final DefaultHttpClient client = new DefaultHttpClient(); // if (telestaxProxyEnabled) { // // This will work as a flag for LB that this request will need to be modified and proxied to VI // get.addHeader("TelestaxProxy", String.valueOf(telestaxProxyEnabled)); // // This will tell LB that this request is a getAvailablePhoneNumberByAreaCode request // get.addHeader("RequestType", "GetAvailablePhoneNumbersByAreaCode"); // //This will let LB match the DID to a node based on the node host+port // for (SipURI uri: containerConfiguration.getOutboundInterfaces()) { // get.addHeader("OutboundIntf", uri.getHost()+":"+uri.getPort()+":"+uri.getTransportParam()); // } // } if (logger.isDebugEnabled()) { logger.debug("Nexmo query " + queryUri); } final HttpResponse response = client.execute(get); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { final String content = StringUtils.toString(response.getEntity().getContent()); JsonParser parser = new JsonParser(); JsonObject jsonResponse = parser.parse(content).getAsJsonObject(); if (logger.isDebugEnabled()) { logger.debug("Nexmo response " + jsonResponse.toString()); } JsonPrimitive countPrimitive = jsonResponse.getAsJsonPrimitive("count"); if (countPrimitive == null) { if (logger.isDebugEnabled()) { logger.debug("No numbers found"); } return new ArrayList<PhoneNumber>(); } long count = countPrimitive.getAsLong(); if (logger.isDebugEnabled()) { logger.debug("Number of numbers found : " + count); } JsonArray nexmoNumbers = jsonResponse.getAsJsonArray("numbers"); final List<PhoneNumber> numbers = toAvailablePhoneNumbers(nexmoNumbers, listFilters); return numbers; } else { logger.warn("Couldn't reach uri for getting Phone Numbers. Response status was: " + response.getStatusLine().getStatusCode()); } } catch (final Exception e) { logger.warn("Couldn't reach uri for getting Phone Numbers" + uri, e); } return new ArrayList<PhoneNumber>(); }
From source file:org.moe.tools.natjgen.AbstractBinding.java
License:Apache License
@Override public void setJsonObject(JsonObject json) { final JsonPrimitive jsonType = json.getAsJsonPrimitive("type"); if (jsonType == null) { throw new NullPointerException(); }//from ww w. j a v a2s.c o m if (!type.equals(jsonType.getAsString())) { throw new IllegalArgumentException(); } setName(null); final JsonPrimitive jsonName = json.getAsJsonPrimitive("name"); if (jsonName != null) { setName(jsonName.getAsString()); } setObjcClassGenerationMode(null); final JsonPrimitive jsonObjcClassGenerationMode = json.getAsJsonPrimitive("objcClassGenerationMode"); if (jsonObjcClassGenerationMode != null) { setObjcClassGenerationMode(jsonObjcClassGenerationMode.getAsString()); } else { setObjcClassGenerationMode(Bindings.BINDING); } }
From source file:org.moe.tools.natjgen.Bindings.java
License:Apache License
@Override public void setJsonObject(JsonObject json) { setOutputDirectory(null);//from w w w . j a va 2 s . c o m final JsonPrimitive jsonOutput = json.getAsJsonPrimitive("output"); if (jsonOutput != null) { setOutputDirectory(jsonOutput.getAsString()); } setPlatform(null); final JsonPrimitive jsonPlatform = json.getAsJsonPrimitive("platform"); if (jsonPlatform != null) { setPlatform(jsonPlatform.getAsString()); } setTypeConfigInput(null); final JsonPrimitive jsonTypeConfigInput = json.getAsJsonPrimitive("type-config-input"); if (jsonTypeConfigInput != null) { setTypeConfigInput(jsonTypeConfigInput.getAsString()); } setTypeConfigOutput(null); final JsonPrimitive jsonTypeConfigOutput = json.getAsJsonPrimitive("type-config-output"); if (jsonTypeConfigOutput != null) { setTypeConfigOutput(jsonTypeConfigOutput.getAsString()); } setInlineFunctionBindingOutput(null); final JsonPrimitive jsonInlineFunctionBindingOutput = json .getAsJsonPrimitive("inline-function-binding-output"); if (jsonInlineFunctionBindingOutput != null) { setInlineFunctionBindingOutput(jsonInlineFunctionBindingOutput.getAsString()); } bindings.clear(); final JsonArray jsonBindings = json.getAsJsonArray("bindings"); if (jsonBindings != null) { for (JsonElement jsonBinding : jsonBindings) { final JsonObject element = (JsonObject) jsonBinding; final String type = element.getAsJsonPrimitive("type").getAsString(); if ("framework".equals(type)) { FrameworkBinding binding = new FrameworkBinding(); binding.setJsonObject(element); bindings.add(binding); } else if ("header".equals(type)) { HeaderBinding binding = new HeaderBinding(); binding.setJsonObject(element); bindings.add(binding); } else { throw new RuntimeException("unrecognized binding type " + type); } } } }
From source file:org.moe.tools.natjgen.FrameworkBinding.java
License:Apache License
@Override public void setJsonObject(JsonObject json) { super.setJsonObject(json); setFrameworkPath(null);//from ww w . j av a2 s . com final JsonPrimitive jsonFrameworkPath = json.getAsJsonPrimitive("frameworkPath"); if (jsonFrameworkPath != null) { setFrameworkPath(jsonFrameworkPath.getAsString()); } setPackageBase(null); final JsonPrimitive jsonPackageBase = json.getAsJsonPrimitive("packageBase"); if (jsonPackageBase != null) { setPackageBase(jsonPackageBase.getAsString()); } setImportCode(null); final JsonPrimitive jsonImportCode = json.getAsJsonPrimitive("importCode"); if (jsonImportCode != null) { setImportCode(jsonImportCode.getAsString()); } }
From source file:org.moe.tools.natjgen.HeaderBinding.java
License:Apache License
@Override public void setJsonObject(JsonObject json) { super.setJsonObject(json); setHeaderPath(null);//from ww w. j a va 2 s .c om final JsonPrimitive jsonHeaderPath = json.getAsJsonPrimitive("headerPath"); if (jsonHeaderPath != null) { setHeaderPath(jsonHeaderPath.getAsString()); } readJsonStringArray(json.getAsJsonArray("headerSearchPaths"), headerSearchPaths); readJsonStringArray(json.getAsJsonArray("userHeaderSearchPaths"), userHeaderSearchPaths); readJsonStringArray(json.getAsJsonArray("frameworkSearchPaths"), frameworkSearchPaths); setPackageBase(null); final JsonPrimitive jsonPackageBase = json.getAsJsonPrimitive("packageBase"); if (jsonPackageBase != null) { setPackageBase(jsonPackageBase.getAsString()); } setImportCode(null); final JsonPrimitive jsonImportCode = json.getAsJsonPrimitive("importCode"); if (jsonImportCode != null) { setImportCode(jsonImportCode.getAsString()); } setExplicitLibrary(null); final JsonPrimitive jsonExplicitLibrary = json.getAsJsonPrimitive("explicitLibrary"); if (jsonExplicitLibrary != null) { setExplicitLibrary(jsonExplicitLibrary.getAsString()); } }
From source file:org.mymediadb.api.mmdb.internal.api.MmdbApiImpl.java
License:Open Source License
@Override public Token getAccessToken(String username, String password) { URI uri = getUri(OAUTH_TOKEN_ENDPOINT); UrlEncodedFormEntity postParameters = createUrlEncodedFormParameters( new BasicNameValuePair("client_id", clientId), new BasicNameValuePair("client_secret", clientSecret), new BasicNameValuePair("grant_type", "password"), new BasicNameValuePair("username", username), new BasicNameValuePair("password", password)); HttpPost post = new HttpPost(uri); post.setEntity(postParameters);/*w w w. java 2s . c o m*/ HttpResponse response = sendRequest(post); if (!isResponseStatusOK(response)) { JsonObject error = jsonParser.parse(getEntityAsString(response)).getAsJsonObject(); throw new MmdbApiOauthException(error.getAsJsonPrimitive("error").getAsString(), response.getStatusLine().getStatusCode()); } else { return gson.fromJson(getEntityAsString(response), TokenImpl.class); } }