FileDocCategorySizeDatePackage
QueryParamsImpl.javaAPI DocAndroid 1.5 API2690Wed May 06 22:41:56 BST 2009com.google.android.gdata.client

QueryParamsImpl

public class QueryParamsImpl extends com.google.wireless.gdata.client.QueryParams
Simple implementation of the QueryParams interface.

Fields Summary
private final Map
mParams
Constructors Summary
public QueryParamsImpl()
Creates a new empty QueryParamsImpl.


              
      
    
Methods Summary
public voidclear()

        setEntryId(null);
        mParams.clear();
    
public java.lang.StringgenerateQueryUrl(java.lang.String feedUrl)


        if (TextUtils.isEmpty(getEntryId()) &&
            mParams.isEmpty()) {
            // nothing to do
            return feedUrl;
        }

        // handle entry IDs
        if (!TextUtils.isEmpty(getEntryId())) {
            if (!mParams.isEmpty()) {
                throw new IllegalStateException("Cannot set both an entry ID "
                        + "and other query paramters.");
            }
            return feedUrl + '/" + getEntryId();
        }

        // otherwise, append the querystring params.
        StringBuilder sb = new StringBuilder();
        sb.append(feedUrl);
        Set<String> params = mParams.keySet();
        boolean first = true;
        if (feedUrl.contains("?")) {
            first = false;
        } else {
            sb.append('?");
        }
        for (String param : params) {
            if (first) {
                first = false;
            } else {
                sb.append('&");
            }
            sb.append(param);
            sb.append('=");
            String value = mParams.get(param);
            String encodedValue = null;

            try {
                encodedValue = URLEncoder.encode(value, "UTF-8");
            } catch (UnsupportedEncodingException uee) {
                // should not happen.
                Log.w("QueryParamsImpl",
                      "UTF-8 not supported -- should not happen.  "
                      + "Using default encoding.", uee);
                encodedValue = URLEncoder.encode(value);
            }
            sb.append(encodedValue);
        }
        return sb.toString();
    
public java.lang.StringgetParamValue(java.lang.String param)

        if (!(mParams.containsKey(param))) {
            return null;
        }
        return mParams.get(param);
    
public voidsetParamValue(java.lang.String param, java.lang.String value)

        mParams.put(param, value);