Java Code Examples for org.apache.commons.lang.StringEscapeUtils.unescapeHtml()

The following are Jave code examples for showing how to use unescapeHtml() of the org.apache.commons.lang.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: rapidminer   File: AnnotationDrawUtils.java   View Source Code Vote up 6 votes
/**
 * Returns plain text from the editor.
 *
 * @param editor
 *            the editor from which to take the text.
 * @param onlySelected
 *            if {@code true} will only return the selected text
 * @return the text of the editor converted to plain text
 * @throws BadLocationException
 * @throws IOException
 */
public static String getPlaintextFromEditor(final JEditorPane editor, final boolean onlySelected) throws IOException,
		BadLocationException {
	if (editor == null) {
		throw new IllegalArgumentException("editor must not be null!");
	}
	HTMLDocument document = (HTMLDocument) editor.getDocument();
	StringWriter writer = new StringWriter();
	int start = 0;
	int length = document.getLength();
	if (onlySelected) {
		start = editor.getSelectionStart();
		length = editor.getSelectionEnd() - start;
	}
	editor.getEditorKit().write(writer, document, start, length);
	String text = writer.toString();
	text = AnnotationDrawUtils.removeStyleFromComment(text);
	// switch <br> and <br/> to actual newline (current system)
	text = text.replaceAll("<br.*?>", System.lineSeparator());
	// kill all other html tags
	text = text.replaceAll("\\<.*?>", "");
	text = StringEscapeUtils.unescapeHtml(text);
	return text;
}
 
Example 2
Project: goobi-viewer-indexer   File: MetadataHelper.java   View Source Code Vote up 5 votes
/**
 * 
 * @param fieldValue
 * @return
 */
public static String applyValueDefaultModifications(String fieldValue) {
    String ret = fieldValue;
    if (StringUtils.isNotEmpty(ret)) {
        // Remove any prior HTML escaping, otherwise strings like '&amp;amp;' might occur
        ret = StringEscapeUtils.unescapeHtml(ret);
    }

    return ret;
}
 
Example 3
Project: hadoop-oss   File: ReconfigurationServlet.java   View Source Code Vote up 4 votes
/**
 * Apply configuratio changes after admin has approved them.
 */
private void applyChanges(PrintWriter out, Reconfigurable reconf,
    HttpServletRequest req) throws ReconfigurationException {
  Configuration oldConf = reconf.getConf();
  Configuration newConf = new Configuration();

  Enumeration<String> params = getParams(req);

  synchronized(oldConf) {
    while (params.hasMoreElements()) {
      String rawParam = params.nextElement();
      String param = StringEscapeUtils.unescapeHtml(rawParam);
      String value =
        StringEscapeUtils.unescapeHtml(req.getParameter(rawParam));
      if (value != null) {
        if (value.equals(newConf.getRaw(param)) || value.equals("default") ||
            value.equals("null") || value.isEmpty()) {
          if ((value.equals("default") || value.equals("null") || 
               value.isEmpty()) && 
              oldConf.getRaw(param) != null) {
            out.println("<p>Changed \"" + 
                        StringEscapeUtils.escapeHtml(param) + "\" from \"" +
                        StringEscapeUtils.escapeHtml(oldConf.getRaw(param)) +
                        "\" to default</p>");
            reconf.reconfigureProperty(param, null);
          } else if (!value.equals("default") && !value.equals("null") &&
                     !value.isEmpty() && 
                     (oldConf.getRaw(param) == null || 
                      !oldConf.getRaw(param).equals(value))) {
            // change from default or value to different value
            if (oldConf.getRaw(param) == null) {
              out.println("<p>Changed \"" + 
                          StringEscapeUtils.escapeHtml(param) + 
                          "\" from default to \"" +
                          StringEscapeUtils.escapeHtml(value) + "\"</p>");
            } else {
              out.println("<p>Changed \"" + 
                          StringEscapeUtils.escapeHtml(param) + "\" from \"" +
                          StringEscapeUtils.escapeHtml(oldConf.
                                                       getRaw(param)) +
                          "\" to \"" +
                          StringEscapeUtils.escapeHtml(value) + "\"</p>");
            }
            reconf.reconfigureProperty(param, value);
          } else {
            LOG.info("property " + param + " unchanged");
          }
        } else {
          // parameter value != newConf value
          out.println("<p>\"" + StringEscapeUtils.escapeHtml(param) + 
                      "\" not changed because value has changed from \"" +
                      StringEscapeUtils.escapeHtml(value) + "\" to \"" +
                      StringEscapeUtils.escapeHtml(newConf.getRaw(param)) +
                      "\" since approval</p>");
        }
      }
    }
  }
}
 
Example 4
Project: Ins_fb_pictureSpider_WEB   File: EncodeUtils.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String htmlUnescape(String htmlEscaped) {
    return StringEscapeUtils.unescapeHtml(htmlEscaped);
}
 
Example 5
Project: hadoop   File: ReconfigurationServlet.java   View Source Code Vote up 4 votes
/**
 * Apply configuratio changes after admin has approved them.
 */
private void applyChanges(PrintWriter out, Reconfigurable reconf,
    HttpServletRequest req) throws ReconfigurationException {
  Configuration oldConf = reconf.getConf();
  Configuration newConf = new Configuration();

  Enumeration<String> params = getParams(req);

  synchronized(oldConf) {
    while (params.hasMoreElements()) {
      String rawParam = params.nextElement();
      String param = StringEscapeUtils.unescapeHtml(rawParam);
      String value =
        StringEscapeUtils.unescapeHtml(req.getParameter(rawParam));
      if (value != null) {
        if (value.equals(newConf.getRaw(param)) || value.equals("default") ||
            value.equals("null") || value.isEmpty()) {
          if ((value.equals("default") || value.equals("null") || 
               value.isEmpty()) && 
              oldConf.getRaw(param) != null) {
            out.println("<p>Changed \"" + 
                        StringEscapeUtils.escapeHtml(param) + "\" from \"" +
                        StringEscapeUtils.escapeHtml(oldConf.getRaw(param)) +
                        "\" to default</p>");
            reconf.reconfigureProperty(param, null);
          } else if (!value.equals("default") && !value.equals("null") &&
                     !value.isEmpty() && 
                     (oldConf.getRaw(param) == null || 
                      !oldConf.getRaw(param).equals(value))) {
            // change from default or value to different value
            if (oldConf.getRaw(param) == null) {
              out.println("<p>Changed \"" + 
                          StringEscapeUtils.escapeHtml(param) + 
                          "\" from default to \"" +
                          StringEscapeUtils.escapeHtml(value) + "\"</p>");
            } else {
              out.println("<p>Changed \"" + 
                          StringEscapeUtils.escapeHtml(param) + "\" from \"" +
                          StringEscapeUtils.escapeHtml(oldConf.
                                                       getRaw(param)) +
                          "\" to \"" +
                          StringEscapeUtils.escapeHtml(value) + "\"</p>");
            }
            reconf.reconfigureProperty(param, value);
          } else {
            LOG.info("property " + param + " unchanged");
          }
        } else {
          // parameter value != newConf value
          out.println("<p>\"" + StringEscapeUtils.escapeHtml(param) + 
                      "\" not changed because value has changed from \"" +
                      StringEscapeUtils.escapeHtml(value) + "\" to \"" +
                      StringEscapeUtils.escapeHtml(newConf.getRaw(param)) +
                      "\" since approval</p>");
        }
      }
    }
  }
}
 
Example 6
Project: DWSurvey   File: EncodeUtils.java   View Source Code Vote up 4 votes
/**
 * Html 解码.
 */
public static String htmlUnescape(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml(htmlEscaped);
}