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:sturesy.voting.chartcontroller.MultipleChoiceBarChartController.java
/** * Creates a Dataset containing percent values * /*from w w w. j a v a2s . co m*/ * @param votes * array of votes * @param answers * List of answer strings * @return CategoryDataset containing percent values */ protected CategoryDataset createDatasetPercent(double[] votes, List<String> answers) { final DefaultCategoryDataset result = new DefaultCategoryDataset(); for (int i = 0; i < votes.length; i++) { double value = votes[i] * 100 / _votes.size(); value = MathUtils.roundToDecimals(value, 1); String answer = StringEscapeUtils.unescapeHtml4(HTMLStripper.stripHTML2(answers.get(i))); String columnKey = (char) ('A' + i) + ": " + answer; result.addValue(value, "SERIES", columnKey); } return result; }
From source file:sturesy.voting.chartcontroller.SingleChoiceBarChartController.java
@Override public void updateUI() { double[] votesarr = prepareVotesForDataSet(_question.getAnswerSize(), _votes); CategoryDataset dataset = createDataSet(votesarr, _question.getAnswers()); final String unescapeHtml4 = StringEscapeUtils .unescapeHtml4(HTMLStripper.stripHTML2(_question.getQuestion())); List<Integer> answers = Arrays.asList(_question.getCorrectAnswer()); _gui.createNewChartPanel(dataset, unescapeHtml4, _backgroundcolor, _showCorrectAnswer, answers, _showPercent);/* w w w .ja va 2s .c o m*/ }
From source file:sturesy.voting.chartcontroller.TextBarChartController.java
@Override public void updateUI() { double[] votesarr = prepareVotesForDataset(); final String correctA = Localize.getString("label.textquestion.correctanswers"); final String wrongA = Localize.getString("label.textquestion.wronganswers"); CategoryDataset dataset = createDataSet(votesarr, Arrays.asList(correctA, wrongA)); final String unescapeHtml4 = StringEscapeUtils .unescapeHtml4(HTMLStripper.stripHTML2(_question.getQuestion())); _gui.createNewChartPanel(dataset, unescapeHtml4, _backgroundcolor, _showCorrectAnswer, Arrays.asList(0), _showPercent);/*from w ww . j a va2 s . c o m*/ }
From source file:tiwolij.service.wikidata.WikidataRepository.java
public String extractImageAttribution(Integer wikidataId) { String imageAttribution = null; String wikimediaImageinfo = env.getProperty("wikimedia.imageinfo"); String artist = "Unknown Artist"; String license = "Unspecified License"; try {// w w w. j av a 2 s. co m WikibaseDataFetcher data = WikibaseDataFetcher.getWikidataDataFetcher(); ItemDocument item = (ItemDocument) data.getEntityDocument("Q" + wikidataId); if (item.hasStatement("P18")) { Value value = item.findStatementGroup("P18").getStatements().get(0).getValue(); String file = value.toString().replaceAll("^\"|\"$", "").replace(" ", "_"); URL url = new URL("https://" + wikimediaImageinfo + file); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(url.openStream()); Node artistNode = document.getElementsByTagName("Artist").item(0); Node licenseNode = document.getElementsByTagName("LicenseShortName").item(0); if (artistNode != null) { artist = artistNode.getAttributes().getNamedItem("value").getNodeValue(); artist = StringUtils.abbreviate(artist.replaceAll("\\<[^>]*>", ""), 100); } if (licenseNode != null) { license = licenseNode.getAttributes().getNamedItem("value").getNodeValue(); license = StringUtils.abbreviate(license.replaceAll("\\<[^>]*>", ""), 100); } imageAttribution = StringEscapeUtils.unescapeHtml4(artist) + " (" + StringEscapeUtils.unescapeHtml4(license) + ")"; } } catch (Exception e) { } return imageAttribution; }
From source file:tk.jomp16.plugin.google.Google.java
@Command(value = "google", args = { "term:", "num::" }) public void google(CommandEvent commandEvent) throws Exception { if (commandEvent.getOptionSet().has("term")) { String url = String.format(GOOGLE, URLEncoder.encode((String) commandEvent.getOptionSet().valueOf("term"), "UTF-8")); try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) { GoogleSearch search = new Gson().fromJson(reader, GoogleSearch.class); if (!search.responseStatus.equals("200")) { commandEvent.respond("Error while searching"); return; }/*from w ww . j a va2 s . com*/ if (search.responseData.results.size() <= 0) { commandEvent.respond("No results found :'("); return; } String tmp = "\u0002Link #%s: %s\u000F (at %s)"; if (commandEvent.getOptionSet().has("num")) { for (int i = 0; i < Integer .parseInt((String) commandEvent.getOptionSet().valueOf("num")); i++) { String title = StringEscapeUtils .unescapeHtml4(search.responseData.results.get(i).titleNoFormatting); String url2 = URLDecoder.decode(search.responseData.results.get(i).unescapedUrl, "UTF-8"); commandEvent.respond(String.format(tmp, (i + 1), title, url2)); } } else { String title = StringEscapeUtils .unescapeHtml4(search.responseData.results.get(0).titleNoFormatting); String url2 = URLDecoder.decode(search.responseData.results.get(0).unescapedUrl, "UTF-8"); commandEvent.respond(String.format(tmp, 1, title, url2)); } } } else { commandEvent.showUsage(this, "google"); } }
From source file:tk.vigaro.helix.listener.ListenerCommandGoogle.java
@Override public void onMessage(MessageEvent event) throws Exception { String msg = event.getMessage(); if (msg.startsWith(Helix.botPrefix + Commands.googleSearch) && ((msg.length() > (Commands.googleSearch.length() + 2) && msg.charAt(Commands.googleSearch.length() + 1) == ' ') || (msg.length() > (Commands.googleSearch.length() + 3) && Arrays.asList(Helix.valid) .contains(msg.charAt(Commands.googleSearch.length() + 1)) && msg.charAt(Commands.googleSearch.length() + 2) == ' '))) { String q = msg.split(" ", 2)[1]; String max = msg.charAt(Commands.googleSearch.length() + 1) == ' ' ? "1" : String.valueOf(msg.charAt(Commands.googleSearch.length() + 1)); String a = "https://www.googleapis.com/customsearch/v1?fields=items(htmlTitle,link,htmlSnippet)&alt=json&key=" + Helix.properties.getProperty("google.apikey") + "&cx=" + Helix.properties.getProperty("google.searchengineid") + "&q=" + URLEncoder.encode(q, "UTF-8"); String m;/*ww w . j av a 2s . c om*/ try { JSONObject r = new JSONObject(Util.getHTTPResponse(a)).getJSONArray("items") .getJSONObject(Integer.parseInt(max) - 1); String title = StringEscapeUtils.unescapeHtml4( r.getString("htmlTitle").replace("<b>", Colors.BOLD).replace("</b>", Colors.NORMAL)); String link = r.getString("link"); String snip = StringEscapeUtils.unescapeHtml4(r.getString("htmlSnippet").replace("<b>", Colors.BOLD) .replace("</b>", Colors.NORMAL).replace("\n", "").replace("<br>", "")); m = "[" + title + "]" + snip + " " + link; } catch (JSONException e) { m = "No results found for \"" + Colors.BOLD + q + Colors.NORMAL + "\""; } event.getChannel().send().message(m); } }
From source file:twitter.Twokenize.java
/** * Twitter text comes HTML-escaped, so unescape it. * We also first unescape &'s, in case the text has been buggily double-escaped. *///from w w w . j av a 2 s. c om public static String normalizeTextForTagger(String text) { text = text.replaceAll("&", "&"); text = StringEscapeUtils.unescapeHtml4(text); return text; }
From source file:ubiksimdist.UbikSimServlet.java
/** * Genera una respuesta en formato web, en su llamada ya se ha comprobado * que hay respuesta y que la accin se ejecut en el simulador. * * @param response/* w ww .j a v a 2 s .c o m*/ * @param output */ private void printWeb(HttpServletResponse response, String output) { response.setContentType("text/html"); String web = ""; try { PrintWriter out = response.getWriter(); BufferedReader in = new BufferedReader(new FileReader(getServletContext().getRealPath("ubiksim.html"))); while ((web = in.readLine()) != null) { // web += web; out.println(web); if (web.endsWith("<!--SERVLET OUTPUT-->")) {//add pantel with output out.println("<div class=\"panel panel-primary\">"); out.println("<div class=\"panel-heading\">"); out.println("<h3 class=\"panel-title\">Action output:</h3>"); out.println("</div>"); out.println("<div class=\"panel-body\">"); out.println(StringEscapeUtils.unescapeHtml4(output)); out.println("</div>"); out.println("</div>"); } } in.close(); out.close(); } catch (IOException ex) { Logger.getLogger(UbikSimServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:uk.ac.ebi.fg.annotare2.web.server.servlets.utils.FormParams.java
public String getParamValue(String paramName) { if (paramMap.containsKey(paramName)) { return StringEscapeUtils.unescapeHtml4(paramMap.get(paramName).getValue()); }// ww w . j a v a 2 s.com return null; }
From source file:uk.co.sdev.undertow.rx.services.news.NewsItemDigestible.java
private String getStandFirst() { String unescaped = StringEscapeUtils.unescapeHtml4(description); if (unescaped.startsWith("<p>")) { unescaped = unescaped.substring(3, unescaped.indexOf('<', 3)); } else {//from w w w . j a v a 2 s . co m unescaped = unescaped.substring(0, unescaped.indexOf('<')); } return stripWhitespace(unescaped).trim(); }