Package org.apache.commons.codec.net

Examples of org.apache.commons.codec.net.URLCodec


        return str;
      }
    }
   
    public static String sanitizeAndPreserveSlashes(String str) {
      URLCodec codec= new URLCodec();
      try {
        return codec.encode(str).replaceAll("\\+", "%20").replaceAll("%2F", "/");
       }
      catch (EncoderException ee) {
        logger.warn("Error trying to encode string for URI", ee);
        return str;
      }
View Full Code Here


        return str;
      }
    }
   
    public static String unencodeURI(String str) {
         URLCodec codec= new URLCodec();
      try {
        return codec.decode(str);
      }
      catch (DecoderException ee) {
        logger.warn("Error trying to encode string for URI", ee);
        return str;
      }
View Full Code Here

     public static String formUrlEncode(
             final NameValuePair[] pairs,
             final String charset) throws UnsupportedEncodingException {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < pairs.length; i++) {
            URLCodec codec = new URLCodec();
            NameValuePair pair = pairs[i];
            if (pair.getName() != null) {
                if (i > 0) {
                    buf.append("&");
                }
                buf.append(codec.encode(pair.getName(), charset));
                buf.append("=");
                if (pair.getValue() != null) {
                    buf.append(codec.encode(pair.getValue(), charset));
                }
            }
        }
        return buf.toString();
    }
View Full Code Here

 
  public String getTextURLEncoded(){
    if(text==null)return null;
    String s = null;
    try {
      s = new String(new URLCodec().encode(getText()));
    } catch (EncoderException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return s;
View Full Code Here

 
  public String getTextURLEncoded(){
    if(text==null)return null;
    String s = null;
    try {
      s = new String(new URLCodec().encode(getText()));
    } catch (EncoderException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return s;
View Full Code Here

        builder.append(path);

        try
        {
            URLCodec codec = new URLCodec();

            String sep = "?";

            for (String name : getParameterNames())
            {
                String value = _parameters.get(name);

                builder.append(sep);

                // TODO: encode the parameter name?

                builder.append(name);
                builder.append("=");
                builder.append(codec.encode(value));

                sep = "&";
            }
        }
        catch (EncoderException ex)
View Full Code Here

    public void close() {
//        connectionManager.shutdown();
    }
   
    private String querystring(MultivaluedMap<String,String> query) {
        URLCodec urlsafe = new URLCodec("UTF-8");
        String queryString = "";
        ArrayList<String> params = new ArrayList<String>();
        for( String key : query.keySet() ) {
            if( query.get(key) == null ) {
                params.add(key+"=");
            }
            else {
                for( String value : query.get(key) ) {
                    try {
                        params.add(key+"="+urlsafe.encode(value)); // XXX assumes that the keys don't have any special characters
                    } catch (EncoderException ex) {
                        log.error("Cannot encode query parameter: {}", value, ex);
                    }
                }
            }
View Full Code Here

    protected String invokeHTTPRequest(String url, String[] jsonArgs) throws IOException, EncoderException {
       
         HttpClient httpclient = new DefaultHttpClient();
        
        
         URLCodec uc = new URLCodec();
         for (int i=0 ; i<jsonArgs.length; i++) {
             if (i == 0) {
                 url += '?';
             } else {
                 url += '&';
             }
             url += "arg" + i + "=";
             url += uc.encode(jsonArgs[i]);
         }

         HttpGet httpget = new HttpGet(url);

         HttpResponse response = httpclient.execute(httpget);
View Full Code Here

        for (String pair : pairs)
        {
            String[] nameValue = pair.split("=");
            if (nameValue.length == 2)
            {
                URLCodec codec = new URLCodec(outputEncoding);
                String key = codec.decode(nameValue[0]);
                String value = codec.decode(nameValue[1]);
                addToParameterMap(paramMap, key, value);
            }
        }
    }
View Full Code Here

     *
     * @param str string to sanitize
     * @return The string encoded for a URI
     */
    public static String sanitizeForURI(String str) {
      URLCodec codec= new URLCodec();
      try {
        return codec.encode(str).replaceAll("\\+", "%20");
      }
      catch (EncoderException ee) {
        logger.warn("Error trying to encode string for URI", ee);
        return str;
      }
View Full Code Here

TOP

Related Classes of org.apache.commons.codec.net.URLCodec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.