Copyright (c) 2011, salesforce.com, inc. All rights reserved.
========================================
Redistribution and use of this software in source and binary forms, with or without modificatio...
If you think the Android project force_analytics_example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (c) 2013, salesforce.com, inc.
* All rights reserved.//www.java2s.com
* Redistribution and use of this software in source and binary forms, with or
* without modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of salesforce.com, inc. nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission of salesforce.com, inc.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/package com.salesforce.androidsdk.rest.files;
import android.net.Uri;
import com.salesforce.androidsdk.rest.ApiVersionStrings;
/**
* A URI builder for connect URIs, it handles special cases for userId and for
* optional parameters.
*
* @author sfell
*/publicclass ConnectUriBuilder {
publicstaticfinal String EMPTY = "";
privatestaticfinal String ME = "me";
privatestaticfinal String PAGE = "page";
privatestaticfinal String PAGESIZE = "pageSize";
privatestaticfinal String VERSIONNUMBER = "versionNumber";
public ConnectUriBuilder() {
this(Uri.parse(ApiVersionStrings.BASE_CHATTER_PATH).buildUpon());
}
public ConnectUriBuilder(Uri.Builder b) {
this.builder = b;
}
privatefinal Uri.Builder builder;
public ConnectUriBuilder appendPath(String pathSegment) {
builder.appendEncodedPath(pathSegment);
returnthis;
}
public ConnectUriBuilder appendUserId(String userId) {
if (userId != null && EMPTY.equals(userId)) {
thrownew IllegalArgumentException("invalid user id");
}
return appendPath(userId == null ? ME : userId);
}
public ConnectUriBuilder appendFolderId(String folderId) {
if (folderId != null && EMPTY.equals(folderId)) {
thrownew IllegalArgumentException("invalid folder id");
}
return appendPath(folderId);
}
public ConnectUriBuilder appendPageNum(Integer pageNum) {
if (pageNum != null && pageNum < 0) {
thrownew IllegalArgumentException("page number cannot be negative");
}
return appendQueryParam(PAGE, pageNum);
}
public ConnectUriBuilder appendPageSize(Integer pageSize) {
if (pageSize != null && pageSize < 0) {
thrownew IllegalArgumentException("page size cannot be negative");
}
return appendQueryParam(PAGESIZE, pageSize);
}
public ConnectUriBuilder appendVersionNum(String version) {
if (version != null && (EMPTY.equals(version) || Integer.valueOf(version) <= 0)) {
thrownew IllegalArgumentException("version number cannot be smaller than 1");
}
return appendQueryParam(VERSIONNUMBER, version);
}
public ConnectUriBuilder appendQueryParam(String key, Integer val) {
if (key != null && val != null)
builder.appendQueryParameter(key, val.toString());
returnthis;
}
public ConnectUriBuilder appendQueryParam(String key, String val) {
if (key != null && val != null && !EMPTY.equals(val))
builder.appendQueryParameter(key, val);
returnthis;
}
public Uri build() {
return builder.build();
}
@Override
public String toString() {
return build().toString();
}
}