com.hippo.yorozuya.StringUtils Java Examples

The following examples show how to use com.hippo.yorozuya.StringUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GalleryPageParser.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
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));
    }
    m = PATTERN_SHOW_KEY.matcher(body);
    if (m.find()) {
        result.showKey = m.group(1);
    }

    if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.showKey)) {
        return result;
    } else {
        throw new ParseException("Parse image url and show error", body);
    }
}
 
Example #2
Source File: DownloadClient.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private static String getFilenameFromContentDisposition(String contentDisposition) {
    if (contentDisposition == null) {
        return null;
    }

    String[] pieces = StringUtils.split(contentDisposition, ';');
    for (String piece : pieces) {
        int index = piece.indexOf('=');
        if (index < 0) {
            continue;
        }
        String key = piece.substring(0, index).trim();
        String value = piece.substring(index + 1).trim();
        if ("filename".equals(key) && !TextUtils.isEmpty(value)) {
            return value;
        }
    }

    return null;
}
 
Example #3
Source File: ACItemUtils.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
public static CharSequence generateContent(String content, String sage, String title, String name) {
    StringBuilder sb = new StringBuilder(44 + 11 + StringUtils.length(title) +
            11 + StringUtils.length(name) +
            StringUtils.length(content));
    if ("1".equals(sage)) {
        sb.append("<font color=\"red\"><b>SAGE</b></font><br><br>");
    }
    if (!TextUtils.isEmpty(title) && !NO_TITLE.equals(title)) {
        sb.append("<b>").append(title).append("</b><br>");
    }
    if (!TextUtils.isEmpty(name) && !NO_NAME.equals(name)) {
        sb.append("<b>").append(name).append("</b><br>");
    }
    sb.append(content);

    return generateContent(sb.toString());
}
 
Example #4
Source File: GalleryPageParser.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
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));
    }
    m = PATTERN_SHOW_KEY.matcher(body);
    if (m.find()) {
        result.showKey = m.group(1);
    }

    if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.showKey)) {
        return result;
    } else {
        throw new ParseException("Parse image url and show error", body);
    }
}
 
Example #5
Source File: ParserUtils.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static String trim(String str) {
    // Avoid null
    if (str == null) {
        str = "";
    }
    return StringUtils.unescapeXml(str).trim();
}
 
Example #6
Source File: GalleryPageApiParser.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public static Result parse(String body) throws ParseException {
    try {
        Matcher m;
        Result result = new Result();

        JSONObject jo = new JSONObject(body);
        if (jo.has("error")) {
            throw new ParseException(jo.getString("error"), body);
        }

        String i3 = jo.getString("i3");
        m = PATTERN_IMAGE_URL.matcher(i3);
        if (m.find()) {
            result.imageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
        }
        String i6 = jo.getString("i6");
        m = PATTERN_SKIP_HATH_KEY.matcher(i6);
        if (m.find()) {
            result.skipHathKey = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
        }
        String i7 = jo.getString("i7");
        m = PATTERN_ORIGIN_IMAGE_URL.matcher(i7);
        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);
        }
    } catch (JSONException e) {
        throw new ParseException("Can't parse json", body, e);
    }
}
 
Example #7
Source File: ListUrlBuilder.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public boolean equalsQuickSearch(QuickSearch q) {
    if (null == q) {
        return false;
    }

    if (q.mode != mMode) {
        return false;
    }
    if (q.category != mCategory) {
        return false;
    }
    if (!StringUtils.equals(q.keyword, mKeyword)) {
        return false;
    }
    if (q.advanceSearch != mAdvanceSearch) {
        return false;
    }
    if (q.minRating != mMinRating) {
        return false;
    }
    if (q.pageFrom != mPageFrom) {
        return false;
    }
    if (q.pageTo != mPageTo) {
        return false;
    }

    return true;
}
 
Example #8
Source File: ResImageGetter.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable getDrawable(String source) {
    if (StringUtils.isAllDigit(source)) {
        int resId = Integer.parseInt(source);
        Drawable d = sResources.getDrawable(resId);
        if (d != null) {
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            return d;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example #9
Source File: SpiderQueen.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private GalleryPageParser.Result fetchPageResultFromHtml(int index, String pageUrl) throws Throwable {
    GalleryPageParser.Result result = EhEngine.getGalleryPage(null, mHttpClient, pageUrl, mGalleryInfo.gid, mGalleryInfo.token);
    if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
        // Get 509
        // Notify listeners
        notifyGet509(index);
        throw new Image509Exception();
    }

    return result;
}
 
Example #10
Source File: SpiderQueen.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
private GalleryPageApiParser.Result fetchPageResultFromApi(long gid, int index, String pToken, String showKey, String previousPToken) throws Throwable {
    GalleryPageApiParser.Result result = EhEngine.getGalleryPageApi(null, mHttpClient, gid, index, pToken, showKey, previousPToken);
    if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) {
        // Get 509
        // Notify listeners
        notifyGet509(index);
        throw new Image509Exception();
    }

    return result;
}
 
Example #11
Source File: ParserUtils.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static String trim(String str) {
    // Avoid null
    if (str == null) {
        str = "";
    }
    return StringUtils.unescapeXml(str).trim();
}
 
Example #12
Source File: GalleryPageApiParser.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public static Result parse(String body) throws ParseException {
    try {
        Matcher m;
        Result result = new Result();

        JSONObject jo = new JSONObject(body);
        if (jo.has("error")) {
            throw new ParseException(jo.getString("error"), body);
        }

        String i3 = jo.getString("i3");
        m = PATTERN_IMAGE_URL.matcher(i3);
        if (m.find()) {
            result.imageUrl = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
        }
        String i6 = jo.getString("i6");
        m = PATTERN_SKIP_HATH_KEY.matcher(i6);
        if (m.find()) {
            result.skipHathKey = StringUtils.unescapeXml(StringUtils.trim(m.group(1)));
        }
        String i7 = jo.getString("i7");
        m = PATTERN_ORIGIN_IMAGE_URL.matcher(i7);
        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);
        }
    } catch (JSONException e) {
        throw new ParseException("Can't parse json", body, e);
    }
}
 
Example #13
Source File: ListUrlBuilder.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public boolean equalsQuickSearch(QuickSearch q) {
    if (null == q) {
        return false;
    }

    if (q.mode != mMode) {
        return false;
    }
    if (q.category != mCategory) {
        return false;
    }
    if (!StringUtils.equals(q.keyword, mKeyword)) {
        return false;
    }
    if (q.advanceSearch != mAdvanceSearch) {
        return false;
    }
    if (q.minRating != mMinRating) {
        return false;
    }
    if (q.pageFrom != mPageFrom) {
        return false;
    }
    if (q.pageTo != mPageTo) {
        return false;
    }

    return true;
}
 
Example #14
Source File: GalleryCommentsScene.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
public void showVoteStatusDialog(Context context, String voteStatus) {
    String[] temp = StringUtils.split(voteStatus, ',');
    final int length = temp.length;
    final String[] userArray = new String[length];
    final String[] voteArray = new String[length];
    for (int i = 0; i < length; i++) {
        String str = StringUtils.trim(temp[i]);
        int index = str.lastIndexOf(' ');
        if (index < 0) {
            Log.d(TAG, "Something wrong happened about vote state");
            userArray[i] = str;
            voteArray[i] = "";
        } else {
            userArray[i] = StringUtils.trim(str.substring(0, index));
            voteArray[i] = StringUtils.trim(str.substring(index + 1));
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    context = builder.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
    rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
        @Override
        public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new InfoHolder(inflater.inflate(R.layout.item_drawer_favorites, parent, false));
        }

        @Override
        public void onBindViewHolder(InfoHolder holder, int position) {
            holder.key.setText(userArray[position]);
            holder.value.setText(voteArray[position]);
        }

        @Override
        public int getItemCount() {
            return length;
        }
    });
    rv.setLayoutManager(new LinearLayoutManager(context));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
    rv.addItemDecoration(decoration);
    rv.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    rv.setClipToPadding(false);
    builder.setView(rv).show();
}
 
Example #15
Source File: GalleryCommentsScene.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
@SuppressLint("InflateParams")
public void showVoteStatusDialog(Context context, String voteStatus) {
    String[] temp = StringUtils.split(voteStatus, ',');
    final int length = temp.length;
    final String[] userArray = new String[length];
    final String[] voteArray = new String[length];
    for (int i = 0; i < length; i++) {
        String str = StringUtils.trim(temp[i]);
        int index = str.lastIndexOf(' ');
        if (index < 0) {
            Log.d(TAG, "Something wrong happened about vote state");
            userArray[i] = str;
            voteArray[i] = "";
        } else {
            userArray[i] = StringUtils.trim(str.substring(0, index));
            voteArray[i] = StringUtils.trim(str.substring(index + 1));
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    context = builder.getContext();
    final LayoutInflater inflater = LayoutInflater.from(context);
    EasyRecyclerView rv = (EasyRecyclerView) inflater.inflate(R.layout.dialog_recycler_view, null);
    rv.setAdapter(new RecyclerView.Adapter<InfoHolder>() {
        @Override
        public InfoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            return new InfoHolder(inflater.inflate(R.layout.item_drawer_favorites, parent, false));
        }

        @Override
        public void onBindViewHolder(InfoHolder holder, int position) {
            holder.key.setText(userArray[position]);
            holder.value.setText(voteArray[position]);
        }

        @Override
        public int getItemCount() {
            return length;
        }
    });
    rv.setLayoutManager(new LinearLayoutManager(context));
    LinearDividerItemDecoration decoration = new LinearDividerItemDecoration(
            LinearDividerItemDecoration.VERTICAL, AttrResources.getAttrColor(context, R.attr.dividerColor),
            LayoutUtils.dp2pix(context, 1));
    decoration.setPadding(ResourcesUtils.getAttrDimensionPixelOffset(context, R.attr.dialogPreferredPadding));
    rv.addItemDecoration(decoration);
    rv.setSelector(Ripple.generateRippleDrawable(context, !AttrResources.getAttrBoolean(context, R.attr.isLightTheme), new ColorDrawable(Color.TRANSPARENT)));
    rv.setClipToPadding(false);
    builder.setView(rv).show();
}