Changeset 6849 in josm for trunk/src/oauth/signpost/http


Ignore:
Timestamp:
2014-02-13T21:10:18+01:00 (11 years ago)
Author:
stoecker
Message:

see #9710 - update oauth library code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/oauth/signpost/http/HttpParameters.java

    r4231 r6849  
    8787     */
    8888    public String put(String key, String value, boolean percentEncode) {
    89         SortedSet<String> values = wrappedMap.get(key);
    90         if (values == null) {
    91             values = new TreeSet<String>();
    92             wrappedMap.put(percentEncode ? OAuth.percentEncode(key) : key, values);
    93         }
    94         if (value != null) {
    95             value = percentEncode ? OAuth.percentEncode(value) : value;
    96             values.add(value);
    97         }
    98 
    99         return value;
    100     }
     89         // fix contributed by Bjorn Roche - key should be encoded before wrappedMap.get
     90         key = percentEncode ? OAuth.percentEncode(key) : key;
     91         SortedSet<String> values = wrappedMap.get(key);
     92         if (values == null) {
     93             values = new TreeSet<String>();
     94             wrappedMap.put( key, values);
     95         }
     96         if (value != null) {
     97             value = percentEncode ? OAuth.percentEncode(value) : value;
     98             values.add(value);
     99         }
     100
     101         return value;
     102     }
    101103
    102104    /**
     
    200202     */
    201203    public String getAsQueryString(Object key) {
     204        return getAsQueryString(key, true);
     205    }
     206
     207    /**
     208     * Concatenates all values for the given key to a list of key/value pairs
     209     * suitable for use in a URL query string.
     210     *
     211     * @param key
     212     *        the parameter name
     213     * @param percentEncode
     214     *        whether key should be percent encoded before being
     215     *        used with the map
     216     * @return the query string
     217     */
     218     public String getAsQueryString(Object key, boolean percentEncode) {
     219        // fix contributed by Stjepan Rajko - we need the percentEncode parameter
     220        // because some places (like SignatureBaseString.normalizeRequestParameters)
     221        // need to supply the parameter percent encoded
     222
    202223        StringBuilder sb = new StringBuilder();
    203         key = OAuth.percentEncode((String) key);
     224        if(percentEncode)
     225                key = OAuth.percentEncode((String) key);
    204226        Set<String> values = wrappedMap.get(key);
    205227        if (values == null) {
     
    215237        return sb.toString();
    216238    }
    217 
     239   
    218240    public String getAsHeaderElement(String key) {
    219241        String value = getFirst(key);
     
    265287    }
    266288
    267     public Set<java.util.Map.Entry<String, SortedSet<String>>> entrySet() {
     289    public Set<Entry<String, SortedSet<String>>> entrySet() {
    268290        return wrappedMap.entrySet();
    269291    }
     292
     293    public HttpParameters getOAuthParameters() {
     294        HttpParameters oauthParams = new HttpParameters();
     295
     296        for (Entry<String, SortedSet<String>> param : this.entrySet()) {
     297            String key = param.getKey();
     298            if (key.startsWith("oauth_") || key.startsWith("x_oauth_")) {
     299                oauthParams.put(key, param.getValue());
     300            }
     301        }
     302
     303        return oauthParams;
     304    }
    270305}
Note: See TracChangeset for help on using the changeset viewer.