Example usage for org.apache.commons.lang3 StringEscapeUtils unescapeHtml4

List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeHtml4

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils unescapeHtml4.

Prototype

public static final String unescapeHtml4(final String input) 

Source Link

Document

Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.

Usage

From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java

public static void onActionMenuItemSelected(final RedditPreparedPost post, final Activity activity,
        final Action action) {

    switch (action) {

    case UPVOTE:/*from   ww w  .  j a v  a2s  . co m*/
        post.action(activity, RedditAPI.RedditAction.UPVOTE);
        break;

    case DOWNVOTE:
        post.action(activity, RedditAPI.RedditAction.DOWNVOTE);
        break;

    case UNVOTE:
        post.action(activity, RedditAPI.RedditAction.UNVOTE);
        break;

    case SAVE:
        post.action(activity, RedditAPI.RedditAction.SAVE);
        break;

    case UNSAVE:
        post.action(activity, RedditAPI.RedditAction.UNSAVE);
        break;

    case HIDE:
        post.action(activity, RedditAPI.RedditAction.HIDE);
        break;

    case UNHIDE:
        post.action(activity, RedditAPI.RedditAction.UNHIDE);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int which) {
                        post.action(activity, RedditAPI.RedditAction.REPORT);
                        // TODO update the view to show the result
                        // TODO don't forget, this also hides
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case EXTERNAL: {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        String url = (activity instanceof WebViewActivity) ? ((WebViewActivity) activity).getCurrentUrl()
                : post.url;
        intent.setData(Uri.parse(url));
        activity.startActivity(intent);
        break;
    }

    case SELFTEXT_LINKS: {

        final HashSet<String> linksInComment = LinkHandler
                .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext));

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_self);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_selftext_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;
    }

    case SAVE_IMAGE: {

        final RedditAccount anon = RedditAccountManager.getAnon();

        CacheManager.getInstance(activity)
                .makeRequest(new CacheRequest(General.uriFromString(post.imageUrl), anon, null,
                        Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                        Constants.FileType.IMAGE, false, false, false, activity) {

                    @Override
                    protected void onCallbackException(Throwable t) {
                        BugReportActivity.handleGlobalError(context, t);
                    }

                    @Override
                    protected void onDownloadNecessary() {
                        General.quickToast(context, R.string.download_downloading);
                    }

                    @Override
                    protected void onDownloadStarted() {
                    }

                    @Override
                    protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                            String readableMessage) {
                        final RRError error = General.getGeneralErrorForFailure(context, type, t, status,
                                url.toString());
                        General.showResultDialog(activity, error);
                    }

                    @Override
                    protected void onProgress(long bytesRead, long totalBytes) {
                    }

                    @Override
                    protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp,
                            UUID session, boolean fromCache, String mimetype) {

                        File dst = new File(
                                Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                                General.uriFromString(post.imageUrl).getPath());

                        if (dst.exists()) {
                            int count = 0;

                            while (dst.exists()) {
                                count++;
                                dst = new File(
                                        Environment.getExternalStoragePublicDirectory(
                                                Environment.DIRECTORY_PICTURES),
                                        count + "_"
                                                + General.uriFromString(post.imageUrl).getPath().substring(1));
                            }
                        }

                        try {
                            final InputStream cacheFileInputStream = cacheFile.getInputStream();

                            if (cacheFileInputStream == null) {
                                notifyFailure(RequestFailureType.CACHE_MISS, null, null,
                                        "Could not find cached image");
                                return;
                            }

                            General.copyFile(cacheFileInputStream, dst);

                        } catch (IOException e) {
                            notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file");
                            return;
                        }

                        activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                                Uri.parse("file://" + dst.getAbsolutePath())));

                        General.quickToast(context, context.getString(R.string.action_save_image_success) + " "
                                + dst.getAbsolutePath());
                    }
                });

        break;
    }

    case SHARE: {

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, post.title);
        mailer.putExtra(Intent.EXTRA_TEXT, post.url);
        activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share)));
        break;
    }

    case SHARE_COMMENTS: {

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title);
        mailer.putExtra(Intent.EXTRA_TEXT,
                Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString());
        activity.startActivity(
                Intent.createChooser(mailer, activity.getString(R.string.action_share_comments)));
        break;
    }

    case COPY: {

        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        manager.setText(post.url);
        break;
    }

    case GOTO_SUBREDDIT: {

        try {
            final Intent intent = new Intent(activity, PostListingActivity.class);
            intent.setData(SubredditPostListURL.getSubreddit(post.src.subreddit).generateJsonUri());
            activity.startActivityForResult(intent, 1);

        } catch (RedditSubreddit.InvalidSubredditNameException e) {
            Toast.makeText(activity, R.string.invalid_subreddit_name, Toast.LENGTH_LONG).show();
        }

        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(post.src.author).toString());
        break;

    case PROPERTIES:
        PostPropertiesDialog.newInstance(post.src).show(activity);
        break;

    case COMMENTS:
        ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post);
        break;

    case LINK:
        ((RedditPostView.PostSelectionListener) activity).onPostSelected(post);
        break;

    case COMMENTS_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((RedditPostView.PostSelectionListener) activity).onPostCommentsSelected(post);
        break;

    case LINK_SWITCH:
        if (!(activity instanceof MainActivity))
            activity.finish();
        ((RedditPostView.PostSelectionListener) activity).onPostSelected(post);
        break;

    case ACTION_MENU:
        showActionMenu(activity, post);
        break;

    case REPLY:
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra("parentIdAndType", post.idAndType);
        activity.startActivity(intent);
        break;
    }
}

From source file:org.lol.reddit.reddit.prepared.RedditPreparedPost.java

private void rebuildSubtitle(Context context) {

    // TODO customise display
    // TODO preference for the X days, X hours thing

    final TypedArray appearance = context
            .obtainStyledAttributes(new int[] { R.attr.rrPostSubtitleBoldCol, R.attr.rrPostSubtitleUpvoteCol,
                    R.attr.rrPostSubtitleDownvoteCol, R.attr.rrFlairBackCol, R.attr.rrFlairTextCol });

    final int boldCol = appearance.getColor(0, 255), rrPostSubtitleUpvoteCol = appearance.getColor(1, 255),
            rrPostSubtitleDownvoteCol = appearance.getColor(2, 255),
            rrFlairBackCol = appearance.getColor(3, 255), rrFlairTextCol = appearance.getColor(4, 255);

    final BetterSSB postListDescSb = new BetterSSB();

    final int pointsCol;
    int score = src.score;

    if (Boolean.TRUE.equals(src.likes))
        score--;/*from   w  ww .jav a2 s .c  o m*/
    if (Boolean.FALSE.equals(src.likes))
        score++;

    if (isUpvoted()) {
        pointsCol = rrPostSubtitleUpvoteCol;
        score++;
    } else if (isDownvoted()) {
        pointsCol = rrPostSubtitleDownvoteCol;
        score--;
    } else {
        pointsCol = boldCol;
    }

    if (src.over_18) {
        postListDescSb.append(" NSFW ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, Color.WHITE,
                Color.RED, 1f); // TODO color?
        postListDescSb.append("  ", 0);
    }

    if (src.link_flair_text != null && src.link_flair_text.length() > 0) {
        postListDescSb.append(" " + StringEscapeUtils.unescapeHtml4(src.link_flair_text) + " ",
                BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR, rrFlairTextCol,
                rrFlairBackCol, 1f);
        postListDescSb.append("  ", 0);
    }

    postListDescSb.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_points) + " ", 0);
    postListDescSb.append(RRTime.formatDurationFrom(context, src.created_utc * 1000),
            BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    postListDescSb.append(" " + context.getString(R.string.subtitle_by) + " ", 0);
    postListDescSb.append(src.author, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);

    if (showSubreddit) {
        postListDescSb.append(" " + context.getString(R.string.subtitle_to) + " ", 0);
        postListDescSb.append(src.subreddit, BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, boldCol, 0, 1f);
    }

    postListDescSb.append(" (" + src.domain + ")", 0);

    postListDescription = postListDescSb.get();
}

From source file:org.miloss.fgsms.common.UtilityTest.java

@Test
public void testStringEscaping() throws Exception {
    String url = "http://something:99/path/something?wsdl";
    System.out.println(url);//  w  w  w. java2s.c o m
    String encoded = StringEscapeUtils.escapeHtml4(url);
    System.out.println(encoded);
    String back = StringEscapeUtils.unescapeHtml4(encoded);
    System.out.println(back);
    assertEquals(url, back);
}

From source file:org.mind.prebot.robot.PreBot.java

@Override
public void onMessage(String channel, String sender, String login, String hostname, String message) {
    if (!this.getIgnoredList().contains(sender)) {
        String years_str = "", months_str = "", days_str = "", hours_str = "", minutes_str = "",
                seconds_str = "";
        String[] tab = this.decryptData(message, true).trim().split(" ");
        if (tab.length > 0) {
            if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!pre") || tab[0].equalsIgnoreCase("!p"))) {
                if (tab.length > 1) {
                    String names = "";
                    for (Integer i = 1; i < tab.length; i++)
                        names += tab[i] + " ";
                    Release release = this.getMySQLManager().pre(names.trim());
                    if (release.getResults().equals(0))
                        this.sendMessage(channel,
                                this.encryptData("Nothing found for your search: " + names.trim()));
                    else {
                        if (release.getResults() > 1)
                            this.sendMessage(channel, this.encryptData(Colors.TEAL + "[ " + Colors.RED
                                    + release.getResults() + " results found! " + Colors.TEAL + "]"));
                        else
                            this.sendMessage(channel, this.encryptData(Colors.TEAL + "[ " + Colors.RED
                                    + release.getResults() + " result found! " + Colors.TEAL + "]"));
                        Integer years = release.getDiffDate() / 31536000;
                        Integer yearsMod = release.getDiffDate() % 31536000;
                        if (years == 1)
                            years_str = years + " year ";
                        else if (years > 1)
                            years_str = years + " years ";
                        Integer months = yearsMod / 2592000;
                        Integer monthsMod = yearsMod % 2592000;
                        if (months == 1)
                            months_str = months + " month ";
                        else if (months > 1)
                            months_str = months + " months ";
                        Integer days = monthsMod / 86400;
                        Integer daysMod = monthsMod % 86400;
                        if (days == 1)
                            days_str = days + " day ";
                        else if (days > 1)
                            days_str = days + " days ";
                        Integer hours = daysMod / 3600;
                        Integer hoursMod = daysMod % 3600;
                        if (hours == 1)
                            hours_str = hours + " hour ";
                        else if (hours > 1)
                            hours_str = hours + " hours ";
                        Integer minutes = hoursMod / 60;
                        if (minutes == 1)
                            minutes_str = minutes + " minute ";
                        else if (minutes > 1)
                            minutes_str = minutes + " minutes ";
                        Integer seconds = hoursMod % 60;
                        if (seconds == 1)
                            seconds_str = seconds + " second ";
                        else
                            seconds_str = seconds + " seconds ";
                        if (release.getChecked().equals("1") || release.getNuked().equals("0"))
                            this.sendMessage(channel,
                                    this.encryptData(Colors.TEAL + "[" + Colors.YELLOW + " PRED " + Colors.TEAL
                                            + "][ " + Utils.getCategoryCode(release.getCategory())
                                            + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + years_str + months_str + days_str + hours_str + minutes_str
                                            + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL
                                            + "][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]"
                                            + (release.getChecked().equals("1") ? ""
                                                    : "[ " + Colors.RED + "UNCHECKED" + Colors.TEAL + " ]")));
                        else
                            this.sendMessage(channel,
                                    this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL
                                            + "][ " + Utils.getCategoryCode(release.getCategory())
                                            + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + years_str + months_str + days_str + hours_str + minutes_str
                                            + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL
                                            + "][ " + Colors.RED + release.getReason() + Colors.TEAL + " ][ "
                                            + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]"));
                    }/*ww w  . jav  a 2  s .  c  o m*/
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!dupenuke") || tab[0].equalsIgnoreCase("!dnu"))) {
                String names = "";
                String limit = "10";
                for (Integer i = 1; i < tab.length; i++) {
                    if (tab[i].contains("limit"))
                        limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length());
                    else
                        names += tab[i] + " ";
                }
                LinkedList<Release> releases = null;
                if (tab.length > 1)
                    releases = this.getMySQLManager().dupenuke(names.trim(), limit);
                else
                    releases = this.getMySQLManager().dupenuke("", limit);
                if (releases.isEmpty())
                    this.sendMessage(channel, this.encryptData(
                            "Nothing found for your search: " + (tab.length > 1 ? names.trim() : "")));
                else {
                    if (releases.get(0).getResults() > 1)
                        this.sendMessage(channel,
                                this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY
                                        + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.RED
                                        + " nuked " + Colors.LIGHT_GRAY + "results."));
                    else
                        this.sendMessage(channel,
                                this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY
                                        + " last " + Colors.OLIVE + releases.get(0).getResults() + Colors.RED
                                        + " nuked " + Colors.LIGHT_GRAY + "results"));
                    for (Release release : releases) {
                        Integer years = release.getDiffDate() / 31536000;
                        Integer yearsMod = release.getDiffDate() % 31536000;
                        if (years == 1)
                            years_str = years + " year ";
                        else if (years > 1)
                            years_str = years + " years ";
                        Integer months = yearsMod / 2592000;
                        Integer monthsMod = yearsMod % 2592000;
                        if (months == 1)
                            months_str = months + " month ";
                        else if (months > 1)
                            months_str = months + " months ";
                        Integer days = monthsMod / 86400;
                        Integer daysMod = monthsMod % 86400;
                        if (days == 1)
                            days_str = days + " day ";
                        else if (days > 1)
                            days_str = days + " days ";
                        Integer hours = daysMod / 3600;
                        Integer hoursMod = daysMod % 3600;
                        if (hours == 1)
                            hours_str = hours + " hour ";
                        else if (hours > 1)
                            hours_str = hours + " hours ";
                        Integer minutes = hoursMod / 60;
                        if (minutes == 1)
                            minutes_str = minutes + " minute ";
                        else if (minutes > 1)
                            minutes_str = minutes + " minutes ";
                        Integer seconds = hoursMod % 60;
                        if (seconds == 1)
                            seconds_str = seconds + " second ";
                        else
                            seconds_str = seconds + " seconds ";
                        this.sendMessage(sender,
                                this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL
                                        + "][ " + Utils.getCategoryCode(release.getCategory())
                                        + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                        + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                        + years_str + months_str + days_str + hours_str + minutes_str
                                        + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL + "][ "
                                        + Colors.RED + release.getReason() + Colors.TEAL + " ][ " + Colors.OLIVE
                                        + release.getSize() + Colors.TEAL + " ]"));
                    }
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!dupe") || tab[0].equalsIgnoreCase("!d"))) {
                String names = "";
                String limit = "10";
                for (Integer i = 1; i < tab.length; i++) {
                    if (tab[i].contains("limit"))
                        limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length());
                    else
                        names += tab[i] + " ";
                }
                LinkedList<Release> releases = null;
                if (tab.length > 1)
                    releases = this.getMySQLManager().dupe(names.trim(), limit);
                else
                    releases = this.getMySQLManager().dupe("", limit);
                if (releases.isEmpty())
                    this.sendMessage(channel, this.encryptData(
                            "Nothing found for your search: " + (tab.length > 1 ? names.trim() : "")));
                else {
                    if (releases.get(0).getResults() > 1)
                        this.sendMessage(channel,
                                this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY
                                        + " last " + Colors.OLIVE + releases.get(0).getResults()
                                        + Colors.LIGHT_GRAY + " results."));
                    else
                        this.sendMessage(channel,
                                this.encryptData("Sending " + Colors.OLIVE + sender + Colors.LIGHT_GRAY
                                        + " last " + Colors.OLIVE + releases.get(0).getResults()
                                        + Colors.LIGHT_GRAY + " result."));
                    for (Release release : releases) {
                        Integer years = release.getDiffDate() / 31536000;
                        Integer yearsMod = release.getDiffDate() % 31536000;
                        if (years == 1)
                            years_str = years + " year ";
                        else if (years > 1)
                            years_str = years + " years ";
                        Integer months = yearsMod / 2592000;
                        Integer monthsMod = yearsMod % 2592000;
                        if (months == 1)
                            months_str = months + " month ";
                        else if (months > 1)
                            months_str = months + " months ";
                        Integer days = monthsMod / 86400;
                        Integer daysMod = monthsMod % 86400;
                        if (days == 1)
                            days_str = days + " day ";
                        else if (days > 1)
                            days_str = days + " days ";
                        Integer hours = daysMod / 3600;
                        Integer hoursMod = daysMod % 3600;
                        if (hours == 1)
                            hours_str = hours + " hour ";
                        else if (hours > 1)
                            hours_str = hours + " hours ";
                        Integer minutes = hoursMod / 60;
                        if (minutes == 1)
                            minutes_str = minutes + " minute ";
                        else if (minutes > 1)
                            minutes_str = minutes + " minutes ";
                        Integer seconds = hoursMod % 60;
                        if (seconds == 1)
                            seconds_str = seconds + " second ";
                        else
                            seconds_str = seconds + " seconds ";
                        if (release.getChecked().equals("1") || release.getNuked().equals("0"))
                            this.sendMessage(sender,
                                    this.encryptData(Colors.TEAL + "[" + Colors.YELLOW + " PRED " + Colors.TEAL
                                            + "][ " + Utils.getCategoryCode(release.getCategory())
                                            + release.getCategory() + Colors.TEAL + "][ " + Colors.LIGHT_GRAY
                                            + release.getName() + Colors.TEAL + "][ " + Colors.LIGHT_GRAY
                                            + years_str + months_str + days_str + hours_str + minutes_str
                                            + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL
                                            + "][ " + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]"
                                            + (release.getChecked().equals("1") ? ""
                                                    : "[ " + Colors.RED + "UNCHECKED" + Colors.TEAL + " ]")));
                        else
                            this.sendMessage(sender,
                                    this.encryptData(Colors.TEAL + "[" + Colors.RED + " NUKED " + Colors.TEAL
                                            + "][ " + Utils.getCategoryCode(release.getCategory())
                                            + release.getCategory() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + release.getName() + Colors.TEAL + " ][ " + Colors.LIGHT_GRAY
                                            + years_str + months_str + days_str + hours_str + minutes_str
                                            + seconds_str + "ago (" + release.getDate() + ") " + Colors.TEAL
                                            + "][ " + Colors.RED + release.getReason() + Colors.TEAL + " ][ "
                                            + Colors.OLIVE + release.getSize() + Colors.TEAL + " ]"));
                    }
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!nuke") || tab[0].equalsIgnoreCase("!nk"))) {
                if (this.getNukerList().contains(sender)) {
                    String names = "";
                    for (Integer i = 2; i < tab.length; i++)
                        names += tab[i] + " ";
                    if (tab.length > 2) {
                        Integer ret = this.getMySQLManager().nuke(tab[1], names.trim());
                        if (ret > 0)
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has been successfully " + Colors.RED + "nuked"
                                            + Colors.LIGHT_GRAY + "!"));
                        else
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has not been successfully " + Colors.RED + "nuked"
                                            + Colors.LIGHT_GRAY + "!"));
                    }
                } else
                    this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this."));
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!unnuke") || tab[0].equalsIgnoreCase("!un"))) {
                if (this.getNukerList().contains(sender)) {
                    String names = "";
                    for (Integer i = 2; i < tab.length; i++)
                        names += tab[i] + " ";
                    if (tab.length > 2) {
                        Integer ret = this.getMySQLManager().unnuke(tab[1], names.trim());
                        if (ret > 0)
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has been successfully " + Colors.DARK_GREEN + "unnuked"
                                            + Colors.LIGHT_GRAY + "!"));
                        else
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has not been successfully " + Colors.DARK_GREEN + "unnuked"
                                            + Colors.LIGHT_GRAY + "!"));
                    }
                } else
                    this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this."));
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!addpre") || tab[0].equalsIgnoreCase("!ap"))) {
                if (this.getNukerList().contains(sender)) {
                    String names = "";
                    for (Integer i = 3; i < tab.length; i++)
                        names += tab[i] + " ";
                    if (tab.length > 3) {
                        Integer ret = this.getMySQLManager().addpre(tab[1], tab[2], names.trim());
                        if (ret > 0)
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has been successfully " + Colors.DARK_GREEN + "addpred"
                                            + Colors.LIGHT_GRAY + "!"));
                        else
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has not been successfully " + Colors.DARK_GREEN + "addpred"
                                            + Colors.LIGHT_GRAY + "!"));
                    }
                } else
                    this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this."));
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!delpre") || tab[0].equalsIgnoreCase("!dp"))) {
                if (this.getNukerList().contains(sender)) {
                    if (tab.length > 1) {
                        Integer ret = this.getMySQLManager().delpre(tab[1]);
                        if (ret > 0)
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has been successfully " + Colors.DARK_GREEN + "delpred"
                                            + Colors.LIGHT_GRAY + "!"));
                        else
                            this.sendMessage(channel,
                                    this.encryptData(Colors.OLIVE + tab[1] + Colors.LIGHT_GRAY
                                            + " has not been successfully " + Colors.DARK_GREEN + "delpred"
                                            + Colors.LIGHT_GRAY + "!"));
                    }
                } else
                    this.sendMessage(channel, this.encryptData(sender + ": You've to be a nuker to do this."));
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel())
                    && tab[0].equalsIgnoreCase("!vdm")) {
                List<String> vdms = Utils.getMatcher(Utils.VDMRegex, Utils.getCode(Utils.VDMFeed),
                        Pattern.MULTILINE);
                if (!vdms.isEmpty()) {
                    String vdm = vdms.get(new Random().nextInt(vdms.size()));
                    vdm = StringEscapeUtils.unescapeHtml4(vdm);
                    vdm = vdm.substring(30).replaceAll("[\r\n]+", "").replaceAll(" {2,}", " ").trim();
                    this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.BROWN + " VDM "
                            + Colors.TEAL + "] :: [ " + Colors.DARK_GREEN + vdm + Colors.TEAL + " ]"));
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel())
                    && tab[0].equalsIgnoreCase("!cnf")) {
                List<String> cnfs = Utils.getMatcher(Utils.CNFRegex, Utils.getCode(Utils.CNFPage),
                        Pattern.MULTILINE);
                if (!cnfs.isEmpty()) {
                    String cnf = cnfs.get(new Random().nextInt(cnfs.size()));
                    cnf = StringEscapeUtils.unescapeHtml4(cnf);
                    cnf = cnf.substring(cnf.indexOf(">") + 1, cnf.indexOf("</div>")).replaceAll("[\r\n]+", "")
                            .replaceAll(" {2,}", " ").trim();
                    this.sendMessage(channel, this.encryptData(Colors.TEAL + "[" + Colors.RED + " CNF "
                            + Colors.TEAL + "] :: [ " + Colors.DARK_GREEN + cnf + Colors.TEAL + " ]"));
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindChannel())
                    && (tab[0].equalsIgnoreCase("!slap") || tab[0].equalsIgnoreCase("!s"))) {
                if (this.getSlaps() < this.getSlapsRandom())
                    this.setSlaps(this.getSlaps() + 1);
                else {
                    this.kick(channel, sender, this.encryptData("Sorry, you loose this time ^^"));
                    this.setSlaps(0);
                    this.setSlapsRandom(new Random().nextInt(26));
                }
            } else if (tab[0].equalsIgnoreCase("!kick") || tab[0].equalsIgnoreCase("!k")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 2) {
                        String names = "";
                        for (Integer i = 2; i < tab.length; i++)
                            names += tab[i] + " ";
                        this.kick(channel, tab[1], this.encryptData(names.trim()));
                    } else
                        this.kick(channel, tab[1]);
                }
            } else if (tab[0].equalsIgnoreCase("!ban") || tab[0].equalsIgnoreCase("!b")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 1)
                        this.ban(channel, tab[1]);
                }
            } else if (tab[0].equalsIgnoreCase("!mode") || tab[0].equalsIgnoreCase("!m")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 2)
                        this.setMode(channel, tab[1] + " " + tab[2]);
                }
            } else if (tab[0].equalsIgnoreCase("!message") || tab[0].equalsIgnoreCase("!msg")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 2) {
                        String names = "";
                        for (Integer i = 2; i < tab.length; i++)
                            names += tab[i] + " ";
                        this.sendMessage(tab[1], this.encryptData(names.trim()));
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!action") || tab[0].equalsIgnoreCase("!a")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 2) {
                        String names = "";
                        for (Integer i = 2; i < tab.length; i++)
                            names += tab[i] + " ";
                        this.sendAction(tab[1], this.encryptData(names.trim()));
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!notice") || tab[0].equalsIgnoreCase("!n")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 2) {
                        String names = "";
                        for (Integer i = 2; i < tab.length; i++)
                            names += tab[i] + " ";
                        this.sendNotice(tab[1], this.encryptData(names.trim()));
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!ignore") || tab[0].equalsIgnoreCase("!i")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 1) {
                        if (!this.getIgnoredList().contains(tab[1]))
                            this.getIgnoredList().add(tab[1]);
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!unignore") || tab[0].equalsIgnoreCase("!ui")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 1) {
                        if (this.getIgnoredList().contains(tab[1]))
                            this.getIgnoredList().remove(tab[1]);
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!addnuker") || tab[0].equalsIgnoreCase("!an")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 1) {
                        if (!this.getNukerList().contains(tab[1]))
                            this.getNukerList().add(tab[1]);
                    }
                }
            } else if (tab[0].equalsIgnoreCase("!delnuker") || tab[0].equalsIgnoreCase("!dn")) {
                if (sender.equals("BaYbEE")) {
                    if (tab.length > 1) {
                        if (this.getNukerList().contains(tab[1]))
                            this.getNukerList().remove(tab[1]);
                    }
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!showrequest") || tab[0].equalsIgnoreCase("!sr"))) {
                if (tab.length > 1) {
                    String names = "";
                    for (Integer i = 1; i < tab.length; i++)
                        names += tab[i] + " ";
                    Request request = this.getMySQLManager().showrequest(names.trim());
                    if (request.getResults().equals(0))
                        this.sendMessage(channel,
                                this.encryptData("Nothing found for your search: " + names.trim()));
                    else {
                        if (request.getResults() > 1)
                            this.sendMessage(channel, this.encryptData(
                                    "\00310[\00304 " + request.getResults() + " results found! \00310]"));
                        else
                            this.sendMessage(channel, this.encryptData(
                                    "\00310[\00304 " + request.getResults() + " result found! \00310]"));
                        Integer years = request.getDiffDate() / 31536000;
                        Integer yearsMod = request.getDiffDate() % 31536000;
                        if (years == 1)
                            years_str = years + " year ";
                        else if (years > 1)
                            years_str = years + " years ";
                        Integer months = yearsMod / 2592000;
                        Integer monthsMod = yearsMod % 2592000;
                        if (months == 1)
                            months_str = months + " month ";
                        else if (months > 1)
                            months_str = months + " months ";
                        Integer days = monthsMod / 86400;
                        Integer daysMod = monthsMod % 86400;
                        if (days == 1)
                            days_str = days + " day ";
                        else if (days > 1)
                            days_str = days + " days ";
                        Integer hours = daysMod / 3600;
                        Integer hoursMod = daysMod % 3600;
                        if (hours == 1)
                            hours_str = hours + " hour ";
                        else if (hours > 1)
                            hours_str = hours + " hours ";
                        Integer minutes = hoursMod / 60;
                        if (minutes == 1)
                            minutes_str = minutes + " minute ";
                        else if (minutes > 1)
                            minutes_str = minutes + " minutes ";
                        Integer seconds = hoursMod % 60;
                        if (seconds == 1)
                            seconds_str = seconds + " second ";
                        else
                            seconds_str = seconds + " seconds ";
                        if (request.getFilled())
                            this.sendMessage(channel, this.encryptData("\00310[\00308 REQ \00310] [\00315 "
                                    + request.getRequest() + " \00310] [\00315 " + years_str + months_str
                                    + days_str + hours_str + minutes_str + seconds_str + "ago ("
                                    + (request.getRequestDate()) + ") \00310] [ \00307Requested by: \00315"
                                    + request.getRequestBy() + " \00310] [ \00307Filled by: \00315"
                                    + request.getFilledBy() + " \00310]"));
                        else
                            this.sendMessage(channel, this.encryptData("\00310[\00308 REQ \00310] [\00315 "
                                    + request.getRequest() + " \00310] [\00315 " + years_str + months_str
                                    + days_str + hours_str + minutes_str + seconds_str + "ago ("
                                    + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315"
                                    + request.getRequestBy() + " \00310]"));
                    }
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!addrequest") || tab[0].equalsIgnoreCase("!ar"))) {
                String names = "";
                for (Integer i = 1; i < tab.length; i++)
                    names += tab[i] + " ";
                if (tab.length > 1) {
                    Request request = new Request();
                    request.setRequest(names.trim());
                    request.setRequestBy(sender);
                    request.setRequestDate(null);
                    request.setFilled(false);
                    request.setFilledBy("");
                    Integer ret = this.getMySQLManager().addrequest(request);
                    if (ret > 0)
                        this.sendMessage(channel, this.encryptData("\00307" + names.trim()
                                + "\00315 has been successfully \00304requested\00315!"));
                    else
                        this.sendMessage(channel, this.encryptData("\00307" + names.trim()
                                + "\00315 has not been successfully \00304requested\00315!"));
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!fillrequest") || tab[0].equalsIgnoreCase("!fr"))) {
                String names = "";
                for (Integer i = 1; i < tab.length; i++)
                    names += tab[i] + " ";
                if (tab.length > 1) {
                    Integer ret = this.getMySQLManager().fillrequest(names.trim(), sender);
                    if (ret > 0)
                        this.sendMessage(channel, this.encryptData(
                                "\00307" + names.trim() + "\00315 has been successfully \00304filled\00315!"));
                    else
                        this.sendMessage(channel, this.encryptData("\00307" + names.trim()
                                + "\00315 has not been successfully \0030filled\00315!"));
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!duperequest") || tab[0].equalsIgnoreCase("!dr"))) {
                String names = "";
                String limit = "10";
                for (Integer i = 1; i < tab.length; i++) {
                    if (tab[i].contains("limit"))
                        limit = tab[i].substring(tab[i].indexOf("limit:") + 6, tab[i].length());
                    else
                        names += tab[i] + " ";
                }
                LinkedList<Request> requests = null;
                if (tab.length > 1)
                    requests = this.getMySQLManager().duperequest(names.trim(), limit);
                else
                    requests = this.getMySQLManager().duperequest("", limit);
                if (requests.isEmpty())
                    this.sendMessage(channel, this.encryptData(
                            "Nothing found for your search: " + (tab.length > 1 ? names.trim() : "")));
                else {
                    if (requests.get(0).getResults() > 1)
                        this.sendMessage(channel, this.encryptData("Sending \00307" + sender
                                + "\00315 last \00307" + requests.get(0).getResults() + "\00315 results."));
                    else
                        this.sendMessage(channel, this.encryptData("Sending \00307" + sender
                                + "\00315 last \00307" + requests.get(0).getResults() + "\00315 result."));
                    for (Request request : requests) {
                        Integer years = request.getDiffDate() / 31536000;
                        Integer yearsMod = request.getDiffDate() % 31536000;
                        if (years == 1)
                            years_str = years + " year ";
                        else if (years > 1)
                            years_str = years + " years ";
                        Integer months = yearsMod / 2592000;
                        Integer monthsMod = yearsMod % 2592000;
                        if (months == 1)
                            months_str = months + " month ";
                        else if (months > 1)
                            months_str = months + " months ";
                        Integer days = monthsMod / 86400;
                        Integer daysMod = monthsMod % 86400;
                        if (days == 1)
                            days_str = days + " day ";
                        else if (days > 1)
                            days_str = days + " days ";
                        Integer hours = daysMod / 3600;
                        Integer hoursMod = daysMod % 3600;
                        if (hours == 1)
                            hours_str = hours + " hour ";
                        else if (hours > 1)
                            hours_str = hours + " hours ";
                        Integer minutes = hoursMod / 60;
                        if (minutes == 1)
                            minutes_str = minutes + " minute ";
                        else if (minutes > 1)
                            minutes_str = minutes + " minutes ";
                        Integer seconds = hoursMod % 60;
                        if (seconds == 1)
                            seconds_str = seconds + " second ";
                        else
                            seconds_str = seconds + " seconds ";
                        if (request.getFilled())
                            this.sendMessage(sender, this.encryptData("\00310[\00308 REQ \00310] [\00315 "
                                    + request.getRequest() + " \00310] [\00315 " + years_str + months_str
                                    + days_str + hours_str + minutes_str + seconds_str + "ago ("
                                    + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315"
                                    + request.getRequestBy() + " \00310] [ \00307Filled by: \00315"
                                    + request.getFilledBy() + " \00310]"));
                        else
                            this.sendMessage(sender, this.encryptData("\00310[\00308 REQ \00310] [\00315 "
                                    + request.getRequest() + " \00310] [\00315 " + years_str + months_str
                                    + days_str + hours_str + minutes_str + seconds_str + "ago ("
                                    + request.getRequestDate() + ") \00310] [ \00307Requested by: \00315"
                                    + request.getRequestBy() + " \00310]"));
                    }
                }
            } else if (channel.equalsIgnoreCase(this.getParent().getIRCMindPreSearchChannel())
                    && (tab[0].equalsIgnoreCase("!group") || tab[0].equalsIgnoreCase("!g"))) {
                Group group = this.getMySQLManager().group();
                this.sendMessage(channel,
                        this.encryptData(Colors.DARK_GRAY + "Total Releases: " + Colors.GREEN
                                + group.getTotalReleases() + Colors.DARK_GRAY + " Total Nuked: " + Colors.RED
                                + group.getTotalNukes() + Colors.DARK_GRAY + " Total Unuked: " + Colors.OLIVE
                                + group.getTotalUnnukes()));
                this.sendMessage(channel,
                        this.encryptData(Colors.DARK_GRAY + "First Pre: " + Colors.LIGHT_GRAY + "["
                                + Utils.getCategoryCode(group.getCategoryFirstPre())
                                + group.getCategoryFirstPre() + Colors.LIGHT_GRAY + "] " + group.getFirstPre()
                                + " [" + group.getDateFirstPre() + "]"));
                this.sendMessage(channel, this.encryptData(Colors.DARK_GRAY + "Last Pre: " + Colors.LIGHT_GRAY
                        + "[" + Utils.getCategoryCode(group.getCategoryLastPre()) + group.getCategoryLastPre()
                        + Colors.LIGHT_GRAY + "] " + group.getLastPre() + " [" + group.getDateLastPre() + "]"));
            } else {
                for (String t : tab) {
                    if (!Utils.getMatcher(Utils.URLRegex, t, Pattern.DOTALL).isEmpty()) {
                        String title = Utils.getTitleMatcher(Utils.getCode(t));
                        if (title != null) {
                            title = StringEscapeUtils.unescapeHtml4(title);
                            title = title.substring(7, title.length() - 8).replaceAll("[\r\n]+", "")
                                    .replaceAll(" {2,}", " ").trim();
                            this.sendMessage(channel,
                                    this.encryptData("\00310[\00303 Title:\00307 " + title + " \00310]"));
                        }
                    }
                }
            }
        }
    }
}

From source file:org.mobisocial.corral.ContentCorral.java

private static void scrapePage(File storageDir, Uri baseUri, String relativePath) throws IOException {
    File sourceFile = new File(storageDir, relativePath);
    String page = IOUtils.toString(new FileInputStream(sourceFile));
    Matcher matcher = sScriptRegex.matcher(page);
    int offset = 0;
    while (matcher.find(offset)) {
        try {/*from w w w .ja  va2s  .  com*/
            String tag = matcher.group();
            Matcher srcMatcher = sSrcRegex.matcher(tag);
            if (!srcMatcher.find())
                continue;
            String srcPath = srcMatcher.group(1);
            srcPath = srcPath.substring(1, srcPath.length() - 1);
            srcPath = StringEscapeUtils.unescapeHtml4(srcPath);
            //srcPath = absoluteToRelative(baseUri, srcPath);
            if (!srcPath.contains("://")) {
                Uri absolutePath = getAbsoluteUri(baseUri, relativePath, srcPath);
                downloadFile(storageDir, absolutePath, absolutePath.getPath());
            }
        } finally {
            offset = matcher.end();
        }
    }
}

From source file:org.mousephenotype.www.testing.model.GenePage.java

/**
 * Compares a single row of a pageMap grid selected by pageMapIndex to a
 * single row of a downloadData grid selected by downloadIndex.
 * @param pageMap genes HTML table store
 * @param downloadData download data store
 * @param pageMapIndex pageMap row index
 * @param downloadIndex download row index
 * @return //from  ww w .j av  a 2 s .  co  m
 */
private int compareRowData(GridMap pageMap, GridMap downloadData, int pageMapIndex, int downloadIndex) {

    // Validate the page's genes HTML table values against the first row of the download values.
    // If sex = "both", validate against the second download row as well.
    int errorCount = 0;
    List<String> colErrors = new ArrayList();
    String downloadCell;
    String pageCell;

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_PHENOTYPE);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_PHENOTYPE).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: phenotype mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    pageCell = StringEscapeUtils.unescapeHtml4(pageMap.getCell(1, GeneTable.COL_INDEX_GENES_ALLELE));
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_ALLELE).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: allele mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_ZYGOSITY);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_ZYGOSITY).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: zygosity mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    // Special case: if the page sex is "both", use "female" to compare against the download, as "female" is sorted first in the download.
    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_SEX);
    pageCell = (pageCell.compareTo("both") == 0 ? "female" : pageCell);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_SEX).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: sex mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_PROCEDURE_PARAMETER);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_PROCEDURE_PARAMETER).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: procedure | parameter mismatch. Page: '" + pageCell + "'. Download: '"
                + downloadCell + "'");

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_PHENOTYPING_CENTER);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_PHENOTYPING_CENTER).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: phenotyping center mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell
                + "'");

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_SOURCE);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_SOURCE).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: source mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    pageCell = pageMap.getCell(1, GeneTable.COL_INDEX_GENES_P_VALUE);
    downloadCell = downloadData.getCell(1, DownloadGeneMap.COL_INDEX_P_VALUE).trim();
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: p value mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    // When testing using http, the download link compare fails because the page url uses http
    // but the download graph link uses https. Ignore the protocol (but not the hostname).
    pageCell = TestUtils.removeProtocol(pageMap.getCell(1, GeneTable.COL_INDEX_GENES_GRAPH_LINK).trim());

    downloadCell = TestUtils
            .removeProtocol(downloadData.getCell(1, DownloadGeneMap.COL_INDEX_GRAPH_LINK).trim());
    if (!pageCell.equals(downloadCell))
        colErrors.add("ERROR: graph link mismatch. Page: '" + pageCell + "'. Download: '" + downloadCell + "'");

    if (!colErrors.isEmpty()) {
        System.out.println(colErrors.size() + " errors:");
        for (String colError : colErrors) {
            System.out.println("\t" + colError);
        }

        errorCount++;
    }

    return errorCount;
}

From source file:org.nerve.utils.encode.EncodeUtils.java

public static String htmlUnescape(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}

From source file:org.omnaest.utils.table.impl.serializer.XHtmlUnmarshallerImpl.java

@Override
public Table<E> from(Reader reader) {
    try {/*from   w w w.j  a  v a2 s.c  o m*/
        final ByteArrayContainer byteArrayContainerSource = new ByteArrayContainer().copyFrom(reader);
        final String xhtmlContent = StringEscapeUtils.unescapeHtml4(byteArrayContainerSource.toString());
        final Reader readerOfConvertedContent = new StringReader(xhtmlContent);

        final ByteArrayContainer byteArrayContainer = new ByteArrayContainer();
        final Writer writer = byteArrayContainer.getOutputStreamWriter();
        final InputStream inputStreamXSLT = XHtmlMarshallerImpl.class.getResourceAsStream("/XHtmlToXml.xsl");

        final StreamSource xslt = new StreamSource(inputStreamXSLT);
        final StreamSource xml = new StreamSource(readerOfConvertedContent);
        final StreamResult result = new StreamResult(writer);
        XMLHelper.transform(xslt, xml, result, this.exceptionHandler, new XSLTransformerConfiguration());
        writer.close();

        super.from(byteArrayContainer.getReader(this.getEncoding()));
    } catch (Exception e) {
        this.exceptionHandler.handleException(e);
    }

    return this.table;
}

From source file:org.onesun.commons.text.classification.TextClassificaionHelper.java

private static String removeHtmlTags(String text) {
    text = StringEscapeUtils.unescapeHtml4(text);
    text = text.replaceAll("\\<.*?\\>", "");
    return text;/*  ww  w .  j  a v  a 2  s  .co  m*/
}

From source file:org.opendatakit.survey.activities.MainMenuActivity.java

private void transitionToFormHelper(Uri uri, FormIdStruct newForm) {
    // work through switching to that form
    setAppName(newForm.appName);//from  ww w .  j a  v  a2  s. c  o  m
    setCurrentForm(newForm);
    clearSectionScreenState();
    String fragment = uri.getFragment();
    if (fragment != null && fragment.length() != 0) {
        // and process the fragment to find the instanceId, screenPath and other
        // kv pairs
        String[] pargs = fragment.split("&");
        boolean first = true;
        StringBuilder b = new StringBuilder();
        int i;
        for (i = 0; i < pargs.length; ++i) {
            String[] keyValue = pargs[i].split("=");
            if ("instanceId".equals(keyValue[0])) {
                if (keyValue.length == 2) {
                    setInstanceId(StringEscapeUtils.unescapeHtml4(keyValue[1]));
                }
            } else if ("screenPath".equals(keyValue[0])) {
                if (keyValue.length == 2) {
                    setSectionScreenState(StringEscapeUtils.unescapeHtml4(keyValue[1]), null);
                }
            } else if ("refId".equals(keyValue[0]) || "formPath".equals(keyValue[0])) {
                // ignore
            } else {
                if (!first) {
                    b.append("&");
                }
                first = false;
                b.append(pargs[i]);
            }
        }
        String aux = b.toString();
        if (aux.length() != 0) {
            setAuxillaryHash(aux);
        }
    } else {
        setInstanceId(null);
        setAuxillaryHash(null);
    }
    currentFragment = ScreenList.WEBKIT;
}