List of usage examples for org.apache.commons.lang3 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.github.ibole.infrastructure.web.spring.GlobalBindingHandler.java
/** * ??./*from w w w . j a v a 2s . c om*/ * 1. ?StringHTML?XSS * 2. Date?String * @param binder WebDataBinder */ @InitBinder protected void initBinder(WebDataBinder binder) { // String??StringHTML?XSS binder.registerCustomEditor(String.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(text == null ? null : StringEscapeUtils.escapeHtml4(text.trim())); } @Override public String getAsText() { Object value = getValue(); return value != null ? value.toString() : ""; } }); // Date ? binder.registerCustomEditor(Date.class, new PropertyEditorSupport() { @Override public void setAsText(String text) { setValue(DateUtils.parseDate(text)); } // @Override // public String getAsText() { // Object value = getValue(); // return value != null ? DateUtils.formatDateTime((Date)value) : ""; // } }); }
From source file:net.java.sip.communicator.impl.gui.main.chat.replacers.URLReplacer.java
/** * Replace operation for replacing URL's with a hyperlinked version. * * @param target destination to write the replacement result to * @param piece the piece of content to be processed *///from w ww . ja v a2 s . com @Override public void replace(final StringBuilder target, final String piece) { final Matcher m = this.pattern.matcher(piece); int prevEnd = 0; while (m.find()) { target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd, m.start()))); prevEnd = m.end(); String url = m.group().trim(); target.append("<A href=\""); if (url.startsWith("www")) { target.append("http://"); } target.append(url); target.append("\">"); target.append(StringEscapeUtils.escapeHtml4(url)); target.append("</A>"); } target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd))); }
From source file:info.magnolia.ui.vaadin.grid.MagnoliaTable.java
@Override protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) { String result = super.formatPropertyValue(rowId, colId, property); return StringEscapeUtils.escapeHtml4(result); }
From source file:net.mindengine.blogix.markup.converters.CodeBlockConverter.java
private String dataLanguageFromDefinition(String definition) { if (definition != null && definition.length() > 2) { String language = definition.substring(2).trim(); if (!language.isEmpty()) { return String.format(" data-language=\"%s\"", StringEscapeUtils.escapeHtml4(language)); }//from www.j a va2 s.co m } return ""; }
From source file:com.nestedbird.modules.soundcloudreader.SoundcloudReader.java
private String generateRequestUrl(final String url) { return String.format("https://api.soundcloud.com/resolve.json?url=%s&client_id=%s", StringEscapeUtils.escapeHtml4(url), socialConfigSettings.getScClientId()); }
From source file:de.elbe5.base.util.StringUtil.java
public static String toHtmlInput(String src) { if (src == null) { return ""; }/* w ww. j a v a 2s .c om*/ return StringEscapeUtils.escapeHtml4(src); }
From source file:com.seleniumtests.reporter.logger.Snapshot.java
/** * Log Screenshot method//ww w . ja va2 s.c om * Return: screenshot message with links * * @param screenShot * * @return String */ public String buildScreenshotLog() { StringBuilder sbMessage = new StringBuilder(""); sbMessage.append(OUTPUT_PATTERN + StringEscapeUtils.escapeHtml4(screenshot.getTitle()) + ": "); if (screenshot.getLocation() != null) { sbMessage.append("<a href='" + screenshot.getLocation() + "' target=url>Application URL</a>"); } if (screenshot.getHtmlSourcePath() != null) { sbMessage.append( " | <a href='" + screenshot.getHtmlSourcePath() + "' target=html>Application HTML Source</a>"); } if (screenshot.getImagePath() != null) { sbMessage.append( " | <a href='" + screenshot.getImagePath() + "' class='lightbox'>" + SNAPSHOT_PATTERN + "</a>"); } return sbMessage.toString(); }
From source file:com.goody.backend.entities.Todo.java
/** * Escape any HTML and Javascript/*from w ww .j av a2s . c om*/ */ public void cleanTitle() { this.title = StringEscapeUtils.escapeHtml4(StringEscapeUtils.escapeEcmaScript(this.title)); }
From source file:com.opendoorlogistics.studio.tables.grid.HeaderCellRenderer.java
/** * @param value/*from w w w .ja v a2 s . c o m*/ * @param isSelected */ protected void prepareLabel(Object value, boolean isSelected, boolean italics, JLabel label) { StringBuilder builder = new StringBuilder(); if (value != null) { builder.append("<html><strong>"); if (italics) { builder.append("<em>"); } builder.append(StringEscapeUtils.escapeHtml4(value.toString())); if (italics) { builder.append("</em>"); } builder.append("</strong></html>"); } label.setText(builder.toString()); if (isSelected) { label.setBackground(selectedColour); } else { label.setBackground(disabledColour); } }
From source file:com.lyncode.jtwig.functions.builtin.StringFunctions.java
@JtwigFunction(name = "escape", aliases = { "e" }) public String escape(@Parameter String input, @Parameter String strategy) throws FunctionException { switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) { case HTML: return StringEscapeUtils.escapeHtml4(input); case JAVASCRIPT: return StringEscapeUtils.escapeEcmaScript(input); case XML:// w ww .ja v a 2s .c o m return StringEscapeUtils.escapeXml(input); default: throw new FunctionException("Unknown escaping strategy " + strategy); } }