Android Open Source - doubanbook4android Uri Utils






From Project

Back to project page doubanbook4android.

License

The source code is released under:

Eclipse Public License - v 1.0 THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECI...

If you think the Android project doubanbook4android 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

/*
 * UriUtils.java//from w  ww  .  j a v a2 s  .  com
 * classes : org.kevin.douban.util.UriUtils 
 * Created at : 2013-5-9 ????5:51:39
 */
package com.study.doubanbook_for_android.utils;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;

import com.study.doubanbook_for_android.auth.DoubanParameters;

import android.os.Bundle;
import android.util.Log;

/**
 * @author thinkfeed#gmail.com
 * 
 */
public class UriUtils {
  public static String encodeUrl(DoubanParameters parameters) {
    if (parameters == null) {
      return "";
    }

    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (int loc = 0; loc < parameters.size(); loc++) {
      if (first) {
        first = false;
      } else {
        sb.append("&");
      }
      String _key = parameters.getKey(loc);
      String _value = parameters.getValue(_key);
      if (_value == null) {
        Log.i("encodeUrl", "key:" + _key + " 's value is null");
      } else {
        try {
          sb.append(URLEncoder.encode(parameters.getKey(loc), "utf-8")
              + "="
              + URLEncoder.encode(parameters.getValue(loc),
                  "utf-8"));
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }

    }
    return sb.toString();
  }

  public static String encodeParameters(DoubanParameters httpParams) {
    if (null == httpParams || isBundleEmpty(httpParams)) {
      return "";
    }
    StringBuilder buf = new StringBuilder();
    int j = 0;
    for (int loc = 0; loc < httpParams.size(); loc++) {
      String key = httpParams.getKey(loc);
      if (j != 0) {
        buf.append("&");
      }
      try {
        buf.append(URLEncoder.encode(key, "UTF-8"))
            .append("=")
            .append(URLEncoder.encode(httpParams.getValue(key),
                "UTF-8"));
      } catch (java.io.UnsupportedEncodingException neverHappen) {
      }
      j++;
    }
    return buf.toString();

  }

  private static boolean isBundleEmpty(DoubanParameters bundle) {
    if (bundle == null || bundle.size() == 0) {
      return true;
    }
    return false;
  }

  public static Bundle parseUrl(String url) {
    try {
      URL u = new URL(url);
      Bundle b = decodeUrl(u.getQuery());
      b.putAll(decodeUrl(u.getRef()));
      return b;
    } catch (MalformedURLException e) {
      return new Bundle();
    }
  }

  public static Bundle decodeUrl(String s) {
    Bundle params = new Bundle();
    if (s != null) {
      String array[] = s.split("&");
      for (String parameter : array) {
        String v[] = parameter.split("=");
        try {
          params.putString(URLDecoder.decode(v[0], "utf-8"),
              URLDecoder.decode(v[1], "utf-8"));
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    return params;
  }

}




Java Source Code List

.UserListAdapter.java
com.study.doubanbook_for_android.activity.BaseActivity.java
com.study.doubanbook_for_android.activity.BaseP2RActivity.java
com.study.doubanbook_for_android.activity.BookDetailActivity.java
com.study.doubanbook_for_android.activity.BookListsActivity.java
com.study.doubanbook_for_android.activity.BookNoteListActivity.java
com.study.doubanbook_for_android.activity.CollectDetailActivity.java
com.study.doubanbook_for_android.activity.NoteAndUserDetailActivity.java
com.study.doubanbook_for_android.activity.SerchInputActivity.java
com.study.doubanbook_for_android.activity.TextActivity1.java
com.study.doubanbook_for_android.activity.UserDetailActivity.java
com.study.doubanbook_for_android.activity.UserListActivity.java
com.study.doubanbook_for_android.activity.UserNoteActivity.java
com.study.doubanbook_for_android.adapter.BookAdapter.java
com.study.doubanbook_for_android.adapter.CommentAdapter.java
com.study.doubanbook_for_android.adapter.UserNoteAdapter.java
com.study.doubanbook_for_android.api.NetUtils.java
com.study.doubanbook_for_android.api.SSLSocketFactoryEx.java
com.study.doubanbook_for_android.api.WrongMsg.java
com.study.doubanbook_for_android.auth.AccessToken.java
com.study.doubanbook_for_android.auth.DoubanDialogError.java
com.study.doubanbook_for_android.auth.DoubanDialog.java
com.study.doubanbook_for_android.auth.DoubanException.java
com.study.doubanbook_for_android.auth.DoubanOAuthListener.java
com.study.doubanbook_for_android.auth.DoubanParameters.java
com.study.doubanbook_for_android.auth.DoubanRequest.java
com.study.doubanbook_for_android.auth.Douban.java
com.study.doubanbook_for_android.auth.KeepToken.java
com.study.doubanbook_for_android.auth.SimpleDoubanOAuthListener.java
com.study.doubanbook_for_android.auth.Token.java
com.study.doubanbook_for_android.business.DoubanBusiness.java
com.study.doubanbook_for_android.callback.AsynCallback.java
com.study.doubanbook_for_android.imagedownloader.FileCache.java
com.study.doubanbook_for_android.imagedownloader.INetImageDownloader.java
com.study.doubanbook_for_android.imagedownloader.ImageCache.java
com.study.doubanbook_for_android.imagedownloader.ImageDownloaderListener.java
com.study.doubanbook_for_android.imagedownloader.ImageDownloader.java
com.study.doubanbook_for_android.model.Annotations.java
com.study.doubanbook_for_android.model.AuthorUser.java
com.study.doubanbook_for_android.model.BookItem.java
com.study.doubanbook_for_android.model.CollectBookMsg.java
com.study.doubanbook_for_android.model.CollectSuccessResult.java
com.study.doubanbook_for_android.model.CommentItem.java
com.study.doubanbook_for_android.model.Comment.java
com.study.doubanbook_for_android.model.CurrenUserCollection.java
com.study.doubanbook_for_android.model.GeneralNoteResult.java
com.study.doubanbook_for_android.model.GeneralResult.java
com.study.doubanbook_for_android.model.GeneralUserResult.java
com.study.doubanbook_for_android.model.ImageItem.java
com.study.doubanbook_for_android.model.Rating.java
com.study.doubanbook_for_android.model.RequestGrantScope.java
com.study.doubanbook_for_android.model.TagItem.java
com.study.doubanbook_for_android.model.URLMananeger.java
com.study.doubanbook_for_android.utils.EncodeUtils.java
com.study.doubanbook_for_android.utils.JsonParser.java
com.study.doubanbook_for_android.utils.JsonUtil.java
com.study.doubanbook_for_android.utils.UriUtils.java