Java 类net.sf.jasperreports.engine.util.SimpleFileResolver 实例源码

项目:gnvc-ims    文件:ReportGenerator.java   
private void fillReport() {
    // jrVirtualizer = (JRFileVirtualizer) reportParameters
    // .get(JRParameter.REPORT_VIRTUALIZER);
    // if (null == jrVirtualizer) {
    // File tmp = new File(JASPER_PATH + sp + "cache");
    // if (!tmp.exists())
    // tmp.mkdirs();
    // jrVirtualizer = new JRFileVirtualizer(30, tmp.getAbsolutePath());
    // }
    // reportParameters.put(JRParameter.REPORT_VIRTUALIZER, jrVirtualizer);

    try {
        long start = System.currentTimeMillis();
        //set relative path during compilation process in jasper
        fr = new SimpleFileResolver(new File(templateContextPath));
        reportParameters.put(JRParameter.REPORT_FILE_RESOLVER, fr);
        setJasperPrint(JasperFillManager.fillReport(getJasperReport(), reportParameters));
        //System.out.println("isFirmTypeParamSet=" + reportParameters.containsKey("firmTypeParam"));
    } catch (JRException jre) {
        jre.printStackTrace();

    }

    // jrVirtualizer.setReadOnly(true);
}
项目:jasperreports    文件:JasperReportsContextListener.java   
@Override
public void contextInitialized(ServletContextEvent ce) 
{
    LocalJasperReportsContext localJasperReportsContext = new LocalJasperReportsContext(DefaultJasperReportsContext.getInstance());
    SimpleFileResolver fileResolver = 
        new SimpleFileResolver(
            new File(
                new File(ce.getServletContext().getRealPath("/")), 
                ce.getServletContext().getInitParameter("net.sf.jasperreports.web.file.repository.root")
                )
            );
    localJasperReportsContext.setFileResolver(fileResolver);

    AbstractServlet.setJasperReportsContext(localJasperReportsContext);
}
项目:jasperreports    文件:JasperFillManager.java   
/**
 * 
 */
protected JasperReportsContext getLocalJasperReportsContext(File file)
{
    SimpleFileResolver fileResolver =
        new SimpleFileResolver(
            Arrays.asList(new File[]{file.getParentFile(), new File(".")})
            );
    fileResolver.setResolveAbsolutePath(true);

    LocalJasperReportsContext localJasperReportsContext = new LocalJasperReportsContext(jasperReportsContext);
    localJasperReportsContext.setFileResolver(fileResolver);
    return localJasperReportsContext;
}
项目:PDFReporter-Studio    文件:ResourcePage.java   
/**
 * Given a report in the workspace and a resource name
 * it return a file to that resource
 * 
 * @param file file of the report
 * @param str name of the resource
 * @return file to the resource in the filesystem
 */
protected File findFile(IFile file, String str) {
    if (str == null) return null;
    SimpleFileResolver fr = new SimpleFileResolver(
            Arrays.asList(new File[] {
                    new File(file.getParent().getLocationURI()),
                    new File("."), //$NON-NLS-1$
                    new File(file.getProject().getLocationURI()) }));
    fr.setResolveAbsolutePath(true);
    return fr.resolveFile(str);
}
项目:PDFReporter-Studio    文件:FileUtils.java   
public static File findFile(IFile file, String str) {
    if (str == null || str.isEmpty())
        return null;
    IContainer parent = file.getParent();
    SimpleFileResolver fr = new SimpleFileResolver(Arrays.asList(new File[] { new File(parent.getLocationURI()), file.getRawLocation().toFile().getParentFile(),
            new File(file.getProject().getLocationURI()) }));
    fr.setResolveAbsolutePath(true);
    return fr.resolveFile(str);
}
项目:nextreports-server    文件:JasperReportsUtil.java   
public static JasperPrint fillReport(StorageService storageService, String key, JasperReport jasper, Map<String, Object> params, Connection conn) throws JRException, InterruptedException {
        Settings settings = storageService.getSettings();
        params.put(JRParameter.REPORT_FILE_RESOLVER, new SimpleFileResolver(new File(settings.getJasper().getHome())));

        // process stopped before runner starts
        if (JasperRunnerFactory.containsRunner(key)) {
            JasperRunnerFactory.removeRunner(key);
            ConnectionUtil.closeConnection(conn);
            return null;
        }

//        System.out.println("------------------------------");
//        for (String s : params.keySet()) {
//            System.out.println("  -> param="+s + " ["  + params.get(s)  + "]");
//        }
//        System.out.println("------------------------------");

        // Jasper 5.1.0+
        if (ctx == null) {
            LocalJasperReportsContext localContext = new LocalJasperReportsContext(DefaultJasperReportsContext.getInstance());
            localContext.setClassLoader(JasperReportsUtil.class.getClassLoader());
            localContext.setFileResolver(new SimpleFileResolver(new File(settings.getJasper().getHome())));
            ctx = localContext;
        }
        final JasperAsynchronousFillHandle handle = new JasperAsynchronousFillHandle(ctx, jasper, params, conn);
//        final JasperAsynchronousFillHandle handle = new JasperAsynchronousFillHandle(jasper, params, conn);
        JasperPrint print = null;
        try {
            JasperRunnerFactory.addRunner(key, handle);
            //Start the asynchronous thread to fill the report
            handle.startFill();
            //Wait until the thread ends to get the result
            handle.getFillThread().join();

            if (!handle.isCancelled()) {
                print = handle.getJasperPrint();
            } else {
                throw new InterruptedException("Running process was interrupted.");
            }
        } catch (InterruptedException ie) {
            throw ie;
        } catch (Exception e) {
            throw new JRException(e.getMessage());
        } finally {
            JasperRunnerFactory.removeRunner(key);
        }
        return print;
    }