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

The following are Jave code examples for showing how to use unescapeHtml4() of the org.apache.commons.lang3.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BrainBridge   File: BrainBridgeAPI.java   View Source Code Vote up 6 votes
/**
 * Creates a new chat instance.
 * 
 * @return The unique id that identifies the created instance
 */
public String createInstance() {
	final String query = this.mServiceUrl + CREATE_REQUEST;
	try {
		final List<String> content = getWebContent(query);
		// If the answer is empty there was some error
		if (content.isEmpty()) {
			return null;
		}

		// The first line contains the id
		final String firstLine = content.iterator().next();
		if (firstLine.trim().isEmpty()) {
			return null;
		}
		return StringEscapeUtils.unescapeHtml4(firstLine);
	} catch (final IOException e) {
		// Ignore the exception and return null
		return null;
	}
}
 
Example 2
Project: BrainBridge   File: BrainBridgeAPI.java   View Source Code Vote up 6 votes
/**
 * Gets the last answer of the chat bot for the instance with the given id.
 * 
 * @param id
 *            The id of the instance
 * @return The last answer of the chat bot for the given instance or
 *         <tt>null</tt> if there was no or the server experienced an error
 */
public String getLastMessage(final String id) {
	final String query = this.mServiceUrl + GET_MESSAGE_REQUEST + ID_PARAMETER + id;
	try {
		final List<String> content = getWebContent(query);
		// If the answer is empty there was some error
		if (content.isEmpty()) {
			return null;
		}

		// The first line contains the message
		final String firstLine = content.iterator().next();
		if (firstLine.trim().isEmpty()) {
			return null;
		}
		return StringEscapeUtils.unescapeHtml4(firstLine);
	} catch (final IOException e) {
		// Ignore the exception and return null
		return null;
	}
}
 
Example 3
Project: wiseowl   File: WikiClean.java   View Source Code Vote up 5 votes
public final String getTitle(String s) {
  int start = s.indexOf(XML_START_TAG_TITLE);
  int end = s.indexOf(XML_END_TAG_TITLE, start);
  if (start < 0 || end < 0) {
    return "";
  }
  return StringEscapeUtils.unescapeHtml4(s.substring(start + 7, end));
}
 
Example 4
Project: wiseowl   File: WikiClean.java   View Source Code Vote up 5 votes
public String clean(String content) {
  //String content = getWikiMarkup(page);
  content = removeRefs(content);
  content = removeInterWikiLinks(content);
  content = removeParentheticals(content);
  content = fixUnitConversion(content);
  content = ImageCaptionsRemover.remove(content);
  content = DoubleBracesRemover.remove(content);
  content = removeHtmlComments(content);
  content = removeEmphasis(content);
  content = removeHeadings(content);
  content = removeCategoryLinks(content);
  content = removeLinks(content);
  content = removeMath(content);
  content = removeGallery(content);
  content = removeNoToc(content);
  content = removeIndentation(content);

  content = TableRemover.remove(content);

  // For some reason, some HTML entities are doubly encoded.
  content = StringEscapeUtils.unescapeHtml4(StringEscapeUtils.unescapeHtml4(content));
  content = removeHtmlTags(content);

  // Finally, fold multiple newlines.
  content = compressMultipleNewlines(content);
  return content.trim().replaceAll("\\n+", " ");
}
 
Example 5
Project: Slide-RSS   File: MainActivity.java   View Source Code Vote up 5 votes
public static void defaultShareText(String title, String url, Context c) {
    url = StringEscapeUtils.unescapeHtml4(Html.fromHtml(url).toString());
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("text/plain");
    /* Decode html entities */
    title = StringEscapeUtils.unescapeHtml4(title);
    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, title);
    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, url);
    c.startActivity(Intent.createChooser(sharingIntent, c.getString(R.string.title_share)));
}
 
Example 6
Project: Slide-RSS   File: MainActivity.java   View Source Code Vote up 5 votes
public static void defaultShare(String url, Context c) {
    url = StringEscapeUtils.unescapeHtml4(Html.fromHtml(url).toString());
    Uri webpage = LinkUtil.formatURL(url);
    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
    if (intent.resolveActivity(c.getPackageManager()) != null) {
        c.startActivity(intent);
    }
}
 
Example 7
Project: LibreNews-Android   File: FlashManager.java   View Source Code Vote up 5 votes
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 8
Project: nifi-nars   File: CreateContent.java   View Source Code Vote up 5 votes
public static String format(String content, Map<String, String> props) {
    Matcher m = PATTERN.matcher(Pattern.quote(content));
    String result = content;
    while (m.find()) {
        String found = m.group(1);
        String newVal = props.getOrDefault(found.trim(), "null");

        String escaped = StringEscapeUtils.escapeHtml4(newVal);
        result = result.replaceFirst(REGEX, Matcher.quoteReplacement(escaped));
    }
    return StringEscapeUtils.unescapeHtml4(result);
}
 
Example 9
Project: framework   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 10
Project: NEILREN4J   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 11
Project: crawling-framework   File: JsonLdParser.java   View Source Code Vote up 4 votes
public static JsonLdArticle parse(List<String> jsons) {
    try {
        for (String jsonLd : jsons) {
            if (!Strings.isNullOrEmpty(jsonLd)) {
                jsonLd = jsonLd.replaceAll("http://www\\.schema\\.org", "http://schema.org");
                jsonLd = jsonLd.replaceAll("\"http://schema\\.org\"", "\"http://schema.org/\"");
                Object jsonObject = JsonUtils.fromString(jsonLd);
                Map<String, Object> data = JsonLdProcessor.compact(jsonObject, new HashMap(), new JsonLdOptions());
                String type = Objects.toString(data.get("@type"), null);
                if (type == null && data.get(SCHEMA_ATTR_ARTICLE) instanceof Map) {
                    data = (Map<String, Object>) data.get(SCHEMA_ATTR_ARTICLE);
                    type = Objects.toString(data.get("@type"), null);
                }
                if (SCHEMA_CLASS_ARTICLE.equalsIgnoreCase(type) || SCHEMA_CLASS_NEWS_ARTICLE.equalsIgnoreCase(type)) {
                    JsonLdArticle article = new JsonLdArticle();
                    String headline = Objects.toString(data.get(SCHEMA_ATTR_HEADLINE), null);
                    if (!Strings.isNullOrEmpty(headline)) {
                        headline = StringEscapeUtils.unescapeHtml4(headline);
                    }
                    article.setHeadline(headline);
                    String articleBody = Objects.toString(data.get(SCHEMA_ATTR_ARTICLE_BODY), null);
                    if (!Strings.isNullOrEmpty(articleBody)) {
                        articleBody = StringEscapeUtils.unescapeHtml4(articleBody);
                    }
                    article.setArticleBody(articleBody);
                    Object publishedObject = data.get(SCHEMA_ATTR_PUBLISHED);
                    String datePublished = null;
                    if (publishedObject instanceof String) {
                        datePublished = (String) publishedObject;
                    } else if (publishedObject instanceof Map) {
                        datePublished = Objects.toString(((Map) publishedObject).get("@value"), null);
                    }
                    article.setDatePublished(datePublished);
                    return article;
                }
            }
        }
    } catch (Exception e) {
        LOG.warn("Failed to parse ld+json", e);
    }
    return null;
}
 
Example 12
Project: opencron   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 13
Project: ExcelHandle   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 14
Project: lemon   File: StringUtils.java   View Source Code Vote up 4 votes
public static String unescapeHtml(String text) {
    return StringEscapeUtils.unescapeHtml4(text);
}
 
Example 15
Project: easyweb   File: Encodes.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String unescapeHtml(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml4(htmlEscaped);
}
 
Example 16
Project: klask-io   File: EncodingUtil.java   View Source Code Vote up 4 votes
public static String unEscapeString(String stringToUnEscape) {
    return StringEscapeUtils.unescapeHtml4(stringToUnEscape);
}
 
Example 17
Project: aceql-http   File: HtmlConverter.java   View Source Code Vote up 3 votes
/**
    * 
    * Converts special HTML values of characters to their original values. <br>
    * Example : <code>"&amp;eacute;"</code>"is converted to "�"
    * <p>
    * 
    * @param string
    *            A String to convert from HTML to original
    *            <p>
    * @return A String of char converted to original values
    * 
    */

   public static String fromHtml(String string) {

if (DO_NOTHING) return string;

if (string == null) return string;
    
if (string.contains("&")) {
    return StringEscapeUtils.unescapeHtml4(string);
} else {
    return string;
}

   }
 
Example 18
Project: util   File: EscapeUtil.java   View Source Code Vote up 2 votes
/**
 * Html解码,将HTML4格式的字符串转码解码为普通字符串.
 * 
 * 比如 &quot;bread&quot; &amp; &quot;butter&quot;转化为"bread" & "butter"
 */
public static String unescapeHtml(String html) {
	return StringEscapeUtils.unescapeHtml4(html);
}