String exportFormat = htmlTable.getTableConfiguration().getCurrentExportFormat();
ExportConf exportConf = htmlTable.getTableConfiguration().getExportConfiguration().get(exportFormat);
String exportClassName = exportConf.getExportClass();
if (exportClassName == null) {
throw new ExportException("No export class has been configured for the '" + exportFormat
+ "' format. Please configure it before exporting.");
}
logger.debug("Selected export class: {}", exportClassName);
// Check that the class can be instantiated
if (!ClassUtils.isPresent(exportClassName)) {
StringBuilder sb = new StringBuilder("Unable to export in the ");
sb.append(exportFormat);
sb.append(" format because either the export class '");
sb.append(exportClassName);
sb.append("' or some other librairies ");
sb.append(" imported in the export class is not present in the classpath.");
sb.append("Did you forget to add a dependency?");
throw new ExportException(sb.toString());
}
// Instantiates the export class and processes the export
Class<?> exportClass = null;
Object obj = null;
try {
exportClass = ClassUtils.getClass(exportClassName);
obj = ClassUtils.getNewInstance(exportClass);
} catch (ClassNotFoundException e) {
throw new ExportException("Unable to load the class '" + exportClassName + "'", e);
} catch (InstantiationException e) {
throw new ExportException("Unable to instanciate the class '" + exportClassName + "'", e);
} catch (IllegalAccessException e) {
throw new ExportException("Unable to access the class '" + exportClassName + "'", e);
}
((DatatablesExport) obj).initExport(htmlTable);
((DatatablesExport) obj).processExport(stream);