List of usage examples for org.apache.commons.lang StringEscapeUtils escapeHtml
public static String escapeHtml(String input)
From source file:com.edgenius.wiki.render.handler.GalleryMacroHandler.java
public List<RenderPiece> handle(RenderContext renderContext, Map<String, String> values) throws RenderHandlerException { if (atts == null) { throw new RenderHandlerException("No attachmnets."); }/* w ww. j a v a 2 s .c o m*/ List<FileNode> images = getImageList(values.get("filter"), renderContext.getPageVisibleAttachments()); if (images.size() == 0) { throw new RenderHandlerException("No valid images in attachment list."); } List<RenderPiece> pieces = new ArrayList<RenderPiece>(); Map<String, String> wajaxMap = new HashMap<String, String>(); if (!StringUtils.isBlank(values.get("filter"))) { wajaxMap.put("filter", values.get("filter")); } List<String> urls = new ArrayList<String>(); //try to find the image from repository for (FileNode node : images) { //found attachment urls.add(renderContext.buildDownloadURL(node.getFilename(), node.getNodeUuid(), false)); } int width = DEFAULT_THUMB_WIDTH; int height = DEFAULT_THUMB_HEIGHT; String size = values.get("thumbsize"); if (size != null) { String[] si = size.split("\\*"); if (si.length == 2) { width = NumberUtils.toInt(si[0], DEFAULT_THUMB_WIDTH); height = NumberUtils.toInt(si[1], DEFAULT_THUMB_HEIGHT); } else if (si.length == 1) { width = NumberUtils.toInt(si[0], DEFAULT_THUMB_WIDTH); height = width; } wajaxMap.put("thumbsize", size); } int mxCol = DEFAULT_MATRIX_COLUMN; String column = values.get("column"); if (column != null) { mxCol = NumberUtils.toInt(column, DEFAULT_MATRIX_COLUMN); wajaxMap.put("column", column); } int id = renderContext.createIncremetalKey(); String wajax = RichTagUtil.buildWajaxAttributeString(GalleryMacro.class.getName(), wajaxMap); Map<String, String> attributes = new HashMap<String, String>(); attributes.put("aid", "gallery"); attributes.put("class", "macroGallery " + WikiConstants.mceNonEditable); attributes.put("id", "renderGalleryID-" + id); attributes.put(NameConstants.WAJAX, wajax); StringBuffer imgBuf = new StringBuffer(HTMLUtil.buildTagString("div", null, attributes)); int count = 0; int sum = urls.size(); while (count < sum) { imgBuf.append("<ul>"); for (int idj = 0; idj < mxCol && count < sum; idj++) { imgBuf.append("<li><a href=\""); imgBuf.append(urls.get(count)); imgBuf.append("\" title=\""); imgBuf.append(StringEscapeUtils.escapeHtml(images.get(count).getComment())); imgBuf.append("\"/><img src=\""); imgBuf.append(urls.get(count)); imgBuf.append("\" width=\""); imgBuf.append(width); imgBuf.append("\" height=\""); imgBuf.append(height); imgBuf.append("\"/></a></li>"); count++; } imgBuf.append("</ul>"); } imgBuf.append("</div>"); pieces.add(new TextModel(imgBuf.toString())); return pieces; }
From source file:ch.entwine.weblounge.common.impl.util.doc.Parameter.java
/** * Returns an <code>HTML</code> escaped version of the default value. * //from w w w . ja v a 2 s .c o m * @return the escaped default value */ public String getDefaultValueHtml() { return StringEscapeUtils.escapeHtml(defaultValue); }
From source file:edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils.java
public static String getRequestParam(HttpServletRequest req) { String val = "<table>"; Enumeration names = req.getParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); val += "\n\t<tr><td><h3>" + name + "</h3><td><pre>"; String value = null;//from w ww . j av a 2 s.co m try { Object obj = req.getParameter(name); value = (obj == null) ? "[null]" : StringEscapeUtils.escapeHtml(obj.toString()); } catch (Exception ex) { value = "unable to get value"; } catch (Error er) { value = "unable to get value"; } catch (Throwable th) { value = "unable to get value"; } val += value + "</pre><td></tr>\n"; } return val + "</table>"; }
From source file:com.predic8.membrane.core.http.Response.java
private static String htmlMessage(String caption, String text) { return unescapedHtmlMessage(StringEscapeUtils.escapeHtml(caption), StringEscapeUtils.escapeHtml(text)); }
From source file:de.fhg.fokus.openride.services.rating.RatingService.java
@GET @Produces("text/json") public Response getRatings(@Context HttpServletRequest con, @PathParam("username") String username) { System.out.println("getRatings start"); if (!username.equals(con.getRemoteUser())) { /*// w w w . ja v a 2 s. c o m * Ratings may be requested by any logged in user? * return Response.status(Response.Status.FORBIDDEN).build(); */ } CustomerEntity c = customerControllerBean.getCustomerByNickname(username); // build a List of Objects that shall be available in the JSON context. ArrayList list = new ArrayList(); list.add(new ReceivedRatingResponse()); XStream x = Utils.getJasonXStreamer(list); List<RiderUndertakesRideEntity> receivedRatingsAsRider; List<RiderUndertakesRideEntity> receivedRatingsAsDriver; receivedRatingsAsRider = riderUndertakesRideControllerBean.getRatedRidesByRider(c); receivedRatingsAsDriver = riderUndertakesRideControllerBean.getRatedRidesByDriver(c); ArrayList receivedRatings = new ArrayList(); ReceivedRatingResponse response; for (RiderUndertakesRideEntity ride : receivedRatingsAsRider) { response = new ReceivedRatingResponse(); response.setCustRole("d".charAt(0)); // this is a driver's rating response.setCustId(ride.getRideId().getCustId().getCustId()); response.setCustNickname(ride.getRideId().getCustId().getCustNickname()); response.setCustGender(ride.getRideId().getCustId().getCustGender()); // TODO: This should be replaced with Timestamprealized once this is set! response.setTimestamprealized(ride.getStarttimeEarliest().getTime()); //response.setTimestamprealized(ride.getTimestamprealized().getTime()); response.setReceivedRating(ride.getReceivedrating()); response.setReceivedRatingComment(StringEscapeUtils.escapeHtml(ride.getReceivedratingComment())); receivedRatings.add(response); } for (RiderUndertakesRideEntity ride : receivedRatingsAsDriver) { response = new ReceivedRatingResponse(); response.setCustRole("r".charAt(0)); // this is a rider's rating response.setCustId(ride.getCustId().getCustId()); response.setCustNickname(ride.getCustId().getCustNickname()); response.setCustGender(ride.getCustId().getCustGender()); // TODO: This should be replaced with Timestamprealized once this is set! response.setTimestamprealized(ride.getStarttimeEarliest().getTime()); //response.setTimestamprealized(ride.getTimestamprealized().getTime()); response.setReceivedRating(ride.getGivenrating()); response.setReceivedRatingComment(ride.getGivenratingComment()); receivedRatings.add(response); } // sort receivedRatings list by timestamprealized! Collections.sort(receivedRatings); return Response.ok(x.toXML(receivedRatings)).build(); }
From source file:de.xwic.sandbox.base.model.StringUtil.java
/** * escapes Html and then replaces all \n and \r\n with <br /> * //from ww w . ja v a 2 s . c om * @param string * @return "" if string is <code>null</code> */ public static String toHtmlString(String string) { if (string == null) { return ""; } String ds = StringEscapeUtils.escapeHtml(string); String replaceAll = ds.replaceAll("(\n\r)|\n", "<br />"); return replaceAll; }
From source file:io.github.tavernaextras.biocatalogue.ui.search_results.ServiceListCellRenderer.java
/** * //from ww w . j a va 2 s . co m * @param itemToRender * @param expandedView <code>true</code> to indicate that this method generates the top * fragment of the expanded list entry for this SOAP operation / REST method. * @return */ protected GridBagConstraints prepareLoadedEntry(Object itemToRender, boolean selected) { TYPE resourceType = determineResourceType(itemToRender); Service service = (Service) itemToRender; ; // service type if (service.getServiceTechnologyTypes() != null && service.getServiceTechnologyTypes().getTypeList().size() > 0) { if (service.getServiceTechnologyTypes().getTypeList().size() > 1 && !(service.getServiceTechnologyTypes().getTypeList().get(0).toString() .equalsIgnoreCase("SOAP")) && service.getServiceTechnologyTypes().getTypeList().get(1).toString() .equalsIgnoreCase("SOAPLAB")) { jlTypeIcon = new JLabel(ResourceManager.getImageIcon(ResourceManager.SERVICE_TYPE_MULTITYPE_ICON)); } else if (service.getServiceTechnologyTypes().getTypeArray(0).toString().equalsIgnoreCase("SOAP")) { jlTypeIcon = new JLabel(ResourceManager.getImageIcon(ResourceManager.SERVICE_TYPE_SOAP_ICON)); } else if (service.getServiceTechnologyTypes().getTypeArray(0).toString().equalsIgnoreCase("REST")) { jlTypeIcon = new JLabel(ResourceManager.getImageIcon(ResourceManager.SERVICE_TYPE_REST_ICON)); } } else { // can't tell the type - just show as a service of no particular type jlTypeIcon = new JLabel(resourceType.getIcon()); } // service status jlItemStatus = new JLabel(ServiceMonitoringStatusInterpreter.getStatusIcon(service, true)); jlItemTitle = new JLabel(Resource.getDisplayNameForResource(service), JLabel.LEFT); jlItemTitle.setForeground(Color.decode("#AD0000")); // very dark red jlItemTitle.setFont(jlItemTitle.getFont().deriveFont(Font.PLAIN, jlItemTitle.getFont().getSize() + 2)); int descriptionMaxLength = DESCRIPTION_MAX_LENGTH_EXPANDED; String strDescription = Util.stripAllHTML(service.getDescription()); strDescription = (strDescription == null || strDescription.length() == 0 ? "<font color=\"gray\">no description</font>" : StringEscapeUtils .escapeHtml(Util.ensureLineLengthWithinString(strDescription, LINE_LENGTH, false))); if (strDescription.length() > descriptionMaxLength) { strDescription = strDescription.substring(0, descriptionMaxLength) + "<font color=\"gray\">(...)</font>"; } strDescription = "<html><b>Description: </b>" + strDescription + "</html>"; jlDescription = new JLabel(strDescription); return (arrangeLayout(true)); }
From source file:ch.threema.apitool.ConsoleMain.java
private static void usage(boolean htmlOutput) { if (!htmlOutput) { System.out.println("version:" + ConsoleMain.class.getPackage().getImplementationVersion()); System.out.println("usage:\n"); System.out.println("General information"); System.out.println("-------------------\n"); System.out.println("Where a key needs to be specified, it can either be given directly as"); System.out.println("a command line parameter (in hex with a prefix indicating the type;"); System.out.println("not recommended on shared machines as other users may be able to see"); System.out.println("the arguments), or as the path to a file that it should be read from"); System.out.println("(file contents also in hex with the prefix).\n"); }/*www.j a v a2 s.c o m*/ String groupDescriptionTemplate = htmlOutput ? "<h3>%s</h3>\n" : "\n%s\n" + StringUtils.repeat("-", 80) + "\n\n"; String commandTemplate = htmlOutput ? "<pre><code>java -jar threema-msgapi-tool.jar %s</code></pre>\n" : "%s\n"; for (CommandGroup commandGroup : commands.commandGroups) { System.out.format(groupDescriptionTemplate, commandGroup.description); for (ArgumentCommand argumentCommand : commandGroup.argumentCommands) { StringBuilder command = new StringBuilder(); for (int n = 0; n < argumentCommand.arguments.length; n++) { command.append(argumentCommand.arguments[n]).append(" "); } String argumentDescription = argumentCommand.command.getUsageArguments(); if (htmlOutput) { System.out.format("<h4>%s</h4>\n", argumentCommand.command.getSubject()); argumentDescription = StringEscapeUtils.escapeHtml(argumentDescription); } command.append(argumentDescription); System.out.format(commandTemplate, command.toString().trim()); String description = argumentCommand.command.getUsageDescription(); if (htmlOutput) { System.out.format("<p>%s</p>\n\n", description); } else { System.out.println(" " + WordUtils.wrap(description, 76, "\n ", false)); System.out.println(""); } } } }
From source file:com.igormaznitsa.mindmap.plugins.exporters.MDExporter.java
private static void writeTopic(@Nonnull final Topic topic, @Nonnull final String listPosition, @Nonnull final State state) throws IOException { final int level = topic.getTopicLevel(); String prefix = "";//NOI18N final String topicUid = getTopicUid(topic); if (topicUid != null) { state.append("<a name=\"").append(topicUid).append("\">").nextLine();//NOI18N }/* w ww . ja va 2s .c om*/ if (level < STARTING_INDEX_FOR_NUMERATION) { final String headerPrefix = generateString('#', topic.getTopicLevel() + 1);//NOI18N state.append(headerPrefix).append(' ').append(ModelUtils.escapeMarkdownStr(topic.getText())).nextLine(); } else { final String headerPrefix = generateString('#', STARTING_INDEX_FOR_NUMERATION + 1);//NOI18N state.append(prefix).append(headerPrefix).append(' ').append(listPosition).append(' ') .append(ModelUtils.escapeMarkdownStr(topic.getText())).nextLine(); } final ExtraFile file = (ExtraFile) topic.getExtras().get(Extra.ExtraType.FILE); final ExtraLink link = (ExtraLink) topic.getExtras().get(Extra.ExtraType.LINK); final ExtraNote note = (ExtraNote) topic.getExtras().get(Extra.ExtraType.NOTE); final ExtraTopic transition = (ExtraTopic) topic.getExtras().get(Extra.ExtraType.TOPIC); boolean extrasPrinted = false; if (transition != null) { final Topic linkedTopic = topic.getMap().findTopicForLink(transition); if (linkedTopic != null) { state.append(prefix).append("*Related to: ")//NOI18N .append('[')//NOI18N .append(ModelUtils.escapeMarkdownStr(makeLineFromString(linkedTopic.getText()))) .append("](")//NOI18N .append("#")//NOI18N .append(assertNotNull(getTopicUid(linkedTopic))).append(")*")//NOI18N .nextStringMarker().nextLine(); extrasPrinted = true; if (file != null || link != null || note != null) { state.nextStringMarker().nextLine(); } } } if (file != null) { final MMapURI fileURI = file.getValue(); state.append(prefix).append("> File: ")//NOI18N .append(ModelUtils.escapeMarkdownStr( fileURI.isAbsolute() ? fileURI.asFile(null).getAbsolutePath() : fileURI.toString())) .nextStringMarker().nextLine(); extrasPrinted = true; } if (link != null) { final String url = link.getValue().toString(); final String ascurl = link.getValue().asString(true, true); state.append(prefix).append("> Url: ")//NOI18N .append('[')//NOI18N .append(ModelUtils.escapeMarkdownStr(url)).append("](")//NOI18N .append(ascurl).append(')')//NOI18N .nextStringMarker().nextLine(); extrasPrinted = true; } if (note != null) { if (extrasPrinted) { state.nextLine(); } state.append(prefix).append("<pre>")//NOI18N .append(StringEscapeUtils.escapeHtml(note.getValue())).append("</pre>")//NOI18N .nextLine(); } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopLabel.java
private void updateLabel(String text) { if (!htmlEnabled) { text = StringEscapeUtils.escapeHtml(text); if (getWidth() > 0 && getHeight() <= 0) { text = ComponentsHelper.preprocessHtmlMessage("<html>" + text + "</html>"); } else {// w w w .j a va 2s .c om text = ComponentsHelper.preprocessHtmlMessage("<html><nobr>" + text + "</nobr></html>"); } } else { text = "<html>" + text + "</html>"; } impl.setText(text); }