List of usage examples for org.apache.commons.text StringEscapeUtils escapeHtml4
public static final String escapeHtml4(final String input)
Escapes the characters in a String using HTML entities.
For example:
"bread" & "butter"
"bread" & "butter"
.
From source file:com.esri.geoportal.commons.utils.CrlfUtils.java
/** * Sanitizes string for log.//from ww w. j ava 2 s . c o m * @param msg message to sanitize * @return sanitized message */ public static String sanitizeForLog(String msg) { String clean = msg != null ? msg.replace('\n', '_').replace('\r', '_') : ""; clean = StringEscapeUtils.escapeHtml4(clean); if (!msg.equals(clean)) { clean += " (Encoded)"; } return clean; }
From source file:com.twosigma.beakerx.kernel.msg.StacktraceHtmlPrinter.java
public static String printRedBold(String input) { String escaped = StringEscapeUtils.escapeHtml4(input); return INSTANCE.startRedBold() + escaped + INSTANCE.endRedBold(); }
From source file:net.metanotion.web.html.Tag.java
public static Iterator<Object> writeTag(String tagName, Map<String, Object> attributes, boolean selfClose) { final ArrayList<Object> t = new ArrayList<>((attributes.size() * 5) + 2); t.add("<" + tagName); for (final Map.Entry<String, Object> e : attributes.entrySet()) { t.add(" "); t.add(e.getKey());//w ww. j av a 2 s. c o m final Object val = e.getValue(); if (val != null) { t.add("=\""); t.add(StringEscapeUtils.escapeHtml4(val.toString())); t.add("\""); } } t.add(selfClose ? "/>" : ">"); return t.iterator(); }
From source file:com.jwebmp.core.utilities.EscapeChars.java
/** * Escape characters for text appearing in HTML markup. * <p>//from www. j a va 2 s . com * <P>This method exists as a defence against Cross Site Scripting (XSS) hacks. The idea is to neutralize control characters commonly used by scripts, such that they will * not be executed by * the browser. This is done by replacing the control characters with their escaped equivalents. See {link hirondelle.web4j.security.SafeText} as well. * * @param input * * @return */ public static String forHTML(String input) { return StringEscapeUtils.escapeHtml4(input); }
From source file:net.metanotion.web.html.SafeString.java
@Override public Iterator<Object> iterator() { return Arrays.asList((Object) StringEscapeUtils.escapeHtml4(html)).iterator(); }
From source file:net.metanotion.web.html.SafeString.java
@Override public String toString() { return StringEscapeUtils.escapeHtml4(html); }
From source file:com.synopsys.integration.blackduck.service.model.ReportData.java
public String htmlEscape(final String valueToEscape) { if (StringUtils.isBlank(valueToEscape)) { return null; }//from w ww . j a v a2s . c o m return StringEscapeUtils.escapeHtml4(valueToEscape); }
From source file:foam.nanos.servlet.ImageServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // get path//from ww w . jav a2 s . c o m String cwd = System.getProperty("user.dir"); String[] paths = getServletConfig().getInitParameter("paths").split(":"); String reqPath = req.getRequestURI().replaceFirst("/?images/?", "/"); // enumerate each file path for (int i = 0; i < paths.length; i++) { File src = new File(cwd + "/" + paths[i] + reqPath); if (src.isFile() && src.canRead() && src.getCanonicalPath().startsWith(new File(paths[i]).getCanonicalPath())) { String ext = EXTS.get(FilenameUtils.getExtension(src.getName())); try (BufferedInputStream is = new BufferedInputStream(new FileInputStream(src))) { resp.setContentType(!SafetyUtil.isEmpty(ext) ? ext : DEFAULT_EXT); resp.setHeader("Content-Disposition", "filename=\"" + StringEscapeUtils.escapeHtml4(src.getName()) + "\""); resp.setContentLengthLong(src.length()); IOUtils.copy(is, resp.getOutputStream()); return; } } } resp.sendError(resp.SC_NOT_FOUND); }
From source file:de.learnlib.alex.data.entities.actions.web.CheckTextWebAction.java
@Override public ExecuteResult execute(WebSiteConnector connector) { final WebElementLocator nodeWithVariables = new WebElementLocator(insertVariableValues(node.getSelector()), node.getType());// ww w . jav a 2 s .com try { final String source; if (nodeWithVariables.getSelector().equals("document")) { source = connector.getDriver().getPageSource(); } else { source = connector.getElement(nodeWithVariables).getAttribute("innerHTML"); } final String htmlEscapedValue = StringEscapeUtils.escapeHtml4(getValueWithVariableValues()); final boolean found = SearchHelper.search(htmlEscapedValue, source, regexp); LOGGER.info(LoggerMarkers.LEARNER, "Check if the current pages contains '{}' => {} (regExp: {}).", value, found, regexp); return found ? getSuccessOutput() : getFailedOutput(); } catch (NoSuchElementException e) { LOGGER.error(LoggerMarkers.LEARNER, "Could not find text '{}' in element '{}' (regExp: {}).", value, node.getSelector(), regexp); return getFailedOutput(); } catch (Exception e) { LOGGER.error(LoggerMarkers.LEARNER, "Failed to search for text '{}' in element '{}' (regExp: {}).", value, node.getSelector(), regexp, e); return getFailedOutput(); } }
From source file:de.micromata.genome.tpsb.builder.ScenarioDescriber.java
public ScenarioDescriber text(String text) { sb.append(StringEscapeUtils.escapeHtml4(text)); return this; }