Java Code Examples for org.apache.commons.lang3.StringEscapeUtils#unescapeHtml4()

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#unescapeHtml4() . 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: MdTextController.java    From zest-writer with GNU General Public License v3.0 6 votes vote down vote up
@FXML
private void handleValidateButtonAction(ActionEvent event) {
    String s = StringEscapeUtils.unescapeHtml4(markdownToHtml(currentSourceText.getText()));
    if (MdConvertController.corrector == null) {
        MdConvertController.corrector = new Corrector();
    }
    try {
        String result = MdConvertController.corrector.checkHtmlContent(s);
        WebEngine webEngine = currentRenderView.getEngine();
        webEngine.loadContent("<!doctype html><html lang='fr'><head><meta charset='utf-8'><base href='"
                + MainApp.class.getResource("assets").toExternalForm() + "' /></head><body>" + result + "</body></html>");
        webEngine.setUserStyleSheetLocation(MainApp.class.getResource("assets/static/css/content.css").toExternalForm());
    } catch (DOMException e) {
        log.error(e.getMessage(), e);
    }
}
 
Example 2
Source File: CorrectionService.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Task<String> createTask() {
    return new Task<String>() {
        @Override
        protected String call(){
            updateMessage(Configuration.getBundle().getString("ui.task.correction.prepare.label")+" ...");

            Function<Textual, String> prepareValidationReport = (Textual ext) -> {
                updateMessage(ext.getTitle());
                String markdown = ext.readMarkdown();
                if(!mdText.isPythonStarted()) {
                    MainApp.getLogger().debug("Jython en cours de chargement mémoire");
                    return null;
                } else {
                    String htmlText = StringEscapeUtils.unescapeHtml4(MenuController.markdownToHtml(mdText, markdown));
                    return corrector.checkHtmlContentToText(htmlText, ext.getTitle());
                }
            };
            Map<Textual, String> validationResult = content.doOnTextual(prepareValidationReport);

            StringBuilder resultCorrect = new StringBuilder();
            for (Entry<Textual, String> entry : validationResult.entrySet()) {
                resultCorrect.append(entry.getValue());
            }
            return StringEscapeUtils.unescapeHtml4(resultCorrect.toString());
        }
    };
}
 
Example 3
Source File: PaginaURL.java    From ache with Apache License 2.0 5 votes vote down vote up
protected String addLink(String link, HttpUrl base) {
    if (nofollow) {
        return "";
    }
    link = link.trim();
    link = Urls.resolveHttpLink(base, link);
    if (link == null) {
        return "";
    }
    link = Urls.removeFragmentsIfAny(link);
    link = StringEscapeUtils.unescapeHtml4(link);
    if (Urls.isValid(link)) {
        link = Urls.normalize(link);
        if (link != null) {
            boolean exists = links.contains(link);
            if (!exists) {
                if (base != null && !link.equals(base.toString())) {
                    links.add(link);
                } else {
                    links.add(link);
                }
            }
        }
    } else {
        // link is invalid
        link = null;
    }
    return link;
}
 
Example 4
Source File: Utilities.java    From TagRec with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getWikiContent(String xmlString) {
    int startIndex = xmlString.indexOf(REV_START);
    int endIndex = xmlString.indexOf(REV_END);
    if (startIndex != -1 && endIndex != -1) {
        return StringEscapeUtils.unescapeHtml4(xmlString.substring(startIndex + REV_START.length(), endIndex));
    }
    return null;
}
 
Example 5
Source File: FlashManager.java    From LibreNews-Android with GNU General Public License v3.0 5 votes vote down vote up
public void pushFlashNotification(Flash flash) throws JSONException, IOException {
    if (!prefs.getBoolean("notifications_enabled", true)) {
        return;
    }
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(flash.getLink()));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    String text = StringEscapeUtils.unescapeHtml4(flash.getText());
    NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
        Notification.Builder oBuilder = new Notification.Builder(context, getNotificationChannel(context).getId());
        oBuilder.setContentTitle(flash.getChannel() + " • " + flash.getSource())
                .setStyle(new Notification.BigTextStyle()
                        .bigText(text))
                .setContentText(text)
                .setAutoCancel(true)
                .setSound(Uri.parse(prefs.getString("notification_sound", "DEFAULT")))
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.drawable.ic_alert);
        mNotificationManager.notify(flash.getIdAsInteger(), oBuilder.build());
    }else{
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setContentTitle(flash.getChannel() + " • " + flash.getSource())
                .setStyle(new NotificationCompat.BigTextStyle()
                        .bigText(text))
                .setContentText(text)
                .setAutoCancel(true)
                .setSound(Uri.parse(prefs.getString("notification_sound", "DEFAULT")))
                .setContentIntent(pendingIntent);
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBuilder.setSmallIcon(R.drawable.ic_alert);
        } else {
            mBuilder.setSmallIcon(R.drawable.ic_alert_compat);
        }
        mNotificationManager.notify(flash.getIdAsInteger(), mBuilder.build());
    }
}
 
Example 6
Source File: SoundCloudService.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @author Andrew Returns the title of the Soundcloud url provided
 *
 * @return title
 */
private static String getSongTitle(final String HTML) {
	String title = "";

	title = MediaUtils.getBetween(HTML, TITLE_PATTERN, "\",\"");
	title = StringEscapeUtils.escapeHtml4(title.replaceAll(
			"[^\\x20-\\x7e]", ""));
	title = Utils.convertUnicode(title);
	title = StringEscapeUtils.unescapeHtml4(title);

	if (title.contains(",")) {
		title = escapeComma(title);
	}
	return title.trim();
}
 
Example 7
Source File: Chan410Reader.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void parseDate(String date) {
    super.parseDate(date);
    if (currentPost.timestamp == 0) {
        Matcher matcher = SPAN_ADMIN_PATTERN.matcher(date);
        if (matcher.matches()) {
            currentPost.trip = (currentPost.trip == null ? "" : currentPost.trip) + StringEscapeUtils.unescapeHtml4(matcher.group(1).trim());
            super.parseDate(matcher.group(2));
        }
    }
}
 
Example 8
Source File: Content.java    From zest-writer with GNU General Public License v3.0 5 votes vote down vote up
public void saveToHtml(File file, MdTextController index) {
    try (FileOutputStream fos = new FileOutputStream(file)) {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF8"));
        String mdValue = exportContentToMarkdown(0, getDepth());
        String htmlValue = StringEscapeUtils.unescapeHtml4(index.markdownToHtml(mdValue));
        htmlValue = normalizeHtml(htmlValue);
        writer.append(MainApp.getMdUtils().addHeaderAndFooterStrict(htmlValue, getTitle()));
        writer.flush();
    } catch (Exception e) {
        MainApp.getLogger().error(e.getMessage(), e);
    }
}
 
Example 9
Source File: AbstractVichanModule.java    From Overchan-Android with GNU General Public License v3.0 5 votes vote down vote up
private void handleFilter(int i) throws IOException {
    switch (i) {
        case FILTER_INPUT_OPEN:
            currentReading = true;
            currentTextarea = false;
            break;
        case FILTER_TEXTAREA_OPEN:
            currentReading = true;
            currentTextarea = true;
            break;
        case FILTER_NAME_OPEN:
            currentName = StringEscapeUtils.unescapeHtml4(readUntilSequence("\"".toCharArray()));
            break;
        case FILTER_VALUE_OPEN:
            currentValue = StringEscapeUtils.unescapeHtml4(readUntilSequence("\"".toCharArray()));
            break;
        case FILTER_TAG_CLOSE:
            if (currentTextarea) {
                currentValue = StringEscapeUtils.unescapeHtml4(readUntilSequence("<".toCharArray()));
            }
            if (currentReading && currentName != null) result.add(Pair.of(currentName, currentValue != null ? currentValue : ""));
            currentName = null;
            currentValue = null;
            currentReading = false;
            currentTextarea = false;
            break;
        case FILTER_TAG_BEFORE_CLOSE: // <textarea ..... />
            currentTextarea = false;
            break;
    }
}
 
Example 10
Source File: Encodes.java    From easyweb with Apache License 2.0 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 11
Source File: TraceEvent.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
public boolean search(Object searchStrObj) {

        boolean found = false;

        if (searchStrObj instanceof SearchEventType) {

            SearchEventType searchEventType = (SearchEventType) searchStrObj;

            switch (searchEventType) {

            case PAGE_MESSAGES:
                found = isHasMessages();
                break;

            case STATUS_WARN:
                found = isStepStatusWarn();
                break;

            case STATUS_FAIL:
                found = isStepStatusFail();
                break;

            case STATUS_EXCEPTION:
                found = isStepStatusException();
                break;

            case SEPERATOR:
                break;
            default:
                break;
            }
        } else {

            String traceEventStr = getTraceEventStr();
            String searchStr = (String) searchStrObj;

            // traceEventStr will null in case of empty or corrupt TE's
            if ((traceEventStr != null) && (searchStr != null)) {

                traceEventStr = traceEventStr.toLowerCase();
                String traceSearchStr = searchStr.toLowerCase();

                byte[] pattern = traceSearchStr.getBytes();
                byte[] data = traceEventStr.getBytes();

                int index = KnuthMorrisPrattAlgorithm.indexOf(data, pattern);

                if (index != -1) {
                    found = true;
                }

                // double searching - because some data is escaped. but user can use escaped or
                // unescaped text for search.
                if (!found) {

                    // if the unescaped string is same as orig, then dont do second search
                    String unescTraceEventStr = StringEscapeUtils.unescapeHtml4(traceEventStr);

                    if (!unescTraceEventStr.equals(traceEventStr)) {
                        data = unescTraceEventStr.getBytes();

                        index = KnuthMorrisPrattAlgorithm.indexOf(data, pattern);

                        if (index != -1) {
                            found = true;
                        }
                    }
                }
            }
        }

        searchFound = found;

        return found;
    }
 
Example 12
Source File: Encodes.java    From dubai with MIT License 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 13
Source File: DescriptionMapping.java    From rtc2jira with GNU General Public License v2.0 4 votes vote down vote up
public static String convertHtmlToJiraMarkup(String text) {
  String rnProxy = "caburacelhota";
  String rn = "\r\n";

  if (text != null) {
    // line breaks
    text = text.replaceAll("<br/>", rnProxy);
    // bold
    text = text.replaceAll("<b>", "*");
    text = text.replaceAll("</b>", "*");
    // italics
    text = text.replaceAll("<i>", "_");
    text = text.replaceAll("</i>", "_");
    // emphasis
    text = text.replaceAll("<em>", "_");
    text = text.replaceAll("</em>", "_");
    // deleted
    text = text.replaceAll("<del>", "-");
    text = text.replaceAll("</del>", "-");
    // inserted
    text = text.replaceAll("<ins>", "+");
    text = text.replaceAll("</ins>", "+");
    // superscript
    text = text.replaceAll("<sup>", "^");
    text = text.replaceAll("</sup>", "^");
    // subscript
    text = text.replaceAll("<sub>", "~");
    text = text.replaceAll("</sub>", "~");

    text = replaceHtmlAnchors(text, true);

    // delete remaining html tags (open-close)
    text = text.replaceAll("\\<.*?>", " ").replaceAll("\\s+", " ").trim();

    // entities
    text = StringEscapeUtils.unescapeHtml4(text);

    text = text.replaceAll(rnProxy, rn);
  }

  return text;
}
 
Example 14
Source File: Encodes.java    From spring-boot-quickstart with Apache License 2.0 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 15
Source File: ShopifyVariantUpdateRequest.java    From shopify-sdk with Apache License 2.0 4 votes vote down vote up
private boolean doesNotEqual(final String s1, final String s2) {
	final String unescapedS1 = StringEscapeUtils.unescapeHtml4(StringUtils.trim(s1));
	final String unescapedS2 = StringEscapeUtils.unescapeHtml4(StringUtils.trim(s2));
	return !StringUtils.equals(unescapedS1, unescapedS2);
}
 
Example 16
Source File: Encodes.java    From MultimediaDesktop with Apache License 2.0 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 17
Source File: Subscriptions.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
private static String htmlToComment(String html) {
    return StringEscapeUtils.unescapeHtml4(RegexUtils.removeHtmlTags(html.replaceAll("<(br|p)/?>", " ")));
}
 
Example 18
Source File: Encodes.java    From jee-universal-bms with Apache License 2.0 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 19
Source File: UrlRewriter.java    From esigate with Apache License 2.0 4 votes vote down vote up
private String unescapeHtml(String url) {
    // Unescape entities, ex: &apos; or &#39;
    url = StringEscapeUtils.unescapeHtml4(url);
    return url;
}
 
Example 20
Source File: EscapeUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * Html解码,将HTML4格式的字符串转码解码为普通字符串.
 * 
 * 比如 &quot;bread&quot; &amp; &quot;butter&quot;转化为"bread" & "butter"
 */
public static String unescapeHtml(String html) {
	return StringEscapeUtils.unescapeHtml4(html);
}