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:fr.mcc.ginco.extjs.view.FileResponse.java
public FileResponse(File file, String extension, String title) { this.file = file; this.extension = extension; this.title = StringEscapeUtils.unescapeHtml4(title).replaceAll("&apos", "").replaceAll("[^a-zA-Z0-9\\._]+", "_"); }
From source file:com.wiseowl.WiseOwl.wikiClean.WikiClean.java
public final String getTitle(String s) { int start = s.indexOf(XML_START_TAG_TITLE); int end = s.indexOf(XML_END_TAG_TITLE, start); if (start < 0 || end < 0) { return ""; }// ww w . j av a 2 s . c o m return StringEscapeUtils.unescapeHtml4(s.substring(start + 7, end)); }
From source file:jobhunter.monster.Client.java
public Job execute() throws IOException, URISyntaxException { l.debug("Connecting to {}", url); update("Connecting", 1L); final Document doc = Jsoup.connect(url).get(); update("Parsing HTML", 2L); final Job job = Job.of(); job.setPortal(MonsterPlugin.portal); job.setLink(url);/* www .java 2 s. co m*/ final Element form = doc.getElementById("forApply"); job.setPosition(form.getElementById("jobPosition").attr("value")); job.setAddress(form.getElementById("jobLocation").attr("value")); job.setExtId(form.getElementById("jobID").attr("value")); job.getCompany().setName(form.getElementById("jobCompany").attr("value")); job.setDescription(StringEscapeUtils.unescapeHtml4(doc.getElementById("TrackingJobBody").html())); update("Done", 3L); return job; }
From source file:emily.command.fun.FMLCommand.java
@Override public String execute(DiscordBot bot, String[] args, MessageChannel channel, User author, Message inputMessage) {// w w w. j a va 2s . c o m if (items.size() < MIN_QUEUE_ITEMS) { bot.queue.add(channel.sendTyping()); getFMLItems(); } if (!items.isEmpty()) { try { String item = StringEscapeUtils.unescapeHtml4(items.take()); if (item.length() >= 2000) { item = item.substring(0, 1999); } return item; } catch (InterruptedException e) { Launcher.logToDiscord(e, "fml-command", "interrupted"); } } return Templates.command.fml_not_today.formatGuild(channel); }
From source file:me.malladi.dashcricket.LiveScore.java
public LiveScore(JSONObject json) { id = json.optString("object_id", EMPTY); teamOneId = json.optString("team1_id", EMPTY); teamOneName = json.optString("team1_name", EMPTY); teamOneAbbreviation = json.optString("team1_abbreviation", EMPTY); teamTwoId = json.optString("team2_id", EMPTY); teamTwoName = json.optString("team2_name", EMPTY); teamTwoAbbreviation = json.optString("team2_abbreviation", EMPTY); matchTitle = json.optString("cms_match_title", EMPTY); townName = json.optString("town_name", EMPTY); liveScorecardText = StringEscapeUtils.unescapeHtml4(json.optString("live_scorecard_text", EMPTY)); liveScorecardLink = json.optString("live_scorecard_link", EMPTY); matchStatus = json.optString("match_status", EMPTY); matchClock = json.optString("match_clock", EMPTY); result = json.optString("result", EMPTY); }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedMessage.java
public RedditPreparedMessage(final Context context, final RedditMessage message, final long timestamp) { this.src = message; // TODO custom time final TypedArray appearance = context.obtainStyledAttributes( new int[] { R.attr.rrCommentHeaderBoldCol, R.attr.rrCommentHeaderAuthorCol, }); rrCommentHeaderBoldCol = appearance.getColor(0, 255); rrCommentHeaderAuthorCol = appearance.getColor(1, 255); body = RedditCommentTextParser.parse(StringEscapeUtils.unescapeHtml4(message.body)); idAndType = message.name;//from www . j a v a 2 s . co m final BetterSSB sb = new BetterSSB(); if (src.author == null) { sb.append("[" + context.getString(R.string.general_unknown) + "]", BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } else { sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f); } sb.append(" ", 0); sb.append(RRTime.formatDurationMsAgo(context, RRTime.utcCurrentTimeMillis() - src.created_utc * 1000L), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f); header = sb.get(); }
From source file:fr.eolya.utils.http.HttpUtils.java
public static String urlNormalize(String url, String preferedHost) { String ret_url = url.trim();/*from ww w.j ava 2 s .co m*/ // Perform some url nomalizations described here : http://en.wikipedia.org/wiki/URL_normalization try { // Remove last "/" - NO !!! //if (ret_url.lastIndexOf("/") == ret_url.length()-1) // ret_url = ret_url.substring(0, ret_url.length()-1); // Remove final "?" if unique in url - http://www.example.com/display? -> http://www.example.com/display if (ret_url.lastIndexOf("?") == ret_url.length() - 1) ret_url = ret_url.substring(0, ret_url.length() - 1); // Fix "?&" int index = ret_url.indexOf("?&"); //int l = ret_url.length()-2; if (index != -1) { if (index != ret_url.length() - 2) { ret_url = ret_url.substring(0, index + 1) + ret_url.substring(index + 2); } else { ret_url = ret_url.substring(0, ret_url.length() - 2); } } // Replace "&" by "&" ret_url = StringEscapeUtils.unescapeHtml4(ret_url); // Replace " " by "%20" ret_url = ret_url.replace(" ", "%20"); // Replace "'" by "%27" ret_url = ret_url.replace("'", "%27"); // Replace "%5F" by "_" ret_url = ret_url.replace("%5f", "_"); ret_url = ret_url.replace("%5F", "_"); // Remove dot-segments. // http://www.example.com/../a/b/../c/./d.html => http://www.example.com/a/c/d.html URI uri = new URI(ret_url); uri = uri.normalize(); ret_url = uri.toURL().toExternalForm(); // Remove dot-segments at the beginning of the path // http://www.example.com/../a/d.html => http://www.example.com/a/d.html URL tempUrl = new URL(ret_url); String path = tempUrl.getFile(); String pattern = ""; while (path.startsWith("/../")) { path = path.substring(3); pattern += "/.."; } if (!pattern.equals("")) { index = ret_url.indexOf(pattern); ret_url = ret_url.substring(0, index) + ret_url.substring(index + pattern.length()); } // Remove default port if (ret_url.indexOf("http://" + uri.getHost() + ":80") != -1) { ret_url = ret_url.replace("//" + uri.getHost() + ":80", "//" + uri.getHost()); } if (ret_url.indexOf("https://" + uri.getHost() + ":443") != -1) { ret_url = ret_url.replace("//" + uri.getHost() + ":443", "//" + uri.getHost()); } // translate to prefered host (www.site.com vs site.com) if (preferedHost != null && !"".equals(preferedHost)) { if (uri.getHost().equals("www." + preferedHost) || ("www." + uri.getHost()).equals(preferedHost)) { ret_url = ret_url.replace("//" + uri.getHost(), "//" + preferedHost); } } // Remove the fragment. // http://www.example.com/bar.html#section1 => http://www.example.com/bar.html if (ret_url.indexOf("#") != -1) ret_url = ret_url.substring(0, ret_url.indexOf("#")); // Reorder parameters in query string //ret_url = urlReorderParameters (ret_url); return ret_url; } catch (Exception e) { } return ret_url; }
From source file:net.krautchan.data.KCPosting.java
public static String sanitizeContent(String inContent) { String locContent = inContent; locContent = StringEscapeUtils.unescapeHtml4(locContent); locContent = locContent.replaceAll("<p>", ""); locContent = locContent.replaceAll("</p>", " "); locContent = locContent.replaceAll("onclick=\"highlightPost\\(\\'\\d+\\'\\);\"", ""); locContent = locContent.replaceAll(">>>(\\d+)</a>", " onclick='quoteClick(this); return false;' class=\"kclink\">>> $1</a>"); locContent = locContent.replaceAll("<a href=\"/resolve(/.+?)\"\\s*>.+?</a>", "<a href=\"/resolve$1\" class=\"kclink\" onclick=\"Android.openKcLink('$1');return false;\">>> $1</a>"); Matcher m = linkPat.matcher(locContent); StringBuffer buf = new StringBuffer(locContent.length() + 1000); int end = 0;//from w ww.j a v a 2 s . co m while (m.find()) { int gc = m.groupCount(); if (gc > 0) { buf.append(locContent.substring(end, m.start())); end = m.end(); String host = m.group(1); String name = host; String styleClass = "extlink"; String androidFunction = "openExternalLink"; String url = m.group(1) + "/" + m.group(2); if ((host.contains("youtube")) || (host.contains("youtu.be"))) { styleClass = "ytlink"; name = "YouTube"; androidFunction = "openYouTubeVideo"; } else if (host.contains("krautchan.net")) { styleClass = "kclink"; name = ">>"; host = ""; androidFunction = "openKcLink"; } buf.append("<a href=\"http://" + m.group(1) + "/" + m.group(2) + "\" class=\"" + styleClass + "\" onclick=\"Android." + androidFunction + "('" + url + "');return false;\">" + name + "</a>" + m.group(3)); } } buf.append(locContent.substring(end, locContent.length())); return "<p><span>" + buf.toString().trim() + "</span></p>"; }
From source file:model.SentinelHttpParamVirt.java
@Override public String getDecodedValue() { String mutatedValue = ""; switch (encoderType) { case Base64://from www .ja v a 2s . com byte[] mutated = BurpCallbacks.getInstance().getBurp().getHelpers().base64Decode(value); mutatedValue = "BASE64: " + new String(mutated); break; case URL: try { BurpCallbacks.getInstance().print("A: " + value); mutatedValue = "URL: " + URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SentinelHttpParamVirt.class.getName()).log(Level.SEVERE, null, ex); } break; case HTML: mutatedValue = "HTML: " + StringEscapeUtils.unescapeHtml4(value); break; default: mutatedValue = value; } return mutatedValue; }
From source file:emily.util.YTUtil.java
/** * @param videocode youtubecode/*from ww w.j ava 2 s.c om*/ * @return whats in the <title> tag on a youtube page */ public static String getTitleFromPage(String videocode) { String ret = ""; try { URL loginurl = new URL("https://www.youtube.com/watch?v=" + videocode); URLConnection yc = loginurl.openConnection(); yc.setConnectTimeout(10 * 1000); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); StringBuilder input = new StringBuilder(); String inputLine; while ((inputLine = in.readLine()) != null) input.append(inputLine); in.close(); int start = input.indexOf("<title>"); int end = input.indexOf("</title>"); ret = input.substring(start + 7, end - 10); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return StringEscapeUtils.unescapeHtml4(ret); }