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:org.rapidoid.html.Tags.java
public static String escape(String s) { return StringEscapeUtils.escapeHtml4(s); }
From source file:org.roda.core.util.EmailUtility.java
/** * @param from/* w w w . j a v a 2s . c o m*/ * @param recipients * @param subject * @param message * @throws MessagingException */ public void sendMail(String from, String recipients[], String subject, String message) throws MessagingException { boolean debug = false; // Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", this.smtpHost); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Optional : You can also set your custom headers in the Email if you // want // msg.addHeader("MyHeaderName", "myHeaderValue"); String htmlMessage = String.format( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<html><body><pre>%s</pre></body></html>", StringEscapeUtils.escapeHtml4(message)); MimeMultipart mimeMultipart = new MimeMultipart(); MimeBodyPart mimeBodyPart = new MimeBodyPart(); mimeBodyPart.setContent(htmlMessage, "text/html;charset=UTF-8"); mimeMultipart.addBodyPart(mimeBodyPart); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(mimeMultipart); // msg.setContent(message, "text/plain;charset=UTF-8"); Transport.send(msg); }
From source file:org.rythmengine.utils.S.java
/** * Return a {@link org.rythmengine.utils.RawData} type wrapper of * an object with HTML escaping//from w w w . j a v a 2 s. co m * <p/> * <p>Object is {@link #toString(Object) converted to String} before escaping</p> * * @param o * @return html escaped data */ @Transformer public static RawData escapeHTML(Object o) { if (null == o) return RawData.NULL; if (o instanceof RawData) { return (RawData) o; } return new RawData(StringEscapeUtils.escapeHtml4(o.toString())); }
From source file:org.rythmengine.utils.S.java
/** * Change line break in the data string into <tt><br/></tt> * @param data//www. java 2 s. c o m * @return raw data of transformed result */ public static RawData nl2br(Object data) { return new RawData(StringEscapeUtils.escapeHtml4(str(data)).replace("\n", "<br/>")); }
From source file:org.seasr.meandre.components.tools.geo.TupleLocationsToKML.java
@Override public void executeCallBack(ComponentContext cc) throws Exception { String ctxLocation = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_LOCATION))[0]; String[] ctxSentences = DataTypeParser.parseAsString(cc.getDataComponentFromInput(IN_SENTENCES)); Strings inMeta = (Strings) cc.getDataComponentFromInput(IN_META_TUPLE); SimpleTuplePeer inPeer = new SimpleTuplePeer(inMeta); Object input = cc.getDataComponentFromInput(IN_TUPLES); Strings[] tuples;/*from w ww . ja va 2 s. c o m*/ if (input instanceof StringsArray) tuples = BasicDataTypesTools.stringsArrayToJavaArray((StringsArray) input); else if (input instanceof Strings) { Strings inTuple = (Strings) input; tuples = new Strings[] { inTuple }; } else throw new ComponentExecutionException( "Don't know how to handle input of type: " + input.getClass().getName()); if (!Arrays.asList(inPeer.getFieldNames()).containsAll(Arrays.asList(new String[] { _locAttr, OpenNLPNamedEntity.SENTENCE_ID_FIELD, OpenNLPNamedEntity.TEXT_START_FIELD }))) { String dump = inPeer.toString(); throw new ComponentExecutionException(String.format( "The tuple is missing a required attribute. Required: %s, %s, %s%nActual attributes: %s", OpenNLPNamedEntity.SENTENCE_ID_FIELD, _locAttr, OpenNLPNamedEntity.TEXT_START_FIELD, dump)); } SimpleTuple tuple = inPeer.createTuple(); Map<LatLngCoord, Placemark> places = new HashMap<LatLngCoord, Placemark>(); Folder folder = _document.createAndAddFolder().withName(ctxLocation).withOpen(true); for (Strings t : tuples) { tuple.setValues(t); String placeName = tuple.getValue(_locAttr); int sentenceId = Integer.parseInt(tuple.getValue(OpenNLPNamedEntity.SENTENCE_ID_FIELD)); GeoLocation[] locations = GeoLocation.geocode(placeName); if (locations.length == 0) continue; GeoLocation location = locations[0]; Placemark placemark = places.get(location.getCoord()); if (placemark == null) { placemark = folder.createAndAddPlacemark().withName(StringEscapeUtils.escapeHtml4(placeName)); placemark.createAndSetPoint().addToCoordinates(location.getLongitude(), location.getLatitude()); placemark.createAndSetExtendedData(); places.put(location.getCoord(), placemark); } String sentence = ctxSentences[sentenceId]; int offset = Integer.parseInt(tuple.getValue(OpenNLPNamedEntity.TEXT_START_FIELD)); sentence = String.format("%s<span style='%s'>%s</span>%s", StringEscapeUtils.escapeHtml4(sentence.substring(0, offset)), _spanCSS, StringEscapeUtils.escapeHtml4(placeName), StringEscapeUtils.escapeHtml4(sentence.substring(offset + placeName.length()))); placemark.getExtendedData() .addToData(KmlFactory.createData(sentence).withName(Integer.toString(sentenceId))); } for (Placemark placemark : places.values()) { int n = placemark.getExtendedData().getData().size(); placemark.setName(String.format("%s (%d)", placemark.getName(), n)); } if (!_isStreaming) endStream(); }
From source file:org.silverpeas.core.importexport.report.HtmlExportPublicationGenerator.java
public HtmlExportPublicationGenerator(PublicationType publicationType, String wysiwygText, String urlPub, int nbThemes) { this.publicationDetail = publicationType.getPublicationDetail(); if (publicationType.getPublicationContentType() != null) { this.xmlModelContent = publicationType.getPublicationContentType().getXMLModelContentType(); }//from w w w. j av a 2s . c om this.nbThemes = nbThemes + 2; if (publicationType.getAttachmentsType() != null) { this.listAttDetail = publicationType.getAttachmentsType(); } this.wysiwygText = wysiwygText; this.urlPub = StringEscapeUtils.escapeHtml4(urlPub).replaceAll("#", "%23"); }
From source file:org.silverpeas.core.util.EncodeHelper.java
public static String convertHTMLEntities(String text) { String result = StringEscapeUtils.escapeHtml4(text); return result; }
From source file:org.silverpeas.core.util.WebEncodeHelper.java
/** * Convert a java string to a html string for textArea Replace ", >, <, & and \n * * @param javastring Java string to encode * @return html string encoded/*w w w. j a va2 s.c o m*/ */ public static String javaStringToHtmlString(String javastring) { if (!isDefined(javastring)) { return ""; } return StringEscapeUtils.escapeHtml4(javastring).replace("", "œ"); }
From source file:org.silverpeas.core.util.WebEncodeHelper.java
public static String convertHTMLEntities(String text) { return StringEscapeUtils.escapeHtml4(text); }
From source file:org.silverpeas.core.web.glossary.HighlightGlossaryTerms.java
String highlight(String term, String content, String definition, String className, boolean onlyFirst) { // escape HTML character String escapedTerm = StringEscapeUtils.escapeHtml4(term); // regular expression which allows to search all the term except the HTML tag Searches the // exact term String regex = "((?i)\\b" + escapedTerm + "\\b)(?=[^>]*<(?!/a))"; // highlights the term String replacement = "<a href=\"#\" class=\"" + className + "\" title=\"" + definition.replaceAll("\"", """) + "\">" + escapedTerm + "</a>"; if (onlyFirst) { // highlights only the first occurrence return content.replaceFirst(regex, replacement); }/*w w w. jav a 2 s . c o m*/ return content.replaceAll(regex, replacement); }