'Compile & Fill Jasper Report - XML datasource'에 해당되는 글 1건

  1. 2012.02.06 Compile & Fill Jasper Report - XML datasource
53.jasper&ireport2012. 2. 6. 18:10
반응형

public static void main(String[] args) {
        Map map = new RenderReportBean().execute("northwind", "OrdersReport");
 
    }
 
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public Map execute(String sourceFileId, String templateId, Integer[] formats) {
        Map params = new HashMap();
        Document document;
        Map<Integer, Boolean> renderedSuccessList = new HashMap<Integer, Boolean>();
        try {
 
            document = JRXmlUtils.parse(JRLoader.getLocationInputStream(sourceFileId + ".xml"));
 
            params.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
            params.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
            params.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
            params.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.ENGLISH);
            params.put(JRParameter.REPORT_LOCALE, Locale.US);
 
            JasperCompileManager.compileReportToFile(templateId + ".jrxml", templateId + ".jasper");
 
            JasperFillManager.fillReportToFile(templateId + ".jasper", params);
 
            JasperExportManager.exportReportToPdfFile(templateId + ".jrprint", sourceFileId + ".pdf");
 
 
        } catch (Exception e) {
            e.printStackTrace();
            return renderedSuccessList;
        }
        return renderedSuccessList;
    }
Posted by 1010