List of usage examples for org.apache.commons.lang LocaleUtils toLocale
public static Locale toLocale(String str)
Converts a String to a Locale.
This method takes the string format of a locale and creates the locale object from it.
LocaleUtils.toLocale("en") = new Locale("en", "") LocaleUtils.toLocale("en_GB") = new Locale("en", "GB") LocaleUtils.toLocale("en_GB_xxx") = new Locale("en", "GB", "xxx") (#)
(#) The behaviour of the JDK variant constructor changed between JDK1.3 and JDK1.4.
From source file:com.alex.test.saiku.olap.query2.util.olap.query2.dto.olap.util.exception.SaikuProperties.java
private static Locale getLocale() { String locale = null;/* w w w . ja v a 2 s . c o m*/ try { locale = getPropString("saiku.format.default.locale", null); if (locale != null) { return LocaleUtils.toLocale(locale); } } catch (Exception e) { log.warn("Property: saiku.format.default.locale with value: " + locale + ", cannot be used for a Locale, falling back to default locale: " + Locale.getDefault(), e); } return Locale.getDefault(); }
From source file:com.github.cc007.headsinventory.HeadsInventory.java
public static Translator getTranslator() { if (translator == null) { String bundleName = "Translations"; translator = new Translator(bundleName, LocaleUtils.toLocale(HeadsInventory.getPlugin().getConfig().getString("locale", "en_US")), HeadsInventory.getPlugin().getPluginClassLoader()); }/*from w ww. j a v a2 s. c o m*/ return translator; }
From source file:com.jaspersoft.studio.utils.expr.AInterpreter.java
protected Locale getLocale() { if (locale != null) return locale; locale = Locale.getDefault(); Object obj = null;//www . ja v a 2s . co m if (jConfig.getJRParameters() != null) { obj = jConfig.getJRParameters().get(JRParameter.REPORT_LOCALE); if (obj == null) { String str = jConfig.getProperty(JRFiller.PROPERTY_DEFAULT_LOCALE); if (str != null) obj = LocaleUtils.toLocale(str); } } if (obj != null && obj instanceof Locale) locale = (Locale) obj; return locale; }
From source file:edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionSetupTest.java
private Locale stringToLocale(String string) { return LocaleUtils.toLocale(string); }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.AbstractReportMojo.java
/** * Determines the locale to use. The plugin allows the user to override the * locale provided by Maven./*from www . j a va2 s .co m*/ * * @return the locale to use for this report. */ private Locale determineLocale() { return StringUtils.isNotBlank(this.locale) ? LocaleUtils.toLocale(this.locale) : Locale.getDefault(); }
From source file:com.abixen.platform.core.application.service.UserManagementService.java
public UserChangePasswordForm changeUserPassword(final UserChangePasswordForm userChangePasswordForm) { log.debug("changeUserPassword() - userChangePasswordForm: {}", userChangePasswordForm); final User user = userService.find(userChangePasswordForm.getId()); if (user == null) { throw new IllegalArgumentException("User not found"); }//from w w w. jav a2 s. c o m user.changePassword(userChangePasswordForm.getCurrentPassword(), userChangePasswordForm.getNewPassword()); updateUser(user); final Map<String, String> params = new HashMap<>(); params.put("email", user.getUsername()); params.put("password", userChangePasswordForm.getNewPassword()); params.put("firstName", user.getFirstName()); params.put("lastName", user.getLastName()); final String subject = messageSource.getMessage("email.userPasswordChanged.subject", null, LocaleUtils.toLocale(user.getSelectedLanguage().getSelectedLanguage().toLowerCase())); mailService.sendMail(user.getUsername(), params, MailService.USER_PASSWORD_CHANGE_MAIL + "_" + user.getSelectedLanguage().getSelectedLanguage().toLowerCase(), subject); //FIXME - make return type void return userChangePasswordForm; }
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. j a v a2 s . 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:info.magnolia.jcr.node2bean.impl.Node2BeanTransformerImpl.java
@Override public Object convertPropertyValue(Class<?> propertyType, Object value) throws Node2BeanException { if (Class.class.equals(propertyType)) { try {/*from w w w. j av a2s .c o m*/ return Classes.getClassFactory().forName(value.toString()); } catch (ClassNotFoundException e) { log.error("Can't convert property. Class for type [{}] not found.", propertyType); throw new Node2BeanException(e); } } if (Locale.class.equals(propertyType)) { if (value instanceof String) { String localeStr = (String) value; if (StringUtils.isNotEmpty(localeStr)) { return LocaleUtils.toLocale(localeStr); } } } if (Collection.class.equals(propertyType) && value instanceof Map) { // TODO never used ? return ((Map) value).values(); } // this is mainly the case when we are flattening node hierarchies if (String.class.equals(propertyType) && value instanceof Map && ((Map) value).size() == 1) { return ((Map) value).values().iterator().next(); } return value; }
From source file:com.nabla.wapp.report.server.ReportManager.java
public void loadLocaleReportName(final Connection conn, final Integer reportId, final String fileName, final InputStream resource) throws SQLException, InternalErrorException { final String name = FilenameUtils.getBaseName(fileName); int pos = name.indexOf('_'); if (pos < 0) return;//from w w w . ja v a2 s . c om final String locale = name.substring(pos + 1, name.length()); try { LocaleUtils.toLocale(locale); } catch (IllegalArgumentException __) { if (log.isErrorEnabled()) log.error("unsupported locale '" + locale + "'"); return; } // get title in locale final Properties properties = new Properties(); try { properties.load(resource); } catch (Exception e) { if (log.isErrorEnabled()) log.error("fail to load locale properties file '" + fileName + "'", e); return; } final String title = properties.getProperty(ReportDesign.TITLE); if (title == null) return; if (!Database.executeUpdate(conn, "INSERT INTO report_name_localized (report_id,locale,text) VALUES(?,?,?);", reportId, locale, title)) throw new InternalErrorException("failed to add locale report title"); }
From source file:com.opoopress.maven.plugins.plugin.ThemeMojo.java
private void updateThemeConfigurationFile(ConfigImpl siteConfig, File themeDir) throws MojoFailureException { File config = new File(themeDir, "theme.yml"); if (!config.exists()) { throw new MojoFailureException("Config file '" + config + "' not exists."); }/*from www . ja v a 2 s . co m*/ Locale loc = Locale.getDefault(); //locale from parameter String localeString = locale; //locale from site configuration if (StringUtils.isBlank(localeString)) { localeString = siteConfig.get("locale"); } if (StringUtils.isNotEmpty(localeString)) { loc = LocaleUtils.toLocale(localeString); } File localeConfig = new File(themeDir, "theme_" + loc.toString() + ".yml"); if (localeConfig.exists()) { config.renameTo(new File(themeDir, "theme-original.yml")); localeConfig.renameTo(config); } }