Search in sources :

Example 11 with ParseException

use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.

the class GalleryPageParser method parse.

public static Result parse(String body) throws ParseException {
    Matcher m;
    Result result = new Result();
    m = PATTERN_IMAGE_URL.matcher(body);
    if (m.find()) {
        result.imageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
    }
    m = PATTERN_SKIP_HATH_KEY.matcher(body);
    if (m.find()) {
        result.skipHathKey = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
    }
    m = PATTERN_ORIGIN_IMAGE_URL.matcher(body);
    if (m.find()) {
        result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
    }
    if (!TextUtils.isEmpty(result.imageUrl)) {
        return result;
    } else {
        throw new ParseException("Parse image url and skip hath key error", body);
    }
}
Also used : Matcher(java.util.regex.Matcher) ParseException(com.hippo.ehviewer.client.exception.ParseException)

Example 12 with ParseException

use of com.hippo.ehviewer.client.exception.ParseException in project EhViewer by seven332.

the class ProfileParser method parse.

public static Result parse(String body) throws ParseException {
    try {
        Result result = new Result();
        Document d = Jsoup.parse(body);
        Element profilename = d.getElementById("profilename");
        result.displayName = profilename.child(0).text();
        try {
            result.avatar = profilename.nextElementSibling().nextElementSibling().child(0).attr("src");
            if (TextUtils.isEmpty(result.avatar)) {
                result.avatar = null;
            } else if (!result.avatar.startsWith("http")) {
                result.avatar = EhUrl.URL_FORUMS + result.avatar;
            }
        } catch (Exception e) {
            Log.i(TAG, "No avatar");
        }
        return result;
    } catch (Exception e) {
        throw new ParseException("Parse forums error", body);
    }
}
Also used : Element(org.jsoup.nodes.Element) ParseException(com.hippo.ehviewer.client.exception.ParseException) Document(org.jsoup.nodes.Document) ParseException(com.hippo.ehviewer.client.exception.ParseException)

Aggregations

ParseException (com.hippo.ehviewer.client.exception.ParseException)12 Element (org.jsoup.nodes.Element)6 Matcher (java.util.regex.Matcher)5 Document (org.jsoup.nodes.Document)5 Elements (org.jsoup.select.Elements)5 EhException (com.hippo.ehviewer.client.exception.EhException)3 GalleryInfo (com.hippo.ehviewer.client.data.GalleryInfo)2 LargePreviewSet (com.hippo.ehviewer.client.data.LargePreviewSet)2 OffensiveException (com.hippo.ehviewer.client.exception.OffensiveException)2 PiningException (com.hippo.ehviewer.client.exception.PiningException)2 ArrayList (java.util.ArrayList)2 NormalPreviewSet (com.hippo.ehviewer.client.data.NormalPreviewSet)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1