Android Open Source - glvideoplayer-android Html Util






From Project

Back to project page glvideoplayer-android.

License

The source code is released under:

Apache License

If you think the Android project glvideoplayer-android 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 net.binzume.android.nicovideo.util;
/*  ww  w. ja  va 2 s.  c  o m*/
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * HTML???????????(XMLPullParser????????????????????????????)
 * 
 * @author kawahira
 */

public class HtmlUtil {
  
  public static String urlEncode(String s) {
    try {
      return URLEncoder.encode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
      // do not reach here
    }
    return s;
  }
  
    static class HtmlIterator implements Iterable<CharSequence>, Iterator<CharSequence> {
        private Matcher matcher;

        public HtmlIterator(Matcher m) {
            matcher = m;
        }

        public boolean hasNext() {
            return matcher.find();
        }

        public CharSequence next() {
            return matcher.group(2);
        }

        public void remove() {
        }

        public Iterator<CharSequence> iterator() {
            return this;
        }

    }
    
    public static HashMap<String,String> flashVarsToMap(final String data) {
    HashMap<String, String> map = new HashMap<String, String>();
    String[] params = data.split("&");
    for (int i = 0; i < params.length; i++) {
      String[] p = params[i].split("=");
      if (p.length < 2)
        continue;
      try {
        map.put(URLDecoder.decode(p[0], "UTF-8"), URLDecoder.decode(p[1], "UTF-8"));
      } catch (UnsupportedEncodingException e) {
        // do not reach here
      }
    }
      
      return map;
    }

    public static Iterable<CharSequence> getByTagName(CharSequence data, String name) {
        Matcher matcher = Pattern.compile("<(" + name + ")[^>]*>([^<]*)</\\1>", Pattern.DOTALL).matcher(data);
        return new HtmlIterator(matcher);
    }

    public static CharSequence getFirstTag(CharSequence data, String name) {
        Matcher matcher = Pattern.compile("<(" + name + ")[^>]*>([^<]*)</\\1>", Pattern.DOTALL).matcher(data);
        if (matcher.find()) {
            return matcher.group(2);
        }
        return null;
    }

    public static String unescape(CharSequence src) {
        int len = src.length(), p = 0;
        StringBuffer sb = new StringBuffer(len);
        while (p < len) {
            char c = src.charAt(p);
            if (c == '&') {
                int t = p + 1;
                while (t < len) {
                    if (src.charAt(t) == ';') {
                        String s = src.subSequence(p + 1, t).toString();
                        if ("amp".equals(s)) {
                            c = '&';
                        } else if ("quot".equals(s)) {
                            c = '"';
                        } else if ("gt".equals(s)) {
                            c = '>';
                        } else if ("apos".equals(s)) {
                            c = '\'';
                        } else if ("lt".equals(s)) {
                            c = '<';
                        } else if ("#039".equals(s)) {
                            c = '\'';
                        } else {
                            t = p;
                        }
                        p = t;
                        break;
                    }
                    t++;
                }

            }
            sb.append(c);
            p++;
        }
        return sb.toString();
    }

    public static String escape(CharSequence src) {
        int len = src.length(), p = 0;
        StringBuffer sb = new StringBuffer(len + 20);
        while (p < len) {
            char c = src.charAt(p);
            if (c == '&') {
                sb.append("&amp;");
            } else if (c == '>') {
                sb.append("&gt;");
            } else if (c == '<') {
                sb.append("&lt;");
            } else if (c == '"') {
                sb.append("&quot;");
            } else {
                sb.append(c);
            }
            p++;
        }
        return sb.toString();
    }

}




Java Source Code List

net.binzume.android.glvideoplayer.DeviceCameraPlane.java
net.binzume.android.glvideoplayer.FBOTexture.java
net.binzume.android.glvideoplayer.GLShaderProgram.java
net.binzume.android.glvideoplayer.GLVideoRenderer.java
net.binzume.android.glvideoplayer.MainActivity.java
net.binzume.android.glvideoplayer.MediaPlayerPlane.java
net.binzume.android.glvideoplayer.NicoCommentPlane.java
net.binzume.android.glvideoplayer.OESTexture.java
net.binzume.android.glvideoplayer.TextureFactory.java
net.binzume.android.glvideoplayer.Texture.java
net.binzume.android.glvideoplayer.VideoSurfaceView.java
net.binzume.android.nicoplayer.player.CommentController.java
net.binzume.android.nicoplayer.player.CommentLoadTask.java
net.binzume.android.nicoplayer.player.CommentSlot.java
net.binzume.android.nicovideo.ChannelCategoryInfo.java
net.binzume.android.nicovideo.ChannelInfo.java
net.binzume.android.nicovideo.Comment.java
net.binzume.android.nicovideo.MyList.java
net.binzume.android.nicovideo.NicoSession.java
net.binzume.android.nicovideo.ThreadInfo.java
net.binzume.android.nicovideo.VideoFileInfo.java
net.binzume.android.nicovideo.VideoInfo.java
net.binzume.android.nicovideo.util.HtmlUtil.java
net.binzume.android.nicovideo.util.HttpClient.java
net.binzume.android.nicovideo.webapi.ChannelAPI.java
net.binzume.android.nicovideo.webapi.CommentAPI.java
net.binzume.android.nicovideo.webapi.Constants.java
net.binzume.android.nicovideo.webapi.FriendListAPI.java
net.binzume.android.nicovideo.webapi.LoginAPI.java
net.binzume.android.nicovideo.webapi.MyListAPI.java
net.binzume.android.nicovideo.webapi.NotLoginException.java
net.binzume.android.nicovideo.webapi.PaymentRequiredException.java
net.binzume.android.nicovideo.webapi.VideoAPI.java
net.binzume.android.nicovideo.webapi.VideoRssParser.java
net.binzume.android.nicovideo.webapi.VideoSearchAPI.java
net.binzume.android.nicovideo.webapi.WatchItemAPI.java
net.binzume.android.nicovideo.webapi.WebApiException.java