Collections.sort(samples, new AliasComparator(Sample.class));
InputStream in = FormUtils.class.getResourceAsStream("/forms/odt/sampleDeliveryForm.odt");
if (in != null) {
OdfTextDocument oDoc = OdfTextDocument.loadDocument(in);
OdfContentDom contentDom = oDoc.getContentDom();
/*
OfficeTextElement contentRoot = oDoc.getContentRoot();
NodeList nl = contentRoot.getElementsByTagName("TABLE");
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element)nl.item(i);
System.out.println(e.getTagName() + " :: " + e.toString());
}
List<OdfTable> cTables = contentDom.getTableList();
for (OdfTable c : cTables) {
System.out.println(c.getTableName() + " :: " + c.getRowCount() + " :: " + c.getColumnCount());
}
*/
/*
OdfTable cTable = cTables.get(1);
for (OdfTableRow ctr : cTable.getRowList()) {
if (ctr.getRowIndex() == 0) {
OdfTableCell ctc0 = ctr.getCellByIndex(1);
OdfTextParagraph ctcp0 = new OdfTextParagraph(contentDom);
User u = samples.get(0).getProject().getSecurityProfile().getOwner();
ctcp0.setTextContent(u.getFullName() + " " + u.getEmail());
ctcp0.setProperty(StyleTextPropertiesElement.FontSize, "12pt");
ctc0.getOdfElement().appendChild(ctcp0);
}
}
*/
OdfTable oTable = oDoc.getTableByName("SamplesTable");
for (Sample s : samples) {
OdfTableRow row = oTable.appendRow();
OdfTableCell cell0 = row.getCellByIndex(0);
OdfTextParagraph cp0 = new OdfTextParagraph(contentDom);
cp0.setTextContent(s.getAlias());
cp0.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
cell0.getOdfElement().appendChild(cp0);
OdfTableCell cell1 = row.getCellByIndex(1);
OdfTextParagraph cp1 = new OdfTextParagraph(contentDom);
cp1.setTextContent(s.getScientificName());
cp1.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
cell1.getOdfElement().appendChild(cp1);
OdfTableCell cell2 = row.getCellByIndex(2);
OdfTextParagraph cp2 = new OdfTextParagraph(contentDom);
cp2.setTextContent(s.getIdentificationBarcode());
cp2.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
cell2.getOdfElement().appendChild(cp2);
OdfTableCell cell3 = row.getCellByIndex(3);
OdfTextParagraph cp3 = new OdfTextParagraph(contentDom);
cp3.setTextContent(s.getSampleType());
cp3.setProperty(StyleTextPropertiesElement.FontSize, "8pt");
cell3.getOdfElement().appendChild(cp3);
}
int count = 0;
for (OdfTableRow row : oTable.getRowList()) {
if (count % 2 != 0) {
for (int i = 0; i < row.getCellCount(); i++) {
row.getCellByIndex(i).setCellBackgroundColor("#EEEEEE");
}
}
count++;
}
oDoc.save(outpath);
return oDoc;
}
else {
throw new Exception("Could not read from resource");
}