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:alfio.controller.api.admin.UtilsApiController.java
@RequestMapping(value = "/render-commonmark") public String renderCommonmark(@RequestParam("text") String input) { return MustacheCustomTagInterceptor.renderToCommonmark(StringEscapeUtils.escapeHtml4(input)); }
From source file:com.seleniumtests.util.StringUtility.java
/** * Encode string according to provided format * @param message message to encode * @param format 'xml', 'csv', 'html', 'json', 'text'. the later does not change anything * @return/*from w ww.j a va 2s . co m*/ */ public static String encodeString(String message, String format) { String newMessage; switch (format) { case "xml": newMessage = StringEscapeUtils.escapeXml11(message); break; case "csv": newMessage = StringEscapeUtils.escapeCsv(message); break; case "html": newMessage = StringEscapeUtils.escapeHtml4(message); break; case "json": newMessage = StringEscapeUtils.escapeJson(message); break; case "text": newMessage = message; break; default: throw new CustomSeleniumTestsException("only escaping of 'xml', 'html', 'csv', 'json' is allowed"); } return newMessage; }
From source file:de.micromata.genome.tpsb.soapui.SoapUiScenarioExtractor.java
public SoapUiScenarioExtractor text(String s) { sb.append(StringEscapeUtils.escapeHtml4(s)); return this; }
From source file:dk.fambagge.recipes.web.views.RecipeView.java
public String escapeTextWithLineBreaks(String s) { String escaped = StringEscapeUtils.escapeHtml4(s); return escaped.replace("\n", "<br />"); }
From source file:com.seleniumtests.reporter.reporters.SeleniumTestsReporter2.java
/** * Generate result for a single test method * @param ve velocity engine used to generate file * @param testResult result for this test method *//*w w w . ja va2 s . c o m*/ public void generateExecutionLogs(final VelocityEngine ve, final ITestResult testResult) { try { Template t = ve.getTemplate("reporter/templates/report.part.test.logs.vm"); VelocityContext context = new VelocityContext(); // add logs String logs = SeleniumRobotLogger.getTestLogs().get(getTestName(testResult)); if (logs == null) { logs = ""; } // exception handling String[] stack = null; if (testResult.getThrowable() != null) { StringBuilder stackString = new StringBuilder(); generateTheStackTrace(testResult.getThrowable(), testResult.getThrowable().getMessage(), stackString, "html"); stack = stackString.toString().split("\n"); } // encode logs List<String> logLines = new ArrayList<>(); for (String line : logs.split("\n")) { logLines.add(StringEscapeUtils.escapeHtml4(line)); } context.put(STATUS, getTestStatus(testResult)); context.put("stacktrace", stack); context.put("logs", logLines); StringWriter writer = new StringWriter(); t.merge(context, writer); mOut.write(writer.toString()); } catch (Exception e) { generationErrorMessage = "generateExecutionLogs, Exception creating execution logs:" + e.getMessage(); logger.error("Exception creating execution logs.", e); } }
From source file:jmri.web.servlet.operations.HtmlTrainCommon.java
protected String getCarAttribute(Car car, String attribute, boolean isPickup, boolean isLocal) { if (attribute.equals(Setup.LOAD)) { return (car.isCaboose() || car.isPassenger()) ? "" : StringEscapeUtils.escapeHtml4(car.getLoadName()); // NOI18N } else if (attribute.equals(Setup.HAZARDOUS)) { return car.isHazardous() ? Setup.getHazardousMsg() : ""; // NOI18N } else if (attribute.equals(Setup.DROP_COMMENT)) { return car.getDropComment(); } else if (attribute.equals(Setup.PICKUP_COMMENT)) { return car.getPickupComment(); } else if (attribute.equals(Setup.KERNEL)) { return car.getKernelName(); } else if (attribute.equals(Setup.RWE)) { if (!car.getReturnWhenEmptyDestName().equals("")) { return String.format(locale, strings.getProperty("RWELocationAndTrack"), StringEscapeUtils.escapeHtml4(splitString(car.getReturnWhenEmptyDestinationName())), StringEscapeUtils.escapeHtml4(splitString(car.getReturnWhenEmptyDestTrackName()))); }// ww w . ja v a 2 s .c o m return ""; // NOI18N } else if (attribute.equals(Setup.FINAL_DEST)) { if (!car.getFinalDestinationName().equals("")) { return String.format(locale, strings.getProperty("FinalDestinationLocation"), StringEscapeUtils.escapeHtml4(splitString(car.getFinalDestinationName()))); } return ""; } else if (attribute.equals(Setup.FINAL_DEST_TRACK)) { if (!car.getFinalDestinationName().equals("")) { return String.format(locale, strings.getProperty("FinalDestinationLocationAndTrack"), StringEscapeUtils.escapeHtml4(splitString(car.getFinalDestinationName())), StringEscapeUtils.escapeHtml4(splitString(car.getFinalDestinationTrackName()))); } return ""; } return getRollingStockAttribute(car, attribute, isPickup, isLocal); }
From source file:jmri.web.servlet.operations.HtmlTrainCommon.java
protected String getRollingStockAttribute(RollingStock rs, String attribute, boolean isPickup, boolean isLocal) { if (attribute.equals(Setup.NUMBER)) { return splitString(rs.getNumber()); } else if (attribute.equals(Setup.ROAD)) { return StringEscapeUtils.escapeHtml4(rs.getRoadName()); } else if (attribute.equals(Setup.TYPE)) { String[] type = rs.getTypeName().split("-"); // second half of string // can be anything return type[0]; } else if (attribute.equals(Setup.LENGTH)) { return rs.getLength(); } else if (attribute.equals(Setup.COLOR)) { return rs.getColor(); } else if (attribute.equals(Setup.LOCATION) && (isPickup || isLocal) || (attribute.equals(Setup.TRACK) && isPickup)) { if (rs.getTrack() != null) { return String.format(locale, strings.getProperty("FromTrack"), StringEscapeUtils.escapeHtml4(rs.getTrackName())); }//from w ww .j a v a 2s .c o m return ""; } else if (attribute.equals(Setup.LOCATION) && !isPickup && !isLocal) { return ""; // we don't have the car's origin, so nothing to return // Note that the JSON database does have the car's origin, so this could be fixed. // return String.format(locale, strings.getProperty("FromLocation"), StringEscapeUtils.escapeHtml4(rs // .getLocationName())); } else if (attribute.equals(Setup.DESTINATION) && isPickup) { return String.format(locale, strings.getProperty("ToLocation"), StringEscapeUtils.escapeHtml4(splitString(rs.getDestinationName()))); } else if ((attribute.equals(Setup.DESTINATION) || attribute.equals(Setup.TRACK)) && !isPickup) { return String.format(locale, strings.getProperty("ToTrack"), StringEscapeUtils.escapeHtml4(splitString(rs.getDestinationTrackName()))); } else if (attribute.equals(Setup.DEST_TRACK)) { return String.format(locale, strings.getProperty("ToLocationAndTrack"), StringEscapeUtils.escapeHtml4(splitString(rs.getDestinationName())), StringEscapeUtils.escapeHtml4(splitString(rs.getDestinationTrackName()))); } else if (attribute.equals(Setup.OWNER)) { return StringEscapeUtils.escapeHtml4(rs.getOwner()); } else if (attribute.equals(Setup.COMMENT)) { return StringEscapeUtils.escapeHtml4(rs.getComment()); } else if (attribute.equals(Setup.BLANK) || attribute.equals(Setup.NO_NUMBER) || attribute.equals(Setup.NO_ROAD) || attribute.equals(Setup.NO_COLOR) || attribute.equals(Setup.NO_DESTINATION) || attribute.equals(Setup.NO_DEST_TRACK) || attribute.equals(Setup.NO_LOCATION) || attribute.equals(Setup.NO_TRACK) || attribute.equals(Setup.TAB) || attribute.equals(Setup.TAB2) || attribute.equals(Setup.TAB3)) { // attributes that don't print return ""; } return String.format(Bundle.getMessage(locale, "ErrorPrintOptions"), attribute); // something is isn't right! }
From source file:de.micromata.genome.gwiki.controls.GWikiGenDocActionBean.java
public void renderPages(GWikiContext wikiContext, GWikiElement el, int offset) { if (wikiContext.getWikiWeb().getAuthorization().isAllowToView(wikiContext, el.getElementInfo()) == false) { return;//from ww w. j a v a 2 s . co m } if (offset != 0) { wikiContext.append("<h").append(offset).append(">") // .append(StringEscapeUtils .escapeHtml4(wikiContext.getTranslatedProp(el.getElementInfo().getTitle())))// .append("</h").append(offset).append(">\n"); } wikiContext.pushWikiElement(el); try { el.prepareHeader(wikiContext); el.serve(wikiContext); wikiContext.flush(); } finally { wikiContext.popWikiElement(); } List<GWikiElementInfo> childs = wikiContext.getElementFinder() .getPageDirectPages(el.getElementInfo().getId()); Collections.sort(childs, new GWikiElementByChildOrderComparator( new GWikiElementByOrderComparator(new GWikiElementByIntPropComparator("ORDER", 0)))); wikiContext.setRequestAttribute(GWikiFragmentHeading.GWIKI_LAST_HEADING_LEVEL, offset); for (GWikiElementInfo ei : childs) { GWikiElement ce = wikiContext.getWikiWeb().getElement(ei); // wikiContext.append("<h1>").append(WebUtils.escapeHtml(wikiContext.getTranlatedProp(ei.getTitle()))).append("</h1>\n"); renderPages(wikiContext, ce, offset + 1); wikiContext.flush(); } }
From source file:jmri.web.servlet.operations.HtmlTrainCommon.java
protected String getTrackComments(RouteLocation location, List<Car> cars) { StringBuilder builder = new StringBuilder(); if (location.getLocation() != null) { List<Track> tracks = location.getLocation().getTrackByNameList(null); for (Track track : tracks) { // any pick ups or set outs to this track? boolean pickup = false; boolean setout = false; for (Car car : cars) { if (car.getRouteLocation() == location && car.getTrack() != null && car.getTrack() == track) { pickup = true;//from w ww . j a v a 2 s . c om } if (car.getRouteDestination() == location && car.getDestinationTrack() != null && car.getDestinationTrack() == track) { setout = true; } } // print the appropriate comment if there's one if (pickup && setout && !track.getCommentBoth().equals("")) { builder.append(String.format(locale, strings.getProperty("TrackComments"), StringEscapeUtils.escapeHtml4(track.getCommentBoth()))); } else if (pickup && !setout && !track.getCommentPickup().equals("")) { builder.append(String.format(locale, strings.getProperty("TrackComments"), StringEscapeUtils.escapeHtml4(track.getCommentPickup()))); } else if (!pickup && setout && !track.getCommentSetout().equals("")) { builder.append(String.format(locale, strings.getProperty("TrackComments"), StringEscapeUtils.escapeHtml4(track.getCommentSetout()))); } } } return builder.toString(); }
From source file:de.micromata.tpsb.doc.TpsbEnvUtils.java
private static String escapeHtml(String text, boolean html) { if (html == false) { return text; }/*ww w.j av a 2s . co m*/ return StringEscapeUtils.escapeHtml4(text); }