Example usage for org.w3c.dom.html HTMLCollection getLength

List of usage examples for org.w3c.dom.html HTMLCollection getLength

Introduction

In this page you can find the example usage for org.w3c.dom.html HTMLCollection getLength.

Prototype

public int getLength();

Source Link

Document

This attribute specifies the length or size of the list.

Usage

From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java

public List<String> getLists() throws MailmanException {
    HttpClient client = new HttpClient(proxyClientService.getHttpConnectionManager());
    GetMethod get = new GetMethod(getMailmanUrl("/admin"));
    List<String> lists = new ArrayList<String>();
    try {/*from   w  w w  .  j a va 2 s . co m*/
        int result = client.executeMethod(get);
        if (result != HttpServletResponse.SC_OK) {
            LOGGER.warn("Got " + result + " from http request");
            throw new MailmanException("Unable to list mailinglists");
        }
        DOMParser parser = new DOMParser();
        parser.parse(new InputSource(get.getResponseBodyAsStream()));
        Document doc = parser.getDocument();
        NodeList tableNodes = doc.getElementsByTagName("table");
        if (tableNodes.getLength() < 2) {
            throw new MailmanException("Unrecognised page format.");
        }
        HTMLTableElement mainTable = (HTMLTableElement) tableNodes.item(0);
        HTMLCollection rows = mainTable.getRows();
        for (int i = 4; i < rows.getLength(); i++) {
            lists.add(parseListNameFromRow((HTMLTableRowElement) rows.item(i)));
        }
    } catch (SAXException e) {
        throw new MailmanException("Error parsing mailman response", e);
    } catch (HttpException e) {
        throw new MailmanException("HTTP Exception communicating with mailman server", e);
    } catch (IOException e) {
        throw new MailmanException("IOException communicating with mailman server", e);
    } finally {
        get.releaseConnection();
    }
    return lists;
}

From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java

private String parseListNameFromRow(HTMLTableRowElement item) throws MailmanException {
    HTMLCollection cells = item.getCells();
    if (cells.getLength() != 2) {
        throw new MailmanException("Unexpected table row format");
    }/*from   w w  w. j a  v a 2  s  .c  om*/
    return cells.item(0).getTextContent();
}