public JasperReport compileReport(String jrxmlFileName) throws JRException, IOException { JasperReport jasperReport = null; InputStream jrxmlInput = JRLoader.getResourceInputStream(jrxmlFileName); if (jrxmlInput != null) { JasperDesign design; try { design = JRXmlLoader.load(jrxmlInput); } finally { jrxmlInput.close(); } jasperReport = JasperCompileManager.compileReport(design); } return jasperReport; }
/** * Generates sub-reports and adds them into the parameter map. * * @param templateFile * The path to the JR template of the report. * @param parameters * The parameters to be sent to Jasper Report. * @param baseDesignPath * Base design path. * @param connectionProvider * A connection provider in case the report needs it. * @param language * Language to be used when generating the sub-report. * @throws OBException * In case there is any error generating the sub-reports an exception is thrown with the * error message. */ private static void processSubReports(String templateFile, Map<String, Object> parameters, String baseDesignPath, ConnectionProvider connectionProvider, String language) throws OBException { try { JasperDesign jasperDesign = JRXmlLoader.load(templateFile); Object[] parameterList = jasperDesign.getParametersList().toArray(); String parameterName = ""; String subReportName = ""; Collection<String> subreportList = new ArrayList<String>(); File template = new File(templateFile); String templateLocation = template.getParent() + "/"; /* * TODO: At present this process assumes the subreport is a .jrxml file. Need to handle the * possibility that this subreport file could be a .jasper file. */ for (int i = 0; i < parameterList.length; i++) { final JRDesignParameter parameter = (JRDesignParameter) parameterList[i]; if (parameter.getName().startsWith("SUBREP_")) { parameterName = parameter.getName(); subreportList.add(parameterName); subReportName = Replace.replace(parameterName, "SUBREP_", "") + ".jrxml"; JasperReport jasperReportLines = createSubReport(templateLocation, subReportName, baseDesignPath, connectionProvider, language); parameters.put(parameterName, jasperReportLines); } } } catch (final JRException e) { log.error("Error processing subreports for template: " + templateFile, e); throw new OBException(e.getMessage(), e); } }
private static JasperPrint createJasperPrint(InputStream reportFile, org.openbravo.erpCommon.utility.GridReportVO gridReportVO) throws JRException, IOException { JasperDesign jasperDesign = JRXmlLoader.load(reportFile); if (log4j.isDebugEnabled()) log4j.debug("Create JasperDesign"); org.openbravo.erpCommon.utility.ReportDesignBO designBO = new org.openbravo.erpCommon.utility.ReportDesignBO( jasperDesign, gridReportVO); designBO.define(); if (log4j.isDebugEnabled()) log4j.debug("JasperDesign created, pageWidth: " + jasperDesign.getPageWidth() + " left margin: " + jasperDesign.getLeftMargin() + " right margin: " + jasperDesign.getRightMargin()); JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("BaseDir", gridReportVO.getContext()); parameters.put("IS_IGNORE_PAGINATION", gridReportVO.getPagination()); JasperPrint jasperPrint = JasperFillManager .fillReport( jasperReport, parameters, new JRFieldProviderDataSource(gridReportVO.getFieldProvider(), gridReportVO .getDateFormat())); return jasperPrint; }
protected void verifyEvaluation(JRVerifier verifier, XYChartComponent chart) { EvaluationTimeEnum evaluationTime = chart.getEvaluationTime(); if (evaluationTime == EvaluationTimeEnum.AUTO) { verifier.addBrokenRule("Axis chart evaluation time cannot be Auto", chart); } else if (evaluationTime == EvaluationTimeEnum.GROUP) { String groupName = chart.getEvaluationGroup(); if (groupName == null) { verifier.addBrokenRule("Evaluation group not set for axis chart", chart); } else { JasperDesign report = verifier.getReportDesign(); if (!report.getGroupsMap().containsKey(groupName)) { verifier.addBrokenRule("Axis chart evaluation group " + groupName + " not found in report", chart); } } } }
protected void verifyEvaluation(JRVerifier verifier, PieChartComponent chart) { EvaluationTimeEnum evaluationTime = chart.getEvaluationTime(); if (evaluationTime == EvaluationTimeEnum.AUTO) { verifier.addBrokenRule("Pie chart evaluation time cannot be Auto", chart); } else if (evaluationTime == EvaluationTimeEnum.GROUP) { String groupName = chart.getEvaluationGroup(); if (groupName == null) { verifier.addBrokenRule("Evaluation group not set for pie chart", chart); } else { JasperDesign report = verifier.getReportDesign(); if (!report.getGroupsMap().containsKey(groupName)) { verifier.addBrokenRule("Pie chart evaluation group " + groupName + " not found in report", chart); } } } }
@Override public void performAction() throws ActionException { if (zoomValue != null && zoomValue.length() > 0) { CommandTarget target = getCommandTarget(getJasperReportsContext(), getReportContext()); if (target != null) { // execute command try { getCommandStack().execute( new ResetInCacheCommand( new SaveZoomCommand((JasperDesign)target.getIdentifiable(), zoomValue), getJasperReportsContext(), getReportContext(), target.getUri() ) ); } catch (CommandException e) { throw new ActionException(e); } } } else { errors.addAndThrow("net.sf.jasperreports.web.actions.empty.zoom"); } }
@Override public void performAction() { // JasperDesign jasperDesign = getJasperDesign(); JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext()); Map<String, JasperDesignReportResource> cachedResources = cache.getCachedResources(); for (String uri : cachedResources.keySet()) { JasperDesignReportResource resource = cachedResources.get(uri); JasperDesign jasperDesign = resource.getJasperDesign(); if (jasperDesign != null) { JasperReport jasperReport = resource.getReport(); String appRealPath = null;//FIXMECONTEXT WebFileRepositoryService.getApplicationRealPath(); try { JRSaver.saveObject(jasperReport, new File(new File(new File(appRealPath), "WEB-INF/repository"), uri));//FIXMEJIVE harcoded } catch (JRException e) { throw new JRRuntimeException(e); } } } }
/** * */ public ReportConverter(JasperReportsContext jasperReportsContext, JRReport report, boolean ignoreContent) { this.jasperReportsContext = jasperReportsContext; this.componentsEnvironment = ComponentsEnvironment.getInstance(jasperReportsContext); this.report = report; this.locale = readLocale();//allow to pass this explicitly? this.timezone = readTimeZone(); if (report instanceof JasperDesign) { ((JasperDesign)report).preprocess(); } convert(ignoreContent); }
@Override protected void setParentStyle(JRDesignStyle currentStyle, String parentStyleName) { JasperDesign jasperDesign = (JasperDesign) digester.peek(digester.getCount() - 2); Map<String,JRStyle> stylesMap = jasperDesign.getStylesMap(); if (stylesMap.containsKey(parentStyleName)) { JRStyle parent = stylesMap.get(parentStyleName); currentStyle.setParentStyle(parent); } else { currentStyle.setParentStyleNameReference(parentStyleName); } }
@Override public Object createObject(Attributes attrs) throws Exception { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignGenericElement element = new JRDesignGenericElement(jasperDesign); EvaluationTimeEnum evaluationTime = EvaluationTimeEnum.getByName(attrs.getValue(JRXmlConstants.ATTRIBUTE_evaluationTime)); if (evaluationTime != null) { element.setEvaluationTime(evaluationTime); } if (element.getEvaluationTimeValue() == EvaluationTimeEnum.GROUP) { String groupName = attrs.getValue(JRXmlConstants.ATTRIBUTE_evaluationGroup); if (groupName != null) { element.setEvaluationGroupName(groupName); } } return element; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignSubreport subreport = new JRDesignSubreport(jasperDesign); String isUsingCache = atts.getValue(JRXmlConstants.ATTRIBUTE_isUsingCache); if (isUsingCache != null && isUsingCache.length() > 0) { subreport.setUsingCache(Boolean.valueOf(isUsingCache)); } String runToBottomAttr = atts.getValue(JRXmlConstants.ATTRIBUTE_runToBottom); if (runToBottomAttr != null) { subreport.setRunToBottom(Boolean.valueOf(runToBottomAttr)); } return subreport; }
@Override public void begin(String namespace, String name, Attributes attributes) throws Exception { DesignStyleContainer styleContainer = (DesignStyleContainer) digester.peek(); JasperDesign jasperDesign = (JasperDesign) digester.peek(digester.getCount() - 2); styleContainer.setDefaultStyleProvider(jasperDesign); String styleName = attributes.getValue(styleAttribute); if (styleName != null) { Map<String,JRStyle> stylesMap = jasperDesign.getStylesMap(); if (stylesMap.containsKey(styleName)) { JRStyle style = stylesMap.get(styleName); styleContainer.setStyle(style); } else { styleContainer.setStyleNameReference(styleName); } } }
protected void compileReport() throws JRException, IOException { InputStream jrxmlInput = JRLoader.getResourceInputStream(jrxml); JasperDesign design; try { design = JRXmlLoader.load(jrxmlInput); } finally { jrxmlInput.close(); } report = JasperCompileManager.compileReport(design); fillManager = JasperFillManager.getInstance(jasperReportsContext); }
protected void verifyEvaluation(JRVerifier verifier, SpiderChartComponent chart) { EvaluationTimeEnum evaluationTime = chart.getEvaluationTime(); if (evaluationTime == EvaluationTimeEnum.AUTO) { verifier.addBrokenRule("Spider chart evaluation time cannot be Auto", chart); } else if (evaluationTime == EvaluationTimeEnum.GROUP) { String groupName = chart.getEvaluationGroup(); if (groupName == null) { verifier.addBrokenRule("Evaluation group not set for spider chart", chart); } else { JasperDesign report = verifier.getReportDesign(); if (!report.getGroupsMap().containsKey(groupName)) { verifier.addBrokenRule("Spider chart evaluation group " + groupName + " not found in report", chart); } } } }
@Override public void performAction() throws ActionException { JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)table.getDatasetRun(); String datasetName = datasetRun.getDatasetName(); JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext()); JasperDesign jasperDesign = cache.getJasperDesign(targetUri); JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getDatasetMap().get(datasetName); // execute command try { getCommandStack().execute( new ResetInCacheCommand( new FilterCommand(getJasperReportsContext(), dataset, getFilterData()), getJasperReportsContext(), getReportContext(), targetUri ) ); } catch (CommandException e) { throw new ActionException(e); } }
@Override public void performAction() throws ActionException { JRDesignDatasetRun datasetRun = (JRDesignDatasetRun)table.getDatasetRun(); String datasetName = datasetRun.getDatasetName(); JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext()); JasperDesign jasperDesign = cache.getJasperDesign(targetUri); JRDesignDataset dataset = (JRDesignDataset)jasperDesign.getDatasetMap().get(datasetName); // execute command try { getCommandStack().execute( new ResetInCacheCommand( new SortCommand(getJasperReportsContext(), dataset, getSortData()), getJasperReportsContext(), getReportContext(), targetUri ) ); } catch (CommandException e) { throw new ActionException(e); } }
public static JasperDesign loadJasperDesign(byte[] template) throws SchemaException{ try { byte[] reportTemplate = Base64.decodeBase64(template); InputStream inputStreamJRXML = new ByteArrayInputStream(reportTemplate); JasperDesign jasperDesign = JRXmlLoader.load(inputStreamJRXML); // LOGGER.trace("load jasper design : {}", jasperDesign); return jasperDesign; } catch (JRException ex){ throw new SchemaException(ex.getMessage(), ex.getCause()); } }
@Action(semantics = SemanticsOf.SAFE) @ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT) @MemberOrder(sequence = "3") public Blob imprimirClientesActivos() throws JRException, IOException { ClientesActivosDataSource datasource = new ClientesActivosDataSource(); for (Cliente cli : clientesRepository.listarActivos()){ ClientesActivosReporte reporteClientesActivos=new ClientesActivosReporte(); reporteClientesActivos.setClienteNombre(cli.getClienteNombre()); reporteClientesActivos.setClienteApellido(cli.getClienteApellido()); reporteClientesActivos.setClienteDni(cli.getClienteDni()); reporteClientesActivos.setClienteTipoDocumento(cli.getClienteTipoDocumento().toString()); reporteClientesActivos.setPersonaMail(cli.getPersonaMail()); reporteClientesActivos.setPersonaTelefono(cli.getPersonaTelefono()); datasource.addParticipante(reporteClientesActivos); } String jrxml = "ClientesActivos.jrxml"; String nombreArchivo = "Listado Clientes Activos "; InputStream input = ReporteRepository.class.getResourceAsStream(jrxml); JasperDesign jd = JRXmlLoader.load(input); JasperReport reporte = JasperCompileManager.compileReport(jd); Map<String, Object> parametros = new HashMap<String, Object>(); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, datasource); return ReporteRepository.imprimirReporteLista(jasperPrint, jrxml, nombreArchivo); }
@Action(semantics = SemanticsOf.SAFE) @ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT) @MemberOrder(sequence = "5") public Blob imprimirFacturacionAnualPorCompania() throws JRException, IOException { FacturacionDataSource datasource = new FacturacionDataSource(); for (FacturacionCompaniasViewModel fac : facturacionRepository.facturacion()){ FacturacionReporte facturacionCompania =new FacturacionReporte(); facturacionCompania.setCompania(fac.getCompania().getCompaniaNombre().toString()); facturacionCompania.setPrimaTotal(fac.getPrimaTotal()); datasource.addParticipante(facturacionCompania); } String jrxml = "FacturacionCompanias.jrxml"; String nombreArchivo = "Facturacion companias "; InputStream input = ReporteRepository.class.getResourceAsStream(jrxml); JasperDesign jd = JRXmlLoader.load(input); JasperReport reporte = JasperCompileManager.compileReport(jd); Map<String, Object> parametros = new HashMap<String, Object>(); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, datasource); return ReporteRepository.imprimirReporteLista(jasperPrint, jrxml, nombreArchivo); }
@Action(semantics = SemanticsOf.SAFE) @ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT) @MemberOrder(sequence = "6") public Blob imprimirPolizasPorCompania( @ParameterLayout(named="Compania: ") final Compania companiaSeleccionada) throws JRException, IOException { PolizaPorCompaniaDataSource datasource = new PolizaPorCompaniaDataSource(); for (Poliza pol : polizaRepository.buscarPorCompania(companiaSeleccionada)){ PolizaPorCompaniaReporte reportePolizaPorCompania =new PolizaPorCompaniaReporte(); reportePolizaPorCompania.setPolizasCliente(pol.getPolizaCliente().toString()); reportePolizaPorCompania.setPolizasCompania(pol.getPolizaCompania().getCompaniaNombre()); reportePolizaPorCompania.setPolizaNumero(pol.getPolizaNumero()); reportePolizaPorCompania.setPolizaFechaVigencia(pol.getPolizaFechaVigencia()); reportePolizaPorCompania.setPolizaFechaVencimiento(pol.getPolizaFechaVencimiento()); reportePolizaPorCompania.setPolizaFechaEmision(pol.getPolizaFechaEmision()); reportePolizaPorCompania.setPolizaImporteTotal(pol.getPolizaImporteTotal()); datasource.addParticipante(reportePolizaPorCompania); } String jrxml = "PolizasPorCompania.jrxml"; String nombreArchivo = "Listado de polizas por compania"+" "+companiaSeleccionada.getCompaniaNombre()+" "; InputStream input = ReporteRepository.class.getResourceAsStream(jrxml); JasperDesign jd = JRXmlLoader.load(input); JasperReport reporte = JasperCompileManager.compileReport(jd); Map<String, Object> parametros = new HashMap<String, Object>(); parametros.put("compania", companiaSeleccionada.getCompaniaNombre()); JasperPrint jasperPrint = JasperFillManager.fillReport(reporte, parametros, datasource); return ReporteRepository.imprimirReporteLista(jasperPrint, jrxml, nombreArchivo); }
/** * Generates a compiled and translated report to the language passed as parameter. * * @param conn * The connection provider used to get the translations. * @param reportName * The path to the JR template of the report. * @param language * Language to be used when generating the report. * @param baseDesignPath * Base design path. * @return A JasperReport object with the compiled and translated report. * @throws JRException * In case there is any error generating the translated report an exception is thrown * with the error message. */ public static JasperReport getTranslatedJasperReport(ConnectionProvider conn, String reportName, String language, String baseDesignPath) throws JRException { log.debug("translate report: " + reportName + " for language: " + language); File reportFile = new File(reportName); InputStream reportInputStream = null; if (reportFile.exists()) { TranslationHandler handler = new TranslationHandler(conn); handler.prepareFile(reportName, language, reportFile, baseDesignPath); reportInputStream = handler.getInputStream(); } JasperDesign jasperDesign; if (reportInputStream != null) { log.debug("Jasper report being created with inputStream."); jasperDesign = JRXmlLoader.load(reportInputStream); } else { log.debug("Jasper report being created with strReportName."); jasperDesign = JRXmlLoader.load(reportName); } JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign); return jasperReport; }
public ReportDesignBO(JasperDesign jasperDesign, GridReportVO gridReportVO) { super(); this.jasperDesign = jasperDesign; this.gridReportVO = gridReportVO; if (gridReportVO.getTotalWidth() + jasperDesign.getLeftMargin() + jasperDesign.getRightMargin() > jasperDesign .getPageWidth()) this.jasperDesign.setPageWidth(gridReportVO.getTotalWidth() + jasperDesign.getLeftMargin() + jasperDesign.getRightMargin()); this.pageWidth = jasperDesign.getPageWidth() - jasperDesign.getLeftMargin() - jasperDesign.getRightMargin(); }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); TextInputComponent textInputComponent = new TextInputComponent(jasperDesign); // String isMultiLine = atts.getValue(JRXmlConstants.ATTRIBUTE_multiLine); // if (isMultiLine != null && isMultiLine.length() > 0) // { // textInputComponent.setMultiLine(Boolean.valueOf(isMultiLine).booleanValue()); // } return textInputComponent; }
/** * */ public void compile() throws JRException { long start = System.currentTimeMillis(); JasperDesign jasperDesign = getJasperDesign(); JasperCompileManager.compileReportToFile(jasperDesign, "build/reports/NoXmlDesignReport.jasper"); System.err.println("Compile time : " + (System.currentTimeMillis() - start)); }
/** * */ public void print() throws JRException { long start = System.currentTimeMillis(); JasperDesign jasperDesign = JRXmlLoader.load("reports/FirstJasper.jrxml"); int i = 0; for (; i < 100; i++) { JasperCompileManager.compileReport(jasperDesign); } System.err.println("Average compile time : " + (System.currentTimeMillis() - start) / i); }
@Override public JasperDesign update(JasperDesign jasperDesign) { JRDesignStyle style = (JRDesignStyle)jasperDesign.getStyles()[0]; style.setForecolor(Color.BLUE); style.setFontSize(14f); style.setBold(Boolean.TRUE); return jasperDesign; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_STACKEDBAR); return chart; }
@Override public Object createObject( Attributes atts ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_XYAREA); return chart; }
@Override public Object createObject( Attributes attrs ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_SCATTER); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_HIGHLOW); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_THERMOMETER); return chart; }
@Override public Object createObject( Attributes attrs ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_XYLINE); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_XYBAR); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_STACKEDAREA); return chart; }
/** * Creates an Area chart which is a combination of a Pie dataset and a Pie plot. * @return an instance of {@link net.sf.jasperreports.engine.design.JRDesignChart JRDesignChart} * representing the Area chart */ @Override public Object createObject( Attributes atts ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart areaChart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_AREA); return areaChart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_PIE); return chart; }
@Override public Object createObject( Attributes attrs ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_BAR3D); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_CANDLESTICK); return chart; }
@Override public Object createObject( Attributes attrs ){ JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_TIMESERIES ); return chart; }
@Override public Object createObject(Attributes atts) { JasperDesign jasperDesign = (JasperDesign)digester.peek(digester.getCount() - 2); JRDesignChart chart = new JRDesignChart(jasperDesign, JRChart.CHART_TYPE_PIE3D); return chart; }