List of usage examples for org.apache.commons.lang3 StringEscapeUtils unescapeHtml4
public static final String unescapeHtml4(final String input)
Unescapes a string containing entity escapes to a string containing the actual Unicode characters corresponding to the escapes.
From source file:com.talanlabs.sonar.plugins.gitlab.AbstractCommentBuilder.java
private String buildFreemarkerComment() { Configuration cfg = new Configuration(Configuration.getVersion()); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); try (StringWriter sw = new StringWriter()) { new Template(templateName, template, cfg).process(createContext(), sw); return StringEscapeUtils.unescapeHtml4(sw.toString()); } catch (IOException | TemplateException e) { LOG.error("Failed to create template {}", templateName, e); throw MessageException.of("Failed to create template " + templateName); }//from w w w. java 2 s .c om }
From source file:com.datumbox.framework.utilities.text.cleaners.HTMLCleaner.java
protected static String clear(String text) { return StringCleaner.removeExtraSpaces(StringEscapeUtils.unescapeHtml4(unsafeRemoveAllTags(text))); }
From source file:co.foxdev.foxbot.commands.CommandGoogle.java
@Override public void execute(MessageEvent event, String[] args) { User sender = event.getUser();//from ww w.j a v a2 s . c om Channel channel = event.getChannel(); if (args.length != 0) { String query = StringUtils.join(args, " "); String address = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + query; Connection conn = Jsoup.connect(address).ignoreContentType(true).followRedirects(true).timeout(1000); JSONObject jsonObject; try { jsonObject = new JSONObject(conn.get().text()); } catch (IOException ex) { foxbot.getLogger().error("Error occurred while performing Google search", ex); channel.send().message(Utils .colourise(String.format("(%s) &cSomething went wrong...", Utils.munge(sender.getNick())))); return; } JSONArray jsonArray = jsonObject.getJSONObject("responseData").getJSONArray("results"); if (jsonArray.length() == 0) { channel.send().message( Utils.colourise(String.format("(%s) &cNo results found!", Utils.munge(sender.getNick())))); return; } JSONObject result = jsonArray.getJSONObject(0); String resultCount = jsonObject.getJSONObject("responseData").getJSONObject("cursor") .getString("resultCount"); String title = result.getString("titleNoFormatting"); String url = result.getString("unescapedUrl"); channel.send().message(Utils.colourise(String.format( "(%s's Google Search) &2Title: &r%s &2URL: &r%s &2Results: &r%s", Utils.munge(sender.getNick()), StringEscapeUtils.unescapeHtml4(title), url, resultCount))); return; } sender.send().notice( String.format("Wrong number of args! Use %sgoogle <query>", foxbot.getConfig().getCommandPrefix())); }
From source file:net.dv8tion.discord.commands.AnimeNewsNetworkCommand.java
private String handleSearch(SearchResult result) { String url = result.getUrl(); if (url.contains(ANIME_URL) || url.contains(MANGA_URL)) { String title = null;// ww w. j a v a 2s .c om String altTitle = null; String summary = null; String imageUrl = null; String id = url.replace(ANIME_URL, "").replace(MANGA_URL, ""); String xmlReturn = StringEscapeUtils.unescapeHtml4(Downloader.webpage(ANN_API_URL + id)); Pattern p = Pattern.compile(MAIN_TITLE_REGEX); Matcher m = p.matcher(xmlReturn); if (m.find()) title = m.group(); else title = result.getTitle(); Pattern p2 = Pattern.compile(ALT_TITLE_REGEX); Matcher m2 = p2.matcher(xmlReturn); if (m2.find()) altTitle = m2.group(); Pattern p3 = Pattern.compile(SUMMARY_REGEX); Matcher m3 = p3.matcher(xmlReturn); if (m3.find()) summary = m3.group(); else summary = result.getContent(); Pattern p4 = Pattern.compile("type=\"Picture\".*?>.*?</info>"); Matcher m4 = p4.matcher(xmlReturn); if (m4.find()) { Pattern p41 = Pattern.compile("(?<=img src=\").*?(?=\" width=\"...?.?.?\" height=\"...?.?.?\"/>)"); Matcher m41 = p41.matcher(m4.group(0)); while (m41.find()) { imageUrl = m41.group(0); if (m41.group(0).contains("/thumbnails/max")) { break; } } } return String.format("%s\n**Title:** %s\n%s\n%s", url, title + (altTitle == null ? "" : (" **JPN Title:** " + altTitle)), summary, imageUrl != null ? imageUrl : "No Image Found"); } else { return result.getSuggestedReturn(); } }
From source file:com.recalot.model.data.connections.reddit.RedditDataSource.java
private List<String> splitIntoWords(String sentence) { List<String> words = new ArrayList<>(); sentence = StringEscapeUtils.unescapeHtml4(sentence); String[] parts = sentence.split("(?<!^)\\b"); String last = null;//from ww w.j a v a2 s . c o m boolean concat = false; for (String word : parts) { if (last != null) { if (word.trim().length() == 0) { //spaces? add the last word words.add(last.trim().toLowerCase().intern()); last = null; } else if ((!concat && !word.equals("'") && last != null)) { //punctuation? add the last word and set punctuation as last word words.add(last.trim().toLowerCase().intern()); last = word; } else if (word.equals("'")) { //quotes? concat the following words concat = true; last += word; } else { if (concat) { last += word; } else { last = word; } concat = false; } } else { last = word; } } if (last != null) { //a word in pipeline words.add(last.trim().intern()); } return words; }
From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java
private Function<String, String> unescapeCdataHtmlContent() { return (content) -> replaceAll(content, CDATA_PATTERN, (matchResult) -> StringEscapeUtils.unescapeHtml4(matchResult.group())); }
From source file:io.wcm.handler.url.rewriter.impl.UrlExternalizerTransformer.java
@Override public void startElement(String nsUri, String name, String raw, Attributes attrs) throws SAXException { // check if for this element an attribute for rewriting is configured String rewriteAttr = transformerConfig.getElementAttributeNames().get(name); if (rewriteAttr == null) { log.trace("Rewrite element {}: Skip - No rewrite attribute configured.", name); super.startElement(nsUri, name, raw, attrs); return;/*from w w w . j av a2 s . c o m*/ } // validate URL handler if (urlHandler == null) { log.warn("Rewrite element {}: Skip - Unable to get URL handler/Integrator handler instance.", name); super.startElement(nsUri, name, raw, attrs); return; } // check if attribute exists int attributeIndex = attrs.getIndex(rewriteAttr); if (attributeIndex < 0) { log.trace("Rewrite element {}: Skip - Attribute does not exist: {}", name, rewriteAttr); super.startElement(nsUri, name, raw, attrs); return; } // rewrite URL String url = attrs.getValue(attributeIndex); if (StringUtils.isEmpty(url)) { log.trace("Rewrite element {}: Skip - URL is empty.", name); super.startElement(nsUri, name, raw, attrs); return; } // remove escaping url = StringEscapeUtils.unescapeHtml4(url); // externalize URL (if it is not already externalized) String rewrittenUrl = urlHandler.get(url).buildExternalResourceUrl(); if (StringUtils.equals(url, rewrittenUrl)) { log.debug("Rewrite element {}: Skip - URL is already externalized: {}", name, url); super.startElement(nsUri, name, raw, attrs); return; } // set new attribute value log.debug("Rewrite element {}: Rewrite URL {} to {}", name, url, rewrittenUrl); AttributesImpl newAttrs = new AttributesImpl(attrs); newAttrs.setValue(attributeIndex, rewrittenUrl); super.startElement(nsUri, name, raw, newAttrs); }
From source file:com.griddynamics.deming.ecommerce.controller.cart.CartController.java
@RequestMapping(value = "/add", produces = "application/json") public @ResponseBody Map<String, Object> addJson(HttpServletRequest request, HttpServletResponse response, Model model, @ModelAttribute("addToCartItem") AddToCartItem addToCartItem) throws IOException, PricingException, AddToCartException { Map<String, Object> responseMap = new HashMap<String, Object>(); try {// w ww. ja va2 s . c o m super.add(request, response, model, addToCartItem); if (addToCartItem.getItemAttributes() == null || addToCartItem.getItemAttributes().size() == 0) { responseMap.put("productId", addToCartItem.getProductId()); } String productName = catalogService.findProductById(addToCartItem.getProductId()).getName(); responseMap.put("productName", StringEscapeUtils.unescapeHtml4(productName)); responseMap.put("quantityAdded", addToCartItem.getQuantity()); responseMap.put("cartItemCount", String.valueOf(CartState.getCart().getItemCount())); if (addToCartItem.getItemAttributes() == null || addToCartItem.getItemAttributes().size() == 0) { // We don't want to return a productId to hide actions for when it is a product that has multiple // product options. The user may want the product in another version of the options as well. responseMap.put("productId", addToCartItem.getProductId()); } } catch (AddToCartException e) { if (e.getCause() instanceof RequiredAttributeNotProvidedException) { responseMap.put("error", "allOptionsRequired"); } else if (e.getCause() instanceof ProductOptionValidationException) { ProductOptionValidationException exception = (ProductOptionValidationException) e.getCause(); responseMap.put("error", "productOptionValidationError"); responseMap.put("errorCode", exception.getErrorCode()); responseMap.put("errorMessage", exception.getMessage()); //blMessages.getMessage(exception.get, lfocale)) } else { throw e; } } return responseMap; }
From source file:com.silverpeas.util.EncodeHelper.java
/** * Convert a html string to a java string Replace " *// ww w . j av a 2s . c om * @param htmlstring HTML string to encode * @return html string JAVA encoded */ public static String htmlStringToJavaString(String htmlstring) { if (!isDefined(htmlstring)) { return ""; } return StringEscapeUtils.unescapeHtml4(htmlstring); }
From source file:msearch.filmeSuchen.sender.MediathekSwr.java
private void addToList__() { //Theman suchen final String MUSTER_START = "<div class=\"mediaCon\">"; final String MUSTER_STOPP = "<h2 class=\"rasterHeadline\">OFT GESUCHT</h2>"; final String MUSTER_URL = "<a href=\"tvshow.htm?show="; final String MUSTER_THEMA = "title=\""; MSStringBuilder strSeite = new MSStringBuilder(MSConst.STRING_BUFFER_START_BUFFER); strSeite = getUrlIo.getUri(SENDERNAME, "http://swrmediathek.de/tvlist.htm", MSConst.KODIERUNG_UTF, 2, strSeite, ""); int pos = 0;//w w w.j ava 2s.co m String url; String thema; int stop = strSeite.indexOf(MUSTER_STOPP); while (!MSConfig.getStop() && (pos = strSeite.indexOf(MUSTER_START, pos)) != -1) { if (stop > 0 && pos > stop) { break; } pos += MUSTER_START.length(); url = strSeite.extract(MUSTER_URL, "\"", pos); thema = strSeite.extract(MUSTER_THEMA, "\"", pos); thema = StringEscapeUtils.unescapeHtml4(thema.trim()); //wird gleich benutzt und muss dann schon stimmen if (thema.isEmpty()) { MSLog.fehlerMeldung(-915263078, MSLog.FEHLER_ART_MREADER, "MediathekSwr.addToList__", "kein Thema"); } if (url.isEmpty()) { MSLog.fehlerMeldung(-163255009, MSLog.FEHLER_ART_MREADER, "MediathekSwr.addToList__", "keine URL"); } else { //url = url.replace("&", "&"); String[] add = new String[] { "http://swrmediathek.de/tvshow.htm?show=" + url, thema }; listeThemen.addUrl(add); } } }