<%-- 
    Document   : index
    Created on : Apr 15, 2009, 9:22:50 PM
    Author     : sg128468
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.text.*,
                 java.util.*,
                 org.w3c.dom.*,
                 org.odftoolkit.odfdom.dom.OdfNamespace,
                 org.odftoolkit.odfdom.doc.OdfDocument,
                 org.odftoolkit.odfdom.doc.OdfFileDom,
                 org.odftoolkit.odfdom.doc.element.text.*,
                 org.odftoolkit.odfdom.doc.element.office.*,
                 org.odftoolkit.odfdom.doc.element.table.*,
                 javax.xml.xpath.*" %>
                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Address Data Report</h1>
        <table>
            <%
             ////////////////////////////////////////////////////////////////
             // Start ODFDOM handling
             // 1 Load source document
			 // Edit the lab root - it's the base directory for reading the input file
			 LAB_ROOT = <LAB_ROOT>";
             OdfDocument document = OdfDocument.loadDocument(LAB_ROOT + "/resources/report_data.ods");
             // 2 Get the Content DOM of this source document
             OdfFileDom content = document.getContentDom();

             // 3 Find the data rows
             XPath xpath = XPathFactory.newInstance().newXPath();
             xpath.setNamespaceContext(new OdfNamespace());
             NodeList rows = (NodeList)xpath.evaluate("//table:table-row", content, XPathConstants.NODESET);

             // 4 Print data to report table
             for (int i = 0; i < rows.getLength(); ++i){
                OdfTableRow row = (OdfTableRow)rows.item(i);
                out.print("<tr>");
                NodeList tableRowChilds = row.getChildNodes();
                for (int j = 0; j < tableRowChilds.getLength(); ++j){
                    OdfTableCell cell = (OdfTableCell)tableRowChilds.item(j);
                    out.print(i == 0 ? "<th>" : "<td>");
                    String textContent = cell.getTextContent();
                    out.print(textContent);
                    out.print(i == 0 ? "</th>" : "</td>");
                }
                out.print("</tr>");
             }
            %>
        </table>
    </body>
</html>
