List of usage examples for java.util Locale setDefault
public static synchronized void setDefault(Locale newLocale)
From source file:dbProcs.Getter.java
/** * This method prepares the incremental module menu. This is when Security Shepherd is in "Game Mode". * Users are presented with one uncompleted module at a time. This method also returns a script to be executed every time the menu is chanegd. * This is script defines the animation and operations to be carried out when the menu is interacted with * @param ApplicationRoot The running context of the application. * @param userId The user identifier of the user. * @param csrfToken The cross site request forgery token * @return A HTML menu of a users current module progress and a script for interaction with this menu *///from w w w . ja v a2 s. c o m public static String getIncrementalModules(String ApplicationRoot, String userId, String lang, String csrfToken) { log.debug("*** Getter.getIncrementalChallenges ***"); String output = new String(); Encoder encoder = ESAPI.encoder(); Connection conn = Database.getCoreConnection(ApplicationRoot); Locale.setDefault(new Locale("en")); Locale locale = new Locale(lang); ResourceBundle bundle = ResourceBundle.getBundle("i18n.text", locale); ResourceBundle levelNames = ResourceBundle.getBundle("i18n.moduleGenerics.moduleNames", locale); try { CallableStatement callstmt = conn.prepareCall("call moduleIncrementalInfo(?)"); callstmt.setString(1, userId); log.debug("Gathering moduleIncrementalInfo ResultSet"); ResultSet modules = callstmt.executeQuery(); log.debug("Opening Result Set from moduleIncrementalInfo"); boolean lastRow = false; boolean completedModules = false; //Preparing first Category header; "Completed" output = "<li><a id='completedList' href='javascript:;'><div class='menuButton'>" + bundle.getString("getter.button.completed") + "</div></a>\n" + "<ul id='theCompletedList' style='display: none;' class='levelList'>"; while (modules.next() && !lastRow) { //For each row, prepair the modules the users can select if (modules.getString(4) != null) //If not Last Row { completedModules = true; output += "<li>"; output += "<a class='lesson' id='" + encoder.encodeForHTMLAttribute(modules.getString(3)) + "' href='javascript:;'>" + encoder.encodeForHTML(levelNames.getString(modules.getString(1))) + "</a>"; output += "</li>"; } else { lastRow = true; //Last Row - Highlighed Next Challenge if (completedModules) { output += "</ul></li><li>"; } else { //NO completed modules, so dont show any... output = new String(); } //Second category - Uncompleted output += "<a class='lesson' id='" + encoder.encodeForHTMLAttribute(modules.getString(3)) + "' href='javascript:;'>" + "<div class='menuButton'>" + bundle.getString("getter.button.nextChallenge") + "</div>" + "</a>"; output += "</li>"; } } if (!lastRow) //If true, then the user has completed all challenges { output += "<h2 id='uncompletedList'><a href='javascript:;'>" + bundle.getString("getter.button.finished") + "</a></h2>\n" + "</li>"; } if (output.isEmpty()) //If this method has gone so far without any output, create a error message { output = "<li><a href='javascript:;'>" + bundle.getString("getter.button.noModulesFound") + "</a></li>"; } else //final tags to ensure valid HTML { log.debug("Appending End tags"); //output += "</ul></li>"; //Commented Out to prevent Search Box being pushed into Footer } //This is the script for menu interaction output += "<script>applyMenuButtonActionsCtfMode('" + encoder.encodeForHTML(csrfToken) + "', \"" + encoder.encodeForHTML(bundle.getString("generic.text.sorryError")) + "\");</script>"; } catch (Exception e) { log.error("Challenge Retrieval: " + e.toString()); } Database.closeConnection(conn); log.debug("*** END getIncrementalChallenges() ***"); return output; }
From source file:org.agnitas.web.ExportWizardAction.java
/** * Creates sql query for getting recipients according to the export definition conditions; * gets recipients from database;/*from w w w . j a v a 2 s . c o m*/ * stores the export result in temporary zip file. * * @param aForm ExportWizardForm object * @param aContext application context * @param req HTTP request */ protected void collectContent(ExportWizardForm aForm, ApplicationContext aContext, HttpServletRequest req) { int companyID = AgnUtils.getAdmin(req).getCompany().getId(); Locale loc_old = Locale.getDefault(); aForm.setDbExportStatusMessages(new LinkedList<String>()); aForm.setDbExportStatus(100); aForm.setLinesOK(0); Target aTarget = null; if (aForm.getTargetID() != 0) { aTarget = targetDao.getTarget(aForm.getTargetID(), companyID); aForm.setTargetID(aTarget.getId()); } String charset = aForm.getCharset(); if (charset == null || charset.trim().equals("")) { charset = "UTF-8"; aForm.setCharset(charset); // charset also in form } StringBuffer usedColumnsString = new StringBuffer(); int exportStartColumn = 2; for (String columnName : aForm.getColumns()) { // customer_id is selected by default in the the base sql statement if ("customer_id".equalsIgnoreCase(columnName)) { // mark customer_id to be exported too exportStartColumn = 1; } else { usedColumnsString.append(", cust." + columnName + " " + columnName); } } if (aForm.getMailinglists() != null) { for (int i = 0; i < aForm.getMailinglists().length; i++) { String ml = aForm.getMailinglists()[i]; usedColumnsString.append(", (SELECT m" + ml + ".user_status FROM customer_" + companyID + "_binding_tbl m" + ml + " WHERE m" + ml + ".customer_id = cust.customer_id AND m" + ml + ".mailinglist_id = " + ml + " AND m" + ml + ".mediatype = 0) as Userstate_Mailinglist_" + ml); usedColumnsString.append(", (SELECT m" + ml + "." + AgnUtils.changeDateName() + " FROM customer_" + companyID + "_binding_tbl m" + ml + " WHERE m" + ml + ".customer_id = cust.customer_id AND m" + ml + ".mailinglist_id = " + ml + " AND m" + ml + ".mediatype = 0) as Mailinglist_" + ml + "_Timestamp"); } } StringBuffer whereString = new StringBuffer(""); StringBuffer customerTableSql = new StringBuffer("SELECT * FROM (SELECT DISTINCT cust.customer_id" + usedColumnsString.toString() + " FROM customer_" + companyID + "_tbl cust"); if (aForm.getMailinglistID() != -1 && (aForm.getMailinglistID() > 0 || !aForm.getUserType().equals("E") || aForm.getUserStatus() != 0)) { customerTableSql.append(", customer_" + companyID + "_binding_tbl bind"); whereString.append(" cust.customer_id = bind.customer_id AND bind.mediatype=0"); } if (aForm.getMailinglistID() > 0) { whereString.append(" and bind.mailinglist_id = " + aForm.getMailinglistID()); } if (aForm.getMailinglistID() == NO_MAILINGLIST) { whereString.append(" NOT EXISTS (SELECT 1 FROM customer_" + companyID + "_binding_tbl bind WHERE cust.customer_id = bind.customer_id) "); } else { if (!aForm.getUserType().equals("E")) { whereString .append(" AND bind.user_type = '" + SafeString.getSQLSafeString(aForm.getUserType()) + "'"); } if (aForm.getUserStatus() != 0) { whereString.append(" AND bind.user_status = " + aForm.getUserStatus()); } } if (aForm.getTargetID() != 0) { if (aForm.getMailinglistID() != 0 || !aForm.getUserType().equals("E") || aForm.getUserStatus() != 0) { whereString.append(" AND "); } whereString.append(" (" + aTarget.getTargetSQL() + ")"); } String datesParametersString = getDatesParametersString(aForm); if (!StringUtils.isEmpty(whereString.toString())) { whereString.append(" and "); } whereString.append(datesParametersString); if (whereString.length() > 0) { customerTableSql.append(" WHERE " + whereString); } AgnUtils.userlogger().info("Generated export SQL query: " + customerTableSql); Connection con = DataSourceUtils.getConnection(dataSource); aForm.setCsvFile(null); PrintWriter out = null; Statement stmt = null; ResultSet rset = null; try { File systemUploadDirectory = AgnUtils.createDirectory(AgnUtils.getDefaultValue("system.upload")); File outFile = File.createTempFile("exp" + companyID + "_", ".zip", systemUploadDirectory); ZipOutputStream aZip = new ZipOutputStream(new FileOutputStream(outFile)); AgnUtils.userlogger().info("Export file <" + outFile.getAbsolutePath() + ">"); stmt = con.createStatement(); rset = stmt.executeQuery(customerTableSql.toString()); aZip.putNextEntry(new ZipEntry("emm_export.csv")); Locale.setDefault(new Locale("en")); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(aZip, charset))); ResultSetMetaData mData = rset.getMetaData(); int columnCount = mData.getColumnCount(); // Write CSV-Header line for (int i = exportStartColumn; i <= columnCount; i++) { if (i > exportStartColumn) { out.print(aForm.getSeparator()); } String columnName = mData.getColumnName(i); out.print(aForm.getDelimiter() + escapeChars(columnName, aForm.getDelimiter()) + aForm.getDelimiter()); } out.print("\n"); // Write data lines while (rset.next()) { for (int i = exportStartColumn; i <= columnCount; i++) { if (i > exportStartColumn) { out.print(aForm.getSeparator()); } String aValue; try { aValue = rset.getString(i); } catch (Exception ex) { aValue = null; // Exceptions should not break the export, but should be logged AgnUtils.userlogger().error("Exception in export:collectContent:", ex); } if (aValue == null) { // null values should be displayed as empty string aValue = ""; } else { aValue = escapeChars(aValue, aForm.getDelimiter()); aValue = aForm.getDelimiter() + aValue + aForm.getDelimiter(); } out.print(aValue); } out.print("\n"); aForm.setLinesOK(aForm.getLinesOK() + 1); } aForm.setCsvFile(outFile); } catch (Exception e) { AgnUtils.userlogger().error("collectContent: " + e); e.printStackTrace(); } finally { if (out != null) { out.close(); } if (rset != null) { try { rset.close(); } catch (SQLException e) { e.printStackTrace(); } } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { e.printStackTrace(); } } DataSourceUtils.releaseConnection(con, dataSource); aForm.setDbExportStatus(1001); Locale.setDefault(loc_old); } }
From source file:net.sf.dvstar.transmission.TransmissionView.java
/** * @param defaultLocale the defaultLocale to set *//*from w w w. j av a 2 s . c o m*/ public void setDefaultLocale(Locale defaultLocale) { this.defaultLocale = defaultLocale; Locale.setDefault(defaultLocale); }
From source file:tvbrowser.TVBrowser.java
private static void parseCommandline(String[] args) { showUsage(args);// www . j a v a 2s .c o m for (String argument : args) { if (argument.equalsIgnoreCase("-help") || argument.equalsIgnoreCase("-h")) { System.exit(0); } else if (argument.equalsIgnoreCase("-minimized") || argument.equalsIgnoreCase("-m")) { mMinimized = true; } else if (argument.equalsIgnoreCase("-nosplash") || argument.equalsIgnoreCase("-n")) { mShowSplashScreen = false; } else if (argument.equalsIgnoreCase("-fullscreen") || argument.equalsIgnoreCase("-f")) { mFullscreen = true; } else if (argument.startsWith("-D")) { if (argument.indexOf("=") >= 2) { String key = argument.substring(2, argument.indexOf("=")); String value = StringUtils.substringAfter(argument, "="); if (key.equals("user.language")) { System.getProperties().setProperty("user.language", value); Locale.setDefault(new Locale(value)); } else { System.setProperty(key, value); } } else { mLog.warning("Wrong Syntax in parameter: '" + argument + "'"); } } else { mLog.warning("Unknown command line parameter: '" + argument + "'"); } } }
From source file:edu.ku.brc.specify.utilapps.BuildSampleDatabase.java
/** * //from w w w. j a v a 2 s . c om */ protected void adjustLocaleFromPrefs() { String language = AppPreferences.getLocalPrefs().get("locale.lang", null); //$NON-NLS-1$ if (language != null) { String country = AppPreferences.getLocalPrefs().get("locale.country", null); //$NON-NLS-1$ String variant = AppPreferences.getLocalPrefs().get("locale.var", null); //$NON-NLS-1$ Locale prefLocale = new Locale(language, country, variant); Locale.setDefault(prefLocale); setResourceLocale(prefLocale); } try { ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$ } catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH); setResourceLocale(Locale.ENGLISH); } }
From source file:im.vector.VectorApp.java
/** * Init the application locale from the saved one *///from w w w .j a va 2 s . c o m private static void initApplicationLocale() { Context context = VectorApp.getInstance(); Locale locale = getApplicationLocale(); float fontScale = getFontScaleValue(); String theme = ThemeUtils.getApplicationTheme(context); Locale.setDefault(locale); Configuration config = new Configuration(context.getResources().getConfiguration()); config.locale = locale; config.fontScale = fontScale; context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); // init the theme ThemeUtils.setApplicationTheme(context, theme); // init the known locales in background AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { getApplicationLocales(VectorApp.getInstance()); return null; } }; // should never crash task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:org.exoplatform.wcm.webui.seo.UISEOForm.java
public List<SelectItemOption<String>> getLanguages() throws Exception { WebuiRequestContext rc = WebuiRequestContext.getCurrentInstance(); Locale inLocale = WebuiRequestContext.getCurrentInstance().getLocale(); // Get default locale Locale defaultLocale = Locale.getDefault(); // set default locale to current user selected language Locale.setDefault(Util.getUIPortal().getAncestorOfType(UIPortalApplication.class).getLocale()); LocaleConfigService localService = WCMCoreUtils.getService(LocaleConfigService.class); List<SelectItemOption<String>> languages = new ArrayList<SelectItemOption<String>>(); Iterator<LocaleConfig> iter = localService.getLocalConfigs().iterator(); ResourceBundle resourceBundle = rc.getApplicationResourceBundle(); while (iter.hasNext()) { LocaleConfig localConfig = iter.next(); Locale locale = localConfig.getLocale(); String lang = locale.getLanguage(); String country = locale.getCountry(); if (StringUtils.isNotEmpty(country)) lang += "_" + country; if (seoLanguages == null || !seoLanguages.contains(lang)) { try { languages.add(new SelectItemOption<String>(CapitalFirstLetters(locale.getDisplayName(inLocale)), lang));/*from w w w . ja v a 2 s .c om*/ } catch (MissingResourceException mre) { languages.add(new SelectItemOption<String>(lang, lang)); } } } // Set back to the default locale Locale.setDefault(defaultLocale); Collections.sort(languages, new ItemOptionComparator()); languages.add(0, new SelectItemOption<String>(getLabel(resourceBundle, "select-language"), "language")); return languages; }
From source file:fr.afcepf.atod.wine.data.parser.XmlParser.java
private static void translateProductTypes(List<ProductType> types, IDaoProductType daoProductType, WineService esRepository) {/*ww w . ja v a 2s . c om*/ try { for (ProductType productType : types) { String typefr = ""; if (productType.getType().contains("White Wines")) { typefr = "Vins Blancs"; } else if (productType.getType().contains("Red Wines")) { typefr = "Vins Rouges"; } else if (productType.getType().contains("Ros Wine")) { typefr = "Ross"; } else { typefr = "Champagne"; } Locale.setDefault(Locale.FRANCE); productType.setType(typefr); daoProductType.updateObj(productType); List<Wine> list = esRepository.findByWineTypeId(productType.getId()); for (Wine wine : list) { wine.getType().setType(typefr); esRepository.save(wine); } Locale.setDefault(Locale.US); } } catch (WineException paramE) { // TODO Auto-generated catch block paramE.printStackTrace(); } }
From source file:org.tinymediamanager.core.Settings.java
/** * set Locale.toString() 5 char into settings * /*from w ww. j a v a2 s . co m*/ * @param language * the language to be set */ public void setLanguage(String language) { String oldValue = this.language; this.language = language; Locale.setDefault(Utils.getLocaleFromLanguage(language)); firePropertyChange(LANGUAGE, oldValue, language); }
From source file:dbProcs.Getter.java
/** * This method prepares the incremental module menu. This is when Security Shepherd is in "Game Mode". * Users are presented with one uncompleted module at a time. This method does not return the JS script describing how the menu used should work * @param ApplicationRoot The running context of the application. * @param userId The user identifier of the user. * @param csrfToken The cross site request forgery token * @return A HTML menu of a users current module progress and a script for interaction with this menu *//*from w ww . j a v a 2 s . c om*/ public static String getIncrementalModulesWithoutScript(String ApplicationRoot, String userId, String lang, String csrfToken) { log.debug("*** Getter.getIncrementalChallengesWithoutScript ***"); String output = new String(); Encoder encoder = ESAPI.encoder(); Connection conn = Database.getCoreConnection(ApplicationRoot); Locale.setDefault(new Locale("en")); Locale locale = new Locale(lang); ResourceBundle bundle = ResourceBundle.getBundle("i18n.text", locale); ResourceBundle levelNames = ResourceBundle.getBundle("i18n.moduleGenerics.moduleNames", locale); try { CallableStatement callstmt = conn.prepareCall("call moduleIncrementalInfo(?)"); callstmt.setString(1, userId); log.debug("Gathering moduleIncrementalInfo ResultSet"); ResultSet modules = callstmt.executeQuery(); log.debug("Opening Result Set from moduleIncrementalInfo"); boolean lastRow = false; boolean completedModules = false; //Preparing first Category header; "Completed" output = "<li><a id='completedList' href='javascript:;'><div class='menuButton'>" + bundle.getString("getter.button.completed") + "</div></a>\n" + "<ul id='theCompletedList' style='display: none;' class='levelList'>"; while (modules.next() && !lastRow) { //For each row, prepair the modules the users can select if (modules.getString(4) != null) //If not Last Row { completedModules = true; output += "<li>"; output += "<a class='lesson' id='" + encoder.encodeForHTMLAttribute(modules.getString(3)) + "' href='javascript:;'>" + encoder.encodeForHTML(levelNames.getString(modules.getString(1))) + "</a>"; output += "</li>"; } else { lastRow = true; //Last Row - Highlighed Next Challenge if (completedModules) { output += "</ul></li><li>"; } else { //NO completed modules, so dont show any... output = new String(); } //Second category - Uncompleted output += "<a class='lesson' id='" + encoder.encodeForHTMLAttribute(modules.getString(3)) + "' href='javascript:;'>" + "<div class='menuButton'>" + bundle.getString("getter.button.nextChallenge") + "</div>" + "</a>"; output += "</li>"; } } if (!lastRow) //If true, then the user has completed all challenges { output += "<h2 id='uncompletedList'><a href='javascript:;'>" + bundle.getString("getter.button.finished") + "</a></h2>\n" + "</li>"; } if (output.isEmpty()) //If this method has gone so far without any output, create a error message { output = "<li><a href='javascript:;'>" + bundle.getString("getter.button.noModulesFound") + "</a></li>"; } else //final tags to ensure valid HTML { log.debug("Appending End tags"); //output += "</ul></li>"; //Commented Out to prevent Search Box being pushed into Footer } } catch (Exception e) { log.error("Challenge Retrieval: " + e.toString()); } Database.closeConnection(conn); log.debug("*** END getIncrementalChallengesWithoutScript() ***"); return output; }