KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > IReportCompiler


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * IReportCompiler.java
28  *
29  * Created on 6 giugno 2003, 0.44
30  *
31  */

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 JavaDoc;
43 import java.net.URL JavaDoc;
44 import java.net.URLClassLoader JavaDoc;
45 import javax.persistence.EntityManager;
46 import javax.swing.JOptionPane JavaDoc;
47 import javax.swing.SwingUtilities JavaDoc;
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 /**
60  * Please note that this class is totally different from the old IReportCompiler.class
61  * shipped with iReport 1.
62  * @author Administrator
63  */

64 public class IReportCompiler implements Runnable JavaDoc, 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 JavaDoc OUTPUT_DIRECTORY = "OUTPUT_DIRECTORY";
72    public static final String JavaDoc OUTPUT_FORMAT = "OUTPUT_FORMAT";
73    public static final String JavaDoc USE_EMPTY_DATASOURCE = "USE_EMPTY_DATASOURCE";
74    public static final String JavaDoc USE_CONNECTION = "USE_CONNECTION";
75    public static final String JavaDoc CONNECTION = "CONNECTION";
76    public static final String JavaDoc SCRIPTLET_OUTPUT_DIRECTORY = "SCRIPTLET_OUTPUT_DIRECTORY";
77    public static final String JavaDoc COMPILER = "COMPILER";
78    public static final String JavaDoc EMPTY_DATASOURCE_RECORDS = "EMPTY_DATASOURCE_RECORDS";
79    
80    private String JavaDoc constTabTitle = "";
81    private javax.swing.JList JavaDoc threadList = null;
82    
83    static PrintStream myPrintStream = null;
84    int filledpage=0;
85    
86    
87    private String JavaDoc 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 JavaDoc thread;
102    
103    private LogTextArea logTextArea = null;
104    
105    private String JavaDoc javaFile = "";
106    static private StringBuffer JavaDoc outputBuffer = new StringBuffer JavaDoc();
107       
108    /** Creates a new instance of IReportCompiler */
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 JavaDoc 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 JavaDoc 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    /** When an object implementing interface <code>Runnable</code> is used
142     * to create a thread, starting the thread causes the object's
143     * <code>run</code> method to be called in that separately executing
144     * thread.
145     * <p>
146     * The general contract of the method <code>run</code> is that it may
147     * take any action whatsoever.
148     *
149     * @see java.lang.Thread#run()
150     *
151     */

152    public void run()
153    {
154       
155       if (threadList != null)
156       {
157          javax.swing.DefaultListModel JavaDoc dlm = (javax.swing.DefaultListModel JavaDoc)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 JavaDoc 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 JavaDoc backupJRClasspath = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH);
175       // System.getProperty("jasper.reports.compile.class.path");
176
String JavaDoc backupSystemClasspath = System.getProperty("java.class.path");
177       
178       // Try to look for a good QueryExecutor...
179
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 JavaDoc[]{qe.getClassName(), ""+qe.getLanguage() }));
189
190                break;
191            }
192
193        }
194       
195       
196       boolean compilation_ok = true;
197       long start = System.currentTimeMillis();
198       // Redirect output stream....
199
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 JavaDoc();
210       
211       
212     //by Egon - DEBUG: Something is wrong here, please check. ok? thx.
213
//1 - Line 148 - srcScriptletFileName = C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxmScriptlet.java -> scriptlet filename
214
//2 - Line 157 - Misc.nvl( new File(fileName).getParent(), ".") => . -> report directory
215

216       // Add an entry in the thread list...
217
//by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxml
218
String JavaDoc fileName = jrf.getReport().getFilename();
219       
220     //by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxml
221
String JavaDoc srcFileName = jrf.getReport().getFilename();
222     //by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jasper
223
fileName = Misc.changeFileExtension(fileName,"jasper");
224       
225       
226       File f = new File(fileName);
227       if (properties.get(this.OUTPUT_DIRECTORY) != null)
228       {
229         //by Egon - DEBUG: .\FirstJasper.jasper
230
fileName = (String JavaDoc)properties.get(this.OUTPUT_DIRECTORY);
231          if (!fileName.endsWith(f.separator))
232          {
233             fileName += f.separator;
234          }
235          fileName += f.getName();
236       }
237       
238     //by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxml
239
String JavaDoc scriptletFileName = jrf.getReport().getFilename();
240     //by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxml
241
String JavaDoc srcScriptletFileName = jrf.getReport().getFilename();
242     //by Egon - DEBUG: .\FirstJasper.
243
//fileName = Misc.changeFileExtension(fileName,"");
244
//by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxmScriptlet.java
245
scriptletFileName = srcScriptletFileName.substring(0,scriptletFileName.length()-1)+"Scriptlet.java";
246     //1 - by Egon - DEBUG: C:\jasperreports-0.5.3\demo\samples\jasper\FirstJasper.jrxmScriptlet.java
247
srcScriptletFileName = scriptletFileName;
248       
249       File f2 = new File(scriptletFileName);
250       if (properties.get(this.SCRIPTLET_OUTPUT_DIRECTORY) != null)
251       {
252          scriptletFileName = (String JavaDoc)properties.get(this.SCRIPTLET_OUTPUT_DIRECTORY) + f2.separatorChar + f2.getName();
253       }
254             
255       
256        String JavaDoc reportDirectory = new File(jrf.getReport().getFilename()).getParent();
257        //String classpath = System.getProperty("jasper.reports.compile.class.path");
258
String JavaDoc 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             //System.setProperty("jasper.reports.compile.class.path", classpath);
265
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 += "/";//the file path separator must be present
274
}
275        if(!reportDirectory.startsWith("/")){
276             reportDirectory = "/" + reportDirectory;//it's important to JVM 1.4.2 especially if contains windows drive letter
277
}
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 JavaDoc(new URL JavaDoc[]{new URL JavaDoc("file://"+reportDirectory)}, reportClassLoader));
286        } catch (MalformedURLException JavaDoc mue){
287             mue.printStackTrace();
288        }
289
290        /******************/
291        
292        //.setContextClassLoader(reportClassLoader);
293

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          // Compile the scriptlet class...
301

302          //String tempDirStr = System.getProperty("jasper.reports.compile.temp");
303
String JavaDoc tempDirStr = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR);
304          
305          String JavaDoc 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 JavaDoc[]{javaFile }) + "</font>",true);
323              try
324              {
325                 //JasperCompileManager.compileReportToFile(srcFileName, fileName);
326
net.sf.jasperreports.engine.design.JRJdk13Compiler compiler = new net.sf.jasperreports.engine.design.JRJdk13Compiler();
327                 String JavaDoc 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 JavaDoc[]{javaFile }) +"</b></font>",true);
333                         getLogTextArea().logOnConsole(errors);
334                         compilation_ok = false;
335                     }
336                  }
337              /*
338              catch (Exception jrex)
339              {
340                  
341                 getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#CC0000\"><b>Errors compiling "+scriptletFileName+"!</b></font>",true);
342                 //1. load the java file
343                 Vector source = new Vector();
344                 try
345                 {
346                    java.io.BufferedReader is = new java.io.BufferedReader(new java.io.FileReader( javaFile ));
347                    while (true)
348                    {
349                       String line = is.readLine();
350                       if (line == null) break;
351                       source.addElement(line);
352                    }
353                    is.close();
354                 } catch (Exception ioex)
355                 {
356                    // No file readed....
357                 }
358                 //2. write exception in a string
359                 StringWriter sw = new StringWriter(0);
360                 jrex.printStackTrace(new PrintWriter(sw));
361                 
362                 System.out.println("\n\n\n");
363                 myPrintStream.flush();
364                 parseException( outputBuffer+sw.getBuffer()+"", source);
365     
366              }
367              */

368              catch (Exception JavaDoc 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 JavaDoc 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                     /*
395                    if( oldCompileTemp != null )
396                    {
397                       System.setProperty("jasper.reports.compile.temp", oldCompileTemp);
398                    }
399                    else
400                    {
401                       System.setProperty("jasper.reports.compile.temp", "");
402                    }
403                      */

404                 }//end if using current files directory for compiles
405
}//end finally
406
getLogTextArea().logOnConsole(outputBuffer.toString());
407              outputBuffer=new StringBuffer JavaDoc();
408                  getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\"><b>" +
409                          I18n.getFormattedString("iReportCompiler.compilationRunningTime", "Compilation running time: {0,number}!",
410                                 new Object JavaDoc[]{new Long JavaDoc(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          //System.setProperty("jasper.reports.compile.keep.java.file", "true");
426

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          //System.setProperty("jasper.reports.compile.temp", "C:\\");
437
// Compile report....
438
javaFile = this.jrf.getReport().getName()+".java";
439          
440          //String tempDirStr = System.getProperty("jasper.reports.compile.temp");
441
String JavaDoc tempDirStr = net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR);
442          
443          String JavaDoc 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 JavaDoc 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 +"\"> &nbsp;" +
454                          I18n.getFormattedString("iReportCompiler.compilingToFile", "Compiling to file... {0} -> {1}",
455                                 new Object JavaDoc[]{fileName, javaFile}) + "</font>",true);
456          
457          //String old_jr_classpath = Misc.nvl( System.getProperty("jasper.reports.compile.class.path"), "");
458
//String old_defaul_compiler = Misc.nvl( System.getProperty("jasper.reports.compiler.class"), "");
459
String JavaDoc old_jr_classpath = Misc.nvl(net.sf.jasperreports.engine.util.JRProperties.getProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH), "");
460          String JavaDoc 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                //System.setProperty("jasper.reports.compile.temp", tempDirStr);
467
net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_TEMP_DIR, tempDirStr);
468          
469             }
470             
471             //System.setProperty("jasper.reports.compile.class.path", Misc.nvl( new File(fileName).getParent(), ".") + File.pathSeparator + Misc.getClassPath());
472
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             //System.out.println("CP:" + System.getProperty("jasper.reports.compile.class.path"));
475
//System.out.println("\nOLDCP:" +old_jr_classpath);
476

477             String JavaDoc compiler_name = I18n.getString("iReportCompiler.defaultCompiler", "JasperReports default compiler");
478             String JavaDoc compiler_code = mainFrame.getProperties().getProperty("DefaultCompiler");
479             
480             if (this.getProperties().get(COMPILER) != null)
481             {
482                 //System.setProperty("jasper.reports.compiler.class", ""+this.getProperties().get(COMPILER) );
483
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 JavaDoc[]{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                     //System.setProperty("jasper.reports.compiler.class","net.sf.jasperreports.engine.design.JRJdk13Compiler" );
491
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                     //System.setProperty("jasper.reports.compiler.class","net.sf.jasperreports.engine.design.JRJdtCompiler" );
497
net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "net.sf.jasperreports.engine.design.JRJdtCompiler" ); //"net.sf.jasperreports.engine.design.JRJdtCompiler"
498
compiler_name = I18n.getString("iReportCompiler.jdtCompiler", "JDT Compiler");
499                     //Thread.currentThread().setContextClassLoader( reportClassLoader );
500
ClassLoader JavaDoc cl = getClassLoader();
501                     System.out.println( cl );
502                 }
503                 else if (compiler_code.equals("3"))
504                 {
505                     //System.setProperty("jasper.reports.compiler.class","net.sf.jasperreports.engine.design.JRBshCompiler" );
506
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                     //System.setProperty("jasper.reports.compiler.class","net.sf.jasperreports.engine.design.JRJikesCompiler" );
512
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                  //System.setProperty("jasper.reports.compiler.class","" );
519
net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASS, "" );
520                  Thread.currentThread().setContextClassLoader( reportClassLoader );
521                     ClassLoader JavaDoc cl = getClassLoader();
522                     //System.out.println( cl );
523
}
524             
525             
526            // getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#000000\"><b>Using compiler "+ compiler_name + " (" + System.getProperty("jasper.reports.compiler.class","" ) +")</b></font>",true);
527
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 JavaDoc[]{fileName}) + "</b></font>",true);
538             //1. load the java file
539
Vector source = new Vector();
540             try
541             {
542                java.io.BufferedReader JavaDoc is = new java.io.BufferedReader JavaDoc(new java.io.FileReader JavaDoc( javaFile ));
543                while (true)
544                {
545                   String JavaDoc line = is.readLine();
546                   if (line == null) break;
547                   source.addElement(line);
548                }
549                is.close();
550                
551             } catch (Exception JavaDoc ioex)
552             {
553                // No file readed....
554
}
555             //2. write exception in a string
556
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 JavaDoc 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 JavaDoc 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             //System.setProperty("jasper.reports.compile.class.path", old_jr_classpath);
589
net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, old_jr_classpath );
590             //System.setProperty("jasper.reports.compiler.class", old_defaul_compiler);
591
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             }//end if using current files directory for compiles
613
}//end finally
614
getLogTextArea().logOnConsole(outputBuffer.toString());
615          outputBuffer=new StringBuffer JavaDoc();
616          getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\" color=\"#0000CC\"><b>" +
617                          I18n.getFormattedString("iReportCompiler.compilationRunningTime", "Compilation running time: {0,number}!",
618                                 new Object JavaDoc[]{new Long JavaDoc(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          // Compile report....
636
JasperPrint print = null;
637          URL JavaDoc 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 +"\"> &nbsp;" +
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 +"\"> &nbsp;"+
651                  I18n.getFormattedString("iReportCompiler.locale","Locale: <b>{0}</b>",
652                  new Object JavaDoc[]{Misc.getLocaleFromString(mainFrame.getProperties().getProperty("reportLocale")).getDisplayName()}) + "</font>",true);
653          
654          String JavaDoc reportTimeZoneId = mainFrame.getProperties().getProperty("reportTimeZoneId");
655          String JavaDoc timeZoneName = I18n.getString("timezone.default","Default");
656          if (reportTimeZoneId != null && reportTimeZoneId.length() > 0 )
657          {
658             java.util.TimeZone JavaDoc 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 +"\"> &nbsp;" +
665                  I18n.getFormattedString("iReportCompiler.timeZone","Time zone: <b>{0}</b>",
666                  new Object JavaDoc[]{timeZoneName}) + "</font>",true);
667          
668          
669          
670          int reportMaxCount = 0;
671          try {
672             reportMaxCount = Integer.parseInt(mainFrame.getProperties().getProperty("maxRecords","0"));
673          } catch (Exception JavaDoc 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 +"\"> &nbsp;" +
679                  I18n.getFormattedString("iReportCompiler.maxRecords","Max number of records: <b>{0,number}</b>",
680                  new Object JavaDoc[]{new Integer JavaDoc(reportMaxCount)}) + "</font>",true);
681          
682              hm.put("REPORT_MAX_COUNT", new Integer JavaDoc(reportMaxCount) );
683          }
684          
685          
686         // Thread.currentThread().setContextClassLoader( reportClassLoader );
687

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 +"\"> &nbsp;" +
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 JavaDoc rvName = mainFrame.getProperties().getProperty("ReportVirtualizer", "JRFileVirtualizer");
705                  String JavaDoc vrTmpDirectory = mainFrame.getProperties().getProperty("ReportVirtualizerDirectory", mainFrame.getTranslatedCompileDirectory() );
706                  int vrSize = Integer.parseInt( mainFrame.getProperties().getProperty("ReportVirtualizerSize","100"));
707                  
708                  String JavaDoc msg = "";
709                  
710                  if (rvName.equals("JRGzipVirtualizer"))
711                  {
712                      msg = I18n.getFormattedString("iReportCompiler.JRGzipVirtualizer",
713                                                    "JRGzipVirtualizer Size: {0,number}<br>",
714                                                    new Object JavaDoc[]{new Integer JavaDoc(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 JavaDoc[]{new Integer JavaDoc(vrSize), vrTmpDirectory,
723                                                                 mainFrame.getProperties().getProperty("ReportVirtualizerBlockSize","100"),
724                                                                 mainFrame.getProperties().getProperty("ReportVirtualizerGrownCount","100")});
725                      
726                      //msg = " JRSwapFileVirtualizer " + " Size: " + vrSize +" Swap directory: " + vrTmpDirectory +";<br>";
727
//msg += " ReportVirtualizerBlockSize: " + mainFrame.getProperties().getProperty("ReportVirtualizerBlockSize","100")+"<br>";
728
//msg += " ReportVirtualizerGrownCount: " + mainFrame.getProperties().getProperty("ReportVirtualizerGrownCount","100")+"<br>";
729

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 // default if (rvName.equals("JRFileVirtualizer"))
736
{
737                      msg = I18n.getFormattedString("iReportCompiler.JRFileVirtualizer",
738                                                    "JRFileVirtualizer Size: {0,number} Swap directory: {1};<br>",
739                                                    new Object JavaDoc[]{new Integer JavaDoc(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 +"\"> &nbsp;"
745                          + I18n.getString("iReportCompiler.usingVirtualizer", "Using report virtualizer... ") + msg+ "</font>",true);
746                    
747                  hm.put("REPORT_VIRTUALIZER", virtualizer );
748                  
749              } catch (Throwable JavaDoc 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 JavaDoc)properties.get(EMPTY_DATASOURCE_RECORDS)).intValue();
768                } catch (Exception JavaDoc ex)
769                {
770                    records = 1;
771                }
772                 
773                print = JasperFillManager.fillReport(fileName,hm,new JREmptyDataSource(records));
774                
775                   
776             }
777             catch (OutOfMemoryError JavaDoc ex)
778             {
779                 getLogTextArea().logOnConsole(
780                         I18n.getString("iReportCompiler.outOfMemory", "Out of memory exception!\n")
781                         );
782             }
783             catch (Exception JavaDoc ex)
784             {
785                getLogTextArea().logOnConsole(
786                        I18n.getFormattedString("iReportCompiler.errorFillingPrint",
787                                                    "Error filling print... {0}\n",
788                                                    new Object JavaDoc[]{ex.getMessage()}));
789                        
790                ex.printStackTrace();
791                getLogTextArea().logOnConsole(outputBuffer.toString());
792                outputBuffer = new StringBuffer JavaDoc();
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 JavaDoc ex) {
823                             
824                             getLogTextArea().logOnConsole(
825                                   I18n.getFormattedString("iReportCompiler.errorClosingDatasource",
826                                                    "Error closing datasource: {0}\n",
827                                                    new Object JavaDoc[]{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 JavaDoc ex)
855                        {
856                            throw ex;
857                        } finally
858                        {
859                             if (transaction != null) try { transaction.rollback(); } catch (Exception JavaDoc ex) { }
860                             if (transaction != null) try { session.close(); } catch (Exception JavaDoc 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 JavaDoc 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 JavaDoc 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 // Query Executor mode...
912
{
913                        Thread.currentThread().setContextClassLoader( reportClassLoader );
914                        print = JasperFillManager.fillReport(fileName,hm);
915                    }
916                }
917                
918             } catch (Exception JavaDoc ex)
919             {
920                getLogTextArea().logOnConsole(
921                        I18n.getFormattedString("iReportCompiler.errorFillingPrint",
922                                                    "Error filling print... {0}\n",
923                                                    new Object JavaDoc[]{ex.getMessage()}));
924                ex.printStackTrace();
925                getLogTextArea().logOnConsole(outputBuffer.toString());
926                outputBuffer = new StringBuffer JavaDoc();
927             }
928             catch (Throwable JavaDoc ext)
929             {
930                 getLogTextArea().logOnConsole(
931                        I18n.getFormattedString("iReportCompiler.errorFillingPrint",
932                                                    "Error filling print... {0}\n",
933                                                    new Object JavaDoc[]{ext + " " + ext.getCause()}));
934                ext.printStackTrace();
935                getLogTextArea().logOnConsole(outputBuffer.toString());
936                outputBuffer = new StringBuffer JavaDoc();
937             }
938             finally
939             {
940                 connection.disposeSpecialParameters(hm);
941                 if (connection != null && connection instanceof JRDataSourceProviderConnection)
942                 {
943                         try { ((JRDataSourceProviderConnection)connection).disposeDataSource(); } catch (Exception JavaDoc ex) {
944                             getLogTextArea().logOnConsole(
945                                   I18n.getFormattedString("iReportCompiler.errorClosingDatasource",
946                                                    "Error closing datasource: {0}\n",
947                                                    new Object JavaDoc[]{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 JavaDoc();
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 JavaDoc[]{new Long JavaDoc(System.currentTimeMillis() - start), new Integer JavaDoc(((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 JavaDoc format = Misc.nvl(properties.get(OUTPUT_FORMAT),"pdf");
971             String JavaDoc viewer_program = "";
972             
973             //getLogTextArea().logOnConsole(properties.get(OUTPUT_FORMAT) + "Exporting\n");
974
getLogTextArea().logOnConsole(outputBuffer.toString());
975             outputBuffer = new StringBuffer JavaDoc();
976             
977             String JavaDoc 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 JavaDoc( 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 JavaDoc( 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 JavaDoc( 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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc( 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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc[]{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 JavaDoc( 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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc[]{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 JavaDoc( 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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc( 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 JavaDoc[]{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 JavaDoc(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 JavaDoc[]{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 JavaDoc( 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 JavaDoc( 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 JavaDoc( 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 JavaDoc( 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 JavaDoc[]{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 JavaDoc[]{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 +"\"> &nbsp;" + 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 JavaDoc();
1165               }
1166               else if (format.equalsIgnoreCase("jrviewer"))
1167               {
1168                  //jrv = new net.sf.jasperreports.view.JRViewer(print);
1169
if (print.getPages().size() == 0)
1170                  {
1171                      try {
1172                      SwingUtilities.invokeLater(new Runnable JavaDoc() {
1173                          public void run() {
1174                                  JOptionPane.showMessageDialog(MainFrame.getMainInstance(), I18n.getString("documentHasNoPages","The document has no pages"));
1175                          }
1176                      });
1177                      } catch (Exception JavaDoc ex){}
1178                  }
1179                  else
1180                  {
1181                      JasperViewer jasperViewer =
1182                      new JasperViewer(print,false);
1183                      jasperViewer.setTitle("iReport JasperViewer");
1184                      // Find JRViewer...
1185
/*
1186                        javax.swing.JComponent button = searchButton( (javax.swing.JComponent)jasperViewer.getRootPane() , "Print");
1187                        if (button != null) ((javax.swing.JButton)button).setText("Ciccio");
1188                        button = searchButton( (javax.swing.JComponent)jasperViewer.getRootPane() , "Reload");
1189                        if (button != null) ((javax.swing.JButton)button).setText("Ricarica");
1190                         */

1191                      jasperViewer.setVisible(true);
1192                  }
1193                  //net.sf.jasperreports.view.JasperViewer.viewReport( print, false);
1194
}
1195            } catch (Throwable JavaDoc ex2)
1196            {
1197               
1198               getLogTextArea().logOnConsole(
1199                       I18n.getFormattedString("iReportCompiler.errorExportingPrint",
1200                                                   "Error exporting print... {0}\n",
1201                                                   new Object JavaDoc[]{ex2.getMessage()}));
1202               ex2.printStackTrace();
1203               getLogTextArea().logOnConsole(outputBuffer.toString());
1204               outputBuffer = new StringBuffer JavaDoc();
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 JavaDoc[]{new Long JavaDoc(System.currentTimeMillis() - start), new Integer JavaDoc(((List)print.getPages()).size())}) + "</b></font><hr>",true);
1211           
1212            // Export using the rigth program....
1213

1214            Runtime JavaDoc 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 JavaDoc execute_string = viewer_program + " "+fileName+"";
1233                  getLogTextArea().logOnConsole("<font face=\"SansSerif\" size=\"3\">" +
1234                         I18n.getFormattedString("iReportCompiler.executingString", "Executing: {0}",
1235                                new Object JavaDoc[]{execute_string}) + "</font>",true);
1236                  rt.exec( execute_string );
1237               } catch (Exception JavaDoc ex)
1238               {
1239                  
1240                  getLogTextArea().logOnConsole("Error viewing report...\n");
1241                  ex.printStackTrace();
1242                  getLogTextArea().logOnConsole(outputBuffer.toString());
1243                  outputBuffer = new StringBuffer JavaDoc();
1244               }
1245               //getLogTextArea().logOnConsole("Finished...\n");
1246
}
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          //System.setProperty("jasper.reports.compile.class.path",backupJRClasspath);
1260
net.sf.jasperreports.engine.util.JRProperties.setProperty(net.sf.jasperreports.engine.util.JRProperties.COMPILER_CLASSPATH, backupJRClasspath );
1261      }
1262      else
1263      {
1264          //System.getProperties().remove("jasper.reports.compile.class.path");
1265
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      //System.setOut(out);
1273
//System.setErr(err);
1274
}
1275   
1276   
1277   public void removeThread()
1278   {
1279       if (threadList != null)
1280      {
1281         javax.swing.DefaultListModel JavaDoc dlm = (javax.swing.DefaultListModel JavaDoc)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   /** Getter for property command.
1290    * @return Value of property command.
1291    *
1292    */

1293   public int getCommand()
1294   {
1295      return command;
1296   }
1297   
1298   /** Setter for property command.
1299    * @param command New value of property command.
1300    *
1301    */

1302   public void setCommand(int command)
1303   {
1304      this.command = command;
1305   }
1306   
1307   /** Getter for property iReportConnection.
1308    * @return Value of property iReportConnection.
1309    *
1310    */

1311   public it.businesslogic.ireport.IReportConnection getIReportConnection()
1312   {
1313      return iReportConnection;
1314   }
1315   
1316   /** Setter for property iReportConnection.
1317    * @param iReportConnection New value of property iReportConnection.
1318    *
1319    */

1320   public void setIReportConnection(it.businesslogic.ireport.IReportConnection iReportConnection)
1321   {
1322      this.iReportConnection = iReportConnection;
1323   }
1324   
1325   /** Getter for property jrf.
1326    * @return Value of property jrf.
1327    *
1328    */

1329   public JReportFrame getJrf()
1330   {
1331      return jrf;
1332   }
1333   
1334   /** Setter for property jrf.
1335    * @param jrf New value of property jrf.
1336    *
1337    */

1338   public void setJrf(JReportFrame jrf)
1339   {
1340      this.jrf = jrf;
1341   }
1342   
1343   /** Getter for property mainFrame.
1344    * @return Value of property mainFrame.
1345    *
1346    */

1347   public MainFrame getMainFrame()
1348   {
1349      return mainFrame;
1350   }
1351   
1352   /** Setter for property mainFrame.
1353    * @param mainFrame New value of property mainFrame.
1354    *
1355    */

1356   public void setMainFrame(MainFrame mainFrame)
1357   {
1358      this.mainFrame = mainFrame;
1359   }
1360   
1361   /** Getter for property properties.
1362    * @return Value of property properties.
1363    *
1364    */

1365   public HashMap getProperties()
1366   {
1367      return properties;
1368   }
1369   
1370   /** Setter for property properties.
1371    * @param properties New value of property properties.
1372    *
1373    */

1374   public void setProperties(HashMap properties)
1375   {
1376      this.properties = properties;
1377   }
1378   
1379   public String JavaDoc 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 JavaDoc aString = new String JavaDoc(b);
1394         outputBuffer.append( aString );
1395         
1396         if (outputBuffer.length() > maxBufferSize) // 5000000
1397
{
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 JavaDoc aString = new String JavaDoc(b , off , len);
1405         outputBuffer.append( aString );
1406         if (outputBuffer.length() > maxBufferSize)
1407         {
1408             outputBuffer = outputBuffer.delete(0, outputBuffer.length()-maxBufferSize);
1409         }
1410         //getLogTextArea().logOnConsole(aString);
1411
}
1412   }
1413   
1414   public void start()
1415   {
1416      this.thread = new Thread JavaDoc(this);
1417      
1418    //using the report directory to load classes and resources
1419
try{
1420          String JavaDoc reportDirectory = new File(jrf.getReport().getFilename()).getParent();
1421      
1422          //set classpath
1423
//String classpath = System.getProperty("jasper.reports.compile.class.path");
1424
String JavaDoc 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              //System.setProperty("jasper.reports.compile.class.path", classpath);
1431
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          // Add all the hidden files.... (needed only by JWS)
1441
if (MainFrame.getMainInstance().isUsingWS())
1442          {
1443            try {
1444               Enumeration e = MainFrame.getMainInstance().getReportClassLoader().getResources("META-INF/MANIFEST.MF");
1445               while (e.hasMoreElements()) {
1446                  URL JavaDoc url = (URL JavaDoc) e.nextElement();
1447                  String JavaDoc 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;//it's important to JVM 1.4.2 especially if contains windows drive letter
1470
}
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 JavaDoc exc) {
1480                MainFrame.getMainInstance().logOnConsole("exception ex:" + exc.getMessage());
1481                exc.printStackTrace();
1482              }
1483              System.setProperty("java.class.path", classpath);
1484          }
1485          //MainFrame.getMainInstance().logOnConsole("CLASSPATH" + classpath);
1486

1487          //include report directory for resource search path
1488
reportDirectory = reportDirectory.replace('\\', '/');
1489          if(!reportDirectory.endsWith("/")){
1490              reportDirectory += "/";//the file path separator must be present
1491
}
1492          if(!reportDirectory.startsWith("/")){
1493              reportDirectory = "/" + reportDirectory;//it's important to JVM 1.4.2 especially if contains windows drive letter
1494
}
1495          
1496          thread.setContextClassLoader(new URLClassLoader JavaDoc(new URL JavaDoc[]{
1497              new URL JavaDoc("file://"+reportDirectory)
1498          }, MainFrame.getMainInstance().getReportClassLoader()));
1499  
1500     } catch (MalformedURLException JavaDoc mue){
1501      mue.printStackTrace();
1502    }
1503      
1504      this.thread.start();
1505   }
1506   
1507   public void parseException(String JavaDoc exception, Vector sourceLines)
1508   {
1509      
1510      // Create a single outString...
1511
String JavaDoc outString = "";
1512      
1513      // For each row, looking for a file name followed by a row number...
1514
//javax.swing.JOptionPane.showMessageDialog(null,exception);
1515
StringTokenizer st = new StringTokenizer(exception, "\n");
1516      while (st.hasMoreElements())
1517      {
1518         
1519         String JavaDoc line = st.nextToken();
1520         if (line.startsWith(this.javaFile))
1521         {
1522            // The next line is an expression error....
1523
//getLogTextArea().logOnConsole(line+"\n");
1524
outString += Misc.toHTML(line+"\n");
1525            String JavaDoc 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            // Take the element name....
1531

1532            String JavaDoc reference = "";
1533            if (sourceLines.size() >= ln)
1534            {
1535               
1536               String JavaDoc lineCode = (String JavaDoc)sourceLines.elementAt(ln);
1537               //getLogTextArea().logOnConsole( "Line: " + ln + "> " + lineCode+"\n");
1538
if (lineCode.indexOf(" case") == 0 &&
1539               lineCode.indexOf(" : // ") >0)
1540               {
1541                  // We have found the comment where jasperReport puts the expression ref.
1542
reference = lineCode.substring(lineCode.indexOf(" : // ")+6).trim();
1543               }
1544            }
1545            
1546            if (st.hasMoreElements())
1547            {
1548               try
1549               {
1550                  String JavaDoc error_line = st.nextToken();
1551                  if (error_line.startsWith("found"))
1552                  {
1553                     //getLogTextArea().logOnConsole( error_line+"\n");
1554
outString += Misc.toHTML(error_line+"\n");
1555                     error_line = st.nextToken();
1556                  }
1557                  if (error_line.startsWith("required"))
1558                  {
1559                     //getLogTextArea().logOnConsole( error_line+"\n");
1560
outString += Misc.toHTML(error_line+"\n");
1561                     error_line = st.nextToken();
1562                  }
1563                  if (error_line.startsWith("symbol"))
1564                  {
1565                     //getLogTextArea().logOnConsole( error_line+"\n");
1566
outString += Misc.toHTML(error_line+"\n");
1567                     error_line = st.nextToken();
1568                  }
1569                  if (error_line.startsWith("location"))
1570                  {
1571                     //getLogTextArea().logOnConsole( error_line+"\n");
1572
outString += Misc.toHTML(error_line+"\n");
1573                     error_line = st.nextToken();
1574                  }
1575                  
1576                  // Find the link....
1577
// Count space at begin of line...
1578
String JavaDoc html = "";
1579                  for (int i=0; i<error_line.length(); ++i)
1580                  {
1581                     if (error_line.charAt(i) == ' ')
1582                     {
1583                        html += "&nbsp;";
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                  //getLogTextArea().logOnConsole( html,true);
1590
outString += html;
1591               } catch (Exception JavaDoc ex)
1592               {
1593                  //getLogTextArea().logOnConsole( "Error parsing\n!");
1594
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            //getLogTextArea().logOnConsole("<a HREF=\"http://warning\">"+Misc.toHTML(line)+"</a>",true);
1601
outString += "<a HREF=\"http://warning:"+ jrf.getWindowID() +"\">"+Misc.toHTML(line)+"</a>";
1602         }
1603         else
1604         {
1605            //getLogTextArea().logOnConsole(line+"\n");
1606
outString += Misc.toHTML(line+"\n");
1607         }
1608      }
1609      getLogTextArea().logOnConsole(outString,true);
1610      //getLogTextArea().logOnConsole( "<a HREF=\"http://problem\">*****<hr><font face=\"Courier New\" size=\"3\">"+ exception +"</a>", true);
1611
outputBuffer = new StringBuffer JavaDoc();
1612   }
1613   
1614   public javax.swing.JComponent JavaDoc searchButton(javax.swing.JComponent JavaDoc root, String JavaDoc text)
1615   {
1616      if (root instanceof javax.swing.JButton JavaDoc && ((javax.swing.JButton JavaDoc)root).getText()!=null && ((javax.swing.JButton JavaDoc)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 JavaDoc)
1621         {
1622            getLogTextArea().logOnConsole(""+ ((javax.swing.JComponent JavaDoc)root.getComponent(i)) +"\n");
1623            javax.swing.JComponent JavaDoc res = searchButton((javax.swing.JComponent JavaDoc)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 JavaDoc getThreadList() {
1642        return threadList;
1643    }
1644
1645    public void setThreadList(javax.swing.JList JavaDoc 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 JavaDoc() {
1656                    public void run() {
1657                            threadList.updateUI();
1658                    }
1659            } );
1660         } catch (Exception JavaDoc ex) {}
1661    }
1662     
1663    private ClassLoader JavaDoc getClassLoader()
1664    {
1665        ClassLoader JavaDoc classLoader = Thread.currentThread().getContextClassLoader();
1666
1667        if (classLoader != null)
1668        {
1669            //try
1670
//{
1671
// Class.forName(net.sf.jasperreports.engine.design.JRJdtCompiler.class.getName(), true, Thread.currentThread().getContextClassLoader());
1672
//}
1673
//catch (ClassNotFoundException e)
1674
//{
1675
// classLoader = null;
1676
// //if (log.isWarnEnabled())
1677
// // log.warn("Failure using Thread.currentThread().getContextClassLoader() in JRJdtCompiler class. Using JRJdtCompiler.class.getClassLoader() instead.");
1678
//}
1679
}
1680    
1681        if (classLoader == null)
1682        {
1683            //classLoader = JRClassLoader.class.getClassLoader();
1684
}
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