All pastes #249288 Raw Edit

Miscellany

public java v1 · immutable
#249288 ·published 2006-11-15 16:59 UTC
rendered paste body
    /**     * Returns the description for the given id from ann     * @param annId      * @return the description for the given id from ann     */    private String getAnnDescription(String annId) {        try {            String url = "http://66.207.162.94/encyclopedia/anime.php?id=" + annId;                        HttpClient client = new HttpClient();            HttpMethod method = new GetMethod(url);            client.executeMethod(method);                        StringWriter sw = new StringWriter();            InputStream pageStream = method.getResponseBodyAsStream();            IOUtils.copy(pageStream, sw);            String page = sw.toString();                                    Pattern pattern = Pattern.compile(".*<DIV.*?>(Plot Summary\\:.*?</DIV>.*)", Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);            Matcher matcher = pattern.matcher(page);            if (matcher.matches()) {                String match = matcher.group(1);                Pattern innerPattern = Pattern.compile("(.*)<DIV.*?>(.*?)</DIV>(.*)", Pattern.MULTILINE | Pattern.DOTALL | Pattern.CASE_INSENSITIVE);                Matcher m = innerPattern.matcher(match);                while (m.matches()) {                    match = m.group(1)+m.group(2)+m.group(3);                     m = innerPattern.matcher(match);                }                match = match.replaceAll("(?m)(?i)(?s)</DIV>.*", "");                                match = match.replaceAll("(?m)(?i)(?s)<[^>]*?>", "");                match = match.replaceFirst("Plot Summary:", "");                match = match.trim();                match = match.replaceAll("\\s\\s", " ");                return match;            }        } catch (Exception e) {            e.printStackTrace();        }        return null;    }