public XInputStream getXInputStream(ReportTemplate reportTemplate) { try { return new OfficeInputStream(IOUtils.toByteArray(reportTemplate.getDocumentContent())); } catch (java.io.IOException e) { throw new OpenOfficeException("An error occurred while converting template to XInputStream", e); } }
public XInputStream getXInputStream(ReportTemplate reportTemplate) { try { return new OfficeInputStream(IOUtils.toByteArray(reportTemplate.getDocumentContent())); } catch (java.io.IOException e) { throw new OpenOfficeException("An error occurred while converting template to XInputStream", e); } }
protected groovy.text.Template getGroovyTemplate() { try { GStringTemplateEngine templateEngine = new GStringTemplateEngine(); String templateContent = IOUtils.toString(reportTemplate.getDocumentContent(), StandardCharsets.UTF_8); groovy.text.Template htmlTemplate = templateEngine.createTemplate(templateContent); return htmlTemplate; } catch (Exception e) { throw wrapWithReportingException("An error occurred while creating groovy template", e); } } }
protected void loadDocument(OfficeResourceProvider ooResourceProvider) throws com.sun.star.lang.IllegalArgumentException, IOException { xComponent = ooResourceProvider.loadXComponent(reportTemplate.getDocumentContent()); officeComponent = new OfficeComponent(ooResourceProvider, xComponent); }
protected void loadDocument(OfficeResourceProvider ooResourceProvider) throws com.sun.star.lang.IllegalArgumentException, IOException { xComponent = ooResourceProvider.loadXComponent(reportTemplate.getDocumentContent()); officeComponent = new OfficeComponent(ooResourceProvider, xComponent); }
protected void readTemplateData() { checkThreadInterrupted(); InputStream documentContent = reportTemplate.getDocumentContent(); BufferedReader in = new BufferedReader(new InputStreamReader(documentContent)); StringBuilder headerData = new StringBuilder(); try { String line; while((line = in.readLine()) != null) { checkThreadInterrupted(); Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(line); if (!matcher.find()) headerData.append(line); else { separator = detectSeparator(line); matcher.reset(); while (matcher.find()) { String parameterName = unwrapParameterName(matcher.group()); parametersToInsert.add(parameterName); } } } in.close(); } catch (IOException e) { throw new ReportFormattingException("Error while reading template data"); } header = headerData.toString().replaceAll(String.valueOf(CSVWriter.DEFAULT_QUOTE_CHARACTER), "").split(String.valueOf(separator)); } }
protected void readTemplateData() { checkThreadInterrupted(); InputStream documentContent = reportTemplate.getDocumentContent(); BufferedReader in = new BufferedReader(new InputStreamReader(documentContent)); StringBuilder headerData = new StringBuilder(); try { String line; while((line = in.readLine()) != null) { checkThreadInterrupted(); Matcher matcher = UNIVERSAL_ALIAS_PATTERN.matcher(line); if (!matcher.find()) headerData.append(line); else { separator = detectSeparator(line); matcher.reset(); while (matcher.find()) { String parameterName = unwrapParameterName(matcher.group()); parametersToInsert.add(parameterName); } } } in.close(); } catch (IOException e) { throw new ReportFormattingException("Error while reading template data"); } header = headerData.toString().replaceAll(String.valueOf(CSVWriter.DEFAULT_QUOTE_CHARACTER), "").split(String.valueOf(separator)); } }
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 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); } }
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 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); } }
@Override public void renderDocument() { try { switch (getExtension(reportTemplate)) { case JASPER_EXT: printReport((JasperReport) JRLoader.loadObject(reportTemplate.getDocumentContent())); break; case JRXML_EXT: JasperDesign design = JRXmlLoader.load(reportTemplate.getDocumentContent()); if (!design.getParametersMap().containsKey(CUBA_PARAM)) design.addParameter(createJRParameter()); printReport(JasperCompileManager.compileReport(design)); break; default: throw new ReportFormattingException("Error handling template extension"); } } catch (JRException e) { throw new ReportFormattingException("Error formatting jasper report: " + e.getMessage(), e); } }
@Override public void renderDocument() { try { switch (getExtension(reportTemplate)) { case JASPER_EXT: printReport((JasperReport) JRLoader.loadObject(reportTemplate.getDocumentContent())); break; case JRXML_EXT: JasperDesign design = JRXmlLoader.load(reportTemplate.getDocumentContent()); if (!design.getParametersMap().containsKey(CUBA_PARAM)) design.addParameter(createJRParameter()); printReport(JasperCompileManager.compileReport(design)); break; default: throw new ReportFormattingException("Error handling template extension"); } } catch (JRException e) { throw new ReportFormattingException("Error formatting jasper report: " + e.getMessage(), e); } }