List of usage examples for java.util ResourceBundle ResourceBundle
public ResourceBundle()
From source file:com.yoncabt.ebr.executor.jasper.JasperReport.java
@Override public void exportTo(ReportRequest request, ReportOutputFormat outputFormat, EBRConnection connection, ReportDefinition reportDefinition) throws ReportException, IOException { Map<String, Object> params = request.getReportParams(); String locale = request.getLocale(); String uuid = request.getUuid(); // nce genel parametreleri dolduralm. logo_path falan gibi EBRConf.INSTANCE.getMap().entrySet().stream().forEach((es) -> { String key = es.getKey(); if (key.startsWith("report.jrproperties.")) { key = key.substring("report.jrproperties.".length()); String value = es.getValue(); DefaultJasperReportsContext.getInstance().setProperty(key, value); }/*w w w . ja v a 2s . com*/ if (key.startsWith("report.params.")) { key = key.substring("report.params.".length()); String value = es.getValue(); params.put(key, value); } }); params.put("__extension", outputFormat.name()); params.put("__start_time", System.currentTimeMillis()); params.put(JRParameter.REPORT_LOCALE, LocaleUtils.toLocale(locale)); File jrxmlFile = reportDefinition.getFile(); //alttaki satr tehlikeli olabilir mi ? String resourceFileName = "messages_" + locale + ".properties"; try { File resourceFile = new File(jrxmlFile.getParentFile(), resourceFileName); Properties properties = new Properties(); try (FileInputStream fis = new FileInputStream(resourceFile)) { properties.load(fis); } ResourceBundle rb = new ResourceBundle() { @Override protected Object handleGetObject(String key) { return properties.get(key); } @Override public Enumeration<String> getKeys() { return (Enumeration<String>) ((Enumeration<?>) properties.keys()); } }; // FIXME yerelletime dosyalar buradan okunacak params.put(JRParameter.REPORT_RESOURCE_BUNDLE, rb); } catch (FileNotFoundException e) { logManager.info(resourceFileName + " file does not found!"); } String virtDir = EBRConf.INSTANCE.getValue(EBRParams.REPORTS_VIRTUALIZER_DIRECTORY, "/tmp/ebr/virtualizer"); int maxSize = EBRConf.INSTANCE.getValue(EBRParams.REPORTS_VIRTUALIZER_MAXSIZE, Integer.MAX_VALUE); JRAbstractLRUVirtualizer virtualizer = new JRFileVirtualizer(maxSize, virtDir); params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer); net.sf.jasperreports.engine.JasperReport jasperReport; try { jasperReport = (net.sf.jasperreports.engine.JasperReport) JRLoader .loadObject(com.yoncabt.ebr.executor.jasper.JasperReport.compileIfRequired(jrxmlFile)); } catch (JRException ex) { throw new ReportException(ex); } for (JRParameter param : jasperReport.getParameters()) { Object val = params.get(param.getName()); if (val == null) { continue; } params.put(param.getName(), Convert.to(val, param.getValueClass())); } reportLogger.logReport(request, outputFormat, new ByteArrayInputStream(new byte[0])); JasperPrint jasperPrint; try { jasperPrint = JasperFillManager.fillReport(jasperReport, /*jasper parametreleri deitiriyor*/ new HashMap<>(params), connection); } catch (JRException ex) { throw new ReportException(ex); } File outBase = new File(EBRConf.INSTANCE.getValue(EBRParams.REPORTS_OUT_PATH, "/usr/local/reports/out")); outBase.mkdirs(); File exportReportFile = new File(outBase, uuid + "." + outputFormat.name()); Exporter exporter; ExporterOutput output; switch (outputFormat) { case pdf: exporter = new JRPdfExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case html: exporter = new HtmlExporter(); output = new SimpleHtmlExporterOutput(exportReportFile); break; case xls: exporter = new JRXlsExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case xlsx: exporter = new JRXlsxExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case rtf: exporter = new JRRtfExporter(); output = new SimpleWriterExporterOutput(exportReportFile); break; case csv: exporter = new JRCsvExporter(); output = new SimpleWriterExporterOutput(exportReportFile); break; case xml: exporter = new JRXmlExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case docx: exporter = new JRDocxExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case odt: exporter = new JROdtExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case ods: exporter = new JROdsExporter(); output = new SimpleOutputStreamExporterOutput(exportReportFile); break; case jprint: case txt: exporter = new JRTextExporter(); output = new SimpleWriterExporterOutput(exportReportFile); putTextParams((JRTextExporter) exporter, params, reportDefinition.getTextTemplate()); break; default: throw new AssertionError(outputFormat.toString() + " not supported"); } exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(output); try { exporter.exportReport(); } catch (JRException ex) { throw new ReportException(ex); } if (outputFormat.isText() && !"utf-8".equals(reportDefinition.getTextEncoding())) { String reportData = FileUtils.readFileToString(exportReportFile, "utf-8"); if ("ascii".equals(reportDefinition.getTextEncoding())) { FileUtils.write(exportReportFile, ASCIIFier.ascii(reportData)); } else { FileUtils.write(exportReportFile, reportData, reportDefinition.getTextEncoding()); } } try (FileInputStream fis = new FileInputStream(exportReportFile)) { reportLogger.logReport(request, outputFormat, fis); } exportReportFile.delete(); }
From source file:org.flowerplatform.tests.EclipseIndependentTestSuite.java
/** * Starts a plugin with a mocked {@link BundleContext} and {@link ResourceBundle}. *///from ww w.jav a 2s . c om public static void startPlugin(final AbstractFlowerJavaPlugin plugin) throws Exception { BundleContext context = mock(BundleContext.class); Bundle bundle = mock(Bundle.class); when(context.getBundle()).thenReturn(bundle); when(bundle.getSymbolicName()).thenReturn(""); ResourceBundle resourceBundle = new ResourceBundle() { @Override protected Object handleGetObject(String key) { return ""; } @Override public Enumeration<String> getKeys() { return null; } }; Field field = AbstractFlowerJavaPlugin.class.getDeclaredField("resourceBundle"); field.setAccessible(true); field.set(plugin, resourceBundle); try { plugin.start(context); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.omegat.gui.scripting.ScriptItem.java
public ResourceBundle getResourceBundle() { if (m_res != null) { return m_res; }/*w w w .j a v a2 s . co m*/ // Create empty resource for confirmation return new ResourceBundle() { final String MISSING_BUNDLE_MESSAGE = "ResourceBundle (.properties file for localization) is missing."; @Override protected Object handleGetObject(String key) { throw new MissingResourceException(MISSING_BUNDLE_MESSAGE, null, key); } @Override public Enumeration<String> getKeys() { throw new MissingResourceException(MISSING_BUNDLE_MESSAGE, null, null); } }; }