Html.java :  » RSS » androidnews » vn » evolus » droidreader » util » Android Open Source

Android Open Source » RSS » androidnews 
androidnews » vn » evolus » droidreader » util » Html.java
package vn.evolus.droidreader.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Html {
  private static final Pattern bodyPattern = Pattern.compile("<body[^>]*?>([\\s\\S]*?)</body>", Pattern.CASE_INSENSITIVE);
  
  public static String getBodyContent(String dirtyHtml) {
    Matcher matcher = bodyPattern.matcher(dirtyHtml);
    if (matcher.find()) {
      return matcher.group(1);
    }
    return null;
  }
  
  public static String toText(String html) {
    if (html == null) return html;    
    return html.replaceAll("</?[^>]+>", "").trim();
  }
  
  public static String decode(String html) {
    if (html == null) return html;
        return html
          .replace("&lt;", "<")
          .replace("&gt;", ">")
          .replace("&quot;", "\"")
          .replace("&apos;", "'")
          .replace("&nbsp;", " ")
          .replace("&amp;", "&")
          .replace("&mdash;", "")
          .replace("&#39;", "'");
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.