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

The following examples show how to use org.apache.commons.lang.StringEscapeUtils#unescapeHtml() . 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: OsioKeycloakTestAuthServiceClient.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
private String loginAndGetFormPostURL()
    throws IOException, MalformedURLException, ProtocolException {
  CookieManager cookieManager = new CookieManager();
  CookieHandler.setDefault(cookieManager);
  HttpURLConnection conn =
      (HttpURLConnection)
          new URL(osioAuthEndpoint + "/api/login?redirect=https://che.openshift.io")
              .openConnection();
  conn.setRequestMethod("GET");

  String htmlOutput = IOUtils.toString(conn.getInputStream());
  Pattern p = Pattern.compile("action=\"(.*?)\"");
  Matcher m = p.matcher(htmlOutput);
  if (m.find()) {
    String formPostURL = StringEscapeUtils.unescapeHtml(m.group(1));
    return formPostURL;
  } else {
    LOG.error("Unable to login - didn't find URL to send login form to.");
    throw new RuntimeException("Unable to login - didn't find URL to send login form to.");
  }
}
 
Example 2
Source File: TaskDefinitionToDslConverter.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Reverse engineers a {@link TaskDefinition} into a semantically equivalent DSL text representation.
 * @param taskDefinition task definition to be converted into DSL
 * @return the textual DSL representation of the task
 */
public String toDsl(TaskDefinition taskDefinition) {

	if (StringUtils.hasText(taskDefinition.getDslText())) {
		TaskParser taskParser = new TaskParser("__dummy", taskDefinition.getDslText(), true, true);
		Assert.isTrue(!taskParser.parse().isComposed(),
				"The TaskDefinitionToDslConverter doesn't support Composed Tasks!");
	}

	StringBuilder dslBuilder = new StringBuilder();
	Map<String, String> properties = taskDefinition.getProperties();
	dslBuilder.append(taskDefinition.getRegisteredAppName());
	for (String propertyName : properties.keySet()) {
		if (!dataFlowAddedProperties.contains(propertyName)) {
			String propertyValue = StringEscapeUtils.unescapeHtml(properties.get(propertyName));
			dslBuilder.append(" --").append(propertyName).append("=").append(
					DefinitionUtils.escapeNewlines(DefinitionUtils.autoQuotes(propertyValue)));
		}
	}
	return dslBuilder.toString();
}
 
Example 3
Source File: Revision.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the textual content of this revision.
 *
 * @return content
 */
public String getRevisionText()
{
	if (this.revisionText == null) {
		revisionApi.setRevisionTextAndParts(this);
	}
	return StringEscapeUtils.unescapeHtml(this.revisionText);
}
 
Example 4
Source File: TextUtils.java    From webarchive-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces HTML Entity Encodings.
 * @param cs The CharSequence to remove html codes from
 * @return the same CharSequence or an escaped String.
 */
public static CharSequence unescapeHtml(final CharSequence cs) {
    if (cs == null) {
        return cs;
    }
    
    return StringEscapeUtils.unescapeHtml(cs.toString());
}
 
Example 5
Source File: Const.java    From hop with Apache License 2.0 5 votes vote down vote up
/**
 * UnEscape HTML content. i.e. replace characters with &values;
 *
 * @param content content
 * @return unescaped content
 */
public static String unEscapeHtml( String content ) {
  if ( Utils.isEmpty( content ) ) {
    return content;
  }
  return StringEscapeUtils.unescapeHtml( content );
}
 
Example 6
Source File: WikiMetadata.java    From wikireverse with MIT License 5 votes vote down vote up
private String formatField(String value, int fieldLength) {
	if (value != null) {
		// Normalise whitespace to single spaces
		value = value.replaceAll("\\s+", " ");

		// Remove carriage returns and newlines
		value = value.replaceAll("(\r\n|\r|\n)", "");

		// Decode HTML entities
		value = StringEscapeUtils.unescapeHtml(value);
		value = truncateField(value, fieldLength);
	} else value = "";
	
	return value;
}
 
Example 7
Source File: HTMLSanitizer.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String sanitizeSimpleText(String unsafeHtmlContent) {
	OutputSettings outputSettings = new OutputSettings().indentAmount(0).prettyPrint(false);
	Whitelist whiteList = Whitelist.simpleText().preserveRelativeLinks(false);
	String sanitized = Jsoup.clean(unsafeHtmlContent, "", whiteList, outputSettings);
	sanitized = StringEscapeUtils.unescapeHtml(sanitized);
	return sanitized;
}
 
Example 8
Source File: ForumRTFFormatter.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * @param originalText
 * @return
 */
private String convertHTMLMarkupToRTF(final String originalText) {
    String htmlText = originalText;

    final Matcher mb = PATTERN_HTML_BOLD.matcher(htmlText);
    final StringBuffer bolds = new StringBuffer();
    while (mb.find()) {
        mb.appendReplacement(bolds, "{\\\\b $1} ");
    }
    mb.appendTail(bolds);
    htmlText = bolds.toString();

    final Matcher mi = PATTERN_HTML_ITALIC.matcher(htmlText);
    final StringBuffer italics = new StringBuffer();
    while (mi.find()) {
        mi.appendReplacement(italics, "{\\\\i $1} ");
    }
    mi.appendTail(italics);
    htmlText = italics.toString();

    final Matcher mbr = PATTERN_HTML_BREAK.matcher(htmlText);
    final StringBuffer breaks = new StringBuffer();
    while (mbr.find()) {
        mbr.appendReplacement(breaks, "\\\\line ");
    }
    mbr.appendTail(breaks);
    htmlText = breaks.toString();

    final Matcher mofo = PATTERN_CSS_O_FOQUOTE.matcher(htmlText);
    final StringBuffer foquotes = new StringBuffer();
    while (mofo.find()) {
        mofo.appendReplacement(foquotes, "\\\\line {\\\\i $1} {\\\\pard $2\\\\par}");
    }
    mofo.appendTail(foquotes);
    htmlText = foquotes.toString();

    final Matcher mp = PATTERN_HTML_PARAGRAPH.matcher(htmlText);
    final StringBuffer paragraphs = new StringBuffer();
    while (mp.find()) {
        mp.appendReplacement(paragraphs, "\\\\line $1 \\\\line");
    }
    mp.appendTail(paragraphs);
    htmlText = paragraphs.toString();

    final Matcher mahref = PATTERN_HTML_AHREF.matcher(htmlText);
    final StringBuffer ahrefs = new StringBuffer();
    while (mahref.find()) {
        mahref.appendReplacement(ahrefs, "{\\\\field{\\\\*\\\\fldinst{HYPERLINK\"$1\"}}{\\\\fldrslt{\\\\ul $2}}}");
    }
    mahref.appendTail(ahrefs);
    htmlText = ahrefs.toString();

    final Matcher mli = PATTERN_HTML_LIST.matcher(htmlText);
    final StringBuffer lists = new StringBuffer();
    while (mli.find()) {
        mli.appendReplacement(lists, "$1\\\\line ");
    }
    mli.appendTail(lists);
    htmlText = lists.toString();

    final Matcher mtp = PATTERN_THREEPOINTS.matcher(htmlText);
    final StringBuffer tps = new StringBuffer();
    while (mtp.find()) {
        mtp.appendReplacement(tps, THREEPOINTS);
    }
    mtp.appendTail(tps);
    htmlText = tps.toString();

    // strip all other html-fragments, because not convertable that easy
    htmlText = FilterFactory.getHtmlTagsFilter().filter(htmlText);
    // Remove all &nbsp;
    final Matcher tmp = HTML_SPACE_PATTERN.matcher(htmlText);
    htmlText = tmp.replaceAll(" ");
    htmlText = StringEscapeUtils.unescapeHtml(htmlText);

    return htmlText;
}
 
Example 9
Source File: StringHelper.java    From olat with Apache License 2.0 4 votes vote down vote up
public static final String unescapeHtml(String str) {
    return StringEscapeUtils.unescapeHtml(str);
}
 
Example 10
Source File: LDAPConfigCmd.java    From cosmic with Apache License 2.0 4 votes vote down vote up
public void setQueryFilter(final String queryFilter) {
    this.queryFilter = StringEscapeUtils.unescapeHtml(queryFilter);
}
 
Example 11
Source File: ReconfigurationServlet.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * 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 12
Source File: EncodeUtils.java    From DWSurvey with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Html 解码.
 */
public static String htmlUnescape(String htmlEscaped) {
	return StringEscapeUtils.unescapeHtml(htmlEscaped);
}
 
Example 13
Source File: CSSValidator.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Adds the CSS errors.
 * 
 * @param errors
 *            the array of errors
 * @param sourcePath
 *            the source path
 * @param manager
 *            the validation manager
 * @param items
 *            the list that stores the added validation items
 */
private void addErrors(String[] errors, String sourcePath, List<IProblem> items, List<String> filters)
{
	Map<String, String> map;
	for (String error : errors)
	{
		map = getProperties(error);

		int lineNumber = Integer.parseInt(map.get("line")); //$NON-NLS-1$
		String message = map.get("message"); //$NON-NLS-1$
		String context = map.get("context"); //$NON-NLS-1$
		String property = map.get("property"); //$NON-NLS-1$
		String skippedstring = map.get("skippedstring"); //$NON-NLS-1$
		String errorsubtype = map.get("errorsubtype"); //$NON-NLS-1$

		// Don't attempt to add errors if there are already errors on this line
		if (hasErrorOrWarningOnLine(items, lineNumber))
		{
			continue;
		}

		if (message == null)
		{
			if (property == null)
			{
				property = context;
			}
			if (skippedstring.equals("[empty string]")) //$NON-NLS-1$
			{
				// alters the text a bit
				skippedstring = "no properties defined"; //$NON-NLS-1$
			}
			message = MessageFormat.format("{0} : {1} for {2}", errorsubtype, skippedstring, property); //$NON-NLS-1$
		}
		message = StringEscapeUtils.unescapeHtml(message);
		message = message.replaceAll("\\s+", " "); //$NON-NLS-1$ //$NON-NLS-2$

		if (!isIgnored(message, filters) && !containsCSS3Property(message) && !containsCSS3AtRule(message)
				&& !isFiltered(message))
		{
			// there is no info on the line offset or the length of the errored text
			items.add(createError(message, lineNumber, 0, 0, sourcePath));
		}
	}
}
 
Example 14
Source File: BuildMonitorDescriptorTest.java    From jenkins-build-monitor-plugin with MIT License 4 votes vote down vote up
private String htmlDecoded(String message) {
    return StringEscapeUtils.unescapeHtml(message);
}
 
Example 15
Source File: Twokenize.java    From topic-detection with Apache License 2.0 4 votes vote down vote up
/**
 * Twitter text comes HTML-escaped, so unescape it.
 * We also first unescape &amp;'s, in case the text has been buggily double-escaped.
 */
public static String normalizeTextForTagger(String text) {
	text = text.replaceAll("&amp;", "&");
	text = StringEscapeUtils.unescapeHtml(text);
	return text;
}
 
Example 16
Source File: FileLinkGraphPanel.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public FileVertex(@Nonnull final File file, @Nonnull final FileVertexType type) {
  this.type = type;
  this.text = file.getName();
  this.tooltip = "<html><b>" + type.toString() + "</b><br>" + StringEscapeUtils.unescapeHtml(FilenameUtils.normalizeNoEndSeparator(file.getAbsolutePath())) + "</html>"; //NOI18N
  this.file = file;
}
 
Example 17
Source File: PsiTopic.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public PsiTopic(@Nonnull final ASTNode node) {
  super(node);
  final String text = node.getText();
  this.level = ModelUtils.calcCharsOnStart('#', text);
  this.unescapedText = StringEscapeUtils.unescapeHtml(text.substring(level).trim());
}
 
Example 18
Source File: AbstractExtraData.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public AbstractExtraData(@Nonnull final ASTNode node) {
  super(node);
  final String text = node.getText();
  final String groupPre = getExtraType().preprocessString(text.substring(5, text.length() - 6));
  this.processedText = StringEscapeUtils.unescapeHtml(groupPre);
}
 
Example 19
Source File: PsiTopicTitle.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public PsiTopicTitle(@Nonnull final ASTNode node) {
  super(node);
  this.unescapedText = StringEscapeUtils.unescapeHtml(node.getText());
}
 
Example 20
Source File: ReconfigurationServlet.java    From RDFS with Apache License 2.0 4 votes vote down vote up
/**
 * Apply configuration changes after admin has approved them.
 */
private void applyChanges(PrintWriter out, Reconfigurable reconf,
                          HttpServletRequest req)
  throws IOException, 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.equals("")) {
          if ((value.equals("default") || value.equals("null") ||
               value.equals("")) &&
              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.equals("") &&
                     (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>");
        }
      }
    }
  }
}