Java 类net.sf.jasperreports.engine.xml.JRXmlLoader 实例源码

项目:Omoikane    文件:EtiquetaGenerator.java   
public void generate(String reportURL,Collection<Articulo> articulos)
{
    try {
        InputStream is = loadReport(reportURL);
        JasperDesign design = JRXmlLoader.load(is);
        JasperReport report = JasperCompileManager.compileReport(design);
        jp = JasperFillManager.fillReport(report,new HashMap(),new JRBeanCollectionDataSource(articulos));

        JasperViewer jasperViewer = new JasperViewer(jp, false);
        jasperViewer.setDefaultCloseOperation(JasperViewer.DISPOSE_ON_CLOSE);
        jasperViewer.setTitle("Etiquetas");
        jasperViewer.setZoomRatio((float) 1.25);
        jasperViewer.setExtendedState(JasperViewer.MAXIMIZED_BOTH);
        jasperViewer.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        jasperViewer.requestFocus();
        jasperViewer.setVisible(true);
    }catch (Exception e) {
        logger.error("Error al generar etiquetas", e);
    }

}
项目:jasperreports    文件:AbstractTest.java   
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;
}
项目:openbravo-brazil    文件:ReportingUtils.java   
/**
 * 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);
  }
}
项目:openbravo-brazil    文件:GridBO.java   
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;
}
项目:jasperreports    文件:TableReportContextXmlRule.java   
@Override
public void begin(String namespace, String name, Attributes attributes)
        throws Exception
{
    JRXmlLoader xmlLoader = getXmlLoader();
    TableComponent table = getTableComponent();
    JRDatasetRun datasetRun = table.getDatasetRun();
    String datasetName = datasetRun == null ? null : datasetRun.getDatasetName();

    if (log.isDebugEnabled())
    {
        log.debug("Pushing report context for dataset name " + datasetName);
    }

    XmlLoaderReportContext reportContext = new XmlLoaderReportContext(datasetName);
    xmlLoader.pushReportContext(reportContext);
}
项目:jasperreports    文件:Report.java   
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);
}
项目:engerek    文件:ReportTypeUtil.java   
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());
            }
        }
项目:ERDesignerNG    文件:JasperUtils.java   
private static void findReports(Map<File, String> aReportMap, File aDirectory) throws JRException {
    Thread.currentThread().setContextClassLoader(JasperUtils.class.getClassLoader());
    if (aDirectory != null && aDirectory.exists() && aDirectory.canRead()) {
        for (File theFile : aDirectory.listFiles()) {
            String theName = theFile.getName();
            if (theName.endsWith(".jrxml") && (!theName.contains("_"))) {
                try {
                    JasperDesign theDesign = JRXmlLoader.load(new FileInputStream(theFile));
                    String theReportName = theDesign.getName();
                    if (StringUtils.isNotEmpty(theReportName)) {
                        aReportMap.put(theFile, theReportName);
                    }
                } catch (FileNotFoundException e) {
                    // This cannot happen
                }

            } else {
                if ((theFile.isDirectory()) && (!".".equals(theName)) && (!"..".equals(theName))) {
                    findReports(aReportMap, theFile);
                }
            }
        }
    }
}
项目:maf-desktop-app    文件:ReportingUtilsImpl.java   
/**
 * Load the report definitions.
 */
@Override
public void loadDefinitions() {

    jasperReports = new HashMap<String, JasperReport>();

    for (Reporting report : ReportingDao.getReportingAsList()) {
        File reportFile = getReportPath(report);
        if (reportFile != null && reportFile.exists()) {
            try {
                JasperDesign jasperDesign = JRXmlLoader.load(reportFile);
                JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
                jasperReports.put(report.template, jasperReport);
                if (log.isDebugEnabled()) {
                    log.debug("the jasper report " + report.template + " has been loaded");
                }
            } catch (Exception e) {
                log.error("Error while loading the report " + report.template, e.getMessage());
            }

        } else {
            log.error("Jasper report " + report.template + " not found !");
        }
    }

}
项目:FACE-RECOGNITION-BASED-ATTENDANCE-MANAGEMENT-SYSTEM    文件:Report.java   
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
        InputStream inputStream = new FileInputStream (".\\src\\reports\\test_jasper.jrxml");

        DataBeanMaker dataBeanMaker = new DataBeanMaker();
        ArrayList<DataBean> dataBeanList = dataBeanMaker.getDataBeanList(null);

        JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataBeanList);

        Map parameters = new HashMap();

JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
//JasperExportManager.exportReportToPdfFile(jasperPrint, "c:/test_jasper.pdf");
    JRViewer jv=new JRViewer(jasperPrint);
JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(1000,800));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
项目:FACE-RECOGNITION-BASED-ATTENDANCE-MANAGEMENT-SYSTEM    文件:Report.java   
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
        InputStream inputStream = new FileInputStream (".\\src\\reports\\test_jasper.jrxml");

        DataBeanMaker dataBeanMaker = new DataBeanMaker();
        ArrayList<DataBean> dataBeanList = dataBeanMaker.getDataBeanList(null);

        JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataBeanList);

        Map parameters = new HashMap();

JasperDesign jasperDesign = JRXmlLoader.load(inputStream);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
//JasperExportManager.exportReportToPdfFile(jasperPrint, "c:/test_jasper.pdf");
    JRViewer jv=new JRViewer(jasperPrint);
JFrame jf = new JFrame();
    jf.getContentPane().add(jv);
    jf.validate();
    jf.setVisible(true);
    jf.setSize(new Dimension(1000,800));
    jf.setLocation(300,100);
    jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
项目:PDFReporter-Studio    文件:JrxmlPublishContributor.java   
protected void publishSubreport(MReportUnit mrunit, IProgressMonitor monitor, JasperDesign jasper, Set<String> fileset, IFile file, JRDesignElement ele, String version) throws Exception {
    MJrxml fres = (MJrxml) impSRP.publish(jasper, ele, mrunit, monitor, fileset, file);
    if (fres == null)
        return;

    IFile[] fs = root.findFilesForLocationURI(fres.getFile().toURI());
    if (fs != null && fs.length > 0) {
        InputStream jrxmlInputStream = JRXMLUtils.getJRXMLInputStream(jrConfig, fs[0].getContents(), fs[0].getFileExtension(), fs[0].getCharset(true), version);
        InputSource is = new InputSource(new InputStreamReader(jrxmlInputStream, "UTF-8"));
        JasperDesign jrd = new JRXmlLoader(jrConfig, JasperReportsConfiguration.getJRXMLDigester()).loadXML(is);
        if (jrd != null) {
            fres.setJd(jrd);
            publishJrxml(fres, monitor, jrd, fileset, fs[0]);
            File f = FileUtils.createTempFile("jrsres", ".jrxml");
            FileUtils.writeFile(f, JRXmlWriterHelper.writeReport(jrConfig, jrd, version));
            fres.setFile(f);
        }
    }
}
项目:PDFReporter-Studio    文件:Publish2ServerWizard.java   
private void initJDesign(IFile file) {
    try {
        if (file != null && file.exists()) {
            if (jrConfig == null)
                jrConfig = new JasperReportsConfiguration(DefaultJasperReportsContext.getInstance(), file);
            else
                jrConfig.init(file);
            String fext = file.getFileExtension();
            if (jDesign == null && fext.equalsIgnoreCase(FileExtension.JRXML) || fext.equalsIgnoreCase(FileExtension.JASPER)) {
                jDesign = new JRXmlLoader(jrConfig, JasperReportsConfiguration.getJRXMLDigester()).loadXML(file.getContents());
                jrConfig.setJasperDesign(jDesign);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:PDFReporter-Studio    文件:RVPropertyPage.java   
private JRBaseReport getFromJRXML(String path) {
    InputStream in = null;
    JRBaseReport jd = null;
    try {
        in = RepositoryUtil.getInstance(dto.getjConfig()).getInputStreamFromLocation(path);
        if (in != null) {
            InputSource is = new InputSource(new InputStreamReader(in, "UTF-8"));
            jd = new JRXmlLoader(dto.getjConfig(), JasperReportsConfiguration.getJRXMLDigester()).loadXML(is);
        }
    } catch (Exception e) {
        // e.printStackTrace();
    } finally {
        FileUtils.closeStream(in);
    }
    return jd;
}
项目:PDFReporter-Studio    文件:JrxmlEditor.java   
/**
 * Xml2model.
 * 
 * @throws JRException
 *           the jR exception
 */
private void xml2model() throws Exception {
    InputStream in = null;
    try {
        IDocumentProvider dp = xmlEditor.getDocumentProvider();
        IDocument doc = dp.getDocument(xmlEditor.getEditorInput());
        in = new ByteArrayInputStream(doc.get().getBytes("UTF-8"));

        JasperDesign jd = new JRXmlLoader(jrContext, JasperReportsConfiguration.getJRXMLDigester()).loadXML(in);
        jrContext.setJasperDesign(jd);
        JaspersoftStudioPlugin.getExtensionManager().onLoad(jd, this);
        setModel(ReportFactory.createReport(jrContext));
    } finally {
        FileUtils.closeStream(in);
    }
}
项目:ireport-fork    文件:IReportCompiler.java   
/**
 * Code to load a JasperDesign. We should not load a jasperDesign, since we already have one in memory.
 * This code must be replaced at some point. Please note that this code use the SourceTraceDigester digester
 * (not used in the JrxmlLoader. We should merge this code with the one provided by JrxmlLoader.
 */
public static JasperDesign loadJasperDesign(InputStream fileStream, SourceTraceDigester digester) throws JRException
{
        try
        {
                JasperDesign jd = JRXmlLoader.load(fileStream);
                return jd;
        }
        finally
        {
                try
                {
                        fileStream.close();
                }
                catch (IOException e)
                {
                        // ignore
                }
        }
}
项目:ireport-fork    文件:JrxmlNotifier.java   
public void resourceWillBeUpdated(RepositoryFile repositoryFile, RepositoryReportUnit reportUnit, File file) throws Exception {

        try {
            JasperDesign jd = (JasperDesign) JRXmlLoader.load(file);
            if (jd.getQuery() != null &&
                jd.getQuery().getLanguage() != null &&
                jd.getQuery().getLanguage().equalsIgnoreCase("xmla-mdx"))
            {
                JOptionPane.showMessageDialog(Misc.getMainFrame(), "You are trying to upload on JasperServer a report which uses the xmla-mdx query language.\nThis language is not supported by JasperServer and it is outdated.\nYou should use the mdx language instead.", "Unsupported language", JOptionPane.WARNING_MESSAGE);

            }

        } catch (Exception ex)
        {
            ex.printStackTrace();
        }


    }
项目:io-addon    文件:JasperStaticTemplateLoader.java   
@Override
public JasperTemplate load(String name) {
    URL url = templateURLs.get(name);
    if (url != null) {
        JasperDesign jasperDesign;
        try {
            jasperDesign = JRXmlLoader.load(url.openStream());
        } catch (Exception e) {
            throw SeedException.wrap(e, JasperErrorCode.ERROR_LOADING_JASPER_REPORT)
                    .put("template", name)
                    .put("url", url.toExternalForm());
        }
        return new JasperTemplate(jasperDesign, url.getFile());
    } else {
        return null;
    }
}
项目:carbon-commons    文件:JPCreator.java   
/**
 * generate report ByteArrayOutputStream
 *
 * @param jrDataSource data for report
 * @param template       report template
 * @return report ByteArrayOutputStream
 * @throws JRException will occurred generating report
 */
public JasperPrint createJasperPrint(JRDataSource jrDataSource, String template)throws JRException {

    // create a byte array from given report template

    byte[] templateBytes = template.getBytes();
    InputStream templateInputStream = new ByteArrayInputStream(templateBytes);
    JasperPrint jasperPrint;
    try {
        // load JasperDesign
        JasperDesign jasperDesign = JRXmlLoader.load(templateInputStream);
        // compiling JasperDesign from JasperCompileManager
        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
        // generate JasperPrint Object from given JasperReport file and JRDataSource by JasperFillManager
        jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap(), jrDataSource);
    } catch (JRException e) {
        throw new JRException("JasperPrint creation failed from " + template , e);
    }
    return jasperPrint;
}
项目:gnvc-ims    文件:ReportGenerator.java   
/**
 * Compile Template Design and produce .jasper file
 *
 * @throws IDXReportException
 */
private void compileToFile() {
    try {
        log.info("JRXML_FILE:" + JRXML_FILENAME);
        setJasperDesign(JRXmlLoader.load(new FileInputStream(JRXML_FILENAME)));

        /*
         * JasperDesign design = JRXmlLoader.load(
        new LegacyJasperInputStream(new FileInputStream("MyXsdBasedDesign.jrxml"))
        );

         */
        if (getJasperDesign() == null) {
            log.error("jasper design is null");
        }
        setJasperReport(JasperCompileManager.compileReport(getJasperDesign()));
        JRSaver.saveObject(getJasperReport(), JASPER_FILENAME);
    } catch (FileNotFoundException ex) {
        log.error(ex);
    } catch (JRException jre) {
        jre.printStackTrace();
    }
}
项目:gnvc-ims    文件:ReportGenerator.java   
private void compileToFile(InputStream is) {
    try {
        setJasperDesign(JRXmlLoader.load(is));

        /*
         * JasperDesign design = JRXmlLoader.load(
        new LegacyJasperInputStream(new FileInputStream("MyXsdBasedDesign.jrxml"))
        );

         */
        if (getJasperDesign() == null) {
            log.error("jasper design is null");
        }
        Boolean compileStatus = compileSubReport();
        if(!compileStatus)
            log.error("subreport compilation failed");
        setJasperReport(JasperCompileManager.compileReport(getJasperDesign()));
        JRSaver.saveObject(getJasperReport(), JASPER_FILENAME);
    } catch (JRException jre) {
        jre.printStackTrace();
    }
}
项目:yarg    文件:JasperFormatter.java   
@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);
    }
}
项目:Proyecto2017Seguros    文件:ReporteMenu.java   
@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);

}
项目:Proyecto2017Seguros    文件:ReporteMenu.java   
@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);

   }
项目:Proyecto2017Seguros    文件:ReporteMenu.java   
@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);
   }
项目:openbravo-brazil    文件:ReportingUtils.java   
/**
 * 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;
}
项目:openbravo-pos    文件:JPanelReport.java   
public void init(AppView app) throws BeanFactoryException {   

    m_App = app;
    DataLogicSales dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales");
    taxsent = dlSales.getTaxList();

    editor = getEditorCreator();
    if (editor instanceof ReportEditorCreator) {
        jPanelFilter.add(((ReportEditorCreator) editor).getComponent(), BorderLayout.CENTER);
    }

    reportviewer = new JRViewer300(null);                        

    add(reportviewer, BorderLayout.CENTER);

    try {     

        InputStream in = getClass().getResourceAsStream(getReport() + ".ser");
        if (in == null) {      
            // read and compile the report
            JasperDesign jd = JRXmlLoader.load(getClass().getResourceAsStream(getReport() + ".jrxml"));            
            jr = JasperCompileManager.compileReport(jd);    
        } else {
            // read the compiled report
            ObjectInputStream oin = new ObjectInputStream(in);
            jr = (JasperReport) oin.readObject();
            oin.close();
        }
    } catch (Exception e) {
        MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadreport"), e);
        msg.show(this);
        jr = null;
    }  
}
项目:jasperreports    文件:IconLabelApp.java   
/**
 *
 */
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);
}
项目:jasperreports    文件:JasperCompileManager.java   
/**
 * Compiles the XML report design file specified by the parameter.
 * The result of this operation is another file that will contain the serialized  
 * {@link net.sf.jasperreports.engine.JasperReport} object representing the compiled report design,
 * having the same name as the report design as declared in the XML plus the <code>*.jasper</code> extension,
 * located in the same directory as the XML source file.
 * 
 * @param sourceFileName XML source file name
 * @return resulting file name containing a serialized {@link net.sf.jasperreports.engine.JasperReport} object 
 */
public String compileToFile(String sourceFileName) throws JRException
{
    File sourceFile = new File(sourceFileName);

    JasperDesign jasperDesign = JRXmlLoader.load(sourceFileName);

    File destFile = new File(sourceFile.getParent(), jasperDesign.getName() + ".jasper");
    String destFileName = destFile.toString();

    compileToFile(jasperDesign, destFileName);

    return destFileName;
}
项目:jasperreports    文件:JasperCompileManager.java   
/**
 * Compiles the XML representation of the report design read from the supplied input stream and
 * writes the generated compiled report design object to the output stream specified 
 * by the second parameter.
 * 
 * @param inputStream  XML source input stream
 * @param outputStream output stream to write the compiled report design to
 */
public void compileToStream(
    InputStream inputStream,
    OutputStream outputStream
    ) throws JRException
{
    JasperDesign jasperDesign = JRXmlLoader.load(inputStream);

    compileToStream(jasperDesign, outputStream);
}
项目:jasperreports    文件:JRDesignViewerController.java   
@Override
protected void setReport(String fileName, boolean isXmlReport) throws JRException
{
    if (isXmlReport)
    {
        JasperDesign jasperDesign = JRXmlLoader.load(fileName);
        setReport(jasperDesign);
    }
    else
    {
        setReport((JRReport) JRLoader.loadObjectFromFile(fileName));
    }
}
项目:jasperreports    文件:JRDesignViewerController.java   
@Override
protected void setReport(InputStream is, boolean isXmlReport) throws JRException
{
    if (isXmlReport)
    {
        JasperDesign jasperDesign = JRXmlLoader.load(is);
        setReport(jasperDesign);
    }
    else
    {
        setReport((JRReport) JRLoader.loadObject(is));
    }
}
项目:jasperreports    文件:TableReportContextXmlRule.java   
@Override
public void end(String namespace, String name) throws Exception
{
    JRXmlLoader xmlLoader = getXmlLoader();

    if (log.isDebugEnabled())
    {
        log.debug("Popping report context");
    }

    xmlLoader.popReportContext();
}
项目:ERDesignerNG    文件:JasperUtils.java   
public static JasperPrint runJasperReport(File aModelXMLFile, File aJRXMLFile) throws JRException,
        FileNotFoundException {

    String theFileName = aJRXMLFile.getAbsolutePath();
    int p = theFileName.indexOf(".jrxml");
    String theTemplateName = theFileName.substring(0, p) + ".jasper";

    File theTemplateFile = new File(theTemplateName);

    JasperDesign theDesign = JRXmlLoader.load(new FileInputStream(aJRXMLFile));
    JRQuery theQuery = theDesign.getQuery();
    String theQueryText = null;

    if (theQuery != null) {
        theQueryText = theQuery.getText();
    }
    if (StringUtils.isEmpty(theQueryText)) {
        throw new RuntimeException("Cannot extract query from Jasper template");
    }

    Map<String, Object> theParams = new HashMap<>();
    theParams.put(JRParameter.REPORT_LOCALE, Locale.getDefault());

    String theSubreportDir = theTemplateFile.getParent();
    if (!theSubreportDir.endsWith(File.separator)) {
        theSubreportDir += File.separator;
    }
    theParams.put("SUBREPORT_DIR", theSubreportDir);

    JRXmlDataSource theDataSource = new JRXmlDataSource(aModelXMLFile, theQueryText);
    return JasperFillManager.fillReport(new FileInputStream(theTemplateFile), theParams,
            theDataSource);
}
项目:TG-BUYME    文件:ProdutoProntoDAO.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
public void gerarRelatorioEstoquePdf(String sql, int totalProdutos){
    try{
        String caminhoSalvar = "";
        DirectoryChooser directoryChooser = new DirectoryChooser();
           File selectedDirectory = directoryChooser.showDialog(null);

           if(selectedDirectory == null){
               System.out.println("N�o selecionou nada");
           }else{
               caminhoSalvar = selectedDirectory.getAbsolutePath();
           }
           if(!caminhoSalvar.isEmpty()){
            Connection conn = new ConexaoBD().getConnection();
            HashMap param = new HashMap();
            param.put("totalProdutos", totalProdutos);
            JasperDesign jd = JRXmlLoader.load("src/main/java/br/com/buyme/report/VerificaEstoque.jrxml");
            JRDesignQuery newQuery = new JRDesignQuery();
            newQuery.setText(sql);
            jd.setQuery(newQuery);
            JasperReport jr = JasperCompileManager.compileReport(jd);
            JasperPrint jp = JasperFillManager.fillReport(jr, param,conn);
            JasperExportManager.exportReportToPdfFile(jp,caminhoSalvar+"/Estoque.pdf");
            conn.close();
           }
    }catch(Exception e){
        e.printStackTrace();
    }
}
项目:TG-BUYME    文件:RelatorioMotivoPerdaLoteDAO.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
public void gerarRelatorioPdf(String sql){
    try{
        String caminhoSalvar = "";
        DirectoryChooser directoryChooser = new DirectoryChooser();
           File selectedDirectory = directoryChooser.showDialog(null);

           if(selectedDirectory == null){
               System.out.println("N�o selecionou nada");
           }else{
               caminhoSalvar = selectedDirectory.getAbsolutePath();
           }
           if(!caminhoSalvar.isEmpty()){
            Connection conn = new ConexaoBD().getConnection();
            HashMap param = new HashMap();

            JasperDesign jd = JRXmlLoader.load("src/main/java/br/com/buyme/report/MotivoPerda.jrxml");
            JRDesignQuery newQuery = new JRDesignQuery();
            newQuery.setText(sql);
            jd.setQuery(newQuery);
            JasperReport jr = JasperCompileManager.compileReport(jd);
            JasperPrint jp = JasperFillManager.fillReport(jr, param,conn);
            JasperExportManager.exportReportToPdfFile(jp,caminhoSalvar+"/MotivoPerda.pdf");

            conn.close();
           }
    }catch(Exception e){
        e.printStackTrace();
    }

}
项目:wifepos    文件:JPanelReport.java   
/**
     *
     * @param app
     * @throws BeanFactoryException
     */
    @Override
    public void init(AppView app) throws BeanFactoryException {   

        m_App = app;

        DataLogicSales dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales");
        taxsent = dlSales.getTaxList();

        editor = getEditorCreator();
        if (editor instanceof ReportEditorCreator) {
            jPanelFilter.add(((ReportEditorCreator) editor).getComponent(), BorderLayout.CENTER);
        }

        reportviewer = new JRViewer300(null);                        

        add(reportviewer, BorderLayout.CENTER);

        try {     

            InputStream in = getClass().getResourceAsStream(getReport() + ".ser");
            if (in == null) {      
                // read and compile the report
                JasperDesign jd = JRXmlLoader.load(getClass().getResourceAsStream(getReport() + ".jrxml"));            
                jr = JasperCompileManager.compileReport(jd);    
            } else {
// JG 16 May 12 use try-with-resources
                try (ObjectInputStream oin = new ObjectInputStream(in)) {
                    jr = (JasperReport) oin.readObject();
                }
            }
// JG 16 May 12 use multicatch
        } catch (JRException | IOException | ClassNotFoundException e) {
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadreport"), e);
            msg.show(this);
            jr = null;
        }  
    }
项目:micro-Blagajna    文件:JPanelReport.java   
/**
     *
     * @param app
     * @throws BeanFactoryException
     */
    @Override
    public void init(AppView app) throws BeanFactoryException {   

        m_App = app;

        DataLogicSales dlSales = (DataLogicSales) app.getBean("com.openbravo.pos.forms.DataLogicSales");
        taxsent = dlSales.getTaxList();

        editor = getEditorCreator();
        if (editor instanceof ReportEditorCreator) {
            jPanelFilter.add(((ReportEditorCreator) editor).getComponent(), BorderLayout.CENTER);
        }

        reportviewer = new JRViewer300(null);                        

        add(reportviewer, BorderLayout.CENTER);

        try {     

            InputStream in = getClass().getResourceAsStream(getReport() + ".ser");
            if (in == null) {      
                // read and compile the report
                JasperDesign jd = JRXmlLoader.load(getClass().getResourceAsStream(getReport() + ".jrxml"));            
                jr = JasperCompileManager.compileReport(jd);    
            } else {
// JG 16 May 12 use try-with-resources
                try (ObjectInputStream oin = new ObjectInputStream(in)) {
                    jr = (JasperReport) oin.readObject();
                }
            }
// JG 16 May 12 use multicatch
        } catch (JRException | IOException | ClassNotFoundException e) {
            MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.cannotloadreport"), e);
            msg.show(this);
            jr = null;
        }  
    }
项目:egd-web    文件:PdfGenerator.java   
public static byte[] generatePDF(Map<String, Object> params, InputStream jrxmlAsStream, JRDataSource source) throws JRException {
    log.debug("generatePDF: Generate pdf with JRDataSource");
    JasperDesign jasperDesign = JRXmlLoader.load(jrxmlAsStream);
    JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, source);
    return JasperExportManager.exportReportToPdf(jasperPrint);
}
项目:PDFReporter-Studio    文件:JrxmlExporter.java   
@Override
public IFile exportToIFile(AFileResource res, ResourceDescriptor rd, String fkeyname, IProgressMonitor monitor) throws Exception {
    IFile f = super.exportToIFile(res, rd, fkeyname, monitor);
    if (f != null) {
        JasperReportsConfiguration jrConfig = res.getJasperConfiguration();
        if (jrConfig == null) {
            jrConfig = JasperReportsConfiguration.getDefaultJRConfig(f);
            res.setJasperConfiguration(jrConfig);
        } else
            jrConfig.init(f);
        try {
            JasperDesign jd = JRXmlLoader.load(jrConfig, f.getContents());
            setPropServerURL(res, jd);
            setPropReportUnit(res, jd);
            getResources(res, jd);

            MServerProfile sp = (MServerProfile) res.getRoot();
            if (sp != null)
                f.setContents(new ByteArrayInputStream(JRXmlWriterHelper.writeReport(null, jd, sp.getValue().getJrVersion()).getBytes("UTF-8")), IFile.KEEP_HISTORY | IFile.FORCE, monitor);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    if (f != null)
        f.setPersistentProperty(KEY_REPORT_ISMAIN, Boolean.toString(rd.isMainReport()));
    return f;
}