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:org.heliosphere.thot.akka.chat.client.TerminalActor.java
/** * Handles a {@link org.heliosphere.thot.akka.chat.supervisor.ChatSupervisorProtocol.LobbyList} message. * <hr>/*from w w w .j a v a 2 s . com*/ * @param response Message to handle. */ @SuppressWarnings("nls") private void handleMessageLobbyList(final LobbyMessageProtocol.LobbyList response) { if (response.getLobbies().isEmpty()) { terminal.getTerminal().println("No lobby!"); } else { terminal.getTerminal().println(String.format("%1d existing lobby(ies):", response.getLobbies().size())); for (Locale locale : response.getLobbies()) { terminal.getTerminal().println(String.format("| %1s", locale.toString())); } terminal.getTerminal().println(); } terminal.resume(); }
From source file:com.jfinal.core.Controller.java
public Controller setLocaleToCookie(Locale locale, int maxAge) { setCookie(I18N_LOCALE, locale.toString(), maxAge); return this; }
From source file:org.sakaiproject.emailtemplateservice.service.impl.EmailTemplateServiceImpl.java
public EmailTemplate getEmailTemplate(String key, Locale locale) { if (key == null || "".equals(key)) { throw new IllegalArgumentException("key cannot be null or empty"); }//from ww w. j a v a 2s .co m if (log.isDebugEnabled()) { log.debug("getEmailTemplate(key=" + key + ", locale=" + locale + ")"); } EmailTemplate et = null; // TODO make this more efficient if (locale != null) { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", locale.toString())); et = dao.findOneBySearch(EmailTemplate.class, search); if (et == null) { search.addRestriction(new Restriction("locale", locale.getLanguage())); et = dao.findOneBySearch(EmailTemplate.class, search); } } if (et == null) { Search search = new Search("key", key); search.addRestriction(new Restriction("locale", EmailTemplate.DEFAULT_LOCALE)); et = dao.findOneBySearch(EmailTemplate.class, search); } if (et == null) { log.warn("no template found for: " + key + " in locale " + locale); } return et; }
From source file:no.abmu.common.locale.LocaleUtil.java
/** * Method for logging of locale. Used under test and development. * /* w w w . j a va 2 s. c o m*/ * @param request current HTTP request */ public void logLocale(HttpServletRequest request) { HttpSession session = request.getSession(false); String parameterSiteLocale = request.getParameter("siteLocale"); String parameterStartLocale = request.getParameter("startLocale"); String rcSiteLocale = (String) request.getAttribute("siteLocale"); // String seSiteLocale = (String) session.getAttribute("siteLocale"); Locale locale = RequestContextUtils.getLocale(request); logger.info("request siteLocale: " + rcSiteLocale); logger.info("request parameter siteLocale: " + parameterSiteLocale); logger.info("request parameter startLocale: " + parameterStartLocale); // logger.info("session siteLocale: " + seSiteLocale); logger.info("Locale getDisplayCountry: " + locale.getDisplayCountry()); logger.info("Locale getDisplayLanguage: " + locale.getDisplayLanguage()); logger.info("Locale getDisplayVariant: " + locale.getDisplayVariant()); logger.info("Locale getDisplayName: " + locale.getDisplayName()); logger.info("Locale getISO3Country: " + locale.getISO3Country()); logger.info("Locale getLanguage: " + locale.getLanguage()); logger.info("Locale getVariant: " + locale.getVariant()); logger.info("Locale toString: " + locale.toString()); }
From source file:org.apache.jackrabbit.core.query.lucene.JahiaSearchIndex.java
@Override protected IndexingConfiguration createIndexingConfiguration(NamespaceMappings namespaceMappings) { final IndexingConfiguration configuration = super.createIndexingConfiguration(namespaceMappings); // make sure the AnalyzerRegistry configured in the configuration gets the proper Analyzer if (configuration instanceof JahiaIndexingConfigurationImpl) { JahiaIndexingConfigurationImpl jahiaConfiguration = (JahiaIndexingConfigurationImpl) configuration; final LanguageCustomizingAnalyzerRegistry registry = jahiaConfiguration.getAnalyzerRegistry(); // retrieve the default analyzer from the Jackrabbit configuration. // Should be a JackrabbitAnalyzer instance set with the default Analyzer configured using the 'analyzer' // param of the 'SearchIndex' section in repository.xml final Analyzer analyzer = super.getTextAnalyzer(); registry.setDefaultAnalyzer(analyzer); // attempt to get a default language specific Analyzer final SettingsBean settings = SettingsBean.getInstance(); final Locale defaultLocale = settings.getDefaultLocale(); Analyzer specific = registry.getAnalyzer(defaultLocale.toString()); if (specific == null) { specific = registry.getAnalyzer(defaultLocale.getLanguage()); }//from w ww .java2s.c o m if (specific != null) { // if we've found one, use it if (analyzer instanceof JackrabbitAnalyzer) { JackrabbitAnalyzer jrAnalyzer = (JackrabbitAnalyzer) analyzer; jrAnalyzer.setDefaultAnalyzer(specific); } else { throw new IllegalArgumentException( "Analyzer wasn't a JackrabbitAnalyzer. Couldn't set default language Analyzer as a consequence."); } } } return configuration; }
From source file:com.opensymphony.xwork2.util.DefaultLocalizedTextProvider.java
/** * Creates a key to used for lookup/storing in the bundle misses cache. * * @param prefix the prefix for the returning String - it is supposed to be the ClassLoader hash code. * @param aBundleName the name of the bundle (usually it's FQN classname). * @param locale the locale.//from w ww .j a va 2s . c o m * @return the key to use for lookup/storing in the bundle misses cache. */ private String createMissesKey(String prefix, String aBundleName, Locale locale) { return prefix + aBundleName + "_" + locale.toString(); }
From source file:org.alfresco.repo.search.impl.lucene.LuceneQueryParser.java
protected Query addContentAttributeQuery(String queryText, SubQuery subQueryBuilder, AnalysisMode analysisMode, LuceneFunction luceneFunction, String expandedFieldName, List<Locale> expandedLocales, MLAnalysisMode mlAnalysisMode) throws ParseException { if (mlAnalysisMode.includesAll()) { return subQueryBuilder.getQuery(expandedFieldName, queryText, analysisMode, luceneFunction); }//from w w w. j av a 2 s . c o m if (expandedLocales.size() > 0) { BooleanQuery booleanQuery = new BooleanQuery(); Query contentQuery = subQueryBuilder.getQuery(expandedFieldName, queryText, analysisMode, luceneFunction); if (contentQuery != null) { booleanQuery.add(contentQuery, Occur.MUST); BooleanQuery subQuery = new BooleanQuery(); for (Locale locale : (expandedLocales)) { StringBuilder builder = new StringBuilder(); builder.append(expandedFieldName).append(FIELD_LOCALE_SUFFIX); String localeString = locale.toString(); if (localeString.indexOf("*") == -1) { Query localeQuery = getFieldQuery(builder.toString(), localeString); if (localeQuery != null) { subQuery.add(localeQuery, Occur.SHOULD); } else { subQuery.add(createNoMatchQuery(), Occur.SHOULD); } } else { Query localeQuery = getWildcardQuery(builder.toString(), localeString); if (localeQuery != null) { subQuery.add(localeQuery, Occur.SHOULD); } else { subQuery.add(createNoMatchQuery(), Occur.SHOULD); } } } booleanQuery.add(subQuery, Occur.MUST); } return booleanQuery; } else { Query query = subQueryBuilder.getQuery(expandedFieldName, queryText, analysisMode, luceneFunction); if (query != null) { return query; } else { return createNoMatchQuery(); } } }
From source file:custom.application.search.java
public Object query(String query) throws ApplicationException { StringBuffer html = new StringBuffer(); String[] keywords;//from w w w . j ava 2s. c om int page = 1, pageSize = 20; this.request = (HttpServletRequest) this.context.getAttribute("HTTP_REQUEST"); if (this.request.getParameter("page") == null || this.request.getParameter("page").toString().trim().length() <= 0) { page = 1; } else { page = Integer.parseInt(this.request.getParameter("page").toString()); } int startIndex = (page - 1) * pageSize; if (query.trim().length() > 0) { query = StringUtilities.htmlSpecialChars(query); keywords = query.split(" "); this.setVariable("keyword", query); this.setVariable("search.title", query + " - "); } else { this.setVariable("keyword", ""); return this; } StringBuffer condition = new StringBuffer(); int i = 0, j, k = 0; while (i < keywords.length) { if (condition.length() == 0) { condition.append(" bible.content like '%" + keywords[i] + "%' "); } else { condition.append(" AND bible.content like '%" + keywords[i] + "%' "); /*if(true) condition.append(" AND bible.content like '%"+keywords[i]+"%' "); else condition.append(" OR bible.content like '%"+keywords[i]+"%' ");*/ } i++; } Locale locale = this.getLocale(); if (condition.length() == 0) condition.append(" book.language='" + locale + "' "); else condition.append(" AND book.language='" + locale + "' "); book book = new book(); bible bible = new bible(); if (locale.toString().equalsIgnoreCase(Locale.US.toString())) { bible.setTableName("NIV"); } else if (locale.toString().equalsIgnoreCase(Locale.UK.toString())) { bible.setTableName("ESV"); } else { bible.setTableName(locale.toString()); } String SQL = "SELECT bible.*,book.book_name FROM " + bible.getTableName() + " as bible left join " + book.getTableName() + " as book on bible.book_id=book.book_id where " + condition + " order by bible.book_id,bible.chapter_id limit " + startIndex + "," + pageSize; String look = "SELECT count(bible.id) AS size FROM " + bible.getTableName() + " as bible left join " + book.getTableName() + " as book on bible.book_id=book.book_id where " + condition; Table vtable = bible.find(SQL, new Object[] {}); boolean noResult = vtable.size() > 0; if (!noResult) { try { Table list = book.findWith("WHERE language=? and book_name=?", new Object[] { this.getLocale().toString(), query }); if (list.size() > 0) { this.response = (HttpServletResponse) this.context.getAttribute("HTTP_RESPONSE"); Reforward reforward = new Reforward(request, response); query = URLEncoder.encode(query, "utf-8"); reforward.setDefault(this.context.getAttribute("HTTP_HOST") + query); reforward.forward(); return reforward; } } catch (ApplicationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Row found = bible.findOne(look, new Object[] {}); long startTime = System.currentTimeMillis(); Pager pager = new Pager(); pager.setPageSize(pageSize); pager.setCurrentPage(page); pager.setListSize(found.getFieldInfo("size").intValue()); Field field; int next = pager.getStartIndex();//????ID html.append("<ol class=\"searchresults\" start=\"" + next + "\">\r\n"); String finded, word; Row row; Enumeration<Row> table = vtable.elements(); int n = 0; while (table.hasMoreElements()) { row = table.nextElement(); Iterator<Field> iterator = row.iterator(); n++; while (iterator.hasNext()) { field = iterator.next(); finded = field.get("content").value().toString(); j = 0; while (j < keywords.length) { finded = StringUtilities.sign(finded, keywords[j++]); } html.append("<li" + (n % 2 == 0 ? " class=\"even\"" : " class=\"odd\"") + "><a href=\"" + this.context.getAttribute("HTTP_HOST") + "bible/" + field.get("book_id").value().toString() + "/" + field.get("chapter_id").value().toString() + "/" + field.get("part_id").value().toString() + "\" target=\"_blank\">" + this.setText("search.bible.info", field.get("book_name").value().toString(), field.get("chapter_id").value().toString(), field.get("part_id").value().toString()) + "</a><p>" + finded + "</p></li> \r\n"); next++; } } Table ktable; Row krow; while (k < keywords.length && noResult) { word = keywords[k++]; keyword keyword = new keyword(); keyword.setKeyword(word); ktable = keyword.setRequestFields("id,visit").findWith("WHERE keyword=?", new Object[] { word }); if (ktable.size() == 0) { keyword.setVisit(0); keyword.append(); } else { krow = ktable.get(0); keyword.setId(krow.getFieldInfo("id").value()); keyword.setVisit(krow.getFieldInfo("visit").intValue() + 1); keyword.update(); } } html.append("</ol>\r\n"); String actionURL = this.context.getAttribute("HTTP_HOST") + "bible/search/" + query + "&page"; pager.setFirstPageText(this.getProperty("page.first.text")); pager.setLastPageText(this.getProperty("page.last.text")); pager.setCurrentPageText(this.getProperty("page.current.text")); pager.setNextPageText(this.getProperty("page.next.text")); pager.setEndPageText(this.getProperty("page.end.text")); pager.setControlBarText(this.getProperty("page.controlbar.text")); html.append("<div class=\"pagination\" style=\"cursor:default\">" + pager.getPageControlBar(actionURL) + "</div>\r\n"); html.append("<!-- " + String.valueOf(System.currentTimeMillis() - startTime) + " -->"); int start = page - 1 == 0 ? 1 : (page - 1) * pageSize + 1, end = page * pageSize; this.setVariable("start", String.valueOf(start)); this.setVariable("end", String.valueOf(end)); this.setVariable("size", String.valueOf(pager.getSize())); this.setVariable("value", html.toString()); this.setVariable("action", this.config.get("default.base_url") + this.context.getAttribute("REQUEST_ACTION").toString()); this.setText("search.info", start, end, query, pager.getSize()); HttpSession session = request.getSession(); if (session.getAttribute("usr") != null) { this.usr = (User) session.getAttribute("usr"); this.setVariable("user.status", ""); this.setVariable("user.profile", "<a href=\"javascript:void(0)\" onmousedown=\"profileMenu.show(event,'1')\">" + this.usr.getEmail() + "</a>"); } else { this.setVariable("user.status", "<a href=\"" + this.getLink("user/login") + "\">" + this.getProperty("page.login.caption") + "</a>"); this.setVariable("user.profile", ""); } return this; }
From source file:org.alfresco.repo.exporter.ViewXMLExporter.java
public void startValueMLText(NodeRef nodeRef, Locale locale, boolean isNull) { AttributesImpl attrs = new AttributesImpl(); attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, LOCALE_LOCALNAME, LOCALE_QNAME.toPrefixString(), null, locale.toString()); if (isNull) { attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_PREFIX, ISNULL_LOCALNAME, ISNULL_QNAME.toPrefixString(), null, "true"); }//from w w w . j a va2 s .c o m try { contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, MLVALUE_LOCALNAME, MLVALUE_QNAME.toPrefixString(), attrs); } catch (SAXException e) { throw new ExporterException("Failed to process start mlvalue", e); } }
From source file:org.codice.ddf.registry.source.configuration.SourceConfigurationHandler.java
private ObjectClassDefinition getObjectClassDefinition(Bundle bundle, String pid) { Locale locale = Locale.getDefault(); if (bundle != null && metaTypeService != null) { MetaTypeInformation mti = metaTypeService.getMetaTypeInformation(bundle); if (mti != null) { try { return mti.getObjectClassDefinition(pid, locale.toString()); } catch (IllegalArgumentException e) { // MetaTypeProvider.getObjectClassDefinition might throw illegal // argument exception. So we must catch it here, otherwise the // other configurations will not be shown // See https://issues.apache.org/jira/browse/FELIX-2390 // https://issues.apache.org/jira/browse/FELIX-3694 }/*from w w w . ja v a2s .com*/ } } // fallback to nothing found return null; }