public static final boolean openEditor(IFile file, String path) { try { if (file != null && path != null) { // String pathname = FileUtils.findRelativePath(rpath, path); FileResolver fileResolver = getFileResolver(file); File fileToBeOpened = fileResolver.resolveFile(path); if (file != null && fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToBeOpened.toURI()); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IDE.openEditorOnFileStore(page, fileStore); return true; } } } catch (PartInitException e) { e.printStackTrace(); } return false; }
/** * */ @SuppressWarnings("deprecation") protected void ensureJasperReportsContext() { if ( parameters.containsKey(JRExporterParameter.CLASS_LOADER) || parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY) || parameters.containsKey(JRExporterParameter.FILE_RESOLVER) ) { LocalJasperReportsContext localJasperReportsContext = new LocalJasperReportsContext(jasperReportsContext); if (parameters.containsKey(JRExporterParameter.CLASS_LOADER)) { localJasperReportsContext.setClassLoader((ClassLoader)parameters.get(JRExporterParameter.CLASS_LOADER)); } if (parameters.containsKey(JRExporterParameter.URL_HANDLER_FACTORY)) { localJasperReportsContext.setURLStreamHandlerFactory((URLStreamHandlerFactory)parameters.get(JRExporterParameter.URL_HANDLER_FACTORY)); } if (parameters.containsKey(JRExporterParameter.FILE_RESOLVER)) { localJasperReportsContext.setFileResolver((FileResolver)parameters.get(JRExporterParameter.FILE_RESOLVER)); } setJasperReportsContext(localJasperReportsContext); } FontUtil.getInstance(jasperReportsContext).resetThreadMissingFontsCache(); }
@SuppressWarnings("deprecation") public static ResourcesFillContext setResourcesFillContext(Map<String,Object> parameterValues) { ResourcesFillContext context = new ResourcesFillContext(); ClassLoader classLoader = (ClassLoader) parameterValues.get( JRParameter.REPORT_CLASS_LOADER); if (classLoader != null) { JRResourcesUtil.setThreadClassLoader(classLoader); context.setClassLoader(classLoader); } URLStreamHandlerFactory urlHandlerFactory = (URLStreamHandlerFactory) parameterValues.get(JRParameter.REPORT_URL_HANDLER_FACTORY); if (urlHandlerFactory != null) { JRResourcesUtil.setThreadURLHandlerFactory(urlHandlerFactory); context.setUrlHandlerFactory(urlHandlerFactory); } FileResolver fileResolver = (FileResolver) parameterValues.get( JRParameter.REPORT_FILE_RESOLVER); if (fileResolver != null) { JRResourcesUtil.setThreadFileResolver(fileResolver); context.setFileResolver(fileResolver); } return context; }
public static FileResolver getFileResolver() { IEditorPart ep = getActiveJRXMLEditor(); if (ep != null && ep.getEditorInput() instanceof IFileEditorInput) { IFileEditorInput fe = ((IFileEditorInput) ep.getEditorInput()); return getFileResolver(fe.getFile()); } URLFileResolver fileResolver = new URLFileResolver(Arrays.asList(new File[] { new File(".") })); //$NON-NLS-1$ fileResolver.setResolveAbsolutePath(true); return fileResolver; }
protected static IFile resolveTemplates(IFile refFile, List<Object> plist, JasperReportsConfiguration jConfig, JRDesignReportTemplate drt) { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); String str = ExpressionUtil.eval(drt.getSourceExpression(), jConfig); if (str != null) { if (refFile == null) refFile = ((IFileEditorInput) SelectionHelper.getActiveJRXMLEditor().getEditorInput()).getFile(); for (int i = plist.size() - 1; i >= 0; i--) { Object obj = plist.get(i); if (obj instanceof JRDesignReportTemplate) { str = ExpressionUtil.eval(((JRDesignReportTemplate) obj).getSourceExpression(), jConfig); } else if (obj instanceof JRTemplateReference) { str = ((JRTemplateReference) obj).getLocation(); } FileResolver fileResolver = SelectionHelper.getFileResolver(refFile); File fileToBeOpened = fileResolver.resolveFile(str); if (fileToBeOpened != null && fileToBeOpened.exists() && fileToBeOpened.isFile()) { IFile[] fs = root.findFilesForLocationURI(fileToBeOpened.toURI()); if (fs != null && fs.length > 0) { refFile = fs[0]; } else break; } } return refFile; } return null; }
public static Object getResource(FileResolver fileResolver, String filename) { if (fileResolver == null || !(fileResolver instanceof ClassPathFileResolver)) { return filename; } for (String path : ((ClassPathFileResolver) fileResolver).getClassPath()) { InputStream is = RU.class.getResourceAsStream(path + "/" + filename); if (is != null) { return is; } } return filename; }
/** * Add a resolver on top of the list.... * * @param resolver */ public void addResolver(FileResolver resolver) { if (!resolvers.contains(resolver)) { resolvers.add(0, resolver); } }
public File resolveFile(String arg0) { for (FileResolver res : resolvers) { try { File f = res.resolveFile(arg0); if (f!= null) return f; } catch (Exception ex) { } } return null; }
public java.util.List<FileResolver> getFileResolvers() { if (fileResolvers == null) { fileResolvers = new ArrayList<FileResolver>(); } return fileResolvers; }
public FileResolver getFileResolver() { return fileResolver; }
public void setFileResolver(FileResolver fileResolver) { this.fileResolver = fileResolver; }
/** * */ public void setFileResolver(FileResolver fileResolver) { this.fileResolver = fileResolver; }
public void removeResolver(FileResolver resolver) { resolvers.remove(resolver); }
public ProxyFileResolver() { resolvers = new ArrayList<FileResolver>(); }
public ProxyFileResolver(List<FileResolver> resolverList) { this(); resolvers.addAll(resolverList); }
public void setFileResolvers(java.util.List<FileResolver> fileResolvers) { this.fileResolvers = fileResolvers; }