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.primeleaf.krystal.web.view.console.HomeView.java
@SuppressWarnings("unchecked") private void printBookmarks() { try {/* w ww . j a v a 2 s . co m*/ out.println("<div class=\"panel panel-default\">"); out.println("<div class=\"panel-heading\">"); out.println("<h5><i class=\"fa fa-bookmark fa-lg \"></i> Bookmarks</h5>"); out.println("</div>"); ArrayList<Bookmark> bookmarkList = (ArrayList<Bookmark>) request.getAttribute("BOOKMARKS"); if (bookmarkList.size() > 0) { out.println("<ul class=\"list-group\">"); for (Bookmark bookmark : bookmarkList) { out.println("<li class=\"list-group-item\">"); out.println("<h4 class=\"\">" + StringEscapeUtils.escapeHtml4(bookmark.getBookmarkName()) + "</h4>"); out.println("<h5>Document ID : " + bookmark.getDocumentId() + " Revision ID : " + bookmark.getRevisionId() + "</h5>"); out.println("<p><h6>"); out.println("<a href=\"/console/viewdocument?documentid=" + bookmark.getDocumentId() + "&revisionid=" + bookmark.getRevisionId() + "\" title=\"View Document\">View Document</a>"); out.println(" | <a href=\"/console/deletebookmark?bookmarkid=" + bookmark.getBookmarkId() + "\" class=\"confirm\" title=\"Are you sure you want to delete bookmark?\">Delete Bookmark</a>"); out.println("</h6></p>"); out.println("</li>");//list-group-item } // for } else { out.println("<div class=\"panel-body\">"); out.println("There are no bookmarks available currently"); out.println("</div>"); } out.println("</div>"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:carisma.ui.eclipse.CarismaGUI.java
/** * //from ww w .j a va2s. c o m * @param analysisResult * the analysis result * */ /* * * Currently changed to output HTML-Files */ public final static void openReport(final AnalysisResult analysisResult) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IContainer container = analysisResult.getAnalysis().getIFile().getParent(); IFile file = null; if (container instanceof IFolder) { IFolder folder = (IFolder) container; file = folder .getFile("report-" + analysisResult.getName() + "-" + analysisResult.getTimestamp() + ".html"); // changedfrom // txt } else if (container instanceof IProject) { IProject project = (IProject) container; file = project .getFile("report-" + analysisResult.getName() + "-" + analysisResult.getTimestamp() + ".html"); // changedfrom // txt } else { Logger.log(LogLevel.ERROR, "Analyzed file is not part of a project."); return; } // new... String htmlOpen = "<!DOCTYPE html>\n" + "<html lang=\"de\">\n" + "<head>\n" + "\t<meta charset=\"utf-8\">\n" + "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" + "\t<title>CARiSMA Report</title>\n" + "</head>\n" + "<body>\n" + "\t<p>\n\t"; String htmlClose = "</p>\n" + "</body>\n" + "</html>"; String htmlBody = StringEscapeUtils.escapeHtml4(analysisResult.getReport()); htmlBody = htmlBody.replace("\t", " ").replaceAll("\\r|\\n", "<br/>" + System.lineSeparator() + "\t"); String html = (htmlOpen + htmlBody + htmlClose); try { if (!(file.exists())) { //file.create(Utils.createInputStreamFromString(analysisResult.getReport()), true, null); file.create(StringInputStream.createInputStreamFromString(html), true, null); } IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); try { page.openEditor(new FileEditorInput(file), desc.getId()); } catch (PartInitException e) { Logger.log(LogLevel.ERROR, "Could not start editor, \"" + desc.getId() + "\".", e); } } catch (CoreException e) { Logger.log(LogLevel.ERROR, "", e); } }
From source file:annis.gui.paging.PagingComponent.java
/** * Cuts off long queries. Actually they are restricted to 50 characters. The * full query is available with descriptions (tooltip in gui) * * @param text the query to display in the result view panel */// w w w.j av a 2 s. co m public void setInfo(String text) { if (text != null && text.length() > 0) { String prefix = "Result for: <span class=\"" + Helper.CORPUS_FONT_FORCE + "\">"; lblInfo.setDescription(prefix + text.replaceAll("\n", " ") + "</span>"); lblInfo.setValue( text.length() < 50 ? prefix + StringEscapeUtils.escapeHtml4(text.substring(0, text.length())) : prefix + StringEscapeUtils.escapeHtml4(text.substring(0, 50)) + " ... </span>"); } }
From source file:me.vertretungsplan.utils.SubstitutionTextUtils.java
private static String simpleDiff(String oldS, String newS) { if (hasData(oldS) && hasData(newS)) { if (oldS.equals(newS)) { return StringEscapeUtils.escapeHtml4(oldS); } else {//ww w . j a v a 2 s .c o m return String.format("<del>%s</del><ins>%s</ins>", StringEscapeUtils.escapeHtml4(oldS), StringEscapeUtils.escapeHtml4(newS)); } } else { return commonDiff(oldS, newS); } }
From source file:com.searchcode.app.service.CodeMatcher.java
/** * Given a string and the terms we want to highlight attempts to parse it apart and surround the matching * terms with <strong> tags.// ww w. j a v a2 s. com * TODO a bug exists here, see test cases for details */ public String highlightLine(String line, List<String> matchTerms) throws StringIndexOutOfBoundsException { List<String> terms = matchTerms.stream() .filter(s -> !"AND".equals(s) && !"OR".equals(s) && !"NOT".equals(s)).map(s -> s.toLowerCase()) .collect(Collectors.toList()); List<String> tokens = Arrays.asList(line.split(" ")); List<String> returnList = new ArrayList<>(); for (String token : tokens) { String longestTerm = ""; for (String term : terms) { // Find the longest matching if (term.replace(")", "").endsWith("*")) { if (token.toLowerCase().contains(term.replace(")", "").replace("*", ""))) { if (term.length() > longestTerm.length()) { longestTerm = term; } } } else { if (token.toLowerCase().contains(term)) { if (term.length() > longestTerm.length()) { longestTerm = term; } } } } if (!"".equals(longestTerm)) { if (longestTerm.replace(")", "").endsWith("*")) { int loc = token.toLowerCase().indexOf(longestTerm.replace(")", "").replace("*", "")); returnList.add(StringEscapeUtils.escapeHtml4(token.substring(0, loc)) + "<strong>" + StringEscapeUtils.escapeHtml4(token.substring(loc, token.length())) + "</strong>"); } else { int loc = token.toLowerCase().indexOf(longestTerm); returnList.add(StringEscapeUtils.escapeHtml4(token.substring(0, loc)) + "<strong>" + StringEscapeUtils.escapeHtml4(token.substring(loc, loc + longestTerm.length())) + "</strong>" + this.highlightLine( token.substring(loc + longestTerm.length(), token.length()), matchTerms)); } } else { returnList.add(StringEscapeUtils.escapeHtml4(token)); } } return StringUtils.join(returnList, " "); }
From source file:me.vertretungsplan.utils.SubstitutionTextUtils.java
private static String commonDiff(String oldS, String newS) { if (hasData(oldS)) { return String.format("<del>%s</del>", StringEscapeUtils.escapeHtml4(oldS)); } else if (hasData(newS)) { return String.format("<ins>%s</ins>", StringEscapeUtils.escapeHtml4(newS)); } else {/*from w w w .j ava2 s . c om*/ return ""; } }
From source file:at.gv.egovernment.moa.id.advancedlogging.StatisticLogger.java
private String getErrorMessageWithMaxLength(String error, int maxlength) { if (error != null) { if (error.length() > maxlength) return StringEscapeUtils.escapeHtml4(error.substring(0, maxlength)); else//from ww w. j ava2 s . com return StringEscapeUtils.escapeHtml4(error); } else return new String(); }
From source file:com.nttec.everychan.ui.downloading.HtmlBuilder.java
private void buildPost(PostModel model, boolean isOpPost) throws IOException { if (!isOpPost && !writeDeleted && model.deleted) return;// w w w. ja va 2s . co m if (!isOpPost) { buf.write("<table><tbody><tr><td class=\"doubledash\">>></td> <td class=\"reply\" id=\"reply"); buf.write(model.number); buf.write("\"> "); } buf.write("<a name=\""); buf.write(model.number); buf.write("\"></a> <label><input type=\"checkbox\" name=\"delete\" value=\""); buf.write(model.number); buf.write("\" /> <span class=\""); buf.write(isOpPost ? "filetitle" : "replytitle"); buf.write("\">"); if (model.subject != null) buf.write(StringEscapeUtils.escapeHtml4(model.subject)); buf.write("</span> <span class=\""); if (!isOpPost) buf.write("comment"); buf.write("postername\">"); if (model.color != Color.TRANSPARENT) { buf.write("<font color=\""); buf.write(String.format("#%06X", (0xFFFFFF & model.color))); buf.write("\">■</font>"); } String name = StringEscapeUtils.escapeHtml4(model.name == null ? model.email : model.name); if (name != null) { if (model.email != null && model.email.length() != 0) { buf.write("<a href=\""); if (!model.email.contains(":")) buf.write("mailto:"); buf.write(model.email); buf.write("\">"); buf.write(name); buf.write("</a>"); } else buf.write(name); } buf.write("</span> "); if (model.icons != null) { boolean firstIcon = true; for (BadgeIconModel icon : model.icons) { if (!firstIcon) buf.write(" "); firstIcon = false; buf.write("<img hspace=\"3\" src=\""); buf.write(refsGetter.getIcon(icon)); buf.write("\" title=\""); buf.write((icon.description != null && icon.description.length() != 0) ? icon.description : (icon.source == null ? "" : icon.source.substring(icon.source.lastIndexOf('/') + 1))); buf.write("\" border=\"0\" />"); } buf.write(' '); } if (model.trip != null && model.trip.length() != 0) { buf.write("<span class=\"postertrip\">"); buf.write(StringEscapeUtils.escapeHtml4(model.trip)); buf.write("</span> "); } if (model.op) buf.write("<span class=\"opmark\"># OP</span> "); buf.write(StringEscapeUtils.escapeHtml4(dateFormat.format(model.timestamp))); buf.write("</label> <span class=\"reflink\"> <a href=\"javascript:insert('>>"); buf.write(model.number); buf.write("')\">No."); buf.write(model.number); buf.write("</a> </span>"); if (model.deleted) buf.write("<span class=\"de-post-deleted\"></span>"); buf.write(" "); if (model.attachments != null && model.attachments.length != 0) { buf.write("<br />"); boolean single = model.attachments.length == 1; for (AttachmentModel attachment : model.attachments) buildAttachment(attachment, single); if (!single) buf.write("<br clear=\"left\" />"); } buf.write("<blockquote>"); buf.write(fixComment(model.comment)); buf.write("</blockquote>"); if (!isOpPost) { buf.write("</td></tr></tbody></table>"); } }
From source file:com.day.cq.wcm.foundation.ImageMap.java
/** * Returns the HTML code required for the image map. * <p>/*from w w w. ja va 2s . co m*/ * Parameters <code>originalSize</code> and <code>scaled</code> can be used to create * a scaled map that is suitable for a scaled image. * * @param id id of the image map * @return HTML code representing the image map */ public String draw(String id) { StringBuilder htmlCode = new StringBuilder(128); htmlCode.append("<map name=\"").append(id).append("\">"); for (ImageArea areaToDraw : this.areas) { htmlCode.append("<area shape=\"").append(areaToDraw.getType()).append("\""); String coords = areaToDraw.getCoordinates(); htmlCode.append(" coords=\"").append(coords).append("\""); String href = areaToDraw.getHref(); if (href != null) { if (href.startsWith("/")) { int extensionPos = href.lastIndexOf("."); int slashPos = href.lastIndexOf("/"); if ((extensionPos < 0) || (extensionPos < slashPos)) { href += ".html"; } } htmlCode.append(" href=\"").append(href).append("\""); } String altText = areaToDraw.getAltText(); if (altText != null) { htmlCode.append(" alt=\"").append(StringEscapeUtils.escapeHtml4(altText)).append("\""); htmlCode.append(" title=\"").append(StringEscapeUtils.escapeHtml4(altText)).append("\""); } String target = areaToDraw.getTarget(); if (target != null) { htmlCode.append(" target=\"").append(target).append("\""); } htmlCode.append(">"); } htmlCode.append("</map>"); log.debug("Image map HTML code: {}", htmlCode); return htmlCode.toString(); }
From source file:com.github.xbn.linefilter.alter.NewTextLineAltererFor.java
public String getAlteredPostResetCheck(String ignored, String to_alter) { declareAltered(Altered.YES, NeedsToBeDeleted.NO); return StringEscapeUtils.escapeHtml4(to_alter); }