下面列出了org.apache.commons.lang3.StringEscapeUtils#unescapeHtml4 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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());
}
};
}
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;
}
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());
}
}
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);
}
}
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;
}
}
@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));
}
}
}
/**
* @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();
}
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;
}
private String unescapeHtml(String url) {
// Unescape entities, ex: ' or '
url = StringEscapeUtils.unescapeHtml4(url);
return url;
}
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
private static String htmlToComment(String html) {
return StringEscapeUtils.unescapeHtml4(RegexUtils.removeHtmlTags(html.replaceAll("<(br|p)/?>", " ")));
}
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
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);
}
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
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;
}
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
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;
}
/**
* Html 解码.
*/
public static String unescapeHtml(String htmlEscaped) {
return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
/**
* Html解码,将HTML4格式的字符串转码解码为普通字符串.
*
* 比如 "bread" & "butter"转化为"bread" & "butter"
*/
public static String unescapeHtml(String html) {
return StringEscapeUtils.unescapeHtml4(html);
}