Java 类net.sf.jasperreports.engine.data.JRXmlDataSource 实例源码

项目:Java-Danfe    文件:DanfeNfe.java   
private static void gerarDanfeNfse(String url, List<String> emit, List<String> dest, List<String> ser, List<String> nota, String xml, String logo) {
    try {
        // Teste
        //String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";;
        String output = "danfe.pdf"; 
        map.put("emit", emit);
        map.put("dest", dest);
        map.put("ser", ser);
        map.put("nota", nota);
        map.put("logo", logo);
        // brasao
        String brasao = Paths.get(System.getProperty("user.dir"), "danfe","brasao.png").toAbsolutePath().toString();
        map.put("brasao", brasao);
        // JrDataSource
        JRDataSource jr = new JRXmlDataSource(xml);
        // Relatório compilado
        JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url);
        JasperPrint print = JasperFillManager.fillReport(report, map, jr);
        JasperExportManager.exportReportToPdfFile(print, output);
    } catch (JRException e) {
        System.out.println("erro: "+e.getMessage());
    }
}
项目:bisis-v4    文件:NabavkaPoNacinu.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();

    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", query);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        NabavkaPoNacinu.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/NabavkaPoNacinu.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        return null;
    }
}
项目:bisis-v4    文件:PogodciPoPeriodu.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils.getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", query);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        PogodciPoPeriodu.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/PogodciPoPeriodu.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        return null;
    }
}
项目:bisis-v4    文件:PogodciPoPovezu.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();  
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();  
        param.put("query", query);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        PogodciPoPovezu.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/PogodciPoPovezu.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        return null;
    }
}
项目:bisis-v4    文件:PogodciPoJezicima.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", query);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        NabavkaPoNacinu.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/JeziciPoOgrancima.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        return null;
    }
}
项目:bisis-v4    文件:CountFields.java   
public static JasperPrint execute(int[] hits, String query,String fields) {
    itemMap = new HashMap<String, Item>();
    fieldList=fields.split(",");
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator fieldIDs = keys.iterator();
    while (fieldIDs.hasNext()) {
        String key = (String) fieldIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("\n</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", query);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        CountFields.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/CountFields.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        return null;
    }
}
项目:bisis-v4    文件:ReportUtils.java   
/**
 *  Prikazuje ucitani izvestaj.
 */
public static void showReport(String xml,String fileName, Report report) {
  HashMap<String, Object> params = new HashMap<String, Object>();
  try {
  for (ReportParam p : report.getReportSettings().getParams()){
    if(p.getName().compareToIgnoreCase("subjasper")==0){
        JasperReport subreport = (JasperReport) JRLoader.loadObject(ReportUtils.class
            .getResource(p.getValue()).openStream());
        params.put("subjasper", subreport);
    }else{
       params.put(p.getName(), p.getValue());
    }
  }

  DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance(); //dodato zbog jaxena
  JRPropertiesUtil.getInstance(context).setProperty("net.sf.jasperreports.xpath.executer.factory", "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");   

  params.put("period", getPeriod(fileName));
    JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
        .getDocumentFromString(xml), "/report/item");
    JasperPrint jp = JasperFillManager.fillReport(Report.class.getResource(
        report.getJasper()).openStream(), params, dataSource);
    BisisApp.getMainFrame().addReportFrame(report.getName(), jp);
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
项目: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);
}
项目:jasperstarter    文件:DbNGTest.java   
/**
 * Test of getXmlDataSource method, of class Db.
 */
@Test
public void testGetXmlDataSource() throws Exception {
    System.out.println("getxmlDataSource");
    Config config = new Config();
    config.dbType = DsType.xml;
    config.dataFile = new File("target/test-classes/CancelAck.xml");
    config.xmlXpath = "/CancelResponse/CancelResult/ID";
    Db instance = new Db();
    JRXmlDataSource jRXmlDataSource = instance.getXmlDataSource(config);
    jRXmlDataSource.next();
    // ToDo: don't know jet how to get any value out of it here. 
    // So just checking if object exists:
    assertEquals(jRXmlDataSource.getClass().getCanonicalName(), "net.sf.jasperreports.engine.data.JRXmlDataSource");
}
项目:DEM    文件:DisclosureReport.java   
private void GenerateByXML() throws Exception {
    if (this.m_strRootXPath.isEmpty()) {
        throw new Exception("Root XPath is required.");
    }

    Map<String, Object> hm = new HashMap<String, Object>();
    File file = new File(m_strDataSourceFile);

    if (!file.canRead()) {
        throw new Exception("Unable to read XML data source file.");
    }

    JRXmlDataSource jrxmlds = new JRXmlDataSource(file, m_strRootXPath);
    exportOutputFile(JasperFillManager.fillReport(m_strJasperCompiledFile, hm, jrxmlds));
}
项目:dynamicreports-jasper    文件:XmlReportTest.java   
private JasperReportBuilder createSubreport() throws JRException {
    JasperReportBuilder report = report();
    report.setLocale(Locale.ENGLISH)
        .columns(
            column4 =   col.column("Column4", field("field4", type.stringType()).setDescription("@field4")),
            column5 =   col.column("Column5", field("field5", type.integerType()).setDescription("field5")),
            column6 =   col.column("Column6", field("field6", type.bigDecimalType())))
        .setUseFieldNameAsDescription(false)
        .setDataSource(new JRXmlDataSource(XmlReportTest.class.getResourceAsStream("data.xml"), "/data/row2"));
    return report;
}
项目:bisis-v4    文件:PogodciPoOgrancima.java   
public static JasperPrint execute(int[]hits, String query) {
  HashMap branchMap = new HashMap();
  for (int i = 0; i < hits.length; i++) {
    process(BisisApp.getRecordManager().getRecord(hits[i]), branchMap);
  }

  StringBuffer buff = new StringBuffer();
  buff.append("<report>\n");
  List keys = new ArrayList();
  keys.addAll(branchMap.keySet());
  Collections.sort(keys);
  Iterator branchIDs = keys.iterator();
  int sum = 0;
  while (branchIDs.hasNext()) {
    String key = (String)branchIDs.next();
    Integer value = (Integer)branchMap.get(key);
    buff.append("  <row><branch>");
    buff.append(key);
/*    buff.append(" - ");
    buff.append(HoldingsDataCoders.getValue(HoldingsDataCoders.ODELJENJE_CODER, key));*/
    buff.append("</branch><count>");
    buff.append(value);
    buff.append("</count></row>\n");
    sum += value.intValue();
  }
  buff.append("  <row><branch>Ukupno primeraka</branch><count>");
  buff.append(sum);
  buff.append("</count></row>\n");
  buff.append(" <row><branch>Ukupno zapisa</branch><count>");
  buff.append(hits.length);
  buff.append("</count></row>\n");
  buff.append("</report>\n");
  try {
   JRXmlDataSource dataSource = new JRXmlDataSource(
      XMLUtils.getDocumentFromString(buff.toString()), "/report/row");
Map param=new HashMap();
param.put("query", query);
    JasperPrint jp = JasperFillManager.fillReport(
        PogodciPoOgrancima.class.getResource(
          "/com/gint/app/bisis4/client/hitlist/groupview/PogodciPoOgrancima.jasper")
        .openStream(),param, dataSource);
      return jp;

  } catch (Exception ex) {
     return null;
  }
}
项目:bisis-v4    文件:PogodciPoInvNapomeni.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();
    oldQuery = query;
    int indexBI = query.indexOf("BI:");
    int indexAP = query.indexOf("AP:");
    if (indexAP != -1) {
        odeljenjeQuery = oldQuery.substring(indexAP);
        if (odeljenjeQuery.indexOf(" ")!= -1){
        odeljenjeQuery = odeljenjeQuery.substring(3,odeljenjeQuery.indexOf(" ") );
        }else{
           odeljenjeQuery = odeljenjeQuery.substring(3);
        }
    }
    if(!query.contains("BI:"))
        return null;
    query = query.substring(indexBI);
    int indexS = query.indexOf(" ");
    if (indexS != -1)
        query = query.substring(0, indexS);
    if (query.contains("*")) {
        datefromQuery = query.substring(3).replace("*", ".*");
    } else if (query.contains("?")) {
        datefromQuery = query.substring(3).replace("?", ".*");
    } else {
        datefromQuery = query.substring(3);
    }
    datefromQuery=".*"+datefromQuery+".*";
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));    
    }
    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", oldQuery);
        JasperPrint jp = JasperFillManager
                .fillReport(
                        PogodciPoInvNapomeni.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/PogodciPoInvNapomeni.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
项目:bisis-v4    文件:PogodciPoDatumuInventara.java   
public static JasperPrint execute(int[] hits, String query) {
    itemMap = new HashMap<String, Item>();
    if(query.startsWith("DA:")){
        if(query.contains("*")){
            datefromQuery=query.substring(3).replace("*", "");
        }else if(query.contains("?")){
            datefromQuery=query.substring(3).replace("?", "");
        }else{
        datefromQuery=query.substring(3);
        }

    }
    for (int i = 0; i < hits.length; i++) {
        process(BisisApp.getRecordManager().getRecord(hits[i]));
    }

    StringBuffer buff = new StringBuffer();
    buff.append("<report>\n");
    List keys = new ArrayList();
    keys.addAll(itemMap.keySet());
    Collections.sort(keys);
    Iterator branchIDs = keys.iterator();
    while (branchIDs.hasNext()) {
        String key = (String) branchIDs.next();
        Item item = (Item) itemMap.get(key);
        buff.append(item.toString());
    }
    buff.append("</report>\n");
    try {
        JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                .getDocumentFromString(buff.toString()), "/report/item");
        Map param = new HashMap();
        param.put("query", query);
        param.put("datum", datefromQuery);
        if(query.startsWith("DA:")){
            param.put("query", datefromQuery);
        }
        JasperPrint jp = JasperFillManager
                .fillReport(
                        PogodciPoDatumuInventara.class
                                .getResource(
                                        "/com/gint/app/bisis4/client/hitlist/groupview/BranchesPoDatumu.jasper")
                                .openStream(), param, dataSource);
        return jp;

    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
项目:bisis-v4    文件:WarningsFrame.java   
private void getReport(){
        try{
      doc = makeDoc(getTfBegDate().getDate(), getTfEndDate().getDate());
      if (doc != null){
        if (getChbSave().isSelected()){
          getManager().saveWarnings(warn_to_save, counters);
        }
            boolean cyr = false;
            if (doc.getRoot().getCirilica() == 1){
                cyr = true;
            }

            StringWriter sw = new StringWriter();
            XmlOptions xmlOptions = new XmlOptions();
        xmlOptions.setSavePrettyPrint();
        doc.save(sw,xmlOptions);
        JasperReport subreport = (JasperReport)JRLoader.loadObject(
            WarningsFrame.class.getResource(
              "/com/gint/app/bisis4/client/circ/warnings/jaspers/details.jasper").openStream());
         JasperReport warning = (JasperReport)JRLoader.loadObject(
              WarningsFrame.class.getResource(
                "/com/gint/app/bisis4/client/circ/warnings/jaspers/warning.jasper").openStream());
           Map params = new HashMap(2);
           params.put("sub", subreport);
           params.put("warning", warning);

//             JRXmlDataSource ds = new JRXmlDataSource(XMLUtils
//                     .getDocumentFromString(sw.toString()), "/root/opomena");
             //JRXmlDataSource ds = new JRXmlDataSource(new ByteArrayInputStream((sw.toString().getBytes())), "/root/opomena");
             JRXmlDataSource ds = new JRXmlDataSource(doc.newInputStream(), "/root/opomena");
             JasperPrint jp = JasperFillManager.fillReport(
                     WarningsFrame.class.getResource(
                         "/com/gint/app/bisis4/client/circ/warnings/jaspers/all.jasper").openStream(), 
                         params, ds);   
             JRViewer jr = new JRViewer(jp);
             getReportPanel().add(jr, java.awt.BorderLayout.CENTER);


             String naslov = Utils.convert("Spisak " + ((WarningTypes)getCmbType().getSelectedItem()).getName() + " posaltih na dan " + new SimpleDateFormat("dd.MM.yyyy.").format(new Date()), cyr);
             String rbr = Utils.convert("R.br.", cyr);
             String bropomene = Utils.convert("Br.opomene", cyr);
             String brclana = Utils.convert("Br.\u010dlana", cyr);
             String ime = Utils.convert("Prezime i ime", cyr);
             String datum = Utils.convert("Rok vra\u0107anja", cyr);
             //String napomena = Utils.convert("Napomena", cyr);
             Map paramslist = new HashMap(7);
           paramslist.put("naslov", naslov);
           paramslist.put("rbr", rbr);
           paramslist.put("bropomene", bropomene);
           paramslist.put("brclana", brclana);
           paramslist.put("ime", ime);
           paramslist.put("datum", datum);
           //paramslist.put("napomena", napomena);

           JRXmlDataSource dslist = new JRXmlDataSource(XMLUtils
                     .getDocumentFromString(sw.toString()), "/root/opomena");
           JasperPrint jplist = JasperFillManager.fillReport(
                   WarningsFrame.class.getResource(
                       "/com/gint/app/bisis4/client/circ/warnings/jaspers/list.jasper").openStream(), 
                       paramslist, dslist);           
           JRViewer jrlist = new JRViewer(jplist);
           getReportListPanel().add(jrlist, java.awt.BorderLayout.CENTER);
      }    
        }catch(Exception e){
            e.printStackTrace();
        }
    }
项目:bisis-v4    文件:ReportRunner.java   
public JasperPrint run(String odInvBr, String doInvBr, String reportName) {
    JasperPrint jp = null;
    try {
        List<String> listaInventarnih = new ArrayList<String>();
        int odBr = Integer.parseInt(odInvBr.substring(4));
        String odeljenje = odInvBr.substring(0, 2);
        String tippubl = odInvBr.substring(2, 4);
        int doBr = Integer.parseInt(doInvBr.substring(4));
        for (int brojac = odBr; brojac <= doBr; brojac++) {
            String brojStr = String.valueOf(brojac);
            brojStr = "00000000000".substring(0, 7 - brojStr.length())
                    + brojStr;
            listaInventarnih.add(odeljenje + tippubl + brojStr);
        }
        CachingWrapperFilter filter = new CachingWrapperFilter(
                new BisisFilter(listaInventarnih));
        Result result = BisisApp.getRecordManager().selectAll3x(
                SerializationUtils.serialize(new MatchAllDocsQuery()),
                SerializationUtils.serialize(filter), null);
        Record[] records = BisisApp.getRecordManager().getRecords(result.getRecords());
        StringBuffer buff = new StringBuffer();

        for (Report r : reportCollection.getReports()) {

            if (!r.getReportSettings().getParam("menuitem").equalsIgnoreCase(reportName)) 
                continue;
                buff.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                buff.append("<report>");
                r.init();
                for (Record rec : records) {
                    r.handleRecord(rec);                    
                }
                r.finishOnline(buff);
                buff.append("</report>");
                JRXmlDataSource dataSource = new JRXmlDataSource(XMLUtils
                        .getDocumentFromString(buff.toString()),
                        "/report/item");
                Map param = new HashMap();
                if (r.getReportSettings().getParam("subjasper") != null) {
                    JasperReport subreport = (JasperReport) JRLoader
                            .loadObject(ReportRunner.class.getResource(
                                    r.getReportSettings().getParam(
                                            "subjasper")).openStream());
                    param.put("subjasper", subreport);
                }
                jp = JasperFillManager.fillReport(ReportRunner.class
                        .getResource(
                                r.getReportSettings().getParam("jasper"))
                        .openStream(), param, dataSource);
            }


    } catch (Exception e) {
        e.printStackTrace();
    }
    return jp;
}