text = text.trim();
    public List retrieveListing(URL url, boolean includeFiles,        boolean includeDirectories) throws IOException {        List urlList = new ArrayList();        // add trailing slash for relative urls        if (!url.getPath().endsWith("/")) {            url = new URL(url.getProtocol(), url.getHost(), url.getPort(),                    url.getPath() + "/");        }        BufferedReader r =            new BufferedReader(new InputStreamReader(URLHandlerRegistry.getDefault()                                                                       .openStream(url)));        String htmlText = FileUtil.readEntirely(r);        Matcher matcher = PATTERN.matcher(htmlText);        while (matcher.find()) {            // get the href text and the displayed text            String href = matcher.group(1);            String text = matcher.group(2);                        if ((href == null) || (text == null)) {                // the groups were not found (shouldn't happen, really)                continue;            }            // absolute href: convert to relative one            if (href.startsWith("/")) {                int slashIndex = href.substring(0, href.length() - 1).lastIndexOf('/');                href= href.substring(slashIndex+1);            }            // exclude those where they do not match            // href will never be truncated, text may be truncated by apache            // may have a '.' from either the extension (.jar) or "..&gt;"            int dotIndex = text.indexOf('.');            if ( ((dotIndex != -1) && !href.startsWith(text.substring(0, dotIndex)))                || ((dotIndex == -1) && !href.equalsIgnoreCase(text)) ) {                // the href and the text do not "match"                continue;            }            boolean directory = href.endsWith("/");            if ((directory && includeDirectories)                || (!directory && includeFiles)) {                URL child = new URL(url, href);                urlList.add(child);                Message.debug("ApacheURLLister found URL=[" + child + "].");            }        }        return urlList;    }