Android Open Source - Simple-Dilbert Find Urls






From Project

Back to project page Simple-Dilbert.

License

The source code is released under:

Apache License

If you think the Android project Simple-Dilbert 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.mareksebera.simpledilbert.utilities;
//from  www. ja  v  a  2s  .c om
import android.net.Uri;
import android.util.Log;

import com.mareksebera.simpledilbert.preferences.DilbertPreferences;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.joda.time.LocalDate;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;

final public class FindUrls {
    private static final String LOG_TAG = "FindUrls";

    private FindUrls() {
    }

    private static final Pattern url_match_pattern = Pattern
            .compile("<img.*img-comic.*src=\"([a-zA-Z0-9:\\/\\.]*)\"\\s+");

    private static final Pattern date_match_pattern = Pattern
            .compile(".*([\\d]{4}-[\\d]{2}-[\\d]{2}).*");

    public static String extractUrls(HttpResponse response) {
        String found = null;
        try {
            Scanner scan;
            Header contentEncoding = response
                    .getFirstHeader("Content-Encoding");
            if (contentEncoding != null
                    && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                scan = new Scanner(new GZIPInputStream(response.getEntity()
                        .getContent()));
            } else {
                scan = new Scanner(response.getEntity().getContent());
            }

            found = scan.findWithinHorizon(url_match_pattern, 0);
            if (null != found) {
                Matcher m = url_match_pattern.matcher(found);
                if (m.matches())
                    found = m.group(1);
            }
            scan.close();
            response.getEntity().consumeContent();
        } catch (Throwable t) {
            Log.e(LOG_TAG, "Error Occurred", t);
        }
        return found;
    }

    public static LocalDate extractCurrentDateFromIntentUrl(Uri path) {
        try {
            Matcher m = date_match_pattern.matcher(path.toString());
            if (m.matches()) {
                return LocalDate.parse(m.group(1), DilbertPreferences.DATE_FORMATTER);
            }
        } catch (Throwable t) {
            Log.e(LOG_TAG, "extractCurrentDateFromIntentUrl failed", t);
        }
        return null;
    }
}




Java Source Code List

com.mareksebera.simpledilbert.AppController.java
com.mareksebera.simpledilbert.core.DilbertFragmentActivity.java
com.mareksebera.simpledilbert.core.DilbertFragmentAdapter.java
com.mareksebera.simpledilbert.core.DilbertFragmentInterface.java
com.mareksebera.simpledilbert.core.DilbertFragment.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedActivity.java
com.mareksebera.simpledilbert.favorites.DilbertFavoritedFragmentAdapter.java
com.mareksebera.simpledilbert.favorites.FavoritedItem.java
com.mareksebera.simpledilbert.picker.FolderPickerActivity.java
com.mareksebera.simpledilbert.picker.FolderPickerAdapter.java
com.mareksebera.simpledilbert.picker.FolderPickerFragment.java
com.mareksebera.simpledilbert.preferences.DilbertPreferencesActivity.java
com.mareksebera.simpledilbert.preferences.DilbertPreferences.java
com.mareksebera.simpledilbert.utilities.ActionBarUtility.java
com.mareksebera.simpledilbert.utilities.DownloadManagerBroadcastReceiver.java
com.mareksebera.simpledilbert.utilities.FailSafeBitmapDisplayer.java
com.mareksebera.simpledilbert.utilities.FindUrls.java
com.mareksebera.simpledilbert.utilities.FixedViewPager.java
com.mareksebera.simpledilbert.utilities.GetStripUrlInterface.java
com.mareksebera.simpledilbert.utilities.GetStripUrl.java
com.mareksebera.simpledilbert.widget.WidgetProvider.java