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.microsoft.azure.storage.analytics.LogRecordStreamReader.java
/** * Read a URI from the stream./*from ww w .j a va 2s . c om*/ * * @return * the URI read. * @throws URISyntaxException * @throws IOException */ public URI readUri() throws URISyntaxException, IOException { String temp = this.readField(true /* isQuotedString */); if (Utility.isNullOrEmpty(temp)) { return null; } else { return new URI(StringEscapeUtils.unescapeHtml4(temp)); } }
From source file:com.aurel.track.exchange.docx.exporter.DocxExportBL.java
/** * Serializes the docx content into the response's output stream * @param response/*w ww. ja v a 2 s . com*/ * @param wordMLPackage * @return */ static String prepareReportResponse(HttpServletResponse response, String baseFileName, WordprocessingMLPackage wordMLPackage) { if (baseFileName == null) { baseFileName = "TrackReport"; } else { baseFileName = StringEscapeUtils.unescapeHtml4(baseFileName); StringBuffer sb = new StringBuffer(baseFileName.replaceAll("[^a-zA-Z0-9_]", "_")); Pattern regex = Pattern.compile("(_[a-z])"); Matcher regexMatcher = regex.matcher(sb); StringBuffer sb2 = new StringBuffer(); try { while (regexMatcher.find()) { regexMatcher.appendReplacement(sb2, regexMatcher.group(1).toUpperCase()); } regexMatcher.appendTail(sb2); } catch (Exception e) { LOGGER.error(e.getMessage()); } baseFileName = sb2.toString().replaceAll("_", ""); } response.reset(); response.setHeader("Content-Type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); response.setHeader("Content-Disposition", "attachment; filename=\"" + baseFileName + ".docx\""); DownloadUtil.prepareCacheControlHeader(ServletActionContext.getRequest(), response); OutputStream outputStream = null; try { outputStream = response.getOutputStream(); } catch (IOException e) { LOGGER.error("Getting the output stream failed with " + e.getMessage()); LOGGER.error(ExceptionUtils.getStackTrace(e)); } try { Docx4J.save(wordMLPackage, outputStream, Docx4J.FLAG_NONE); /*SaveToZipFile saver = new SaveToZipFile(wordMLPackage); saver.save(outputStream);*/ } catch (Exception e) { LOGGER.error("Exporting the docx failed with throwable " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } return null; }
From source file:accountgen.controller.Controller.java
private void setName(Document doc, Person p) { Elements e = doc.getElementsByClass("address"); Element name = e.select("h3").first(); p.setFirstname(StringEscapeUtils.unescapeHtml4(name.html().split(" ")[0]).trim()); p.setMiddlename(""); p.setLastname(StringEscapeUtils.unescapeHtml4(name.html().split(name.html().split(" ")[0])[1]).trim()); }
From source file:fr.mcc.ginco.rest.services.ExportRestService.java
private File writeExportFile(Thesaurus targetThesaurus, boolean alphabetical) { File temp;/*from ww w . j a v a 2 s . co m*/ BufferedWriter out = null; try { temp = File.createTempFile("pattern", ".suffix"); temp.deleteOnExit(); out = new BufferedWriter(new FileWriter(temp)); if (alphabetical) { out.write(LabelUtil.getResourceLabel("export-alphabetical").concat(" ")); } else { out.write(LabelUtil.getResourceLabel("export-hierarchical").concat(" ")); } out.write(targetThesaurus.getTitle()); out.newLine(); out.newLine(); out.flush(); List<FormattedLine> result; if (alphabetical) { result = exportService.getAlphabeticalText(targetThesaurus); } else { result = exportService.getHierarchicalText(targetThesaurus); } for (FormattedLine results : result) { for (int i = 0; i < results.getTabs(); i++) { out.write(TABULATION_DELIMITER); } out.write(StringEscapeUtils.unescapeHtml4(results.getText().replace("'", "'")) .replaceAll("<br>", "")); out.newLine(); out.flush(); } out.close(); } catch (IOException e) { throw new BusinessException("Cannot create temp file!", "cannot-create-file", e); } return temp; }
From source file:com.norconex.collector.http.url.impl.GenericCanonicalLinkDetector.java
private String toAbsolute(String pageReference, String link) { if (link == null) { return null; }/*from w ww . ja v a 2s. co m*/ if (link.matches("^https{0,1}://")) { return link; } return URIUtils.resolve(URI.create(pageReference), StringEscapeUtils.unescapeHtml4(link)).toString(); }
From source file:com.zack6849.alphabot.api.Utils.java
public static String google(String s) { try {/*from w w w .j a v a 2 s . c o m*/ String temp = String.format("https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=%s", URLEncoder.encode(s, "UTF-8")); URL u = new URL(temp); URLConnection c = u.openConnection(); c.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17"); BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); String json = ""; String tmp; while ((tmp = in.readLine()) != null) { json += tmp + "\n"; } in.close(); JsonElement jelement = new JsonParser().parse(json); JsonObject output = jelement.getAsJsonObject(); output = output.getAsJsonObject("responseData").getAsJsonArray("results").get(0).getAsJsonObject(); String title = StringEscapeUtils.unescapeJava(StringEscapeUtils .unescapeHtml4(output.get("titleNoFormatting").toString().replaceAll("\"", ""))); String content = StringEscapeUtils.unescapeJava(StringEscapeUtils.unescapeHtml4(output.get("content") .toString().replaceAll("\\s+", " ").replaceAll("\\<.*?>", "").replaceAll("\"", ""))); String url = StringEscapeUtils.unescapeJava(output.get("url").toString().replaceAll("\"", "")); String result = String.format("Google: %s | %s | (%s)", title, content, url); if (result != null) { return result; } else { return "No results found for query " + s; } } catch (IOException ex) { Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:cx.fbn.nevernote.threads.IndexRunner.java
public void indexNoteContent() { foundWords.clear();/*from w w w .j ava2s. c om*/ logger.log(logger.EXTREME, "Entering indexRunner.indexNoteContent()"); logger.log(logger.EXTREME, "Getting note content"); Note n = conn.getNoteTable().getNote(guid, true, false, true, true, true); String data; if (indexNoteBody) { data = n.getContent(); data = conn.getNoteTable().getNoteContentNoUTFConversion(n.getGuid()); logger.log(logger.EXTREME, "Removing any encrypted data"); data = removeEnCrypt(data.toString()); logger.log(logger.EXTREME, "Removing xml markups"); } else data = ""; String text; if (indexNoteTitle) text = removeTags(StringEscapeUtils.unescapeHtml4(data) + " " + n.getTitle()); else text = removeTags(StringEscapeUtils.unescapeHtml4(data)); logger.log(logger.EXTREME, "Splitting words"); String[] result = text.toString().split(regex); conn.commitTransaction(); conn.beginTransaction(); logger.log(logger.EXTREME, "Deleting existing words for note from index"); conn.getWordsTable().expungeFromWordIndex(guid, "CONTENT"); logger.log(logger.EXTREME, "Number of words found: " + result.length); for (int j = 0; j < result.length && keepRunning; j++) { if (interrupt) { processInterrupt(); } if (!result[j].trim().equals("")) { logger.log(logger.EXTREME, "Result word: " + result[j].trim()); addToIndex(guid, result[j], "CONTENT"); } } // Add tags for (int j = 0; j < n.getTagNamesSize(); j++) { if (n.getTagNames() != null && n.getTagNames().get(j) != null && !n.getTagNames().get(j).trim().equals("")) addToIndex(guid, n.getTagNames().get(j), "CONTENT"); } // If we were interrupted, we will reindex this note next time if (Global.keepRunning) { logger.log(logger.EXTREME, "Resetting note guid needed"); conn.getNoteTable().setIndexNeeded(guid, false); } conn.commitTransaction(); uncommittedCount = 0; logger.log(logger.EXTREME, "Leaving indexRunner.indexNoteContent()"); }
From source file:accountgen.controller.Controller.java
private void setAddress(Document doc, Person p) { Elements e = doc.getElementsByClass("address"); Element ad = e.select(".adr").first(); Address address = new Address(); String streetnumber = StringEscapeUtils .unescapeHtml4(//from w w w . j ava2s .c o m ad.html().split("<br />")[0].split(" ")[ad.html().split("<br />")[0].split(" ").length - 1]) .trim(); String state = StringEscapeUtils .unescapeHtml4( ad.html().split("<br />")[1].split(" ")[ad.html().split("<br />")[1].split(" ").length - 1]) .trim(); address.setStreetnumber(streetnumber); address.setStreetname(StringEscapeUtils.unescapeHtml4(ad.html().split(streetnumber)[0]).trim()); address.setState(state); address.setPostcode( StringEscapeUtils.unescapeHtml4(ad.html().split("<br />")[1].split(state)[0]).trim().split(" ")[0]); address.setCountry(Consts.COUNTRY); p.setAdress(address); }
From source file:com.bitplan.mediawiki.japi.MediaWikiApiImpl.java
/** * decode the given html markup//from w w w . j a v a 2 s .com * @param html * @return decoded html * @throws Exception */ protected String decode(String html) throws Exception { String result = StringEscapeUtils.unescapeHtml4(html); return result; }
From source file:fredboat.command.util.MALCommand.java
private boolean handleAnime(TextChannel channel, Member invoker, String terms, String body) { String msg = MessageFormat.format(I18n.get(channel.getGuild()).getString("malRevealAnime"), invoker.getEffectiveName()); //Read JSON//from w ww. ja va 2s.co m log.info(body); JSONObject root = XML.toJSONObject(body); JSONObject data; try { data = root.getJSONObject("anime").getJSONArray("entry").getJSONObject(0); } catch (JSONException ex) { data = root.getJSONObject("anime").getJSONObject("entry"); } ArrayList<String> titles = new ArrayList<>(); titles.add(data.getString("title")); if (data.has("synonyms")) { titles.addAll(Arrays.asList(data.getString("synonyms").split(";"))); } if (data.has("english")) { titles.add(data.getString("english")); } int minDeviation = Integer.MAX_VALUE; for (String str : titles) { str = str.replace(' ', '+').trim(); int deviation = str.compareToIgnoreCase(terms); deviation = deviation - Math.abs(str.length() - terms.length()); if (deviation < minDeviation) { minDeviation = deviation; } } log.debug("Anime search deviation: " + minDeviation); if (minDeviation > 3) { return false; } msg = data.has("title") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malTitle"), msg, data.get("title")) : msg; msg = data.has("english") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEnglishTitle"), msg, data.get("english")) : msg; msg = data.has("synonyms") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynonyms"), msg, data.get("synonyms")) : msg; msg = data.has("episodes") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEpisodes"), msg, data.get("episodes")) : msg; msg = data.has("score") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malScore"), msg, data.get("score")) : msg; msg = data.has("type") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malType"), msg, data.get("type")) : msg; msg = data.has("status") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStatus"), msg, data.get("status")) : msg; msg = data.has("start_date") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malStartDate"), msg, data.get("start_date")) : msg; msg = data.has("end_date") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malEndDate"), msg, data.get("end_date")) + "\n" : msg; if (data.has("synopsis")) { Matcher m = Pattern.compile("^[^\\n\\r<]+") .matcher(StringEscapeUtils.unescapeHtml4(data.getString("synopsis"))); m.find(); msg = data.has("synopsis") ? MessageFormat.format(I18n.get(channel.getGuild()).getString("malSynopsis"), msg, m.group(0)) : msg; } msg = data.has("id") ? msg + "http://myanimelist.net/anime/" + data.get("id") + "/" : msg; channel.sendMessage(msg).queue(); return true; }