private String getExtension(ReportTemplate reportTemplate) { String[] split = reportTemplate.getDocumentName().split("\\."); return split[split.length - 1].toLowerCase(); } }
private String getExtension(ReportTemplate reportTemplate) { String[] split = reportTemplate.getDocumentName().split("\\."); return split[split.length - 1].toLowerCase(); } }
protected ReportingException wrapWithReportingException(String message, Exception e) { if (e instanceof ReportingInterruptedException) { return (ReportingInterruptedException) e; } else { return new ReportFormattingException(message + ". Template name [" + reportTemplate.getDocumentName() + "]", e); } }
protected ReportFormattingException wrapWithReportingException(String message) { return new ReportFormattingException(message + ". Template name [" + reportTemplate.getDocumentName() + "]"); }
protected ReportingException wrapWithReportingException(String message, Exception e) { if (e instanceof ReportingInterruptedException) { return (ReportingInterruptedException) e; } else { return new ReportFormattingException(message + ". Template name [" + reportTemplate.getDocumentName() + "]", e); } }
protected ReportFormattingException wrapWithReportingException(String message) { return new ReportFormattingException(message + ". Template name [" + reportTemplate.getDocumentName() + "]"); }
protected freemarker.template.Template getFreemarkerTemplate() { try { String templateContent = IOUtils.toString(reportTemplate.getDocumentContent(), StandardCharsets.UTF_8); StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate(reportTemplate.getDocumentName(), templateContent); Configuration fmConfiguration = new Configuration(); fmConfiguration.setTemplateLoader(stringLoader); fmConfiguration.setDefaultEncoding("UTF-8"); freemarker.template.Template htmlTemplate = fmConfiguration.getTemplate(reportTemplate.getDocumentName()); htmlTemplate.setObjectWrapper(objectWrapper); return htmlTemplate; } catch (Exception e) { throw wrapWithReportingException("An error occurred while creating freemarker template", e); } }
protected Template getTemplate() { try { String templateContent = IOUtils.toString(reportTemplate.getDocumentContent(), StandardCharsets.UTF_8); StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate(reportTemplate.getDocumentName(), templateContent); Configuration fmConfiguration = new Configuration(); fmConfiguration.setTemplateLoader(stringLoader); fmConfiguration.setDefaultEncoding("UTF-8"); Template htmlTemplate = fmConfiguration.getTemplate(reportTemplate.getDocumentName()); htmlTemplate.setObjectWrapper(objectWrapper); return htmlTemplate; } catch (Exception e) { throw wrapWithReportingException("An error occurred while creating freemarker template", e); } } }
protected void generateReport(Report report, ReportTemplate reportTemplate, ReportOutputType outputType, OutputStream outputStream, Map<String, Object> handledParams, BandData rootBand) { String extension = StringUtils.substringAfterLast(reportTemplate.getDocumentName(), "."); if (reportTemplate.isCustom()) { try { byte[] bytes = reportTemplate.getCustomReport().createReport(report, rootBand, handledParams); IOUtils.write(bytes, outputStream); } catch (IOException e) { throw new ReportingException(format("An error occurred while processing custom template [%s].", reportTemplate.getDocumentName()), e); } } else { FormatterFactoryInput factoryInput = new FormatterFactoryInput(extension, rootBand, reportTemplate, outputType, outputStream); ReportFormatter formatter = formatterFactory.createFormatter(factoryInput); formatter.renderDocument(); } }
protected void generateReport(Report report, ReportTemplate reportTemplate, ReportOutputType outputType, OutputStream outputStream, Map<String, Object> handledParams, BandData rootBand) { String extension = StringUtils.substringAfterLast(reportTemplate.getDocumentName(), "."); if (reportTemplate.isCustom()) { try { byte[] bytes = reportTemplate.getCustomReport().createReport(report, rootBand, handledParams); IOUtils.write(bytes, outputStream); } catch (IOException e) { throw new ReportingException(format("An error occurred while processing custom template [%s].", reportTemplate.getDocumentName()), e); } } else { FormatterFactoryInput factoryInput = new FormatterFactoryInput(extension, rootBand, reportTemplate, outputType, outputStream); ReportFormatter formatter = formatterFactory.createFormatter(factoryInput); formatter.renderDocument(); } }
public void renderDocument() { try { doCreateDocument(outputStream); } catch (ReportingInterruptedException ie) { throw ie; } catch (Exception e) {//just try again if any exceptions occurred log.warn(String.format("An error occurred while generating doc report [%s]. System will retry to generate report again.", reportTemplate.getDocumentName()), e); for (int i = 0; i < officeIntegration.getCountOfRetry(); i++) { try { checkThreadInterrupted(); doCreateDocument(outputStream); return; } catch (NoFreePortsException e1) { if (e instanceof NoFreePortsException) { throw (NoFreePortsException) e; } } } throw wrapWithReportingException("An error occurred while generating doc report.", e); } finally { IOUtils.closeQuietly(outputStream); } }
protected void loadDocument() { if (reportTemplate == null) throw new NullPointerException("Template file can't be null."); try { wordprocessingMLPackage = WordprocessingMLPackage.load(reportTemplate.getDocumentContent()); documentWrapper = new DocumentWrapper(new DocxFormatterDelegate(this), wordprocessingMLPackage); } catch (Docx4JException e) { throw wrapWithReportingException(String.format("An error occurred while reading docx template. File name [%s]", reportTemplate.getDocumentName()), e); } }
protected void loadDocument() { if (reportTemplate == null) throw new NullPointerException("Template file can't be null."); try { wordprocessingMLPackage = WordprocessingMLPackage.load(reportTemplate.getDocumentContent()); documentWrapper = new DocumentWrapper(new DocxFormatterDelegate(this), wordprocessingMLPackage); } catch (Docx4JException e) { throw wrapWithReportingException(String.format("An error occurred while reading docx template. File name [%s]", reportTemplate.getDocumentName()), e); } }
public void renderDocument() { try { doCreateDocument(outputStream); } catch (ReportingInterruptedException ie) { throw ie; } catch (Exception e) {//just try again if any exceptions occurred log.warn(String.format("An error occurred while generating doc report [%s]. System will retry to generate report again.", reportTemplate.getDocumentName()), e); for (int i = 0; i < officeIntegration.getCountOfRetry(); i++) { try { checkThreadInterrupted(); doCreateDocument(outputStream); return; } catch (NoFreePortsException e1) { if (e instanceof NoFreePortsException) { throw (NoFreePortsException) e; } } } throw wrapWithReportingException("An error occurred while generating doc report.", e); } finally { IOUtils.closeQuietly(outputStream); } }
protected void initWorkbook() { try { templateWorkbook = new HSSFWorkbook(reportTemplate.getDocumentContent()); resultWorkbook = new HSSFWorkbook(reportTemplate.getDocumentContent()); } catch (IOException e) { throw wrapWithReportingException("An error occurred while parsing xls template " + reportTemplate.getDocumentName(), e); } for (int sheetNumber = 0; sheetNumber < templateWorkbook.getNumberOfSheets(); sheetNumber++) { HSSFSheet templateSheet = templateWorkbook.getSheetAt(sheetNumber); HSSFSheet resultSheet = resultWorkbook.getSheetAt(sheetNumber); templateToResultSheetsMapping.put(templateSheet, resultSheet); initMergeRegions(templateSheet); copyCharts(resultSheet); removeMergedRegions(resultSheet); cleanupCells(resultSheet); } copyPicturesToResultWorkbook(); initNamedStyleCache(); }
protected void initWorkbook() { try { templateWorkbook = new HSSFWorkbook(reportTemplate.getDocumentContent()); resultWorkbook = new HSSFWorkbook(reportTemplate.getDocumentContent()); } catch (IOException e) { throw wrapWithReportingException("An error occurred while parsing xls template " + reportTemplate.getDocumentName(), e); } for (int sheetNumber = 0; sheetNumber < templateWorkbook.getNumberOfSheets(); sheetNumber++) { HSSFSheet templateSheet = templateWorkbook.getSheetAt(sheetNumber); HSSFSheet resultSheet = resultWorkbook.getSheetAt(sheetNumber); templateToResultSheetsMapping.put(templateSheet, resultSheet); initMergeRegions(templateSheet); copyCharts(resultSheet); removeMergedRegions(resultSheet); cleanupCells(resultSheet); } copyPicturesToResultWorkbook(); initNamedStyleCache(); }
protected void writeTemplates(Report report, Element root) { Map<String, ReportTemplate> reportTemplates = report.getReportTemplates(); Element reportTemplatesElement = root.addElement("templates"); for (ReportTemplate reportTemplate : reportTemplates.values()) { Element reportTemplateElement = reportTemplatesElement.addElement("template"); reportTemplateElement.addAttribute("code", reportTemplate.getCode()); reportTemplateElement.addAttribute("documentName", reportTemplate.getDocumentName()); reportTemplateElement.addAttribute("documentPath", reportTemplate.getDocumentPath()); reportTemplateElement.addAttribute("outputType", reportTemplate.getOutputType().getId()); reportTemplateElement.addAttribute("outputNamePattern", reportTemplate.getOutputNamePattern()); } }
protected void writeTemplates(Report report, Element root) { Map<String, ReportTemplate> reportTemplates = report.getReportTemplates(); Element reportTemplatesElement = root.addElement("templates"); for (ReportTemplate reportTemplate : reportTemplates.values()) { Element reportTemplateElement = reportTemplatesElement.addElement("template"); reportTemplateElement.addAttribute("code", reportTemplate.getCode()); reportTemplateElement.addAttribute("documentName", reportTemplate.getDocumentName()); reportTemplateElement.addAttribute("documentPath", reportTemplate.getDocumentPath()); reportTemplateElement.addAttribute("outputType", reportTemplate.getOutputType().getId()); reportTemplateElement.addAttribute("outputNamePattern", reportTemplate.getOutputNamePattern()); } }
protected void init() { try { template = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result.getWorkbook().getCalcPr().setCalcMode(STCalcMode.AUTO); result.getWorkbook().getCalcPr().setFullCalcOnLoad(true); marshaller = XmlCopyUtils.createMarshaller(Context.jcSML); unmarshaller = XmlCopyUtils.createUnmarshaller(Context.jcSML); } catch (Exception e) { throw wrapWithReportingException(String.format("An error occurred while loading template [%s]", reportTemplate.getDocumentName()), e); } }
protected void init() { try { template = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result = Document.create(SpreadsheetMLPackage.load(reportTemplate.getDocumentContent())); result.getWorkbook().getCalcPr().setCalcMode(STCalcMode.AUTO); result.getWorkbook().getCalcPr().setFullCalcOnLoad(true); marshaller = XmlCopyUtils.createMarshaller(Context.jcSML); unmarshaller = XmlCopyUtils.createUnmarshaller(Context.jcSML); } catch (Exception e) { throw wrapWithReportingException(String.format("An error occurred while loading template [%s]", reportTemplate.getDocumentName()), e); } }