1 32 33 package it.businesslogic.ireport; 34 import it.businesslogic.ireport.gui.*; 35 import it.businesslogic.ireport.gui.locale.TimeZoneWrapper; 36 import it.businesslogic.ireport.gui.logpane.*; 37 import it.businesslogic.ireport.connection.*; 38 import it.businesslogic.ireport.gui.queryexecuters.QueryExecuterDef; 39 import it.businesslogic.ireport.util.*; 40 import java.util.*; 41 import java.io.*; 42 import java.net.MalformedURLException ; 43 import java.net.URL ; 44 import java.net.URLClassLoader ; 45 import javax.persistence.EntityManager; 46 import javax.swing.JOptionPane ; 47 import javax.swing.SwingUtilities ; 48 49 import net.sf.jasperreports.engine.*; 50 import net.sf.jasperreports.engine.query.JRJpaQueryExecuterFactory; 51 import net.sf.jasperreports.engine.util.JRSwapFile; 52 import net.sf.jasperreports.olap.JRMondrianQueryExecuterFactory; 53 import net.sf.jasperreports.view.*; 54 import net.sf.jasperreports.engine.export.*; 55 import net.sf.jasperreports.engine.query.JRHibernateQueryExecuterFactory; 56 import org.hibernate.Transaction; 57 import org.hibernate.classic.Session; 58 59 64 public class IReportCompiler implements Runnable , JRExportProgressMonitor 65 { 66 67 public static final int CMD_COMPILE = 0x01; 68 public static final int CMD_EXPORT = 0x02; 69 public static final int CMD_COMPILE_SCRIPTLET = 0x04; 70 71 public static final String OUTPUT_DIRECTORY = "OUTPUT_DIRECTORY"; 72 public static final String OUTPUT_FORMAT = "OUTPUT_FORMAT"; 73 public static final String USE_EMPTY_DATASOURCE = "USE_EMPTY_DATASOURCE"; 74 public static final String USE_CONNECTION = "USE_CONNECTION"; 75 public static final String CONNECTION = "CONNECTION"; 76 public static final String SCRIPTLET_OUTPUT_DIRECTORY = "SCRIPTLET_OUTPUT_DIRECTORY"; 77 public static final String COMPILER = "COMPILER"; 78 public static final String EMPTY_DATASOURCE_RECORDS = "EMPTY_DATASOURCE_RECORDS"; 79 80 private String constTabTitle = ""; 81 private javax.swing.JList threadList = null; 82 83 static PrintStream myPrintStream = null; 84 int filledpage=0; 85 86 87 private String status="Starting"; 88 private IReportConnection iReportConnection; 89 private int statusLevel = 0; 90 91 private JReportFrame jrf; 92 93 private int maxBufferSize = 100000; 94 95 private MainFrame mainFrame; 96 97 private int command; 98 99 private HashMap properties; 100 101 private Thread thread; 102 103 private LogTextArea logTextArea = null; 104 105 private String javaFile = ""; 106 static private StringBuffer outputBuffer = new StringBuffer (); 107 108 109 public IReportCompiler() 110 { 111 properties = new HashMap(); 112 command = 0; 113 114 try { 115 maxBufferSize = Integer.parseInt( System.getProperty("ireport.maxbufsize", "100000")); 116 } catch (Exception ex) 117 { 118 maxBufferSize = 1000000; 119 } 120 } 121 122 public void stopThread() 123 { 124 command = 0; 125 if (thread != null && thread.isAlive()) 126 { 127 try { 128 thread.interrupt(); 129 } catch (Exception ex) 130 { 131 ex.printStackTrace(); 132 } 133 } 134 removeThread(); 135 136 getLogTextArea().setTitle("Killed" + constTabTitle); 137 getLogTextArea().setRemovable(true); 138 System.gc(); 139 } 140 141 152 public void run() 153 { 154 155 if (threadList != null) 156 { 157 javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel )threadList.getModel(); 158 dlm.addElement(this); 159 threadList.updateUI(); 160 } 161 162 File f_report_title = new File(this.getJrf().getReport().getFilename()); 163 constTabTitle = " [" + f_report_title.getName() + "]"; 164 165 String queryLanguage = this.jrf.getReport().getQueryLanguage(); 166 167 168 169 logTextArea = getMainFrame().getLogPane().createNewLog(); 170 status = I18n.getString("iReportCompiler.status.starting", "Starting"); 171 172 logTextArea.setTitle(status + constTabTitle); 173 174 String backupJRClasspath = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH); 175 String backupSystemClasspath = System.getProperty("java.class.path"); 177 178 Vector configuredExecuters = MainFrame.getMainInstance().getQueryExecuters(); 180 for (int k=0; k<configuredExecuters.size(); ++k) 181 { 182 QueryExecuterDef qe = (QueryExecuterDef)configuredExecuters.get(k); 183 if (qe.getLanguage().equals( queryLanguage )) 184 { 185 net.sf.jasperreports.engine.util.JRProperties.setProperty("net.sf.jasperreports.query.executer.factory." + qe.getLanguage(), qe.getClassName()); 186 getLogTextArea().logOnConsole( 187 I18n.getFormattedString("iReportCompiler.settingQueryExecuter", "Setting {0} as Query Executer Factory for language: {1}\n", 188 new Object []{qe.getClassName(), ""+qe.getLanguage() })); 189 190 break; 191 } 192 193 } 194 195 196 boolean compilation_ok = true; 197 long start = System.currentTimeMillis(); 198 PrintStream out = System.out; 200 PrintStream err = System.err; 201 if (myPrintStream == null) 202 myPrintStream =new PrintStream(new FilteredStream(new ByteArrayOutputStream())); 203 204 if (out != myPrintStream) 205 System.setOut(myPrintStream); 206 if (err != myPrintStream) 207 System.setErr(myPrintStream); 208 209 outputBuffer= new StringBuffer (); 210 211 212 216 String fileName = jrf.getReport().getFilename(); 219 220 String srcFileName = jrf.getReport().getFilename(); 222 fileName = Misc.changeFileExtension(fileName,"jasper"); 224 225 226 File f = new File(fileName); 227 if (properties.get(this.OUTPUT_DIRECTORY) != null) 228 { 229 fileName = (String )properties.get(this.OUTPUT_DIRECTORY); 231 if (!fileName.endsWith(f.separator)) 232 { 233 fileName += f.separator; 234 } 235 fileName += f.getName(); 236 } 237 238 String scriptletFileName = jrf.getReport().getFilename(); 240 String srcScriptletFileName = jrf.getReport().getFilename(); 242 scriptletFileName = srcScriptletFileName.substring(0,scriptletFileName.length()-1)+"Scriptlet.java"; 246 srcScriptletFileName = scriptletFileName; 248 249 File f2 = new File(scriptletFileName); 250 if (properties.get(this.SCRIPTLET_OUTPUT_DIRECTORY) != null) 251 { 252 scriptletFileName = (String )properties.get(this.SCRIPTLET_OUTPUT_DIRECTORY) + f2.separatorChar + f2.getName(); 253 } 254 255 256 String reportDirectory = new File(jrf.getReport().getFilename()).getParent(); 257 String classpath = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH); 259 260 261 262 if(classpath != null){ 263 classpath += File.pathSeparator + reportDirectory; 264 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, classpath); 266 } else if (System.getProperty("java.class.path") != null){ 267 classpath = System.getProperty("java.class.path"); 268 classpath += File.pathSeparator + reportDirectory; 269 System.setProperty("java.class.path", classpath); 270 } 271 reportDirectory = reportDirectory.replace('\\', '/'); 272 if(!reportDirectory.endsWith("/")){ 273 reportDirectory += "/"; } 275 if(!reportDirectory.startsWith("/")){ 276 reportDirectory = "/" + reportDirectory; } 278 ReportClassLoader reportClassLoader = new ReportClassLoader(mainFrame.getReportClassLoader()); 279 reportClassLoader.setRelodablePaths( reportDirectory ); 280 reportClassLoader.rescanLibDirectory(); 281 282 283 284 try{ 285 Thread.currentThread().setContextClassLoader(new URLClassLoader (new URL []{new URL ("file://"+reportDirectory)}, reportClassLoader)); 286 } catch (MalformedURLException mue){ 287 mue.printStackTrace(); 288 } 289 290 291 292 294 if ((command & CMD_COMPILE_SCRIPTLET) != 0) 295 { 296 status = I18n.getString("iReportCompiler.status.compilingScriptlet", "Compiling scriptlet"); 297 updateThreadList(); 298 start = System.currentTimeMillis(); 299 300 302 String tempDirStr = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR); 304 305 String oldCompileTemp = tempDirStr; 306 if (tempDirStr == null || tempDirStr.length() == 0 || mainFrame.isUsingCurrentFilesDirectoryForCompiles()) 307 { 308 tempDirStr = mainFrame.getTranslatedCompileDirectory(); 309 } 310 File tempDirFile = new File(tempDirStr); 311 javaFile = srcScriptletFileName; 312 javaFile = (new File(tempDirFile,javaFile)).getPath(); 313 314 javaFile = jrf.getReport().getScriptletFileName(); 315 316 317 318 if (Misc.getLastWriteTime(javaFile) > Misc.getLastWriteTime(Misc.changeFileExtension(javaFile, "class" ))) 319 { 320 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\">" + 321 I18n.getFormattedString("iReportCompiler.compilingScriptlet", "Compiling scriptlet source file... {0}", 322 new Object []{javaFile }) + "</font>",true); 323 try 324 { 325 net.sf.jasperreports.engine.design.JRJdk13Compiler compiler = new net.sf.jasperreports.engine.design.JRJdk13Compiler(); 327 String errors = compiler.compileClass( new File(javaFile), Misc.getClassPath() ); 328 if (errors != null && errors.length() > 0) 329 { 330 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 331 I18n.getFormattedString("iReportCompiler.errorsCompilingScriptlet", "Errors compiling {0}!", 332 new Object []{javaFile }) +"</b></font>",true); 333 getLogTextArea().logOnConsole(errors); 334 compilation_ok = false; 335 } 336 } 337 368 catch (Exception ex) 369 { 370 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 371 I18n.getString("iReportCompiler.errorsCompilingScriptletJavaSource", "Error compiling the Scriptlet java source!") + 372 "</b></font>",true); 373 StringWriter sw = new StringWriter(0); 374 ex.printStackTrace(new PrintWriter(sw)); 375 myPrintStream.flush(); 376 parseException( outputBuffer.toString()+sw.getBuffer()+"", null); 377 compilation_ok = false; 378 } 379 catch (Throwable ext) 380 { 381 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 382 I18n.getString("iReportCompiler.errorsCompilingScriptletJavaSource", "Error compiling the Scriptlet java source!") + 383 "</b></font>",true); 384 StringWriter sw = new StringWriter(0); 385 ext.printStackTrace(new PrintWriter(sw)); 386 myPrintStream.flush(); 387 parseException( outputBuffer.toString()+sw.getBuffer()+"", null); 388 compilation_ok = false; 389 } 390 finally 391 { 392 if(mainFrame.isUsingCurrentFilesDirectoryForCompiles()) 393 { 394 404 } } getLogTextArea().logOnConsole(outputBuffer.toString()); 407 outputBuffer=new StringBuffer (); 408 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\"><b>" + 409 I18n.getFormattedString("iReportCompiler.compilationRunningTime", "Compilation running time: {0,number}!", 410 new Object []{new Long (System.currentTimeMillis() - start)}) + "</b></font><hr>",true); 411 } 412 } 413 414 if (!compilation_ok) { 415 416 removeThread(); 417 return; 418 } 419 420 if ((command & CMD_COMPILE) != 0) 421 { 422 status = I18n.getString("iReportCompiler.status.compilingReport", "Compiling report"); 423 updateThreadList(); 424 425 427 if (mainFrame.getProperties().getProperty("KeepJavaFile","true").equals("false") ) 428 { 429 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_KEEP_JAVA_FILE, false); 430 } 431 else 432 { 433 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_KEEP_JAVA_FILE, true); 434 } 435 436 javaFile = this.jrf.getReport().getName()+".java"; 439 440 String tempDirStr = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR); 442 443 String oldCompileTemp = tempDirStr; 444 if (tempDirStr == null || tempDirStr.length() == 0 || mainFrame.isUsingCurrentFilesDirectoryForCompiles()) 445 { 446 tempDirStr = mainFrame.getTranslatedCompileDirectory(); 447 } 448 File tempDirFile = new File(tempDirStr); 449 javaFile = (new File(tempDirFile,javaFile)).getPath(); 450 451 URL img_url_comp = this.getClass().getResource("/it/businesslogic/ireport/icons/comp1_mini.jpg"); 452 453 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url_comp +"\"> " + 454 I18n.getFormattedString("iReportCompiler.compilingToFile", "Compiling to file... {0} -> {1}", 455 new Object []{fileName, javaFile}) + "</font>",true); 456 457 String old_jr_classpath = Misc.nvl(net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH), ""); 460 String old_defaul_compiler = Misc.nvl(net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS), ""); 461 462 try 463 { 464 if( mainFrame.isUsingCurrentFilesDirectoryForCompiles() ) 465 { 466 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR, tempDirStr); 468 469 } 470 471 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, Misc.nvl( new File(fileName).getParent(), ".") + File.pathSeparator + Misc.getClassPath()); 473 474 477 String compiler_name = I18n.getString("iReportCompiler.defaultCompiler", "JasperReports default compiler"); 478 String compiler_code = mainFrame.getProperties().getProperty("DefaultCompiler"); 479 480 if (this.getProperties().get(COMPILER) != null) 481 { 482 net.sf.jasperreports.engine.util.JRProperties. setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, ""+this.getProperties().get(COMPILER)); 484 compiler_name = I18n.getFormattedString("iReportCompiler.specialLanguageCompiler", "Special language compiler ({0})", new Object []{this.getProperties().get(COMPILER)}); 485 } 486 else if (compiler_code != null && !compiler_code.equals("0") && !compiler_code.equals("")) 487 { 488 if (compiler_code.equals("1")) 489 { 490 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "net.sf.jasperreports.engine.design.JRJdk13Compiler"); 492 compiler_name = I18n.getString("iReportCompiler.javaCompiler", "Java Compiler"); 493 } 494 else if (compiler_code.equals("2")) 495 { 496 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "net.sf.jasperreports.engine.design.JRJdtCompiler" ); compiler_name = I18n.getString("iReportCompiler.jdtCompiler", "JDT Compiler"); 499 ClassLoader cl = getClassLoader(); 501 System.out.println( cl ); 502 } 503 else if (compiler_code.equals("3")) 504 { 505 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "net.sf.jasperreports.compilers.JRBshCompiler" ); 507 compiler_name = I18n.getString("iReportCompiler.beanShellCompiler", "BeanShell Compiler"); 508 } 509 else if (compiler_code.equals("4")) 510 { 511 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "net.sf.jasperreports.engine.design.JRJikesCompiler" ); 513 compiler_name = I18n.getString("iReportCompiler.jikesCompiler", "Jikes Compiler"); 514 } 515 } 516 else 517 { 518 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "" ); 520 Thread.currentThread().setContextClassLoader( reportClassLoader ); 521 ClassLoader cl = getClassLoader(); 522 } 524 525 526 start = System.currentTimeMillis(); 528 529 JasperCompileManager.compileReportToFile(srcFileName, fileName); 530 531 532 } catch (JRException jrex) 533 { 534 compilation_ok = false; 535 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 536 I18n.getFormattedString("iReportCompiler.errorsCompiling", "Errors compiling {0}!", 537 new Object []{fileName}) + "</b></font>",true); 538 Vector source = new Vector(); 540 try 541 { 542 java.io.BufferedReader is = new java.io.BufferedReader (new java.io.FileReader ( javaFile )); 543 while (true) 544 { 545 String line = is.readLine(); 546 if (line == null) break; 547 source.addElement(line); 548 } 549 is.close(); 550 551 } catch (Exception ioex) 552 { 553 } 555 StringWriter sw = new StringWriter(0); 557 jrex.printStackTrace(new PrintWriter(sw)); 558 559 System.out.println("\n\n\n"); 560 myPrintStream.flush(); 561 parseException( outputBuffer.toString()+sw.getBuffer()+"", source); 562 563 564 565 } 566 catch (Exception ex) 567 { 568 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 569 I18n.getString("iReportCompiler.errorsCompilingReportJavaSource", "Error compiling the report java source!") + "</b></font>",true); 570 StringWriter sw = new StringWriter(0); 571 ex.printStackTrace(new PrintWriter(sw)); 572 myPrintStream.flush(); 573 parseException( outputBuffer.toString()+sw.getBuffer()+"", null); 574 compilation_ok = false; 575 } 576 catch (Throwable ext) 577 { 578 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>" + 579 I18n.getString("iReportCompiler.errorsCompilingReportJavaSource", "Error compiling the report java source!") + "</b></font>",true); 580 StringWriter sw = new StringWriter(0); 581 ext.printStackTrace(new PrintWriter(sw)); 582 myPrintStream.flush(); 583 parseException( outputBuffer.toString()+sw.getBuffer()+"", null); 584 compilation_ok = false; 585 } 586 finally 587 { 588 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, old_jr_classpath ); 590 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, old_defaul_compiler ); 592 593 if(mainFrame.isUsingCurrentFilesDirectoryForCompiles()) 594 { 595 if( oldCompileTemp != null ) 596 { 597 System.setProperty("jasper.reports.compile.temp", oldCompileTemp); 598 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR, oldCompileTemp ); 599 } 600 else 601 { 602 System.setProperty("jasper.reports.compile.temp", ""); 603 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR, "" ); 604 } 605 606 File javaSrcFile = new File(javaFile); 607 if ( javaSrcFile.exists() ) 608 if (mainFrame.getProperties().getProperty("KeepJavaFile","true").equals("false") ) 609 { 610 javaSrcFile.delete(); 611 } 612 } } getLogTextArea().logOnConsole(outputBuffer.toString()); 615 outputBuffer=new StringBuffer (); 616 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\"><b>" + 617 I18n.getFormattedString("iReportCompiler.compilationRunningTime", "Compilation running time: {0,number}!", 618 new Object []{new Long (System.currentTimeMillis() - start)}) + "</b></font><hr>",true); 619 620 } 621 622 623 if (!compilation_ok) { 624 625 removeThread(); 626 return; 627 } 628 629 if ((command & CMD_EXPORT) != 0) 630 { 631 632 status = I18n.getString("iReportCompiler.status.generatingReport", "Generating report"); 633 updateThreadList(); 634 635 JasperPrint print = null; 637 URL img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/rundb1_mini.jpg"); 638 639 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> " + 640 I18n.getString("iReportCompiler.fillingReport","Filling report...")+ "</font>",true); 641 642 643 644 statusLevel = 5; 645 HashMap hm = it.businesslogic.ireport.gui.prompt.Prompter.promptForParameters(this.getJrf().getReport()); 646 647 hm.put("REPORT_LOCALE", Misc.getLocaleFromString(mainFrame.getProperties().getProperty("reportLocale"))); 648 649 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/world.png"); 650 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> "+ 651 I18n.getFormattedString("iReportCompiler.locale","Locale: <b>{0}</b>", 652 new Object []{Misc.getLocaleFromString(mainFrame.getProperties().getProperty("reportLocale")).getDisplayName()}) + "</font>",true); 653 654 String reportTimeZoneId = mainFrame.getProperties().getProperty("reportTimeZoneId"); 655 String timeZoneName = I18n.getString("timezone.default","Default"); 656 if (reportTimeZoneId != null && reportTimeZoneId.length() > 0 ) 657 { 658 java.util.TimeZone tz = java.util.TimeZone.getTimeZone(reportTimeZoneId); 659 hm.put("REPORT_TIME_ZONE", tz ); 660 timeZoneName = new TimeZoneWrapper( tz ) + ""; 661 } 662 663 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/timezone.png"); 664 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> " + 665 I18n.getFormattedString("iReportCompiler.timeZone","Time zone: <b>{0}</b>", 666 new Object []{timeZoneName}) + "</font>",true); 667 668 669 670 int reportMaxCount = 0; 671 try { 672 reportMaxCount = Integer.parseInt(mainFrame.getProperties().getProperty("maxRecords","0")); 673 } catch (Exception ex) {} 674 675 if (reportMaxCount > 0) 676 { 677 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/file-info.png"); 678 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> " + 679 I18n.getFormattedString("iReportCompiler.maxRecords","Max number of records: <b>{0,number}</b>", 680 new Object []{new Integer (reportMaxCount)}) + "</font>",true); 681 682 hm.put("REPORT_MAX_COUNT", new Integer (reportMaxCount) ); 683 } 684 685 686 688 689 690 if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().isIgnorePagination()) 691 { 692 hm.put("IS_IGNORE_PAGINATION", Boolean.TRUE ); 693 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/file-info.png"); 694 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> " + 695 I18n.getString("iReportCompiler.ignoringPagination","Ignoring pagination") + "</font>",true); 696 697 } 698 if (it.businesslogic.ireport.gui.MainFrame.getMainInstance().isUseReportVirtualizer()) 699 { 700 try { 701 702 703 net.sf.jasperreports.engine.JRVirtualizer virtualizer = null; 704 String rvName = mainFrame.getProperties().getProperty("ReportVirtualizer", "JRFileVirtualizer"); 705 String vrTmpDirectory = mainFrame.getProperties().getProperty("ReportVirtualizerDirectory", mainFrame.getTranslatedCompileDirectory() ); 706 int vrSize = Integer.parseInt( mainFrame.getProperties().getProperty("ReportVirtualizerSize","100")); 707 708 String msg = ""; 709 710 if (rvName.equals("JRGzipVirtualizer")) 711 { 712 msg = I18n.getFormattedString("iReportCompiler.JRGzipVirtualizer", 713 "JRGzipVirtualizer Size: {0,number}<br>", 714 new Object []{new Integer (vrSize)}); 715 virtualizer = new net.sf.jasperreports.engine.fill.JRGzipVirtualizer(vrSize); 716 } 717 else if (rvName.equals("JRSwapFileVirtualizer")) 718 { 719 msg = I18n.getFormattedString("iReportCompiler.JRSwapFileVirtualizer", 720 "JRSwapFileVirtualizer Size: {0,number} Swap directory: {1};<br>" + 721 " ReportVirtualizerBlockSize: {2}<br>ReportVirtualizerGrownCount: {3}<br>", 722 new Object []{new Integer (vrSize), vrTmpDirectory, 723 mainFrame.getProperties().getProperty("ReportVirtualizerBlockSize","100"), 724 mainFrame.getProperties().getProperty("ReportVirtualizerGrownCount","100")}); 725 726 730 JRSwapFile swapFile = new JRSwapFile(vrTmpDirectory, 731 Integer.parseInt( mainFrame.getProperties().getProperty("ReportVirtualizerBlockSize","100")), 732 Integer.parseInt( mainFrame.getProperties().getProperty("ReportVirtualizerGrownCount","100"))); 733 virtualizer = new net.sf.jasperreports.engine.fill.JRSwapFileVirtualizer(vrSize,swapFile); 734 } 735 else { 737 msg = I18n.getFormattedString("iReportCompiler.JRFileVirtualizer", 738 "JRFileVirtualizer Size: {0,number} Swap directory: {1};<br>", 739 new Object []{new Integer (vrSize),vrTmpDirectory}); 740 virtualizer = new net.sf.jasperreports.engine.fill.JRFileVirtualizer(vrSize, vrTmpDirectory ); 741 } 742 743 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/file-info.png"); 744 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><img align=\"right\" SRC=\""+ img_url +"\"> " 745 + I18n.getString("iReportCompiler.usingVirtualizer", "Using report virtualizer... ") + msg+ "</font>",true); 746 747 hm.put("REPORT_VIRTUALIZER", virtualizer ); 748 749 } catch (Throwable ex) 750 { 751 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#660000\">" + 752 I18n.getString("iReportCompiler.virtualizerNotAvailable", "WARNING: Report virtualizer not available.") + 753 "</font>",true); 754 755 } 756 } 757 758 start = System.currentTimeMillis(); 759 760 if (properties.get(USE_EMPTY_DATASOURCE) != null && properties.get(USE_EMPTY_DATASOURCE).equals("true")) 761 { 762 try 763 { 764 int records = 1; 765 try { 766 767 records = ((Integer )properties.get(EMPTY_DATASOURCE_RECORDS)).intValue(); 768 } catch (Exception ex) 769 { 770 records = 1; 771 } 772 773 print = JasperFillManager.fillReport(fileName,hm,new JREmptyDataSource(records)); 774 775 776 } 777 catch (OutOfMemoryError ex) 778 { 779 getLogTextArea().logOnConsole( 780 I18n.getString("iReportCompiler.outOfMemory", "Out of memory exception!\n") 781 ); 782 } 783 catch (Exception ex) 784 { 785 getLogTextArea().logOnConsole( 786 I18n.getFormattedString("iReportCompiler.errorFillingPrint", 787 "Error filling print... {0}\n", 788 new Object []{ex.getMessage()})); 789 790 ex.printStackTrace(); 791 getLogTextArea().logOnConsole(outputBuffer.toString()); 792 outputBuffer = new StringBuffer (); 793 } 794 } 795 else if (properties.get(USE_CONNECTION) != null && properties.get(USE_CONNECTION).equals("true")) 796 { 797 IReportConnection connection = (IReportConnection)properties.get(CONNECTION); 798 799 try 800 { 801 802 hm = (HashMap)connection.getSpecialParameters( hm ); 803 804 805 806 if (connection.isJDBCConnection()) 807 { 808 print = JasperFillManager.fillReport(fileName,hm, connection.getConnection()); 809 } 810 else if (connection.isJRDataSource()) 811 { 812 JRDataSource ds = null; 813 if (connection instanceof JRDataSourceProviderConnection) 814 { 815 816 JasperReport jasper_report_obj = JasperManager.loadReport(fileName); 817 ds = (JRDataSource)((JRDataSourceProviderConnection)connection).getJRDataSource(jasper_report_obj); 818 819 if (ds == null) return; 820 print = JasperFillManager.fillReport(jasper_report_obj,hm,ds); 821 822 try { ((JRDataSourceProviderConnection)connection).disposeDataSource(); } catch (Exception ex) { 823 824 getLogTextArea().logOnConsole( 825 I18n.getFormattedString("iReportCompiler.errorClosingDatasource", 826 "Error closing datasource: {0}\n", 827 new Object []{ex.getMessage()}) ); 828 829 } 830 } 831 else 832 { 833 ds = (JRDataSource)connection.getJRDataSource(); 834 print = JasperFillManager.fillReport(fileName,hm,ds); 835 } 836 } 837 else 838 { 839 if (connection instanceof JRHibernateConnection) 840 { 841 Session session = null; 842 Transaction transaction = null; 843 System.out.println(); 844 getLogTextArea().logOnConsole( 845 I18n.getString("iReportCompiler.HibernateSessionOpened", 846 "Hibernate session opened") ); 847 848 try { 849 session = ((JRHibernateConnection)connection).createSession(); 850 transaction = session.beginTransaction(); 851 hm.put(JRHibernateQueryExecuterFactory.PARAMETER_HIBERNATE_SESSION, session); 852 print = JasperFillManager.fillReport(fileName,hm); 853 854 } catch (Exception ex) 855 { 856 throw ex; 857 } finally 858 { 859 if (transaction != null) try { transaction.rollback(); } catch (Exception ex) { } 860 if (transaction != null) try { session.close(); } catch (Exception ex) { } 861 } 862 } 863 else if (connection instanceof EJBQLConnection) 864 { 865 EntityManager em = null; 866 try { 867 868 getLogTextArea().logOnConsole( 869 I18n.getString("iReportCompiler.CreatingEntityManager", 870 "Creating entity manager") ); 871 872 em = ((EJBQLConnection)connection).getEntityManager(); 873 hm.put(JRJpaQueryExecuterFactory.PARAMETER_JPA_ENTITY_MANAGER, em); 874 Thread.currentThread().setContextClassLoader( reportClassLoader ); 875 print = JasperFillManager.fillReport(fileName,hm); 876 877 } catch (Exception ex) 878 { 879 throw ex; 880 } finally 881 { 882 getLogTextArea().logOnConsole( 883 I18n.getString("iReportCompiler.ClosingEntityManager", 884 "Closing entity manager") ); 885 ((EJBQLConnection)connection).closeEntityManager(); 886 } 887 } 888 else if (connection instanceof MondrianConnection) 889 { 890 mondrian.olap.Connection mCon = null; 891 try { 892 getLogTextArea().logOnConsole( 893 I18n.getString("iReportCompiler.OpeningMondrianConnection", 894 "Opening Mondrian connection") ); 895 mCon = ((MondrianConnection)connection).getMondrianConnection(); 896 hm.put(JRMondrianQueryExecuterFactory.PARAMETER_MONDRIAN_CONNECTION, mCon); 897 Thread.currentThread().setContextClassLoader( reportClassLoader ); 898 print = JasperFillManager.fillReport(fileName,hm); 899 900 } catch (Exception ex) 901 { 902 throw ex; 903 } finally 904 { 905 getLogTextArea().logOnConsole( 906 I18n.getString("iReportCompiler.ClosingMondrianConnection", 907 "Closing Mondrian connection") ); 908 ((MondrianConnection)connection).closeMondrianConnection(); 909 } 910 } 911 else { 913 Thread.currentThread().setContextClassLoader( reportClassLoader ); 914 print = JasperFillManager.fillReport(fileName,hm); 915 } 916 } 917 918 } catch (Exception ex) 919 { 920 getLogTextArea().logOnConsole( 921 I18n.getFormattedString("iReportCompiler.errorFillingPrint", 922 "Error filling print... {0}\n", 923 new Object []{ex.getMessage()})); 924 ex.printStackTrace(); 925 getLogTextArea().logOnConsole(outputBuffer.toString()); 926 outputBuffer = new StringBuffer (); 927 } 928 catch (Throwable ext) 929 { 930 getLogTextArea().logOnConsole( 931 I18n.getFormattedString("iReportCompiler.errorFillingPrint", 932 "Error filling print... {0}\n", 933 new Object []{ext + " " + ext.getCause()})); 934 ext.printStackTrace(); 935 getLogTextArea().logOnConsole(outputBuffer.toString()); 936 outputBuffer = new StringBuffer (); 937 } 938 finally 939 { 940 connection.disposeSpecialParameters(hm); 941 if (connection != null && connection instanceof JRDataSourceProviderConnection) 942 { 943 try { ((JRDataSourceProviderConnection)connection).disposeDataSource(); } catch (Exception ex) { 944 getLogTextArea().logOnConsole( 945 I18n.getFormattedString("iReportCompiler.errorClosingDatasource", 946 "Error closing datasource: {0}\n", 947 new Object []{ex.getMessage()}) ); 948 } 949 950 } 951 952 } 953 } 954 net.sf.jasperreports.view.JRViewer jrv = null; 955 net.sf.jasperreports.engine.JRExporter exporter=null; 956 957 getLogTextArea().logOnConsole(outputBuffer.toString()); 958 outputBuffer = new StringBuffer (); 959 960 if (print != null) 961 { 962 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\">" + 963 I18n.getFormattedString("iReportCompiler.fillingRunningTime", "<b>Report fill running time: {0,number}!</b> (pages generated: {1,number})", 964 new Object []{new Long (System.currentTimeMillis() - start), new Integer (((List)print.getPages()).size())}) + "</font><hr>",true); 965 966 status = I18n.getString("iReportCompiler.status.exportingReport", "Exporting report"); 967 updateThreadList(); 968 969 start = System.currentTimeMillis(); 970 String format = Misc.nvl(properties.get(OUTPUT_FORMAT),"pdf"); 971 String viewer_program = ""; 972 973 getLogTextArea().logOnConsole(outputBuffer.toString()); 975 outputBuffer = new StringBuffer (); 976 977 String exportingMessage = ""; 978 979 try 980 { 981 982 if (format.equalsIgnoreCase("pdf")) 983 { 984 exporter = new net.sf.jasperreports.engine.export.JRPdfExporter(); 985 986 if (this.getMainFrame().getProperties().getProperty("PDF_IS_ENCRYPTED") != null) 987 { 988 exporter.setParameter( JRPdfExporterParameter.IS_ENCRYPTED, new Boolean ( this.getMainFrame().getProperties().getProperty("PDF_IS_ENCRYPTED") ) ); 989 } 990 if (this.getMainFrame().getProperties().getProperty("PDF_IS_128_BIT_KEY") != null) 991 { 992 exporter.setParameter( JRPdfExporterParameter.IS_128_BIT_KEY, new Boolean ( this.getMainFrame().getProperties().getProperty("PDF_IS_128_BIT_KEY") ) ); 993 } 994 if (this.getMainFrame().getProperties().getProperty("PDF_USER_PASSWORD") != null) 995 { 996 exporter.setParameter( JRPdfExporterParameter.USER_PASSWORD, this.getMainFrame().getProperties().getProperty("PDF_USER_PASSWORD")); 997 } 998 if (this.getMainFrame().getProperties().getProperty("PDF_OWNER_PASSWORD") != null) 999 { 1000 exporter.setParameter( JRPdfExporterParameter.OWNER_PASSWORD, this.getMainFrame().getProperties().getProperty("PDF_OWNER_PASSWORD")); 1001 } 1002 if (this.getMainFrame().getProperties().getProperty("PDF_PERMISSIONS") != null) 1003 { 1004 exporter.setParameter( JRPdfExporterParameter.PERMISSIONS, new Integer ( this.getMainFrame().getProperties().getProperty("PDF_PERMISSIONS"))); 1005 } 1006 1007 fileName = Misc.changeFileExtension(fileName,"pdf"); 1008 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.pdf", "Exporting pdf to file (using iText)... {0}!", new Object []{fileName}); 1009 viewer_program = mainFrame.getProperties().getProperty("ExternalPDFViewer"); 1010 } 1011 else if (format.equalsIgnoreCase("csv")) 1012 { 1013 exporter = new net.sf.jasperreports.engine.export.JRCsvExporter(); 1014 1015 if (this.getMainFrame().getProperties().getProperty("CSV_FIELD_DELIMITER") != null) 1016 { 1017 exporter.setParameter( JRCsvExporterParameter.FIELD_DELIMITER, this.getMainFrame().getProperties().getProperty("CSV_FIELD_DELIMITER") ); 1018 } 1019 1020 fileName = Misc.changeFileExtension(fileName,"csv"); 1021 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.csv", "Exporting CSV to file... {0}!", new Object []{fileName}); 1022 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalCSVViewer"), ""); 1023 } 1024 else if (format.equalsIgnoreCase("html")) 1025 { 1026 exporter = new net.sf.jasperreports.engine.export.JRHtmlExporter(); 1027 1028 if (this.getMainFrame().getProperties().getProperty("HTML_IMAGES_DIR_NAME") != null) 1029 { exporter.setParameter( JRHtmlExporterParameter.IMAGES_DIR_NAME, this.getMainFrame().getProperties().getProperty("HTML_IMAGES_DIR_NAME") ); } 1030 if (this.getMainFrame().getProperties().getProperty("HTML_IS_OUTPUT_IMAGES_TO_DIR") != null) 1031 { exporter.setParameter( JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, new Boolean ( this.getMainFrame().getProperties().getProperty("HTML_IS_OUTPUT_IMAGES_TO_DIR")) ); } 1032 if (this.getMainFrame().getProperties().getProperty("HTML_IMAGES_URI") != null) 1033 { exporter.setParameter( JRHtmlExporterParameter.IMAGES_URI, this.getMainFrame().getProperties().getProperty("HTML_IMAGES_URI") ); } 1034 if (this.getMainFrame().getProperties().getProperty("HTML_HTML_HEADER") != null) 1035 { exporter.setParameter( JRHtmlExporterParameter.HTML_HEADER, this.getMainFrame().getProperties().getProperty("HTML_HTML_HEADER") ); } 1036 if (this.getMainFrame().getProperties().getProperty("HTML_BETWEEN_PAGES_HTML") != null) 1037 { exporter.setParameter( JRHtmlExporterParameter.BETWEEN_PAGES_HTML, this.getMainFrame().getProperties().getProperty("HTML_BETWEEN_PAGES_HTML") ); } 1038 if (this.getMainFrame().getProperties().getProperty("HTML_HTML_FOOTER") != null) 1039 { exporter.setParameter( JRHtmlExporterParameter.HTML_FOOTER, this.getMainFrame().getProperties().getProperty("HTML_HTML_FOOTER") ); } 1040 if (this.getMainFrame().getProperties().getProperty("HTML_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS") != null) 1041 { exporter.setParameter( JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, new Boolean (this.getMainFrame().getProperties().getProperty("HTML_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS"))); } 1042 if (this.getMainFrame().getProperties().getProperty("HTML_IS_WHITE_PAGE_BACKGROUND") != null) 1043 { exporter.setParameter( JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, new Boolean (this.getMainFrame().getProperties().getProperty("HTML_IS_WHITE_PAGE_BACKGROUND")) ); } 1044 if (this.getMainFrame().getProperties().getProperty("HTML_IS_USING_IMAGES_TO_ALIGN") != null) 1045 { exporter.setParameter( JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, new Boolean (this.getMainFrame().getProperties().getProperty("HTML_IS_USING_IMAGES_TO_ALIGN")) ); } 1046 1047 fileName = Misc.changeFileExtension(fileName,"html"); 1048 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.html", "Exporting HTML to file... {0}!", new Object []{fileName}); 1049 1050 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalHTMLViewer"), ""); 1051 } 1052 else if (format.equalsIgnoreCase("xls")) 1053 { 1054 1055 exporter = new net.sf.jasperreports.engine.export.JRXlsExporter(); 1056 1057 if (this.getMainFrame().getProperties().getProperty("XLS_IS_ONE_PAGE_PER_SHEET") != null) 1058 { exporter.setParameter( JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, new Boolean ( this.getMainFrame().getProperties().getProperty("XLS_IS_ONE_PAGE_PER_SHEET")) ); } 1059 if (this.getMainFrame().getProperties().getProperty("XLS_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS") != null) 1060 { exporter.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS"))); } 1061 if (this.getMainFrame().getProperties().getProperty("XLS_IS_WHITE_PAGE_BACKGROUND") != null) 1062 { exporter.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_WHITE_PAGE_BACKGROUND")) ); } 1063 if (this.getMainFrame().getProperties().getProperty("XLS_IS_DETECT_CELL_TYPE") != null) 1064 { exporter.setParameter( JRXlsExporterParameter.IS_DETECT_CELL_TYPE, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_DETECT_CELL_TYPE")) ); } 1065 1066 1067 fileName = Misc.changeFileExtension(fileName,"xls"); 1068 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.xls", "Exporting xls to file (using POI)... {0}!", new Object []{fileName}); 1069 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalXLSViewer"), ""); 1070 1071 } 1072 else if (format.equalsIgnoreCase("xls2")) 1073 { 1074 1075 exporter = new net.sf.jasperreports.engine.export.JExcelApiExporter(); 1076 1077 if (this.getMainFrame().getProperties().getProperty("XLS_IS_ONE_PAGE_PER_SHEET") != null) 1078 { exporter.setParameter( JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, new Boolean ( this.getMainFrame().getProperties().getProperty("XLS_IS_ONE_PAGE_PER_SHEET")) ); } 1079 if (this.getMainFrame().getProperties().getProperty("XLS_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS") != null) 1080 { exporter.setParameter( JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS"))); } 1081 if (this.getMainFrame().getProperties().getProperty("XLS_IS_WHITE_PAGE_BACKGROUND") != null) 1082 { exporter.setParameter( JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_WHITE_PAGE_BACKGROUND")) ); } 1083 if (this.getMainFrame().getProperties().getProperty("XLS_IS_DETECT_CELL_TYPE") != null) 1084 { exporter.setParameter( JRXlsExporterParameter.IS_DETECT_CELL_TYPE, new Boolean (this.getMainFrame().getProperties().getProperty("XLS_IS_DETECT_CELL_TYPE")) ); } 1085 1086 1087 if (this.getMainFrame().getProperties().getProperty("XLS2_IS_FONT_SIZE_FIX_ENABLED") != null) 1088 { exporter.setParameter( JExcelApiExporterParameter.IS_FONT_SIZE_FIX_ENABLED, new Boolean ( this.getMainFrame().getProperties().getProperty("XLS2_IS_FONT_SIZE_FIX_ENABLED")) ); } 1089 1090 fileName = Misc.changeFileExtension(fileName,"xls"); 1091 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.xls2", "Exporting xls to file (using JExcelApi)... {0}!", new Object []{fileName}); 1092 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalXLSViewer"), ""); 1093 1094 } 1095 else if (format.equalsIgnoreCase("java2D")) 1096 { 1097 1098 exporter = new net.sf.jasperreports.engine.export.JRGraphics2DExporter(); 1099 exportingMessage = " "; 1100 exportingMessage = I18n.getString("iReportCompiler.exportingMessage.java2D", "Exporting to Java2D..."); 1101 viewer_program = null; 1102 } 1103 else if (format.equalsIgnoreCase("jrviewer")) 1104 { 1105 exportingMessage = I18n.getString("iReportCompiler.exportingMessage.jrviewer", "Viewing with JasperReports Viewer"); 1106 exporter = null; 1107 viewer_program = null; 1108 } 1109 else if (format.equalsIgnoreCase("txt")) 1110 { 1111 exporter = new it.businesslogic.ireport.export.JRTxtExporter(); 1112 1113 if (this.getMainFrame().getProperties().getProperty("TXT_PAGE_ROWS") != null) 1114 { exporter.setParameter( it.businesslogic.ireport.export.JRTxtExporterParameter.PAGE_ROWS, this.getMainFrame().getProperties().getProperty("TXT_PAGE_ROWS") ); } 1115 if (this.getMainFrame().getProperties().getProperty("TXT_PAGE_COLUMNS") != null) 1116 { exporter.setParameter( it.businesslogic.ireport.export.JRTxtExporterParameter.PAGE_COLUMNS, this.getMainFrame().getProperties().getProperty("TXT_PAGE_COLUMNS") ); } 1117 if (this.getMainFrame().getProperties().getProperty("TXT_ADD_FORM_FEED") != null) 1118 { exporter.setParameter( it.businesslogic.ireport.export.JRTxtExporterParameter.ADD_FORM_FEED, new Boolean (this.getMainFrame().getProperties().getProperty("TXT_ADD_FORM_FEED"))); } 1119 1120 fileName = Misc.changeFileExtension(fileName,"txt"); 1121 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.txt", "Exporting txt (iReport) to file... {0}!", new Object []{fileName}); 1122 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalTXTViewer"), ""); 1123 } 1124 else if (format.equalsIgnoreCase("txtjr")) 1125 { 1126 exporter = new net.sf.jasperreports.engine.export.JRTextExporter(); 1127 1128 if (this.getMainFrame().getProperties().getProperty("JRTXT_PAGE_WIDTH") != null) 1129 { exporter.setParameter( net.sf.jasperreports.engine.export.JRTextExporterParameter.PAGE_WIDTH, new Integer ( this.getMainFrame().getProperties().getProperty("JRTXT_PAGE_WIDTH")) ); } 1130 if (this.getMainFrame().getProperties().getProperty("JRTXT_PAGE_HEIGHT") != null) 1131 { exporter.setParameter( net.sf.jasperreports.engine.export.JRTextExporterParameter.PAGE_HEIGHT, new Integer ( this.getMainFrame().getProperties().getProperty("JRTXT_PAGE_HEIGHT")) ); } 1132 if (this.getMainFrame().getProperties().getProperty("JRTXT_CHARACTER_WIDTH") != null) 1133 { exporter.setParameter( net.sf.jasperreports.engine.export.JRTextExporterParameter.CHARACTER_WIDTH, new Integer ( this.getMainFrame().getProperties().getProperty("JRTXT_CHARACTER_WIDTH")) ); } 1134 if (this.getMainFrame().getProperties().getProperty("JRTXT_CHARACTER_HEIGHT") != null) 1135 { exporter.setParameter( net.sf.jasperreports.engine.export.JRTextExporterParameter.CHARACTER_HEIGHT, new Integer ( this.getMainFrame().getProperties().getProperty("JRTXT_CHARACTER_HEIGHT")) ); } 1136 if (this.getMainFrame().getProperties().getProperty("JRTXT_BETWEEN_PAGES_TEXT") != null) 1137 { exporter.setParameter( net.sf.jasperreports.engine.export.JRTextExporterParameter.BETWEEN_PAGES_TEXT, this.getMainFrame().getProperties().getProperty("JRTXT_BETWEEN_PAGES_TEXT") ); } 1138 1139 fileName = Misc.changeFileExtension(fileName,"txt"); 1140 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.txtjr", "Exporting txt (jasperReports) to file... {0}!", new Object []{fileName}); 1141 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalTXTViewer"), ""); 1142 } 1143 else if (format.equalsIgnoreCase("rtf")) 1144 { 1145 exporter = new net.sf.jasperreports.engine.export.JRRtfExporter(); 1146 1147 fileName = Misc.changeFileExtension(fileName,"rtf"); 1148 exportingMessage = I18n.getFormattedString("iReportCompiler.exportingMessage.rtf", "Exporting RTF to file... {0}!", new Object []{fileName}); 1149 viewer_program = Misc.nvl( mainFrame.getProperties().getProperty("ExternalRTFViewer"), ""); 1150 } 1151 1152 img_url = this.getClass().getResource("/it/businesslogic/ireport/icons/printer_mini.png"); 1153 1154 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\"><img align=\"right\" SRC=\""+ img_url +"\"> " + exportingMessage + "</font>",true); 1155 1156 1157 if (exporter != null) 1158 { 1159 exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,fileName); 1160 exporter.setParameter(JRExporterParameter.JASPER_PRINT,print); 1161 exporter.setParameter(JRExporterParameter.PROGRESS_MONITOR, this); 1162 exporter.exportReport(); 1163 getLogTextArea().logOnConsole(outputBuffer.toString()); 1164 outputBuffer = new StringBuffer (); 1165 } 1166 else if (format.equalsIgnoreCase("jrviewer")) 1167 { 1168 if (print.getPages().size() == 0) 1170 { 1171 try { 1172 SwingUtilities.invokeLater(new Runnable () { 1173 public void run() { 1174 JOptionPane.showMessageDialog(MainFrame.getMainInstance(), I18n.getString("documentHasNoPages","The document has no pages")); 1175 } 1176 }); 1177 } catch (Exception ex){} 1178 } 1179 else 1180 { 1181 JasperViewer jasperViewer = 1182 new JasperViewer(print,false); 1183 jasperViewer.setTitle("iReport JasperViewer"); 1184 1191 jasperViewer.setVisible(true); 1192 } 1193 } 1195 } catch (Throwable ex2) 1196 { 1197 1198 getLogTextArea().logOnConsole( 1199 I18n.getFormattedString("iReportCompiler.errorExportingPrint", 1200 "Error exporting print... {0}\n", 1201 new Object []{ex2.getMessage()})); 1202 ex2.printStackTrace(); 1203 getLogTextArea().logOnConsole(outputBuffer.toString()); 1204 outputBuffer = new StringBuffer (); 1205 1206 } 1207 1208 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\"><b>" + 1209 I18n.getFormattedString("iReportCompiler.exportRunningTime", "Export running time: {0,number}!", 1210 new Object []{new Long (System.currentTimeMillis() - start), new Integer (((List)print.getPages()).size())}) + "</b></font><hr>",true); 1211 1212 1214 Runtime rt = Runtime.getRuntime(); 1215 if (viewer_program == null || viewer_program.equals("")) 1216 { 1217 1218 if (format.equalsIgnoreCase("jrviewer")) 1219 { 1220 1221 } 1222 else 1223 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\">" + 1224 I18n.getString("iReportCompiler.noExternalViewer","No external viewer specified for this type of print. Set it in the options frame!") + 1225 "</font>",true); 1226 1227 } 1228 else 1229 { 1230 try 1231 { 1232 String execute_string = viewer_program + " "+fileName+""; 1233 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\">" + 1234 I18n.getFormattedString("iReportCompiler.executingString", "Executing: {0}", 1235 new Object []{execute_string}) + "</font>",true); 1236 rt.exec( execute_string ); 1237 } catch (Exception ex) 1238 { 1239 1240 getLogTextArea().logOnConsole("Error viewing report...\n"); 1241 ex.printStackTrace(); 1242 getLogTextArea().logOnConsole(outputBuffer.toString()); 1243 outputBuffer = new StringBuffer (); 1244 } 1245 } 1247 } 1248 else 1249 { 1250 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\">" + 1251 I18n.getString("iReportCompiler.printNotFilled", "Print not filled. Try to use an EmptyDataSource...") + "</font>",true); 1252 getLogTextArea().logOnConsole("\n"); 1253 } 1254 } 1255 1256 removeThread(); 1257 1258 if (backupJRClasspath != null) { 1259 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, backupJRClasspath ); 1261 } 1262 else 1263 { 1264 net.sf.jasperreports.engine.util.JRProperties.restoreProperties(); 1266 } 1267 1268 if (backupSystemClasspath != null) System.setProperty("java.class.path",backupSystemClasspath); 1269 else System.getProperties().remove("java.class.path"); 1270 1271 System.gc(); 1272 } 1275 1276 1277 public void removeThread() 1278 { 1279 if (threadList != null) 1280 { 1281 javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel )threadList.getModel(); 1282 dlm.removeElement(this); 1283 threadList.updateUI(); 1284 getLogTextArea().setTitle( I18n.getString("iReportCompiler.status.finished", "Finished") + constTabTitle); 1285 getLogTextArea().setRemovable(true); 1286 } 1287 1288 } 1289 1293 public int getCommand() 1294 { 1295 return command; 1296 } 1297 1298 1302 public void setCommand(int command) 1303 { 1304 this.command = command; 1305 } 1306 1307 1311 public it.businesslogic.ireport.IReportConnection getIReportConnection() 1312 { 1313 return iReportConnection; 1314 } 1315 1316 1320 public void setIReportConnection(it.businesslogic.ireport.IReportConnection iReportConnection) 1321 { 1322 this.iReportConnection = iReportConnection; 1323 } 1324 1325 1329 public JReportFrame getJrf() 1330 { 1331 return jrf; 1332 } 1333 1334 1338 public void setJrf(JReportFrame jrf) 1339 { 1340 this.jrf = jrf; 1341 } 1342 1343 1347 public MainFrame getMainFrame() 1348 { 1349 return mainFrame; 1350 } 1351 1352 1356 public void setMainFrame(MainFrame mainFrame) 1357 { 1358 this.mainFrame = mainFrame; 1359 } 1360 1361 1365 public HashMap getProperties() 1366 { 1367 return properties; 1368 } 1369 1370 1374 public void setProperties(HashMap properties) 1375 { 1376 this.properties = properties; 1377 } 1378 1379 public String toString() 1380 { 1381 return status; 1382 } 1383 1384 class FilteredStream extends FilterOutputStream 1385 { 1386 public FilteredStream(OutputStream aStream) 1387 { 1388 super(aStream); 1389 } 1390 1391 public void write(byte b[]) throws IOException 1392 { 1393 String aString = new String (b); 1394 outputBuffer.append( aString ); 1395 1396 if (outputBuffer.length() > maxBufferSize) { 1398 outputBuffer = outputBuffer.delete(0, outputBuffer.length()-maxBufferSize); 1399 } 1400 } 1401 1402 public void write(byte b[], int off, int len) throws IOException 1403 { 1404 String aString = new String (b , off , len); 1405 outputBuffer.append( aString ); 1406 if (outputBuffer.length() > maxBufferSize) 1407 { 1408 outputBuffer = outputBuffer.delete(0, outputBuffer.length()-maxBufferSize); 1409 } 1410 } 1412 } 1413 1414 public void start() 1415 { 1416 this.thread = new Thread (this); 1417 1418 try{ 1420 String reportDirectory = new File(jrf.getReport().getFilename()).getParent(); 1421 1422 String classpath = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH ); 1425 1426 1427 if(classpath != null){ 1428 1429 classpath += File.pathSeparator + reportDirectory; 1430 net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, classpath); 1432 1433 } else if( System.getProperty("java.class.path") != null){ 1434 1435 classpath = System.getProperty("java.class.path"); 1436 classpath += File.pathSeparator + reportDirectory; 1437 System.setProperty("java.class.path", classpath); 1438 } 1439 1440 if (MainFrame.getMainInstance().isUsingWS()) 1442 { 1443 try { 1444 Enumeration e = MainFrame.getMainInstance().getReportClassLoader().getResources("META-INF/MANIFEST.MF"); 1445 while (e.hasMoreElements()) { 1446 URL url = (URL ) e.nextElement(); 1447 String newJar = ""+url.getFile(); 1448 1449 if (newJar.endsWith("!/META-INF/MANIFEST.MF")) 1450 { 1451 newJar = newJar.substring(0, newJar.length() - "!/META-INF/MANIFEST.MF".length()); 1452 1453 newJar = java.net.URLDecoder.decode(newJar, "UTF-8"); 1454 1455 MainFrame.getMainInstance().logOnConsole("JX:" + newJar); 1456 1457 newJar = newJar.replace('\\', '/'); 1458 if (newJar.startsWith("file://")) 1459 { 1460 newJar = newJar.substring(7); 1461 } 1462 1463 if (newJar.startsWith("file:")) 1464 { 1465 newJar = newJar.substring(5); 1466 } 1467 1468 if(!newJar.startsWith("/")){ 1469 newJar = "/" + newJar; } 1471 } 1472 1473 if (classpath.indexOf(newJar + File.pathSeparator) < 0 && 1474 !classpath.endsWith(newJar)) 1475 { 1476 classpath += File.pathSeparator + newJar; 1477 } 1478 } 1479 } catch (Exception exc) { 1480 MainFrame.getMainInstance().logOnConsole("exception ex:" + exc.getMessage()); 1481 exc.printStackTrace(); 1482 } 1483 System.setProperty("java.class.path", classpath); 1484 } 1485 1487 reportDirectory = reportDirectory.replace('\\', '/'); 1489 if(!reportDirectory.endsWith("/")){ 1490 reportDirectory += "/"; } 1492 if(!reportDirectory.startsWith("/")){ 1493 reportDirectory = "/" + reportDirectory; } 1495 1496 thread.setContextClassLoader(new URLClassLoader (new URL []{ 1497 new URL ("file://"+reportDirectory) 1498 }, MainFrame.getMainInstance().getReportClassLoader())); 1499 1500 } catch (MalformedURLException mue){ 1501 mue.printStackTrace(); 1502 } 1503 1504 this.thread.start(); 1505 } 1506 1507 public void parseException(String exception, Vector sourceLines) 1508 { 1509 1510 String outString = ""; 1512 1513 StringTokenizer st = new StringTokenizer(exception, "\n"); 1516 while (st.hasMoreElements()) 1517 { 1518 1519 String line = st.nextToken(); 1520 if (line.startsWith(this.javaFile)) 1521 { 1522 outString += Misc.toHTML(line+"\n"); 1525 String lineNumber = line.substring( this.javaFile.length()+1); 1526 lineNumber = lineNumber.substring(0, lineNumber.indexOf(':')); 1527 int ln = Integer.parseInt(lineNumber); 1528 if (ln >= 3) ln -=3; 1529 1530 1532 String reference = ""; 1533 if (sourceLines.size() >= ln) 1534 { 1535 1536 String lineCode = (String )sourceLines.elementAt(ln); 1537 if (lineCode.indexOf(" case") == 0 && 1539 lineCode.indexOf(" : // ") >0) 1540 { 1541 reference = lineCode.substring(lineCode.indexOf(" : // ")+6).trim(); 1543 } 1544 } 1545 1546 if (st.hasMoreElements()) 1547 { 1548 try 1549 { 1550 String error_line = st.nextToken(); 1551 if (error_line.startsWith("found")) 1552 { 1553 outString += Misc.toHTML(error_line+"\n"); 1555 error_line = st.nextToken(); 1556 } 1557 if (error_line.startsWith("required")) 1558 { 1559 outString += Misc.toHTML(error_line+"\n"); 1561 error_line = st.nextToken(); 1562 } 1563 if (error_line.startsWith("symbol")) 1564 { 1565 outString += Misc.toHTML(error_line+"\n"); 1567 error_line = st.nextToken(); 1568 } 1569 if (error_line.startsWith("location")) 1570 { 1571 outString += Misc.toHTML(error_line+"\n"); 1573 error_line = st.nextToken(); 1574 } 1575 1576 String html = ""; 1579 for (int i=0; i<error_line.length(); ++i) 1580 { 1581 if (error_line.charAt(i) == ' ') 1582 { 1583 html += " "; 1584 } 1585 else break; 1586 } 1587 error_line = error_line.trim(); 1588 html += "<a HREF=\"http://error:"+ jrf.getWindowID()+ "/"+reference+"\">"+Misc.toHTML(error_line)+"</a>"; 1589 outString += html; 1591 } catch (Exception ex) 1592 { 1593 outString += Misc.toHTML("Error parsing\n!"); 1595 } 1596 } 1597 } 1598 else if (line.startsWith("Warning :") && line.indexOf("y=")>0 && line.indexOf("height=")>0 && line.indexOf("band-height=")>0) 1599 { 1600 outString += "<a HREF=\"http://warning:"+ jrf.getWindowID() +"\">"+Misc.toHTML(line)+"</a>"; 1602 } 1603 else 1604 { 1605 outString += Misc.toHTML(line+"\n"); 1607 } 1608 } 1609 getLogTextArea().logOnConsole(outString,true); 1610 outputBuffer = new StringBuffer (); 1612 } 1613 1614 public javax.swing.JComponent searchButton(javax.swing.JComponent root, String text) 1615 { 1616 if (root instanceof javax.swing.JButton && ((javax.swing.JButton )root).getText()!=null && ((javax.swing.JButton )root).getText().equals(text) ) return root; 1617 for (int i=0; i<root.getComponentCount(); ++i) 1618 { 1619 1620 if (root.getComponent(i) instanceof javax.swing.JComponent ) 1621 { 1622 getLogTextArea().logOnConsole(""+ ((javax.swing.JComponent )root.getComponent(i)) +"\n"); 1623 javax.swing.JComponent res = searchButton((javax.swing.JComponent )root.getComponent(i), text); 1624 if (res != null) return res; 1625 } 1626 } 1627 return null; 1628 } 1629 1630 public void afterPageExport() { 1631 1632 filledpage++; 1633 if (command == 0) 1634 { 1635 1636 } 1637 1638 1639 } 1640 1641 public javax.swing.JList getThreadList() { 1642 return threadList; 1643 } 1644 1645 public void setThreadList(javax.swing.JList threadList) { 1646 this.threadList = threadList; 1647 } 1648 1649 public void updateThreadList() 1650 { 1651 getLogTextArea().setTitle(status + constTabTitle); 1652 try { 1653 1654 if (threadList != null) javax.swing.SwingUtilities.invokeAndWait( 1655 new java.lang.Runnable () { 1656 public void run() { 1657 threadList.updateUI(); 1658 } 1659 } ); 1660 } catch (Exception ex) {} 1661 } 1662 1663 private ClassLoader getClassLoader() 1664 { 1665 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 1666 1667 if (classLoader != null) 1668 { 1669 } 1680 1681 if (classLoader == null) 1682 { 1683 } 1685 1686 return classLoader; 1687 } 1688 1689 public LogTextArea getLogTextArea() { 1690 return logTextArea; 1691 } 1692 1693 public void setLogTextArea(LogTextArea logTextArea) { 1694 this.logTextArea = logTextArea; 1695 } 1696} 1697 1698 | Popular Tags |