@Test public void should_generate_full_table() { initDefaultTable(); configureExport(new ExportConf.Builder("xml").header(true).build()); processExport(new XmlExport()); Scanner scanner = new Scanner(new String(baos.toByteArray())); String firstLine = scanner.nextLine(); assertThat(firstLine).contains("<?xml version=\"1.0\"?>"); assertThat(firstLine).contains("<persons>"); assertThat(firstLine).contains("</persons>"); assertThat(firstLine).contains("<person id=\"1\" firstName=\"Selma\" lastName=\"Maldonado\" city=\"\" mail=\"venenatis@Duisvolutpat.com\"></person><person id=\"2\" firstName=\"Vanna\" lastName=\"Salas\" city=\"Denny\" mail=\"bibendum.fermentum.metus@ante.ca\"></person>"); }
@Override public void processExport(OutputStream output) { List<String> headers = new ArrayList<String>(); for (HtmlRow row : table.getHeadRows()) { for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { headers.add(StringUtils.uncapitalize(column.getContent().toString())); } } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; String objectType = DatatableOptions.INTERNAL_OBJECTTYPE.valueFrom(table.getTableConfiguration().getOptions()); String normalizedObjectType = objectType.toLowerCase(); try { writer = outputFactory.createXMLStreamWriter(output); writer.writeStartDocument("1.0"); writer.writeStartElement(normalizedObjectType + "s"); for (HtmlRow row : table.getBodyRows()) { writer.writeStartElement(normalizedObjectType); int i = 0; for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { writer.writeAttribute(headers.get(i), column.getContent().toString()); i++; } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } finally { try { writer.close(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } } }
XmlExport implements DatatablesExport { @Override public void processExport(OutputStream output) { List<String> headers = new ArrayList<String>(); for (HtmlRow row : table.getHeadRows()) { for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { headers.add(StringUtils.uncapitalize(column.getContent().toString())); } } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; String objectType = DatatableOptions.INTERNAL_OBJECTTYPE.valueFrom(table.getTableConfiguration().getOptions()); String normalizedObjectType = objectType.toLowerCase(); try { writer = outputFactory.createXMLStreamWriter(output); writer.writeStartDocument("1.0"); writer.writeStartElement(normalizedObjectType + "s"); for (HtmlRow row : table.getBodyRows()) { writer.writeStartElement(normalizedObjectType); int i = 0; for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { writer.writeAttribute(headers.get(i), column.getContent().toString()); i++; } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } finally { try { writer.close(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } } } }
XmlExport implements DatatablesExport { @Override public void processExport(OutputStream output) { List<String> headers = new ArrayList<String>(); for (HtmlRow row : table.getHeadRows()) { for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { headers.add(StringUtils.uncapitalize(column.getContent().toString())); } } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; String objectType = DatatableOptions.INTERNAL_OBJECTTYPE.valueFrom(table.getTableConfiguration().getOptions()); String normalizedObjectType = objectType.toLowerCase(); try { writer = outputFactory.createXMLStreamWriter(output); writer.writeStartDocument("1.0"); writer.writeStartElement(normalizedObjectType + "s"); for (HtmlRow row : table.getBodyRows()) { writer.writeStartElement(normalizedObjectType); int i = 0; for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { writer.writeAttribute(headers.get(i), column.getContent().toString()); i++; } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } finally { try { writer.close(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } } }  }
XmlExport implements DatatablesExport { @Override public void processExport(OutputStream output) { List<String> headers = new ArrayList<String>(); for (HtmlRow row : table.getHeadRows()) { for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { headers.add(StringUtils.uncapitalize(column.getContent().toString())); } } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; String objectType = DatatableOptions.INTERNAL_OBJECTTYPE.valueFrom(table.getTableConfiguration().getOptions()); String normalizedObjectType = objectType.toLowerCase(); try { writer = outputFactory.createXMLStreamWriter(output); writer.writeStartDocument("1.0"); writer.writeStartElement(normalizedObjectType + "s"); for (HtmlRow row : table.getBodyRows()) { writer.writeStartElement(normalizedObjectType); int i = 0; for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { writer.writeAttribute(headers.get(i), column.getContent().toString()); i++; } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } finally { try { writer.close(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } } }  @Override void initExport(HtmlTable table); @Override void processExport(OutputStream output); }
XmlExport implements DatatablesExport { @Override public void processExport(OutputStream output) { List<String> headers = new ArrayList<String>(); for (HtmlRow row : table.getHeadRows()) { for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { headers.add(StringUtils.uncapitalize(column.getContent().toString())); } } XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = null; String objectType = DatatableOptions.INTERNAL_OBJECTTYPE.valueFrom(table.getTableConfiguration().getOptions()); String normalizedObjectType = objectType.toLowerCase(); try { writer = outputFactory.createXMLStreamWriter(output); writer.writeStartDocument("1.0"); writer.writeStartElement(normalizedObjectType + "s"); for (HtmlRow row : table.getBodyRows()) { writer.writeStartElement(normalizedObjectType); int i = 0; for (HtmlColumn column : row.getColumns(ReservedFormat.ALL, ReservedFormat.XML)) { writer.writeAttribute(headers.get(i), column.getContent().toString()); i++; } writer.writeEndElement(); } writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } finally { try { writer.close(); } catch (XMLStreamException e) { StringBuilder sb = new StringBuilder("Something went wrong during the XML generation of the table '"); sb.append(table.getOriginalId()); sb.append("' and with the following export configuration: "); sb.append(exportConf.toString()); throw new DandelionException(sb.toString(), e); } } }  @Override void initExport(HtmlTable table); @Override void processExport(OutputStream output);  }