Example usage for android.net Uri buildUpon

List of usage examples for android.net Uri buildUpon

Introduction

In this page you can find the example usage for android.net Uri buildUpon.

Prototype

public abstract Builder buildUpon();

Source Link

Document

Constructs a new builder, copying the attributes from this Uri.

Usage

From source file:com.he5ed.lib.cloudprovider.apis.OneDriveApi.java

/**
 * Build authorization url base on type of cloud service
 *
 * @return Uri//w ww . j  ava  2 s  .  c o  m
 */
public static Uri buildAuthUri(String stateString) {
    Uri uri = Uri.parse(AUTH_URL);
    return uri.buildUpon().appendQueryParameter("response_type", "code")
            .appendQueryParameter("client_id", CLIENT_ID).appendQueryParameter("redirect_uri", REDIRECT_URL)
            .appendQueryParameter("state", stateString)
            .appendQueryParameter("scope", "wl.emails wl.offline_access onedrive.readwrite").build();
}

From source file:com.he5ed.lib.cloudprovider.apis.OneDriveApi.java

/**
 * Get current user information uri/*from   ww  w .j  ava  2 s. co  m*/
 *
 * @return Uri
 */
public static Uri getUserInfoUri() {
    Uri uri = Uri.parse(LIVE_API_URL);
    return uri.buildUpon().appendEncodedPath("me").build();
}

From source file:org.projecthdata.weight.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class);

    this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.WORKING.toString()).commit();
    //get all readings that are not synced
    try {/*from w w  w . j  av  a  2s  . co  m*/
        Dao<WeightReading, Integer> dao = ormManager.getDatabaseHelper().getWeightDao();
        //TODO: query the database instead of iterating over the whole table

        String url = this.prefs.getString(Constants.PREF_EHR_URL, "");
        Uri uri = Uri.parse(url);
        uri = uri.buildUpon().appendPath("vitalsigns").appendPath("bodyweight").build();
        RestTemplate template = connection.getApi().getRootOperations().getRestTemplate();

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_XML);

        for (WeightReading reading : dao) {

            if (!reading.isSynched()) {
                Result result = new Result();
                //date and time
                result.setResultDateTime(new DateTime(reading.getDateTime().getTime()).toString(dateFormatter));
                //narrative
                result.setNarrative(NARRATIVE);
                //result id
                result.setResultId(UUID.randomUUID().toString());
                //result type code
                result.getResultType().setCode(CODE);
                //result type code system
                result.getResultType().setCodeSystem(CODE_SYSTEM);
                //status code
                result.setResultStatusCode(RESULT_STATUS_CODE);
                //value
                result.setResultValue(reading.getResultValue().toString());
                //value unit
                result.setResultValueUnit(UNITS);

                try {

                    HttpEntity<Result> requestEntity = new HttpEntity<Result>(result, requestHeaders);
                    template.exchange(uri.toString(), HttpMethod.POST, requestEntity, String.class);
                } catch (RestClientException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                reading.setSynched(true);
                dao.update(reading);
            }
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.READY.toString()).commit();

}

From source file:at.bitfire.ical4android.AndroidTaskList.java

public Uri syncAdapterURI(Uri uri) {
    return uri.buildUpon().appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name)
            .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type)
            .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true").build();
}

From source file:org.andstatus.app.net.social.ConnectionTwitter1p1.java

@Override
public List<MbTimelineItem> search(String searchQuery, int limit) throws ConnectionException {
    ApiRoutineEnum apiRoutine = ApiRoutineEnum.SEARCH_MESSAGES;
    String url = this.getApiPath(apiRoutine);
    Uri sUri = Uri.parse(url);
    Uri.Builder builder = sUri.buildUpon();
    if (fixedDownloadLimitForApiRoutine(limit, apiRoutine) > 0) {
        builder.appendQueryParameter("count",
                String.valueOf(fixedDownloadLimitForApiRoutine(limit, apiRoutine)));
    }//from  w  w w  .  j a v  a 2 s  .  c o  m
    if (!TextUtils.isEmpty(searchQuery)) {
        builder.appendQueryParameter("q", searchQuery);
    }
    JSONArray jArr = getRequestArrayInObject(builder.build().toString(), "statuses");
    return jArrToTimeline(jArr, apiRoutine, url);
}

From source file:com.weiboa.data.WeiboOAuthConnect.java

private JSONArray getTimeline(String url, long sinceId, long maxId, long limit, int page) {

    JSONArray jArray = null;//  w  ww .j a  v a2 s .  co  m

    Uri uri = Uri.parse(url);
    Uri.Builder builder = uri.buildUpon();
    if (sinceId != 0) {
        builder.appendQueryParameter("since_id", String.valueOf(sinceId));
    } else if (maxId != 0) {
        builder.appendQueryParameter("max_id", String.valueOf(maxId));
    } else {
        builder.appendQueryParameter("since_id", String.valueOf(sinceId));
    }
    if (limit != 0) {
        builder.appendQueryParameter("count", String.valueOf(limit));
    } else {
        builder.appendQueryParameter("count", String.valueOf(50));
    }
    builder.appendQueryParameter("page", String.valueOf(page));

    HttpGet get = new HttpGet(builder.build().toString());
    try {
        mConsumer.sign(get);
        String response = mClient.execute(get, new BasicResponseHandler());
        jArray = new JSONArray(response);
    } catch (Exception e) {
        e.printStackTrace();
        jArray = null;
    }

    return jArray;
}

From source file:at.bitfire.ical4android.AndroidCalendar.java

public Uri syncAdapterURI(Uri uri) {
    return uri.buildUpon().appendQueryParameter(Calendars.ACCOUNT_NAME, account.name)
            .appendQueryParameter(Calendars.ACCOUNT_TYPE, account.type)
            .appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true").build();
}

From source file:com.xing.android.sdk.network.request.RequestUtilsTest.java

@Test
public void appendParamsToBuilder() throws Exception {
    Uri uriBase = new Uri.Builder().scheme("test").authority("test").build();

    Uri.Builder builder = uriBase.buildUpon();

    // Check nothing happens
    RequestUtils.appendParamsToBuilder(builder, null);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check param with empty key will not be added
    List<Pair<String, String>> pairs = new ArrayList<>();
    pairs.add(new Pair<String, String>(null, null));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check param with empty value will not be added
    pairs.clear();//from  w ww.  java 2  s.c om
    pairs.add(new Pair<String, String>("test", null));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase.toString(), builder.build().toString());

    // Check actual param is added
    pairs.clear();
    pairs.add(new Pair<>("a", "a"));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase + "?a=a", builder.build().toString());

    // Check next 2 params will be appended
    pairs.clear();
    pairs.add(new Pair<>("b", "b"));
    pairs.add(new Pair<String, String>(null, "d"));
    pairs.add(new Pair<String, String>("f", null));
    pairs.add(new Pair<>("c", "c"));

    RequestUtils.appendParamsToBuilder(builder, pairs);
    assertEquals(uriBase + "?a=a&b=b&c=c", builder.build().toString());
}

From source file:org.exoplatform.shareextension.service.UploadAction.java

@Override
protected boolean doExecute() {
    String id = uploadInfo.uploadId;
    String boundary = "----------------------------" + id;
    String CRLF = "\r\n";
    int status = -1;
    OutputStream output = null;/*from ww w .  j av a 2s.  c  o m*/
    PrintWriter writer = null;
    try {
        // Open a connection to the upload web service
        StringBuffer stringUrl = new StringBuffer(postInfo.ownerAccount.serverUrl).append("/portal")
                .append(ExoConstants.DOCUMENT_UPLOAD_PATH_REST).append("?uploadId=").append(id);
        URL uploadUrl = new URL(stringUrl.toString());
        HttpURLConnection uploadReq = (HttpURLConnection) uploadUrl.openConnection();
        uploadReq.setDoOutput(true);
        uploadReq.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
        // Pass the session cookies for authentication
        CookieStore store = ExoConnectionUtils.cookiesStore;
        if (store != null) {
            StringBuffer cookieString = new StringBuffer();
            for (Cookie cookie : store.getCookies()) {
                cookieString.append(cookie.getName()).append("=").append(cookie.getValue()).append("; ");
            }
            uploadReq.addRequestProperty("Cookie", cookieString.toString());
        }
        ExoConnectionUtils.setUserAgent(uploadReq);
        // Write the form data
        output = uploadReq.getOutputStream();
        writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8"), true);
        writer.append("--" + boundary).append(CRLF);
        writer.append("Content-Disposition: form-data; name=\"file\"; filename=\""
                + uploadInfo.fileToUpload.documentName + "\"").append(CRLF);
        writer.append("Content-Type: " + uploadInfo.fileToUpload.documentMimeType).append(CRLF);
        writer.append(CRLF).flush();
        byte[] buf = new byte[1024];
        while (uploadInfo.fileToUpload.documentData.read(buf) != -1) {
            output.write(buf);
        }
        output.flush();
        writer.append(CRLF).flush();
        writer.append("--" + boundary + "--").append(CRLF).flush();
        // Execute the connection and retrieve the status code
        status = uploadReq.getResponseCode();
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error while uploading " + uploadInfo.fileToUpload, e);
    } finally {
        if (uploadInfo != null && uploadInfo.fileToUpload != null
                && uploadInfo.fileToUpload.documentData != null)
            try {
                uploadInfo.fileToUpload.documentData.close();
            } catch (IOException e1) {
                Log.e(LOG_TAG, "Error while closing the upload stream", e1);
            }
        if (output != null)
            try {
                output.close();
            } catch (IOException e) {
                Log.e(LOG_TAG, "Error while closing the connection", e);
            }
        if (writer != null)
            writer.close();
    }
    if (status < HttpURLConnection.HTTP_OK || status >= HttpURLConnection.HTTP_MULT_CHOICE) {
        // Exit if the upload went wrong
        return listener.onError("Could not upload the file " + uploadInfo.fileToUpload.documentName);
    }
    status = -1;
    try {
        // Prepare the request to save the file in JCR
        String stringUrl = postInfo.ownerAccount.serverUrl + "/portal"
                + ExoConstants.DOCUMENT_CONTROL_PATH_REST;
        Uri moveUri = Uri.parse(stringUrl);
        moveUri = moveUri.buildUpon().appendQueryParameter("uploadId", id)
                .appendQueryParameter("action", "save")
                .appendQueryParameter("workspaceName", DocumentHelper.getInstance().workspace)
                .appendQueryParameter("driveName", uploadInfo.drive)
                .appendQueryParameter("currentFolder", uploadInfo.folder)
                .appendQueryParameter("fileName", uploadInfo.fileToUpload.documentName).build();
        HttpGet moveReq = new HttpGet(moveUri.toString());
        // Execute the request and retrieve the status code
        HttpResponse move = ExoConnectionUtils.httpClient.execute(moveReq);
        status = move.getStatusLine().getStatusCode();
    } catch (Exception e) {
        Log.e(LOG_TAG, "Error while saving " + uploadInfo.fileToUpload + " in JCR", e);
    }
    boolean ret = false;
    if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
        ret = listener.onSuccess("File " + uploadInfo.fileToUpload.documentName + "uploaded successfully");
    } else {
        ret = listener.onError("Could not save the file " + uploadInfo.fileToUpload.documentName);
    }
    return ret;
}

From source file:com.he5ed.lib.cloudprovider.apis.CloudDriveApi.java

/**
 * Build authorization url base on type of cloud service
 *
 * @return Uri/*w ww.ja  va2s. c o  m*/
 */
public static Uri buildAuthUri(String stateString) {
    Uri uri = Uri.parse(AUTH_URL);
    return uri.buildUpon().appendQueryParameter("response_type", "code")
            .appendQueryParameter("client_id", CLIENT_ID).appendQueryParameter("redirect_uri", REDIRECT_URL)
            .appendQueryParameter("state", stateString)
            .appendQueryParameter("scope", "profile clouddrive:read_all clouddrive:write").build();
}