Package com.basiscomponents.db
Class ResultSetExporter
- java.lang.Object
-
- com.basiscomponents.db.ResultSetExporter
-
public class ResultSetExporter extends Object
Provides static methods to export acom.basiscomponents.db.ResultSet
in the following formats:- HTML(<table> tag)
- JSON
- TXT
- XLSX
- XML
-
-
Constructor Summary
Constructors Constructor Description ResultSetExporter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
exportToCSV(File outputFile, ResultSet rs)
Exports the content of the given ResultSet from a BBjGridExWidgetstatic void
exportToCSV(File outputFile, ResultSet rs, DataRow baseDR, boolean useLabel)
Method to export a result set to a CSV filestatic net.sf.jasperreports.engine.JasperPrint
exportToJasperPrint(File file, ResultSet rs, SheetConfiguration sheetConfig, boolean baristaMode, int fitTo, boolean landscapeMode)
static File
exportToPdf(File file, net.sf.jasperreports.engine.JasperPrint jasperPrint)
static File
exportToPDF(File file, ResultSet rs, SheetConfiguration sheetConfig, boolean baristaMode, int fitTo, boolean landscapeMode)
Exports the content of the given ResultSet from a BBjGridExWidgetstatic File
exportToPDFByCustomReport(File outputFile, File customReport, ResultSet rs)
Exports the content of the given ResultSet from a BBjGridExWidgetstatic void
writeHTML(ResultSet resultSet, Writer writer)
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.static void
writeHTML(ResultSet resultSet, Writer writer, DataRow baseDR, boolean useLabel)
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.static void
writeHTML(ResultSet resultSet, Writer writer, HashMap<String,String> links)
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.static void
writeHTML(ResultSet resultSet, Writer writer, HashMap<String,String> links, DataRow baseDR, boolean useLabel)
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.static void
writeJSON(ResultSet resultSet, Writer writer)
Converts the given ResultSet object to a JSON String and writes it to the output stream using the given writer object.static void
writeJSON(ResultSet resultSet, Writer writer, Boolean fMeta)
static void
writeTXT(ResultSet resultSet, Writer writer)
Uses the given Writer object to write the ResultSet's content as plain text to the output stream.static void
writeTXT(ResultSet resultSet, Writer writer, DataRow baseDR, Boolean useLabel)
Uses the given Writer object to write the ResultSet's content as plain text to the output stream.static void
writeXLSX(ResultSet rs, File outputFile, boolean writeHeader)
Writes the content of the given ResultSet as XLSX into the specified File.static void
writeXLSX(ResultSet rs, File outputFile, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow AttributesRecord)
Writes the content of the given ResultSet as XLSX into the specified File.static void
writeXLSX(ResultSet rs, File outputFile, boolean writeHeader, SheetConfiguration sheetConfig)
Writes the content of the given ResultSet as XLSX into the specified File.static void
writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader)
Writes the content of the given ResultSet into an output stream.static void
writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow attributesRecord)
Writes the content of the given ResultSet into an output stream.static void
writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow AttributesRecord, SheetConfiguration sheetConfig)
Writes the content of the given ResultSet into an output stream.static void
writeXML(ResultSet resultSet, String rootTagName, String entityName, Writer writer)
Uses the given Writer object to write the ResultSet's content as XML to the output stream.static void
writeXML(ResultSet resultSet, String rootTagName, String entityName, Writer writer, DataRow baseDR, boolean useLabel)
Uses the given Writer object to write the ResultSet's content as XML to the output stream.
-
-
-
Method Detail
-
writeXML
public static void writeXML(ResultSet resultSet, String rootTagName, String entityName, Writer writer) throws Exception
Uses the given Writer object to write the ResultSet's content as XML to the output stream. The given root tag name will be used as the XML's root tag, and the give entity name will be used as surrounding tag for each of the ResultSet's DataRow objects.
Usage:
StringWriter w = new StringWriter(); ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); ResultSetExporter.writeXML(rs, "articles", "article", w); w.flush(); w.close(); System.out.println(w.toString()); FileWriter fw = new FileWriter("D:/test.xml"); ResultSetExporter.writeXML(rs, "articles", "article", fw); fw.flush(); fw.close();
- Parameters:
resultSet
- The ResultSet object whose content will be written in XML format.rootTagName
- The name of the XML Root Tag to use.entityName
- The name of the XML tag to use for each DataRow of the ResultSet.writer
- The Writer object used to write the XML.- Throws:
Exception
- Gets thrown in case the XML could not be written.
-
writeXML
public static void writeXML(ResultSet resultSet, String rootTagName, String entityName, Writer writer, DataRow baseDR, boolean useLabel) throws Exception
Uses the given Writer object to write the ResultSet's content as XML to the output stream. The given root tag name will be used as the XML's root tag, and the give entity name will be used as surrounding tag for each of the ResultSet's DataRow objects.
Usage:
StringWriter w = new StringWriter(); ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); ResultSetExporter.writeXML(rs, "articles", "article", w); w.flush(); w.close(); System.out.println(w.toString()); FileWriter fw = new FileWriter("D:/test.xml"); ResultSetExporter.writeXML(rs, "articles", "article", fw); fw.flush(); fw.close();
- Parameters:
resultSet
- The ResultSet object whose content will be written in XML format.rootTagName
- The name of the XML Root Tag to use.entityName
- The name of the XML tag to use for each DataRow of the ResultSet.writer
- The Writer object used to write the XML.baseDR
- the data row, that holds the column sequence and the column labels (if available)useLabel
- indicates if the label instead of the field name should be used- Throws:
Exception
- Gets thrown in case the XML could not be written.
-
writeHTML
public static void writeHTML(ResultSet resultSet, Writer writer) throws Exception
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); HashMap
links = new HashMap<>(); links.put("feld1", "/rest/test/{feld1}"); links.put("feld2", "/rest/test/{feld1}/{feld2}"); FileWriter fw = new FileWriter("D:/test.html"); ResultSetExporter.writeHTML(rs, fw, links); fw.flush(); fw.close(); - Parameters:
resultSet
- The ResultSet object whose content will be written as HTML <table>writer
- The Writer object used to write the HTML- Throws:
Exception
- Gets thrown in case the HTML could not be written
-
writeHTML
public static void writeHTML(ResultSet resultSet, Writer writer, DataRow baseDR, boolean useLabel) throws Exception
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); HashMap
links = new HashMap<>(); links.put("feld1", "/rest/test/{feld1}"); links.put("feld2", "/rest/test/{feld1}/{feld2}"); FileWriter fw = new FileWriter("D:/test.html"); ResultSetExporter.writeHTML(rs, fw, links); fw.flush(); fw.close(); - Parameters:
resultSet
- The ResultSet to export.writer
- A java.io.Writer Instance.baseDR
- the data row, that holds the column sequence and the column labels (if available)useLabel
- indicates if the label instead of the field name should be used- Throws:
Exception
-
writeHTML
public static void writeHTML(ResultSet resultSet, Writer writer, HashMap<String,String> links) throws Exception
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); HashMap
links = new HashMap<>(); links.put("feld1", "/rest/test/{feld1}"); links.put("feld2", "/rest/test/{feld1}/{feld2}"); FileWriter fw = new FileWriter("D:/test.html"); ResultSetExporter.writeHTML(rs, fw, links); fw.flush(); fw.close(); - Parameters:
resultSet
- The ResultSet to export.writer
- A java.io.Writer Instance.links
- A HashMap with field name / URL pattern pairs, like http://xyz/a/{key}/gy.- Throws:
Exception
-
writeHTML
public static void writeHTML(ResultSet resultSet, Writer writer, HashMap<String,String> links, DataRow baseDR, boolean useLabel) throws Exception
Uses the given Writer object to write the ResultSet's content as HTML <table> element to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); HashMap
links = new HashMap<>(); links.put("feld1", "/rest/test/{feld1}"); links.put("feld2", "/rest/test/{feld1}/{feld2}"); FileWriter fw = new FileWriter("D:/test.html"); ResultSetExporter.writeHTML(rs, fw, links); fw.flush(); fw.close(); - Parameters:
resultSet
- The ResultSet to export.writer
- A java.io.Writer Instance.links
- A HashMap with field name / URL pattern pairs, like http://xyz/a/{key}/gy.baseDR
- the data row, that holds the column sequence and the column labels (if available)useLabel
- indicates if the label instead of the field name should be used- Throws:
Exception
-
writeTXT
public static void writeTXT(ResultSet resultSet, Writer writer) throws Exception
Uses the given Writer object to write the ResultSet's content as plain text to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); FileWriter fw = new FileWriter("D:/test.txt"); ResultSetExporter.writeTXT(rs, fw); fw.flush(); fw.close();
- Parameters:
resultSet
- The ResultSet to export.writer
- A java.io.Writer Instance.- Throws:
Exception
-
writeTXT
public static void writeTXT(ResultSet resultSet, Writer writer, DataRow baseDR, Boolean useLabel) throws Exception
Uses the given Writer object to write the ResultSet's content as plain text to the output stream.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); FileWriter fw = new FileWriter("D:/test.txt"); ResultSetExporter.writeTXT(rs, fw); fw.flush(); fw.close();
- Parameters:
resultSet
- The ResultSet to export.writer
- A java.io.Writer Instance.baseDR
- the data row, that holds the column sequence and the column labels (if available)useLabel
- indicates if the label instead of the field name should be used- Throws:
Exception
-
writeJSON
public static void writeJSON(ResultSet resultSet, Writer writer) throws Exception
Converts the given ResultSet object to a JSON String and writes it to the output stream using the given writer object.
Example Usage with an FileWriter object:
ResultSet rs = new ResultSet(); DataRow dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld2", "TEST2"); rs.add(dr); dr = new DataRow(); dr.setFieldValue("feld1", "TEST1"); dr.setFieldValue("feld3", "TEST3"); rs.add(dr); FileWriter fw = new FileWriter("D:/test.json"); ResultSetExporter.writeJSON(rs, fw); fw.flush(); fw.close();
- Parameters:
resultSet
- The ResultSet object to write as JSON.writer
- The Writer used to write the JSON String.- Throws:
Exception
- Gets thrown in case the ResultSet could not be converted to a JSON String.
-
writeJSON
public static void writeJSON(ResultSet resultSet, Writer writer, Boolean fMeta) throws Exception
- Parameters:
resultSet
- The ResultSet object to write as JSON.writer
- The Writer used to write the JSON String.fMeta
- A Boolean indicating whether to write out the meta data object- Throws:
Exception
- Gets thrown in case the ResultSet could not be converted to a JSON String.
-
writeXLSX
public static void writeXLSX(ResultSet rs, File outputFile, boolean writeHeader) throws Exception
Writes the content of the given ResultSet as XLSX into the specified File.- Parameters:
resultSet
- The ResultSet to export.outputFile
- The File in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.- Throws:
Exception
- Gets thrown in case the ResultSet could not be converted to a XLSX File
-
writeXLSX
public static void writeXLSX(ResultSet rs, File outputFile, boolean writeHeader, SheetConfiguration sheetConfig) throws Exception
Writes the content of the given ResultSet as XLSX into the specified File.- Parameters:
resultSet
- The ResultSet to export.outputFile
- The File in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.sheetConfig
- Object containing customized configurations- Throws:
Exception
- Gets thrown in case the ResultSet could not be converted to a XLSX File
-
writeXLSX
public static void writeXLSX(ResultSet rs, File outputFile, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow AttributesRecord) throws Exception
Writes the content of the given ResultSet as XLSX into the specified File.- Parameters:
resultSet
- The ResultSet to export.outputFile
- The File in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.useLabelIfPresent
- if the attributes record contains labels, use the label instead of the field name.sheetName
- A custom name for the sheetDataRow
- attributesRecord the attributes record for formatting- Throws:
Exception
- Gets thrown in case the ResultSet could not be converted to a XLSX File
-
writeXLSX
public static void writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader) throws Exception
Writes the content of the given ResultSet into an output stream.- Parameters:
resultSet
- The ResultSet to export.out
- The output stream in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.- Throws:
Exception
- Gets thrown in case the ResultSet could not be read or output stream can not be written
-
writeXLSX
public static void writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow attributesRecord) throws Exception
Writes the content of the given ResultSet into an output stream.- Parameters:
resultSet
- The ResultSet to export.out
- The output stream in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.useLabelIfPresent
- if the attributes record contains labels, use the label instead of the field name.sheetName
- A custom name for the sheetattributesRecord
- attributesRecord the attributes record for formattingsheetConfig
- Object containing customized configurations- Throws:
Exception
- Gets thrown in case the ResultSet could not be read or output stream can not be written
-
writeXLSX
public static void writeXLSX(ResultSet rs, OutputStream out, boolean writeHeader, boolean useLabelIfPresent, String sheetName, DataRow AttributesRecord, SheetConfiguration sheetConfig) throws Exception
Writes the content of the given ResultSet into an output stream.- Parameters:
resultSet
- The ResultSet to export.out
- The output stream in which to write the ResultSet's content.writeHeader
- The boolean value indicating whether writing the column headers or not.useLabelIfPresent
- if the attributes record contains labels, use the label instead of the field name.sheetName
- A custom name for the sheetDataRow
- attributesRecord the attributes record for formatting- Throws:
Exception
- Gets thrown in case the ResultSet could not be read or output stream can not be written
-
exportToPDF
public static File exportToPDF(File file, ResultSet rs, SheetConfiguration sheetConfig, boolean baristaMode, int fitTo, boolean landscapeMode)
Exports the content of the given ResultSet from a BBjGridExWidget- Parameters:
file
- The output file.rs
- The ResultSet to export.sheetConfig
- The sheet configuration for the reportbaristaMode
- Indicator if the Barista header should be displayed or notfitTo
- Content fitting indicatorlandscapeMode
- Indicator if the PDF should be created in landscape mode or else in portrait mode- Returns:
- The final exported PDF file
-
exportToPDFByCustomReport
public static File exportToPDFByCustomReport(File outputFile, File customReport, ResultSet rs)
Exports the content of the given ResultSet from a BBjGridExWidget- Parameters:
outputFile
- The output filecustomReport
- The custom report fileresultSet
- The ResultSet to export.- Returns:
- The final exported PDF file
-
exportToJasperPrint
public static net.sf.jasperreports.engine.JasperPrint exportToJasperPrint(File file, ResultSet rs, SheetConfiguration sheetConfig, boolean baristaMode, int fitTo, boolean landscapeMode)
-
exportToPdf
public static File exportToPdf(File file, net.sf.jasperreports.engine.JasperPrint jasperPrint)
-
exportToCSV
public static void exportToCSV(File outputFile, ResultSet rs)
Exports the content of the given ResultSet from a BBjGridExWidget- Parameters:
outputFile
- The output fileresultSet
- The ResultSet to export.
-
exportToCSV
public static void exportToCSV(File outputFile, ResultSet rs, DataRow baseDR, boolean useLabel)
Method to export a result set to a CSV file- Parameters:
outputFile
- the ouput filers
- the result set that holds the data to exportbaseDR
- the data row, that holds the column sequence and the column labels (if available)useLabel
- indicates if the label instead of the field name should be used
-
-