List of usage examples for android.net Uri buildUpon
public abstract Builder buildUpon();
From source file:com.carltondennis.glassphysicalweb.MetadataResolver.java
/** * Create the url metadata request,/*w w w . j a v a 2s. c om*/ * given the json request object * * @param jsonObj The given json object to use in the request * @return The created json request object */ private static JsonObjectRequest createUrlMetadataRequest(JSONObject jsonObj, final boolean isDemoRequest) { return new JsonObjectRequest(isDemoRequest ? DEMO_METADATA_URL : METADATA_URL, jsonObj, new Response.Listener<JSONObject>() { // Called when the server returns a response @Override public void onResponse(JSONObject jsonResponse) { // Build the metadata from the response try { JSONArray foundMetaData = jsonResponse.getJSONArray("metadata"); // Loop through the metadata for each url if (foundMetaData.length() > 0) { for (int i = 0; i < foundMetaData.length(); i++) { JSONObject jsonUrlMetadata = foundMetaData.getJSONObject(i); String title = ""; String url = ""; String description = ""; String iconUrl = "/favicon.ico"; String id = jsonUrlMetadata.getString("id"); if (jsonUrlMetadata.has("title")) { title = jsonUrlMetadata.getString("title"); } if (jsonUrlMetadata.has("url")) { url = jsonUrlMetadata.getString("url"); } if (jsonUrlMetadata.has("description")) { description = jsonUrlMetadata.getString("description"); } if (jsonUrlMetadata.has("icon")) { // We might need to do some magic here. iconUrl = jsonUrlMetadata.getString("icon"); } // TODO: Eliminate this fallback since we expect the server to always return an icon. // Provisions for a favicon specified as a relative URL. if (!iconUrl.startsWith("http")) { // Lets just assume we are dealing with a relative path. Uri fullUri = Uri.parse(url); Uri.Builder builder = fullUri.buildUpon(); // Append the default favicon path to the URL. builder.path(iconUrl); iconUrl = builder.toString(); } // Create the metadata object UrlMetadata urlMetadata = new UrlMetadata(); urlMetadata.title = title; urlMetadata.description = description; urlMetadata.siteUrl = url; urlMetadata.iconUrl = iconUrl; // Kick off the icon download downloadIcon(urlMetadata); if (isDemoRequest) { mMetadataResolverCallback.onDemoUrlMetadataReceived(id, urlMetadata); } else { mMetadataResolverCallback.onUrlMetadataReceived(id, urlMetadata); } } } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.i(TAG, "VolleyError: " + volleyError.toString()); } }); }
From source file:org.physical_web.physicalweb.MetadataResolver.java
/** * Create the url metadata request,// w w w.j a v a2 s .c o m * given the json request object * * @param jsonObj The given json object to use in the request * @return The created json request object */ private static JsonObjectRequest createUrlMetadataRequest(JSONObject jsonObj, final boolean isDemoRequest) { return new JsonObjectRequest(isDemoRequest ? DEMO_METADATA_URL : METADATA_URL, jsonObj, new Response.Listener<JSONObject>() { // Called when the server returns a response @Override public void onResponse(JSONObject jsonResponse) { // Build the metadata from the response try { JSONArray foundMetaData = jsonResponse.getJSONArray("metadata"); // Loop through the metadata for each url if (foundMetaData.length() > 0) { for (int i = 0; i < foundMetaData.length(); i++) { JSONObject jsonUrlMetadata = foundMetaData.getJSONObject(i); String title = ""; String url = ""; String description = ""; String iconUrl = "/favicon.ico"; String id = jsonUrlMetadata.getString("id"); float score = UNDEFINED_SCORE; if (jsonUrlMetadata.has("title")) { title = jsonUrlMetadata.getString("title"); } if (jsonUrlMetadata.has("url")) { url = jsonUrlMetadata.getString("url"); } if (jsonUrlMetadata.has("description")) { description = jsonUrlMetadata.getString("description"); } if (jsonUrlMetadata.has("icon")) { // We might need to do some magic here. iconUrl = jsonUrlMetadata.getString("icon"); } if (jsonUrlMetadata.has("score")) { score = Float.parseFloat(jsonUrlMetadata.getString("score")); } // TODO: Eliminate this fallback since we expect the server to always return an icon. // Provisions for a favicon specified as a relative URL. if (!iconUrl.startsWith("http")) { // Lets just assume we are dealing with a relative path. Uri fullUri = Uri.parse(url); Uri.Builder builder = fullUri.buildUpon(); // Append the default favicon path to the URL. builder.path(iconUrl); iconUrl = builder.toString(); } // Create the metadata object UrlMetadata urlMetadata = new UrlMetadata(); urlMetadata.title = title; urlMetadata.description = description; urlMetadata.siteUrl = url; urlMetadata.iconUrl = iconUrl; urlMetadata.score = score; // Kick off the icon download downloadIcon(urlMetadata); if (isDemoRequest) { mMetadataResolverCallback.onDemoUrlMetadataReceived(id, urlMetadata); } else { mMetadataResolverCallback.onUrlMetadataReceived(id, urlMetadata); } } } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.i(TAG, "VolleyError: " + volleyError.toString()); } }); }
From source file:com.cloudbees.gasp.service.RESTService.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {/* ww w .j a v a 2s .c om*/ if (params == null) { // No params were given or they have already been // attached to the Uri. request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect: " + uri.toString(), e); } }
From source file:org.mobisocial.corral.CorralDownloadClient.java
private static Uri uriForLanContent(String host, DbObj obj) { try {//from ww w .j av a 2 s .co m String localContent = obj.getJson().getString(OBJ_LOCAL_URI); Uri baseUri = Uri.parse("http://" + host + ":" + ContentCorral.SERVER_PORT); return baseUri.buildUpon().appendQueryParameter("content", localContent) .appendQueryParameter("hash", "" + obj.getUniversalHashString()).build(); } catch (Exception e) { Log.d(TAG, "No uri for content " + obj.getHash() + "; " + obj.getJson()); return null; } }
From source file:org.ohmage.sync.OhmageSyncAdapter.java
public static Uri appendSyncAdapterParam(Uri uri) { return uri.buildUpon().appendQueryParameter(IS_SYNCADAPTER, "true").build(); }
From source file:saschpe.birthdays.service.CalendarSyncService.java
/** * Builds URI based on account.// w w w. j a va 2s.c o m */ private static Uri getCalendarUri(Context context, Uri contentUri) { return contentUri.buildUpon().appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true") .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, context.getString(R.string.app_name)) .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, context.getString(R.string.account_type)) .build(); }
From source file:com.cloudbees.gasp.loader.RESTLoader.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {/*w w w . j ava 2 s . com*/ if (params == null) { // No params were given or they have already been // attached to the Uri. request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Log.e(TAG, "URI syntax was incorrect: " + uri.toString()); } }
From source file:io.n7.calendar.caldav.CalDAVService.java
private static Uri asSyncAdapter(Uri uri) { return uri.buildUpon().appendQueryParameter(Calendar.CALLER_IS_SYNCADAPTER, "true").build(); }
From source file:com.scvngr.levelup.core.net.AbstractRequest.java
/** * Returns the portion of an absolute URL before the query string. E.g. * {@code http://example.com/search?q=kittens} would return {@code "http://example.com/search"}. * * @param url the URL to strip.// www . j ava 2 s . c om * @return the URL stripped of any query parameters, including the '?'. * @throws IllegalArgumentException if the URI passed in isn't an absolute URL. */ @NonNull private static String stripQueryParameters(final Uri url) throws IllegalArgumentException { if (!url.isAbsolute() || !url.isHierarchical()) { throw new IllegalArgumentException("Request URI must be an absolute URL"); } return NullUtils.nonNullContract(url.buildUpon().query(null).build().toString()); }
From source file:com.antew.redditinpictures.library.service.RESTService.java
private static void attachUriWithQuery(HttpRequestBase request, Uri uri, Bundle params) { try {//from ww w . j a va2 s. co m if (params == null) { // No params were given or they have already been // attached to the Uri. request.setURI(new URI(uri.toString())); } else { Uri.Builder uriBuilder = uri.buildUpon(); // Loop through our params and append them to the Uri. for (BasicNameValuePair param : paramsToList(params)) { uriBuilder.appendQueryParameter(param.getName(), param.getValue()); } uri = uriBuilder.build(); request.setURI(new URI(uri.toString())); } } catch (URISyntaxException e) { Ln.e(e, "URI syntax was incorrect: %s", uri.toString()); } }