////
import net.sf.jasperreports.engine.*
import net.sf.jasperreports.engine.export.*

Class.forName("com.mysql.jdbc.Driver") 
con = java.sql.DriverManager.getConnection("jdbc:mysql://advanta.sytes.net/airs?user=userairs&password=userairs")

//"репозиторий" откомпилированных шаблонов от iReport 
// (*.jrxml)--> iReport--> (*.jasper)
jasperDir="r:/DROPBOX/edunet/workspace/jasperTest/"

def invalid(template, pH,pServ,pType,pStamp,xf){
  String jasperFile= "$jasperDir${template}.jasper"
  String docFile= "$jasperDir$template$xf"
  def map = new HashMap()
  map.put("pH", pH);  map.put("pServ", pServ);  map.put("pType", pType);  map.put("pStamp", pStamp)
  def jasperPrint = JasperFillManager.fillReport(jasperFile, map, con)
  def exporter
  switch(xf){
    case ".html":
      exporter= new JRHtmlExporter()
      exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, false)
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint)
      exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, docFile)
      exporter.exportReport()
      break;
    case ".rtf":
      return;
      break;
    case ".xls":
      return;
      break;
    default: //.pdf
      JasperExportManager.exportReportToPdfFile(jasperPrint, docFile); break
   } 

   java.awt.Desktop.getDesktop().browse(new URI(docFile))
}
invalid( "invalid", "h2", "2", "a", "201101061100", ".pdf")
////