List of usage examples for java.util Locale toString
@Override public final String toString()
Locale
object, consisting of language, country, variant, script, and extensions as below: language + "_" + country + "_" + (variant + "_#" | "#") + script + "_" + extensionsLanguage is always lower case, country is always upper case, script is always title case, and extensions are always lower case.
From source file:com.vmware.identity.SsoController.java
/** * Handle SAML AuthnRequest for default tenant, UNP entry form */// w ww . j a v a 2s .c o m @RequestMapping(value = "/SAML2/SSO", method = RequestMethod.GET, params = Shared.PASSWORD_ENTRY) public String ssoDefaultTenantPasswordEntry(Locale locale, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.info("Welcome to SP-initiated AuthnRequest handler, PASSWORD entry form! " + "The client locale is " + locale.toString() + ", DEFAULT tenant"); return ssoPasswordEntry(locale, Shared.getDefaultTenant(), model, request, response); }
From source file:org.sakaiproject.emailtemplateservice.service.impl.EmailTemplateServiceImpl.java
public boolean templateExists(String key, Locale locale) { List<EmailTemplate> et = null; Search search = new Search("key", key); if (locale == null) { search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE)); } else {/*www . ja v a2 s .co m*/ search.addRestriction(new Restriction("locale", locale.toString())); } et = dao.findBySearch(EmailTemplate.class, search); if (et != null && et.size() > 0) { return true; } return false; }
From source file:com.bstek.dorado.view.resolver.PageHeaderOutputter.java
public void output(Object object, OutputContext context) throws Exception { DoradoContext doradoContext = DoradoContext.getCurrent(); View view = (View) object; String skin = skinResolver.determineSkin(doradoContext, view); doradoContext.setAttribute("view.skin", skin); int currentClientType = VariantUtils.toInt(doradoContext.getAttribute(ClientType.CURRENT_CLIENT_TYPE_KEY)); if (currentClientType == 0) { currentClientType = ClientType.DESKTOP; }//from www. jav a 2s . c o m Writer writer = context.getWriter(); writer.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=") .append(Constants.DEFAULT_CHARSET).append("\" />\n"); if (StringUtils.isNotEmpty(view.getTitle())) { writer.append("<title>").append(StringEscapeUtils.escapeHtml(view.getTitle())).append("</title>\n"); } Locale locale = localeResolver.resolveLocale(); String contextPath = Configure.getString("web.contextPath"); if (StringUtils.isEmpty(contextPath)) { contextPath = DoradoContext.getAttachedRequest().getContextPath(); } writer.append("<script language=\"javascript\" type=\"text/javascript\" charset=\"UTF-8\" src=\"") .append(contextPath).append("/dorado/client/boot.dpkg?clientType=") .append(ClientType.toString(currentClientType)).append("&skin=").append(skin) .append("&cacheBuster=") .append(CacheBusterUtils.getCacheBuster((locale != null) ? locale.toString() : null)) .append("\"></script>\n").append("<script language=\"javascript\" type=\"text/javascript\">\n"); writer.append("window.$setting={\n"); for (ClientSettingsOutputter clientSettingsOutputter : clientSettingsOutputters) { clientSettingsOutputter.output(writer); } writer.append("\n};\n"); writer.append("$import(\"").append(getBasePackageNames(doradoContext, currentClientType, skin)) .append("\");\n</script>\n").append("<script language=\"javascript\" type=\"text/javascript\">\n"); topViewOutputter.output(view, context); writer.append("</script>\n"); Set<Object> javaScriptContents = context.getJavaScriptContents(); if (javaScriptContents != null && !javaScriptContents.isEmpty()) { writer.append("<script language=\"javascript\" type=\"text/javascript\">\n"); for (Object content : javaScriptContents) { if (content instanceof JavaScriptContent && !((JavaScriptContent) content).getIsController()) { javaScriptResourceManager.outputContent(context, content); } writer.append('\n'); } writer.append("</script>\n"); } Set<Object> styleSheetContents = context.getStyleSheetContents(); if (styleSheetContents != null && !styleSheetContents.isEmpty()) { writer.append("<style type=\"text/css\">\n"); for (Object content : styleSheetContents) { styleSheetResourceManager.outputContent(context, content); writer.append('\n'); } writer.append("</style>\n"); } }
From source file:com.octo.captcha.engine.bufferedengine.buffer.DatabaseCaptchaBuffer.java
/** * Get the size of the buffer for a locale * * @param locale the locale to get the size * * @return The size of the buffer//w w w . j av a 2 s .com */ public int size(Locale locale) { Connection con = null; PreparedStatement ps = null; ResultSet rs = null; int size = 0; try { con = datasource.getConnection(); ps = con.prepareStatement("select count(*) from " + table + " where " + localeColumn + "=?"); ps.setString(1, locale.toString()); rs = ps.executeQuery(); if (rs.next()) { size = rs.getInt(1); } rs.close(); con.commit(); } catch (SQLException e) { log.error(DB_ERROR, e); if (rs != null) { try { rs.close(); } catch (SQLException ex) { } } } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } if (con != null) { try { con.close(); } catch (SQLException e) { } } } return size; }
From source file:com.hichinaschool.flashcards.anki.Preferences.java
private void initializeLanguageDialog() { TreeMap<String, String> items = new TreeMap<String, String>(); for (String localeCode : mAppLanguages) { Locale loc; if (localeCode.length() > 2) { loc = new Locale(localeCode.substring(0, 2), localeCode.substring(3, 5)); } else {//from w ww . ja v a 2s . c om loc = new Locale(localeCode); } items.put(loc.getDisplayName(), loc.toString()); } mLanguageDialogLabels = new CharSequence[items.size() + 1]; mLanguageDialogValues = new CharSequence[items.size() + 1]; mLanguageDialogLabels[0] = getResources().getString(R.string.language_system); mLanguageDialogValues[0] = ""; int i = 1; for (Map.Entry<String, String> e : items.entrySet()) { mLanguageDialogLabels[i] = e.getKey(); mLanguageDialogValues[i] = e.getValue(); i++; } mLanguageSelection = (ListPreference) getPreferenceScreen().findPreference("language"); mLanguageSelection.setEntries(mLanguageDialogLabels); mLanguageSelection.setEntryValues(mLanguageDialogValues); }
From source file:com.vmware.identity.SsoController.java
/** * Handle SAML AuthnRequest//w ww. j a v a 2 s. c o m */ @RequestMapping(value = "/SAML2/SSO/{tenant:.*}", method = { RequestMethod.GET, RequestMethod.POST }) public String sso(Locale locale, @PathVariable(value = "tenant") String tenant, Model model, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.info("Welcome to SP-initiated AuthnRequest handler! " + "The client locale is " + locale.toString() + ", tenant is " + tenant); logger.info("Request URL is " + request.getRequestURL().toString()); try { AuthenticationFilter<AuthnRequestState> authenticator = chooseAuthenticator(request); AuthnRequestState requestState = new AuthnRequestState(request, response, sessionManager, tenant); processSsoRequest(locale, tenant, request, response, authenticator, requestState, messageSource, sessionManager); model.addAttribute("tenant", tenant); model.addAttribute("protocol", "websso"); if (requestState.isChooseIDPViewRequired() != null && requestState.isChooseIDPViewRequired()) { setupChooseIDPModel(model, locale, tenant, requestState); return "chooseidp"; } else if (requestState.isLoginViewRequired() != null && requestState.isLoginViewRequired()) { setupAuthenticationModel(model, locale, tenant, request, requestState); return "unpentry"; } } catch (Exception e) { logger.error("Could not handle SAML Authentication request ", e); sendError(locale, response, e.getMessage()); } return null; }
From source file:org.broadleafcommerce.profile.core.service.handler.EmailNotificationPasswordUpdatedHandler.java
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void passwordChanged(PasswordReset passwordReset, Customer customer, String newPassword) { Locale localeToUse = null; org.broadleafcommerce.common.locale.domain.Locale blLocale = customer.getCustomerLocale(); if (blLocale != null) { String[] splitLocale = blLocale.getLocaleCode().split("_"); if (splitLocale.length > 1) { localeToUse = new Locale(splitLocale[0], splitLocale[1]); } else {//from ww w .java2s . co m localeToUse = new Locale(splitLocale[0]); } } if (localeToUse == null) { localeToUse = getPasswordResetEmailDefaultLocale(); } String subject = getPasswordResetEmailSubject().get(localeToUse); if (subject == null) { LOG.warn("Unable to find an email subject for customer locale: " + localeToUse.toString() + ". Using default locale instead."); subject = getPasswordResetEmailSubject().get(getPasswordResetEmailDefaultLocale()); } String template = getPasswordResetEmailTemplate().get(localeToUse); if (template == null) { LOG.warn("Unable to find an email template for customer locale: " + localeToUse.toString() + ". Using default locale instead."); template = getPasswordResetEmailTemplate().get(getPasswordResetEmailDefaultLocale()); } EmailInfo info = new EmailInfo(); info.setFromAddress(getPasswordResetEmailFromAddress()); info.setSubject(subject); info.setEmailTemplate(template); info.setSendEmailReliableAsync(String.valueOf(passwordReset.isSendResetEmailReliableAsync())); HashMap vars = constructPasswordChangeEmailTemplateVariables(customer, newPassword); emailService.sendTemplateEmail(passwordReset.getEmail(), info, vars); }
From source file:com.bstek.dorado.data.resource.DefaultModelResourceBundleManager.java
protected Resource findResource(Resource modelResource, Locale locale) throws IOException { if (modelResource != null) { Resource resource;//from w ww . ja v a2s. c om String path = modelResource.getPath(); if (StringUtils.isEmpty(path)) { return null; } int i = path.lastIndexOf(PathUtils.PATH_DELIM); if (i >= 0) { path = path.substring(i + 1); } else { i = path.lastIndexOf(':'); if (i >= 0) { path = path.substring(i + 1); } } i = path.indexOf('.'); if (i >= 0) { path = path.substring(0, i); } if (locale != null) { String localeSuffix = '.' + locale.toString(); try { resource = modelResource.createRelative(path + localeSuffix + RESOURCE_FILE_SUFFIX); if (resource != null && resource.exists()) { return resource; } } catch (Exception e) { // JBOSS 5.1snowdrop?VFS??? } } try { resource = modelResource.createRelative(path + RESOURCE_FILE_SUFFIX); if (resource != null && resource.exists()) { return resource; } } catch (Exception e) { // JBOSS 5.1snowdrop?VFS??? } } return null; }
From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java
private void addLocaleSpecificUntokenisedTextRange(String field, String part1, String part2, boolean includeLower, boolean includeUpper, BooleanQuery booleanQuery, MLAnalysisMode mlAnalysisMode, Locale locale, String textFieldName) { if (locale.toString().length() > 0) { String lower = "{" + locale + "}" + part1; String upper = "{" + locale + "}" + part2; Query subQuery = new ConstantScoreRangeQuery(textFieldName, lower, upper, includeLower, includeUpper); booleanQuery.add(subQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); }/*ww w. j a va2s .c o m*/ } else { if ((part1.compareTo("{") > 0) || (part2.compareTo("{") < 0)) { Query subQuery = new ConstantScoreRangeQuery(textFieldName, part1, part2, includeLower, includeUpper); booleanQuery.add(subQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); } } else { // Split to avoid match {en} etc BooleanQuery splitQuery = new BooleanQuery(); Query lowerQuery = new ConstantScoreRangeQuery(textFieldName, part1, "{", includeLower, false); Query upperQuery = new ConstantScoreRangeQuery(textFieldName, "|", part2, true, includeUpper); splitQuery.add(lowerQuery, Occur.SHOULD); splitQuery.add(upperQuery, Occur.SHOULD); booleanQuery.add(splitQuery, Occur.SHOULD); if (booleanQuery.getClauses().length == 0) { booleanQuery.add(createNoMatchQuery(), Occur.SHOULD); } } } }
From source file:org.madsonic.service.LastFMService.java
public void getArtistInfo(List<Artist> artistList) { LOG.debug("## ArtistCount: " + artistList.size()); Locale LastFMLocale = new Locale(settingsService.getLocale().toString()); LOG.debug("## LastFM Locale: " + LastFMLocale.toString()); for (Artist artist : artistList) { try {/*w ww . jav a 2s .c om*/ if (artist.getArtistFolder() != null) { LastFMArtist lastFMartist = new LastFMArtist(); org.madsonic.lastfm.Artist tmpArtist = null; //String escapedArtist = stripNonValidXMLCharacters(StringEscapeUtils.escapeXml(artist.getArtistFolder()) ); String stripedArtist = stripNonValidXMLCharacters(artist.getArtistFolder()); String RequestedArtist = (org.madsonic.lastfm.Artist.getCorrection(stripedArtist, api_key)) .getName(); //todo:error try { tmpArtist = org.madsonic.lastfm.Artist.getInfo(RequestedArtist, LastFMLocale, null, api_key); } catch (Exception e) { Log.error("## FATAL Error! Artist Fetch! " + tmpArtist.getName()); } lastFMartist.setArtistname(tmpArtist.getName()); lastFMartist.setMbid(tmpArtist.getMbid()); lastFMartist.setUrl(tmpArtist.getUrl()); lastFMartist.setSince(tmpArtist.getSince()); lastFMartist.setPlayCount(tmpArtist.getPlaycount()); Collection<Album> TopAlbum = org.madsonic.lastfm.Artist.getTopAlbums(RequestedArtist, api_key, 3); String CollAlbum = null; for (Album album : TopAlbum) { if (album != null) { if (CollAlbum == null) { CollAlbum = album.getName(); } else { CollAlbum = CollAlbum + "|" + album.getName(); } } } lastFMartist.setTopalbum(CollAlbum); Collection<String> GenreTags = tmpArtist.getTags(); String CollTag = null; for (String TopTag : GenreTags) { if (TopTag != null) { if (CollTag == null) { CollTag = TopTag; } else { CollTag = CollTag + "|" + TopTag; } } } lastFMartist.setToptag(CollTag); for (String TopTag : GenreTags) { if (TopTag != null) { lastFMartist.setGenre(TopTag); break; } } // String[] sep = CollTag.split("\\|"); // List list = Arrays.asList(sep); String tmpSum = tmpArtist.getWikiSummary(); tmpSum = StringUtil.removeMarkup(tmpSum); // String tmpText = tmpArtist.getWikiText(); // tmpText = StringUtil.removeMarkup(tmpText); // lastFMartist.setBio(tmpText); lastFMartist.setSummary(tmpSum); // Collection<Tag> TopTags = org.madsonic.lastfm.Artist.getTopTags(tmpArtist.getName(), api_key, 1); Collection<org.madsonic.lastfm.Artist> Similar = org.madsonic.lastfm.Artist .getSimilar(tmpArtist.getName(), 6, api_key); for (org.madsonic.lastfm.Artist x : Similar) { LastFMArtistSimilar s = new LastFMArtistSimilar(); s.setArtistName(tmpArtist.getName()); s.setArtistMbid(tmpArtist.getMbid()); s.setSimilarName(x.getName()); s.setSimilarMbid(x.getMbid()); lastFMArtistSimilarDao.createOrUpdateLastFMArtistSimilar(s); } // /** // * new Artist image importer workaround // */ // if (tmpArtist != null) { // lastFMartist.setCoverart1(tmpArtist.getImageURL(ImageSize.EXTRALARGE)); // } // deprecated // PaginatedResult <Image> artistImage = org.madsonic.lastfm.Artist.getImages(RequestedArtist, 1, 5, api_key); // Collection <Image> Imgs = artistImage.getPageResults(); // // int counter = 0; // for (Image Img : Imgs) // { switch(counter) // { case 0: lastFMartist.setCoverart1(Img.getImageURL(ImageSize.LARGESQUARE));break; // case 1: lastFMartist.setCoverart2(Img.getImageURL(ImageSize.LARGESQUARE));break; // case 2: lastFMartist.setCoverart3(Img.getImageURL(ImageSize.LARGESQUARE));break; // case 3: lastFMartist.setCoverart4(Img.getImageURL(ImageSize.LARGESQUARE));break; // case 4: lastFMartist.setCoverart5(Img.getImageURL(ImageSize.LARGESQUARE));break; // } // counter++; // } if (lastFMartist.getArtistname() != null) { LOG.info("## LastFM ArtistInfo Update: " + lastFMartist.getArtistname()); lastFMArtistDao.createOrUpdateLastFMArtist(lastFMartist); } } } catch (NullPointerException ex) { System.out.println("## ERROR: " + artist.getName()); } } LOG.info("## LastFM ArtistScan Finished"); }