Android Open Source - cnBeta Base Load Source






From Project

Back to project page cnBeta.

License

The source code is released under:

Apache License

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

package com.guest.cnbeta.loadsource;
//from   w  w  w.  java 2 s  .  co m
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public abstract class BaseLoadSource implements LoadSourceInterface {

  public String sessionId;

  public String getUrlHTML(URL url) throws IOException {
    return getUrlHTML(url, "UTF-8");
  }

  public static String getUrlHTML(URL url, String charset) throws IOException {
    BufferedReader reader;
    reader = new BufferedReader(new InputStreamReader(url.openStream(),
        charset));
    String line;
    StringBuffer result = new StringBuffer();
    while ((line = reader.readLine()) != null) {
      result.append(line);
    }
    return result.toString();
  }

  public Bitmap getImage(URL url) throws IOException {
    
    try {
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setDoInput(true);
      conn.connect();
      // int length = conn.getContentLength();
      InputStream is = conn.getInputStream();
      Bitmap img = BitmapFactory.decodeStream(is);
      String cookieValue = conn.getHeaderField("Set-Cookie");
      sessionId = cookieValue.substring(0, cookieValue.indexOf(";"));
      return img;
    } catch (Exception e) {
      // TODO: handle exception
    }

    return null;
  }

  public String replaceHTMLJs(String str) {
    str = str.replace("</p>", "\n");
//    str = str.replace("<br />", "\n");
    Pattern p = Pattern.compile("(?s)<[/!]*?[^<>]*?>");
    Matcher m = p.matcher(str);
    str = m.replaceAll("");
    str = str.replace("&nbsp;", " ");
    str = str.replace("&rdquo;", "??");
    str = str.replace("&quot;", "''");
    str = str.replace("&ldquo;", "");
    str = str.replace("&mdash;", "");
    str = str.replace("&lsquo;", "");
    str = str.replace("&rsquo;", "");
    str = str.replace("&middot;", "");
    str = str.replace("&amp;", "&");
    
    if(str.contains("???")){
      str = str.split("???")[1];
    }
    
    return str;
  }

}




Java Source Code List

.ArticleActivity.java
.ArticleListService.java
.ArticleService.java
.Article.java
.CommentActivity.java
.CommentService.java
.Comment.java
.LoadSourceInterface.java
.LoadSource.java
.MainActivity.java
.PostCommentActivity.java
.Util.java
com.guest.cnbeta.FirstActivity.java
com.guest.cnbeta.SettingsActivity.java
com.guest.cnbeta.database.ArticleDB.java
com.guest.cnbeta.database.BaseDBHelper.java
com.guest.cnbeta.database.BaseDB.java
com.guest.cnbeta.loadsource.BaseLoadSource.java
com.guest.cnbeta.module.Avatar.java
com.guest.cnbeta.service.AvatarListService.java
com.guest.cnbeta.service.BaseService.java
com.guest.cnbeta.util.BaseApplication.java
com.guest.cnbeta.util.DataEngine.java
com.guest.cnbeta.util.FlingGallery.java
com.guest.cnbeta.util.NetworkStatusReceiver.java
com.guest.cnbeta.util.PullToRefreshListView.java
com.guest.cnbeta.util.ScaleAnimationHelper.java
com.guest.cnbeta.util.T.java