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:fi.foyt.fni.view.gamelibrary.GameLibraryPublicationBackingBean.java
@RequestAction public String init() { publication = publicationController.findBookPublicationByUrlName(getUrlName()); if (publication == null) { return navigationController.notFound(); }/*w w w .j a v a 2 s. co m*/ if (!publication.getPublished()) { if (!sessionController.isLoggedIn()) { throw new UnauthorizedException(); } if (!publication.getCreator().getId().equals(sessionController.getLoggedUserId())) { if (!sessionController.hasLoggedUserRole(Role.GAME_LIBRARY_MANAGER)) { return navigationController.accessDenied(); } } } if (StringUtils.isNotBlank(publication.getDescriptionPlain())) { metaDescription = StringEscapeUtils.escapeHtml4(publication.getDescriptionPlain()); } else { metaDescription = ""; } metaTitle = publication.getName(); metaUrl = String.format("%s/gamelibrary/%s", systemSettingsController.getSiteUrl(true, true), publication.getUrlName()); metaImage = String.format("%s/gamelibrary/publicationImages/%d", systemSettingsController.getSiteUrl(true, true), publication.getDefaultImage().getId()); metaLocale = publication.getLanguage() != null ? publication.getLanguage().getLocale().toString() : ""; String description = publication.getDescription(); List<PublicationImage> images = publicationController.listPublicationImagesByPublication(publication); List<PublicationTag> publicationTags = gameLibraryTagController.listPublicationTags(publication); List<PublicationAuthor> publicationAuthors = publicationController.listPublicationAuthors(publication); tags = new ArrayList<>(); authors = new ArrayList<>(); for (PublicationTag publicationTag : publicationTags) { tags.add(publicationTag.getTag().getText()); } for (PublicationAuthor publicationAuthor : publicationAuthors) { authors.add(publicationAuthor.getAuthor()); } this.hasImage = !images.isEmpty(); this.description = StringUtils.isBlank(description) ? "" : description.replace("\n", "<br/>"); this.creativeCommonsLicence = CreativeCommonsUtils.parseLicenseUrl(publication.getLicense()); this.commentCount = publication.getForumTopic() != null ? forumController.countPostsByTopic(publication.getForumTopic()) : null; if (publication instanceof BookPublication) { downloadable = ((BookPublication) publication).getDownloadableFile() != null; purchasable = ((BookPublication) publication).getPrintableFile() != null; pageNumbers = ((BookPublication) publication).getNumberOfPages(); } return null; }
From source file:com.primeleaf.krystal.web.view.console.DocumentNotesView.java
@SuppressWarnings("unchecked") private void printDocumentNotes() throws Exception { try {/*from w w w . j a v a 2 s. c om*/ if (request.getAttribute(HTTPConstants.REQUEST_ERROR) != null) { printErrorDismissable((String) request.getAttribute(HTTPConstants.REQUEST_ERROR)); } if (request.getAttribute(HTTPConstants.REQUEST_MESSAGE) != null) { printSuccessDismissable((String) request.getAttribute(HTTPConstants.REQUEST_MESSAGE)); } ArrayList<DocumentNote> documentNotes = (ArrayList<DocumentNote>) request.getAttribute("NOTES"); out.println("<div class=\"panel panel-default\">"); out.println( "<div class=\"panel-heading\"><h4><i class=\"fa fa-comments-o fa-lg\"></i> Notes</h4></div>"); if (documentNotes.size() > 0) { out.println("<ul class=\"list-group\">"); for (DocumentNote note : documentNotes) { String cssClass = ""; if ("P".equalsIgnoreCase(note.getNoteType())) { cssClass = "text-success"; } out.println("<li class=\"list-group-item " + cssClass + "\">"); out.println("<h4>" + StringEscapeUtils.escapeHtml4(note.getNoteData()) + "</h4>"); out.println("<h5>" + StringEscapeUtils.escapeHtml4(note.getUserName()) + "</h5>"); out.println("<p>" + StringHelper.getFriendlyDateTime(note.getCreated()) + "</p>"); if (note.getUserName().equalsIgnoreCase(loggedInUser.getUserName())) { out.println("<p><a href=\"/console/documentnotes?documentid=" + note.getDocumentId() + "¬eid=" + note.getNoteId() + "\" class=\"confirm\" datatarget=\"#resultNotes\" title=\"Are you sure? you want to delete this note?\">Delete</a></p>"); } out.println("</li>"); } out.println("</ul>"); } else { out.println("<div class=\"panel-body\">"); out.println("There are no notes /comments on this document"); out.println("</div>");//panel-body } out.println("</div>");//panel } catch (Exception ex) { ex.printStackTrace(); } }
From source file:model.SentinelHttpParamVirt.java
@Override public void changeValue(String v) { String mutatedValue = ""; switch (encoderType) { case Base64://from w w w . ja v a2 s. co m byte[] b = BurpCallbacks.getInstance().getBurp().getHelpers().stringToBytes(v); mutatedValue = BurpCallbacks.getInstance().getBurp().getHelpers().base64Encode(b); break; case URL: try { mutatedValue = URLEncoder.encode(v, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SentinelHttpParamVirt.class.getName()).log(Level.SEVERE, null, ex); } break; case HTML: mutatedValue = StringEscapeUtils.escapeHtml4(v); break; default: mutatedValue = value; } this.value = mutatedValue; this.valueEnd = this.valueStart + value.length(); }
From source file:edu.utsa.sifter.SearchHit.java
public SearchHit(final Result doc, final Passage p, final String body) { DocData = doc;/*from w w w . ja v a 2 s . c o m*/ Start = p.getStartOffset(); End = p.getEndOffset(); final int n = p.getNumMatches(); if (n > 0) { final StringBuilder sb = new StringBuilder(); final int[] matchStarts = p.getMatchStarts(); final int[] matchEnds = p.getMatchEnds(); final BytesRef[] terms = p.getMatchTerms(); int curPos = Math.min(Start, matchStarts[0]); for (int i = 0; i < n; ++i) { sb.append(StringEscapeUtils.escapeHtml4(body.substring(curPos, matchStarts[i]))); sb.append("<span class=\"secondarycolorbg\">"); sb.append(StringEscapeUtils.escapeHtml4(body.substring(matchStarts[i], matchEnds[i]))); sb.append("</span>"); curPos = matchEnds[i]; MaxTermLen = Math.max(MaxTermLen, terms[i].length); } sb.append(StringEscapeUtils.escapeHtml4(body.substring(curPos, End))); Passage = sb.toString(); } else { Passage = body.substring(Start, End); } }
From source file:com.opensymphony.xwork3.DefaultActionProxy.java
/** * This constructor is private so the builder methods (create*) should be used to create an DefaultActionProxy. * <p/>/* w w w . j a va2 s . c o m*/ * The reason for the builder methods is so that you can use a subclass to create your own DefaultActionProxy instance * (like a RMIActionProxy). */ protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean cleanupContext) { this.invocation = inv; this.cleanupContext = cleanupContext; if (LOG.isDebugEnabled()) { LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", namespace, actionName); } this.actionName = StringEscapeUtils.escapeHtml4(actionName); this.namespace = namespace; // this.executeResult = executeResult; this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName)); }
From source file:ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor.java
private String format(String theResultBody, EncodingEnum theEncodingEnum) { String str = StringEscapeUtils.escapeHtml4(theResultBody); if (str == null || theEncodingEnum == null) { return str; }//w w w .j av a2 s .c o m StringBuilder b = new StringBuilder(); if (theEncodingEnum == EncodingEnum.JSON) { boolean inValue = false; boolean inQuote = false; for (int i = 0; i < str.length(); i++) { char prevChar = (i > 0) ? str.charAt(i - 1) : ' '; char nextChar = str.charAt(i); char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' '; char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' '; char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' '; char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' '; char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' '; if (inQuote) { b.append(nextChar); if (prevChar != '\\' && nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') { b.append("quot;</span>"); i += 5; inQuote = false; } else if (nextChar == '\\' && nextChar2 == '"') { b.append("quot;</span>"); i += 5; inQuote = false; } } else { if (nextChar == ':') { inValue = true; b.append(nextChar); } else if (nextChar == '[' || nextChar == '{') { b.append("<span class='hlControl'>"); b.append(nextChar); b.append("</span>"); inValue = false; } else if (nextChar == '}' || nextChar == '}' || nextChar == ',') { b.append("<span class='hlControl'>"); b.append(nextChar); b.append("</span>"); inValue = false; } else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') { if (inValue) { b.append("<span class='hlQuot'>""); } else { b.append("<span class='hlTagName'>""); } inQuote = true; i += 5; } else if (nextChar == ':') { b.append("<span class='hlControl'>"); b.append(nextChar); b.append("</span>"); inValue = true; } else { b.append(nextChar); } } } } else { boolean inQuote = false; boolean inTag = false; for (int i = 0; i < str.length(); i++) { char nextChar = str.charAt(i); char nextChar2 = (i + 1) < str.length() ? str.charAt(i + 1) : ' '; char nextChar3 = (i + 2) < str.length() ? str.charAt(i + 2) : ' '; char nextChar4 = (i + 3) < str.length() ? str.charAt(i + 3) : ' '; char nextChar5 = (i + 4) < str.length() ? str.charAt(i + 4) : ' '; char nextChar6 = (i + 5) < str.length() ? str.charAt(i + 5) : ' '; if (inQuote) { b.append(nextChar); if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') { b.append("quot;</span>"); i += 5; inQuote = false; } } else if (inTag) { if (nextChar == '&' && nextChar2 == 'g' && nextChar3 == 't' && nextChar4 == ';') { b.append("</span><span class='hlControl'>></span>"); inTag = false; i += 3; } else if (nextChar == ' ') { b.append("</span><span class='hlAttr'>"); b.append(nextChar); } else if (nextChar == '&' && nextChar2 == 'q' && nextChar3 == 'u' && nextChar4 == 'o' && nextChar5 == 't' && nextChar6 == ';') { b.append("<span class='hlQuot'>""); inQuote = true; i += 5; } else { b.append(nextChar); } } else { if (nextChar == '&' && nextChar2 == 'l' && nextChar3 == 't' && nextChar4 == ';') { b.append("<span class='hlControl'><</span><span class='hlTagName'>"); inTag = true; i += 3; } else { b.append(nextChar); } } } } return b.toString(); }
From source file:com.primeleaf.krystal.web.view.WebView.java
public void printErrorDismissable(String message) throws Exception { out.println(//from w ww.jav a2 s .co m "<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>" + StringEscapeUtils.escapeHtml4(message) + "</div>"); }
From source file:de.blizzy.documentr.markdown.macro.impl.FlattrMacro.java
@Override public String getHtml(IMacroContext macroContext) { try {//from ww w .j a va 2s . com IMacroSettings settings = macroContext.getSettings(); String userId = settings.getSetting("userId"); //$NON-NLS-1$ if (StringUtils.isNotBlank(userId)) { HtmlSerializerContext htmlSerializerContext = macroContext.getHtmlSerializerContext(); String projectName = htmlSerializerContext.getProjectName(); String branchName = htmlSerializerContext.getBranchName(); String path = htmlSerializerContext.getPagePath(); String pageUri = htmlSerializerContext.getPageUri(path); String pageUrl = htmlSerializerContext.getUrl(pageUri); IPageStore pageStore = htmlSerializerContext.getPageStore(); Page page = pageStore.getPage(projectName, branchName, path, false); String title = page.getTitle(); String tags = StringUtils.join(page.getTags(), ","); //$NON-NLS-1$ // http://developers.flattr.net/auto-submit/ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("https://flattr.com/submit/auto") //$NON-NLS-1$ .queryParam("user_id", userId) //$NON-NLS-1$ .queryParam("url", pageUrl) //$NON-NLS-1$ .queryParam("title", title) //$NON-NLS-1$ .queryParam("category", "text"); //$NON-NLS-1$ //$NON-NLS-2$ if (StringUtils.isNotBlank(tags)) { builder.queryParam("tags", tags); //$NON-NLS-1$ } String url = builder.build().encode(Charsets.UTF_8.name()).toUriString(); return "<a href=\"" + StringEscapeUtils.escapeHtml4(url) + "\">" + //$NON-NLS-1$ //$NON-NLS-2$ "<img src=\"https://api.flattr.com/button/flattr-badge-large.png\"/></a>"; //$NON-NLS-1$ } } catch (IOException e) { log.warn("error while rendering Flattr macro", e); //$NON-NLS-1$ } return null; }
From source file:com.opensymphony.xwork2.DefaultActionProxy.java
/** * This constructor is private so the builder methods (create*) should be used to create an DefaultActionProxy. * <p/>//from www .j av a2s . c o m * The reason for the builder methods is so that you can use a subclass to create your own DefaultActionProxy instance * (like a RMIActionProxy). */ protected DefaultActionProxy(ActionInvocation inv, String namespace, String actionName, String methodName, boolean executeResult, boolean cleanupContext) { this.invocation = inv; this.cleanupContext = cleanupContext; if (LOG.isDebugEnabled()) { LOG.debug("Creating an DefaultActionProxy for namespace [#0] and action name [#1]", namespace, actionName); } this.actionName = StringEscapeUtils.escapeHtml4(actionName); this.namespace = namespace; this.executeResult = executeResult; this.method = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(methodName)); }
From source file:com.primeleaf.krystal.web.view.cpanel.RecycleBinView.java
@SuppressWarnings("unchecked") private void printDocumentClasses() throws Exception { printBreadCrumbs();/* ww w . ja v a 2 s . c o m*/ if (request.getAttribute(HTTPConstants.REQUEST_ERROR) != null) { printErrorDismissable((String) request.getAttribute(HTTPConstants.REQUEST_ERROR)); } if (request.getAttribute(HTTPConstants.REQUEST_MESSAGE) != null) { printSuccessDismissable((String) request.getAttribute(HTTPConstants.REQUEST_MESSAGE)); } out.println("<div class=\"panel panel-default\">"); out.println("<div class=\"panel-heading\">"); out.println("<h4><i class=\"fa fa-trash-o fa-lg\"></i> Recyle Bin</h4>"); out.println("</div>"); try { ArrayList<DocumentClass> documentClassList = (ArrayList<DocumentClass>) request .getAttribute("CLASSLIST"); if (documentClassList.size() > 0) { out.println("<ul class=\"list-group\">"); for (DocumentClass documentClass : documentClassList) { int deletedDocuments = (Integer) request .getAttribute(documentClass.getClassName() + "_DELETED"); int expiredDocuments = (Integer) request .getAttribute(documentClass.getClassName() + "_EXPIRED"); out.println("<li class=\"list-group-item\">"); out.println("<div class=\"row\">"); out.println("<div class=\"col-xs-8\">"); out.println("<h4 class=\"text-danger\">" + StringEscapeUtils.escapeHtml4(documentClass.getClassName()) + "</h4>"); out.println( "<h5>" + StringEscapeUtils.escapeHtml4(documentClass.getClassDescription()) + "</h5>"); out.println("</div>"); out.println("<a href=\"" + HTTPConstants.BASEURL + "/cpanel/recyclebincontent?type=" + Hit.STATUS_DELETED + "&classid=" + documentClass.getClassId() + "\" class=\"text-success\">"); out.println("<div class=\"col-xs-2 text-right\">"); out.println("<p>Deleted</p>"); out.println("<h4>" + deletedDocuments + "</h4>"); out.println("<p>Documents</p>"); out.println("</div>"); out.println("</a>"); out.println("<a href=\"" + HTTPConstants.BASEURL + "/cpanel/recyclebincontent?type=" + Hit.STATUS_EXPIRED + "&classid=" + documentClass.getClassId() + "\" class=\"text-success\">"); out.println("<div class=\"col-xs-2 text-right\">"); out.println("<p>Expired</p>"); out.println("<h4>" + expiredDocuments + "</h4>"); out.println("<p>Documents</p>"); out.println("</div>"); out.println("</a>"); out.println("</div>"); out.println("</li>"); } // for out.println("</ul>"); } else { out.println("<div class=\"panel-body\">"); out.println("There are no Deleted or Expired documents found in any of the Document Classes"); out.println("</div>"); } out.println("</div>"); } catch (Exception e) { e.printStackTrace(); } }