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:bfile.util.StringUtils.java
/** * ?// w w w. j a v a 2 s .co m * @param str * @param length ? * @return */ public static String abbr(String str, int length) { if (str == null) { return ""; } try { StringBuilder sb = new StringBuilder(); int currentLength = 0; for (char c : replaceHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) { currentLength += String.valueOf(c).getBytes("GBK").length; if (currentLength <= length - 3) { sb.append(c); } else { sb.append("..."); break; } } return sb.toString(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return ""; }
From source file:net.xby1993.common.util.io.EncodeUtil.java
/** * Html?HTML4???./*from w ww . j av a 2 s . c o m*/ * * "bread" & "butter""bread" & "butter" */ public static String unescapeHtml(String html) { return StringEscapeUtils.unescapeHtml4(html); }
From source file:net.zifnab.google.google.java
public static String[] search(String terms) { String key = "ABQIAAAA6KnsrpTIyjEMJ1EqHjKG_xRBaorPdDj7IJd2xMtxtE9DwSoKhRQgazFCenlI-wnGV1574jW06163iw"; String ip = "173.255.208.207"; System.out.println("Google-ing: " + terms); terms = terms.replace(' ', '+'); try {/*from www .j a va 2s. c om*/ //Opens URL URL googlesearch = new URL("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&" + "q=" + terms + "&key=" + key + "&userip=" + ip); URLConnection connection = googlesearch.openConnection(); connection.addRequestProperty("Referer", "zifnab06.net"); //Read in JSON crap from URL. String line; StringBuilder results = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); while ((line = reader.readLine()) != null) { results.append(line + "\n"); } //JSON Crap. Google needs to use XML.... JSONObject json = new JSONObject(results.toString()); JSONArray ja = json.getJSONObject("responseData").getJSONArray("results"); JSONObject j = ja.getJSONObject(0); //Returns Title: URL String[] ret = { j.toString(), StringEscapeUtils.unescapeHtml4(j.getString("titleNoFormatting")) + ": " + URLDecoder.decode(j.getString("url"), "UTF-8") }; return ret; } catch (MalformedURLException e) { //Shouldn't EVER hit this. System.out.println(e); String[] ret = { "error", e.toString() }; return (ret); } catch (IOException e) { //Shouldn't EVER hit this. System.out.println(e); String[] ret = { "error", e.toString() }; return (ret); } catch (Exception e) { System.out.println(e); String[] ret = { "error", "No results found!" }; return ret; } }
From source file:no.dusken.momus.service.drive.GoogleDocsTextConverter.java
/** * Converts HTML entities to "normal characters", for instance * it converts å to /*from ww w.ja v a 2s .c o m*/ * * But < (<) and > (>) are ignored, to avoid < and > in the written * text to affect our HTML. */ private String unescapeHtml(String in) { // replace all > and < Matcher m = ltToUnicode.matcher(in); String out = m.replaceAll(ltUnicode); m = gtToUnicode.matcher(out); out = m.replaceAll(gtUnicode); //Convert quotes to "guillemets" out = out.replaceAll("“", ""); out = out.replaceAll("”", ""); // convert stuff out = StringEscapeUtils.unescapeHtml4(out); // add the > and <s back m = unicodeToLt.matcher(out); out = m.replaceAll("<"); m = unicodeToGt.matcher(out); out = m.replaceAll(">"); return out; }
From source file:noThreads.Menu.java
public void createMenu() throws IOException, InterruptedException { Document doc = null;/* w w w . j ava 2s . c om*/ BufferedReader br = null; System.out.print("******************** Menu Options ******************** " + "\n1. Get a playlist for all the stations at <e-radio.gr>" + "\n2. View the available station Categories and get a playlist." + "\n3. View the available station Locations and get a playlist." + "\n4. View the station Ratings (Top) and get a playlist." + "\n5. Exit." + "\n\n" + "Please make a choice (1-5): "); br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } switch (choice) { case (1): //GET all the e-radio location links (in order to get all the links) doc = parseUrl(URL, 0); if (doc == null) { print("No connection to the server! Exiting..."); System.exit(1); } Elements links = doc.select("div[id=paneContainer]").select("a[href*=/locations/]"); for (Element link : links) theUrls.add(link.attr("abs:href")); System.out.println("...Processing <All e-radio> station links"); break; case (2): //Get CATEGORIES doc = parseUrl(URL, 0); if (doc == null) { print("No connection to the server! Exiting..."); System.exit(1); } Elements categoryLinks = doc.select("div[id=paneContainer]").select("a[href*=/categories/]"); System.out.println("E-radio stations available categories: " + "\n"); for (int i = 0; i < categoryLinks.size(); i++) { System.out.println(i + 1 + ". " + StringEscapeUtils.unescapeHtml4(categoryLinks.get(i).html())); } System.out.print("\n" + "Please make a choise (1-" + categoryLinks.size() + "): "); br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= categoryLinks.size() && choice >= 1) { theUrls.add(categoryLinks.get(choice - 1).attr("abs:href")); System.out.println("...Processing the <" + StringEscapeUtils.unescapeHtml4(categoryLinks.get(choice - 1).html()) + "> category"); } else { System.out.println("Wrong selection..."); System.out.println("Exiting program..."); System.exit(1); } break; case (3)://Get LOCATIONS doc = parseUrl(URL, 0); if (doc == null) { print("No connection to the server! Exiting..."); System.exit(1); } Elements locationLinks = doc.select("div[id=paneContainer]").select("a[href*=/locations/]"); System.out.println("E-radio stations available locations: " + "\n"); for (int i = 0; i < locationLinks.size(); i++) { System.out.println(i + 1 + ". " + StringEscapeUtils.unescapeHtml4(locationLinks.get(i).html())); } System.out.print("\n" + "Please make a choise (1-" + locationLinks.size() + "): "); br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= locationLinks.size() && choice >= 1) { theUrls.add(locationLinks.get(choice - 1).attr("abs:href")); System.out.println("...Processing <" + StringEscapeUtils.unescapeHtml4(locationLinks.get(choice - 1).html()) + "> locatino"); } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } break; case (4): final int YEARLY_RATING = 10; doc = parseUrl(URL, 0); if (doc == null) { print("No connection to the server! Exiting..."); System.exit(1); } Elements ratingsMenu = doc.select("div[class=menuFly]").select("li").select("a[class=hide]"); print("\nStations ratings: \n"); for (int i = 0; i < ratingsMenu.size(); i++) { System.out.println(i + 1 + ". " + StringEscapeUtils.unescapeHtml4(ratingsMenu.get(i).html())); } System.out.print("\n" + "Please make a choise (1-" + ratingsMenu.size() + "): "); br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } /* * The html of the Ratings menu processed * has this structure: * <div> * <ul> * <li> * <ul> * ... * </ul> * </li> * ... * </ul> * </div> */ if (choice <= ratingsMenu.size() && choice >= 1) { //Get the DIV element with class "menuFly" Elements div = doc.select("div[class=menuFly]"); //div Elements list has only one element. So get the children of div Elements ul = div.get(0).children(); //ul Elements list has only one element. So get the children of ul Elements li = ul.get(0).children(); //remove blank elements for (int j = 0; j < li.size(); j++) { if (li.get(j).hasText() == false) li.remove(li.get(j)); } //get the title of user choice and print it out print("\n%s", StringEscapeUtils.unescapeHtml4(ratingsMenu.get(choice - 1).html()) + "\n"); //check if there is a sub-menu Elements ulTag = li.get(choice - 1).select("ul"); if (ulTag.hasText() == true) { Elements subMenu = ulTag.select("li").select("a[href]"); //print the sub-menu for (int j = 0; j < subMenu.size(); j++) print("%s. %s ", j + 1, StringEscapeUtils.unescapeHtml4(subMenu.get(j).html())); System.out.print("\n" + "Please make a choise (1-" + subMenu.size() + "): "); //read user input br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= subMenu.size() && choice >= 1) { theUrls.add(subMenu.get(choice - 1).attr("abs:href")); System.out.println("...Processing the <" + StringEscapeUtils.unescapeHtml4(subMenu.get(choice - 1).html()) + "> category"); } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } } else { if (choice == YEARLY_RATING) { String url = li.get(choice - 1).select("a[href").attr("abs:href"); doc = parseUrl(url, 0); if (doc != null) { Elements yearTopSubMenu = doc.select("div[id=maintabsid]").select("a[href]"); //print the sub-menu for (int i = 0; i < yearTopSubMenu.size(); i++) print("%s. %s", i + 1, StringEscapeUtils.unescapeHtml4(yearTopSubMenu.get(i).html())); System.out.print("\n" + "Please make a choise (1-" + yearTopSubMenu.size() + "): "); //read user input br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= yearTopSubMenu.size() && choice >= 1) { if (choice == 1) { theUrls.add(yearTopSubMenu.get(choice - 1).attr("abs:href")); print("...Processing the <" + StringEscapeUtils.unescapeHtml4(yearTopSubMenu.get(choice - 1).html()) + "> category"); } else if (choice == 2) { String link = yearTopSubMenu.get(choice - 1).attr("abs:href"); doc = parseUrl(link, 0); //print menu title print("\n%s", StringEscapeUtils.unescapeHtml4(yearTopSubMenu.get(choice - 1).html()) + "\n"); if (doc != null) { Elements elem = doc.select("select[id=selectoption]") .select("option[value]"); ArrayList<Integer> nums = new ArrayList<Integer>(); for (int i = 0; i < elem.size(); i++) { //get the select category values and print the sub-menu int num = Integer.parseInt(elem.get(i).attr("value")); //add them to list nums.add(num); print("%s. %s", i + 1, StringEscapeUtils.unescapeHtml4( elem.get(i).html().replace("Select category: ", ""))); } System.out.print("\n" + "Please make a choise (1-" + elem.size() + "): "); //read user input br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= elem.size() && choice >= 1) { int num = nums.get(choice - 1); String added = "max=100&id=" + num + "&"; String newlink = link.replace("max=100&", added); //print("\nlink: %s", newlink); DEBUG print theUrls.add(newlink); System.out .println("...Processing the <" + StringEscapeUtils.unescapeHtml4(elem.get(choice - 1) .html().replace("Select category: ", "")) + "> category"); print(elem.get(choice - 1).select("a[href]").attr("abs:href")); } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } } else { System.out.println("ERROR: Cannot get links from server!"); System.out.println("Exiting program..."); System.exit(1); } } else { String link = yearTopSubMenu.get(choice - 1).attr("abs:href"); doc = parseUrl(link, 0); //print menu title print("\n%s", StringEscapeUtils.unescapeHtml4(yearTopSubMenu.get(choice - 1).html()) + "\n"); if (doc != null) { Elements elem = doc.select("select[id=selectoption]") .select("option[value]"); ArrayList<Integer> nums = new ArrayList<Integer>(); for (int i = 0; i < elem.size(); i++) { //get the select category values and print the sub-menu int num = Integer.parseInt(elem.get(i).attr("value")); //add them to list nums.add(num); print("%s. %s", i + 1, StringEscapeUtils.unescapeHtml4( elem.get(i).html().replace("Select location: ", ""))); } System.out.print("\n" + "Please make a choise (1-" + elem.size() + "): "); //read user input br = new BufferedReader(new InputStreamReader(System.in)); try { choice = Integer.parseInt(br.readLine()); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } if (choice <= elem.size() && choice >= 1) { int num = nums.get(choice - 1); String[] linkParts = link.split("&", 4); String finalLink = linkParts[0] + "&" + linkParts[1] + "&" + "id=" + num + "&" + linkParts[3]; //print("\nlink: %s \n link2: %s \n link3: %s \n link: %s \nsize: %s", linkParts[0], linkParts[1], linkParts[2], linkParts[3], linkParts.length); // DEBUG print //print(finalLink); theUrls.add(finalLink); System.out .println("...Processing the <" + StringEscapeUtils.unescapeHtml4(elem.get(choice - 1) .html().replace("Select category: ", "")) + "> category"); print(elem.get(choice - 1).select("a[href]").attr("abs:href")); } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } } else { System.out.println("ERROR: Cannot get links from server!"); System.out.println("Exiting program..."); System.exit(1); } } } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } } else { System.out.println("ERROR: Cannot get links from server!"); System.out.println("Exiting program..."); System.exit(1); } } else { theUrls.add(li.get(choice - 1).select("a[href").attr("abs:href")); System.out.println("...Processing the <" + StringEscapeUtils.unescapeHtml4(ratingsMenu.get(choice - 1).html()) + "> category"); print(li.get(choice - 1).select("a[href]").attr("abs:href")); } } } else { System.out.println("Wrong selection!"); System.out.println("Exiting program..."); System.exit(1); } break; case (5): System.out.println("Exiting program..."); System.exit(0); break; default: System.out.println("Invalid choice! Exiting..."); System.exit(1); break; } }
From source file:nya.miku.wishmaster.api.AbstractLynxChanModule.java
private PostModel mapPostModel(JSONObject object) { PostModel model = new PostModel(); try {/*from w ww . jav a2s.c om*/ model.timestamp = CHAN_DATEFORMAT.parse(object.optString("creation")).getTime(); } catch (ParseException e) { Logger.e(TAG, "cannot parse date; make sure you choose the right DateFormat for this chan", e); } model.name = StringEscapeUtils.unescapeHtml4(object.optString("name")); model.email = StringEscapeUtils.unescapeHtml4(object.optString("email")); model.subject = StringEscapeUtils.unescapeHtml4(object.optString("subject")); model.comment = object.optString("markdown", object.optString("message")); model.comment = RegexUtils.replaceAll(model.comment, RED_TEXT_MARK_PATTERN, "<font color=\"red\"><b>$1</b></font>"); model.comment = RegexUtils.replaceAll(model.comment, GREEN_TEXT_MARK_PATTERN, "<span class=\"quote\">$1</span>"); model.comment = RegexUtils.replaceAll(model.comment, REPLY_NUMBER_PATTERN, ">>$1"); String banMessage = object.optString("banMessage", ""); if (!banMessage.equals("")) model.comment = model.comment + "<br/><em><font color=\"red\">(" + banMessage + ")</font></em>"; String flag = object.optString("flag", ""); if (!flag.equals("")) { BadgeIconModel icon = new BadgeIconModel(); icon.description = object.optString("flagName"); icon.source = flag; model.icons = new BadgeIconModel[] { icon }; } int post_number = object.optInt("postId", -1); model.number = post_number == -1 ? null : Integer.toString(post_number); if (model.number == null) { int thread_number = object.optInt("threadId", -1); model.number = thread_number == -1 ? "" : Integer.toString(thread_number); } String signedRole = object.optString("signedRole", ""); if (!signedRole.equals("")) model.trip = "##" + signedRole; String id = object.optString("id", ""); model.sage = id.equalsIgnoreCase("Heaven") || model.email.toLowerCase(Locale.US).contains("sage"); if (!id.equals("")) { model.name += (" ID:" + id); model.color = CryptoUtils.hashIdColor(id); } JSONArray files = object.optJSONArray("files"); if (files != null) { model.attachments = new AttachmentModel[files.length()]; for (int i = 0, len = files.length(); i < len; ++i) { model.attachments[i] = mapAttachment(files.getJSONObject(i)); } } return model; }
From source file:nya.miku.wishmaster.chans.AbstractVichanModule.java
protected PostModel mapPostModel(JSONObject object, String boardName) { PostModel model = new PostModel(); model.number = Long.toString(object.getLong("no")); model.name = StringEscapeUtils .unescapeHtml4(object.optString("name", "Anonymous").replaceAll("</?span[^>]*?>", "")); model.subject = StringEscapeUtils.unescapeHtml4(object.optString("sub", "")); model.comment = object.optString("com", ""); model.email = object.optString("email", ""); model.trip = object.optString("trip", ""); String capcode = object.optString("capcode", "none"); if (!capcode.equals("none")) model.trip += "##" + capcode; String countryIcon = object.optString("country", ""); if (!countryIcon.equals("")) { BadgeIconModel icon = new BadgeIconModel(); icon.source = "/static/flags/" + countryIcon.toLowerCase(Locale.US) + ".png"; icon.description = object.optString("country_name"); model.icons = new BadgeIconModel[] { icon }; }// w w w.ja v a 2s . c o m model.op = false; String id = object.optString("id", ""); model.sage = id.equalsIgnoreCase("Heaven") || model.email.toLowerCase(Locale.US).contains("sage"); if (!id.equals("")) model.name += (" ID:" + id); if (!id.equals("") && !id.equalsIgnoreCase("Heaven")) model.color = CryptoUtils.hashIdColor(id); model.timestamp = object.getLong("time") * 1000; model.parentThread = object.optString("resto", "0"); if (model.parentThread.equals("0")) model.parentThread = model.number; List<AttachmentModel> attachments = null; boolean isSpoiler = object.optInt("spoiler") == 1; AttachmentModel rootAttachment = mapAttachment(object, boardName, isSpoiler); if (rootAttachment != null) { attachments = new ArrayList<>(); attachments.add(rootAttachment); JSONArray extraFiles = object.optJSONArray("extra_files"); if (extraFiles != null && extraFiles.length() != 0) { for (int i = 0, len = extraFiles.length(); i < len; ++i) { AttachmentModel attachment = mapAttachment(extraFiles.getJSONObject(i), boardName, isSpoiler); if (attachment != null) attachments.add(attachment); } } } String embed = object.optString("embed", ""); if (!embed.equals("")) { AttachmentModel embedAttachment = new AttachmentModel(); embedAttachment.type = AttachmentModel.TYPE_OTHER_NOTFILE; Matcher linkMatcher = ATTACHMENT_EMBEDDED_LINK.matcher(embed); if (linkMatcher.find()) { embedAttachment.path = linkMatcher.group(1); if (embedAttachment.path.startsWith("//")) embedAttachment.path = (useHttps() ? "https:" : "http:") + embedAttachment.path; Matcher thumbMatcher = ATTACHMENT_EMBEDDED_THUMB.matcher(embed); if (thumbMatcher.find()) { embedAttachment.thumbnail = thumbMatcher.group(1); if (embedAttachment.thumbnail.startsWith("//")) embedAttachment.thumbnail = (useHttps() ? "https:" : "http:") + embedAttachment.thumbnail; } embedAttachment.isSpoiler = isSpoiler; embedAttachment.size = -1; if (attachments != null) attachments.add(embedAttachment); else attachments = Collections.singletonList(embedAttachment); } } if (attachments != null) model.attachments = attachments.toArray(new AttachmentModel[attachments.size()]); return model; }
From source file:nya.miku.wishmaster.chans.arhivach.ArhivachBoardReader.java
protected void readPost() throws IOException { skipUntilSequence(FILTERS_OPEN[FILTER_THREAD_LINK]); String link = readUntilSequence(FILTERS_CLOSE[FILTER_THREAD_LINK]); Matcher matcher = Pattern.compile("(href *= *\"(.*)\")").matcher(link); String url = ""; if (matcher.find()) url = matcher.group(1);/* www .j av a 2s .c o m*/ matcher = Pattern.compile("(\\d+)").matcher(url); if (matcher.find()) currentPost.number = matcher.group(0); String commentData = readUntilSequence(FILTERS_CLOSE[FILTER_END_COMMENT]); matcher = Pattern.compile("<b>(.*)</b>\\s*—\\s*").matcher(commentData); if (matcher.find()) { currentPost.subject = StringEscapeUtils.unescapeHtml4(matcher.group(1)); currentPost.comment = commentData.substring(matcher.group(0).length()); } else { currentPost.comment = commentData; } }
From source file:nya.miku.wishmaster.chans.cirno.Chan410CatalogReader.java
private void handleFilter(int filterIndex) throws IOException { switch (filterIndex) { case FILTER_START: String threadUrl = readUntilSequence(FILTERS_CLOSE[filterIndex]); Matcher matcher = PATTERN_THREADNUMBER.matcher(threadUrl); if (matcher.matches()) { currentThread.posts[0].number = matcher.group(1); }// w w w. ja va 2 s . co m break; case FILTER_THUMBNAIL: AttachmentModel attachment = new AttachmentModel(); attachment.type = AttachmentModel.TYPE_IMAGE_STATIC; attachment.size = -1; attachment.width = -1; attachment.height = -1; attachment.thumbnail = readUntilSequence(FILTERS_CLOSE[filterIndex]); attachment.path = attachment.thumbnail.replace("/thumb/", "/src/").replaceAll("(\\d+)c\\.", "$1."); currentThread.posts[0].attachments = new AttachmentModel[] { attachment }; break; case FILTER_SUBJECT: currentThread.posts[0].subject = StringEscapeUtils .unescapeHtml4(readUntilSequence(FILTERS_CLOSE[filterIndex])).trim(); break; case FILTER_COMMENT: currentThread.posts[0].comment = readUntilSequence(FILTERS_CLOSE[filterIndex]); break; case FILTER_OMITTED: int postsOmitted = -1; try { postsOmitted = Integer.parseInt(readUntilSequence(FILTERS_CLOSE[filterIndex])); } catch (NumberFormatException e) { } if (postsOmitted > 0) currentThread.postsCount = 1 + postsOmitted; break; case FILTER_STATUS: String status = readUntilSequence(FILTERS_CLOSE[filterIndex]); if (status.contains("closed")) currentThread.isClosed = true; if (status.contains("sticked")) currentThread.isSticky = true; break; case FILTER_END: finalizeThread(); break; } }
From source file:nya.miku.wishmaster.chans.ernstchan.ErnstModule.java
@Override public String sendPost(SendPostModel model, ProgressListener listener, CancellableTask task) throws Exception { String url = getUsingUrl() + "/wakaba.pl"; ExtendedMultipartBuilder postEntityBuilder = ExtendedMultipartBuilder.create().setDelegates(listener, task) .addString("task", "post").addString("board", model.boardName); if (model.threadNumber != null) postEntityBuilder.addString("parent", model.threadNumber); if (model.sage) postEntityBuilder.addString("field2", "sage"); postEntityBuilder.addString("gb2", "thread").addString("field1", model.name) .addString("field3", model.subject).addString("field4", model.comment) .addString("captcha", model.captchaAnswer).addString("password", model.password); if (model.attachments != null && model.attachments.length > 0) { for (int i = 0; i < model.attachments.length; ++i) { postEntityBuilder.addFile("file", model.attachments[i], model.randomHash); }/*ww w. j a v a2 s .co m*/ } HttpRequestModel request = HttpRequestModel.builder().setPOST(postEntityBuilder.build()).setNoRedirect(true) .build(); HttpResponseModel response = null; try { response = HttpStreamer.getInstance().getFromUrl(url, request, httpClient, null, task); if (response.statusCode == 303) { for (Header header : response.headers) { if (header != null && HttpHeaders.LOCATION.equalsIgnoreCase(header.getName())) { return fixRelativeUrl(header.getValue()); } } } else if (response.statusCode == 200) { ByteArrayOutputStream output = new ByteArrayOutputStream(1024); IOUtils.copyStream(response.stream, output); String htmlResponse = output.toString("UTF-8"); if (htmlResponse.contains("<div class=\"error\">")) { int start = htmlResponse.indexOf("<div class=\"info\">"); if (start != -1) { int end = htmlResponse.indexOf("</div>", start + 18); if (end != -1) { throw new Exception(StringEscapeUtils .unescapeHtml4(htmlResponse.substring(start + 18, end).trim())); } } } } else throw new Exception(response.statusCode + " - " + response.statusReason); } finally { if (response != null) response.release(); } return null; }