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

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

Introduction

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

Prototype

public Node item(int index);

Source Link

Document

This method retrieves a node specified by ordinal index.

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 {/*w w w  . j  ava  2s.c  o 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");
    }/*  w w  w .ja  v  a 2  s. co m*/
    return cells.item(0).getTextContent();
}