@SuppressWarnings("deprecation") public static void revertResourcesFillContext(ResourcesFillContext context) { if (context.getClassLoader() != null) { JRResourcesUtil.resetClassLoader(); } if (context.getUrlHandlerFactory() != null) { JRResourcesUtil.resetThreadURLHandlerFactory(); } if (context.getFileResolver() != null) { JRResourcesUtil.resetThreadFileResolver(); } }
/** * Returns the {@link ResourceBundle} associated to the specified dataset. * As fallback solution we look in the main dataset. * * @param dataset the dataset to look into * @param jconfig the {@link JasperReportsContext} instance * @return the {@link ResourceBundle} if any, <code>null</code> otherwise */ public static ResourceBundle getResourceBundle(JRDataset dataset, JasperReportsConfiguration jconfig) { String baseName = dataset.getResourceBundle(); ResourceBundle loadedBundle = null; if(baseName==null) { baseName = jconfig.getJasperDesign().getMainDataset().getResourceBundle(); } if(!Misc.isNullOrEmpty(baseName)) { Locale locale = Locale.getDefault(); Object obj = jconfig.getJRParameters().get(JRParameter.REPORT_LOCALE); if (obj instanceof Locale) { locale = (Locale) obj; } try { loadedBundle = JRResourcesUtil.loadResourceBundle(baseName, locale, jconfig.getClassLoader()); } catch (MissingResourceException e) { JaspersoftStudioPlugin.getInstance().logError( NLS.bind("Unable to get the resource bundle with base name {0}.",baseName), e); } } return loadedBundle; }
/** * Loads the resource bundle corresponding to the resource bundle base name and locale. */ protected ResourceBundle loadResourceBundle() { ResourceBundle loadedBundle; if (resourceBundleBaseName == null) { loadedBundle = null; } else { loadedBundle = JRResourcesUtil.loadResourceBundle(getJasperReportsContext(), resourceBundleBaseName, locale); } return loadedBundle; }
@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; }
@Override public InputStream getInputStream(String uri) { try { URL url = JRResourcesUtil.createURL(uri, urlHandlerFactory); if (url != null) { return JRLoader.getInputStream(url); } File file = JRResourcesUtil.resolveFile(uri, fileResolver); if (file != null) { return JRLoader.getInputStream(file); } url = JRResourcesUtil.findClassLoaderResource(uri, classLoader); if (url != null) { return JRLoader.getInputStream(url); } } catch (JRException e) { throw new JRRuntimeException(e); } return null; }
protected ResourceBundle getResourceBundle() { if (rb == null) rb = JRResourcesUtil.loadResourceBundle(getBundleName(), getLocale(), jConfig.getClassLoader()); return rb; }