List of usage examples for java.util Locale Locale
public Locale(String language)
From source file:com.joliciel.jochre.boundaries.TrainingCorpusShapeSplitterTest.java
@Test public void testSplit(@NonStrict final Shape shape, @NonStrict final Shape shape1, @NonStrict final Shape shape2, @NonStrict final Shape shape3, @NonStrict final Shape shape4) throws IOException { locator = JochreServiceLocator.getInstance(); locator.setDataSourcePropertiesResource("jdbc-live.properties"); GraphicsService graphicsService = locator.getGraphicsServiceLocator().getGraphicsService(); BoundaryServiceInternal boundaryService = (BoundaryServiceInternal) locator.getBoundaryServiceLocator() .getBoundaryService();//from w w w . j a va2s . co m new NonStrictExpectations() { GroupOfShapes group; RowOfShapes row; Paragraph paragraph; JochreImage jochreImage; JochrePage jochrePage; JochreDocument jochreDocument; Iterator<Split> i; List<Split> splits; Split split1, split2, split3; { shape.getLetter(); returns("?"); shape.getLeft(); returns(100); shape.getRight(); returns(200); shape.getTop(); returns(100); shape.getBottom(); returns(200); shape.getGroup(); returns(group); shape.getJochreImage(); returns(jochreImage); group.getRow(); returns(row); row.getParagraph(); returns(paragraph); paragraph.getImage(); returns(jochreImage); jochreImage.getPage(); returns(jochrePage); jochrePage.getDocument(); returns(jochreDocument); jochreDocument.getLocale(); returns(new Locale("yi")); shape.getSplits(); returns(splits); splits.iterator(); returns(i); i.hasNext(); returns(true, true, true, false); i.next(); returns(split1, split2, split3); split1.getPosition(); returns(35); split2.getPosition(); returns(59); split3.getPosition(); returns(82); jochreImage.getShape(100, 100, 135, 200); returns(shape1); jochreImage.getShape(136, 100, 159, 200); returns(shape2); jochreImage.getShape(160, 100, 182, 200); returns(shape3); jochreImage.getShape(183, 100, 200, 200); returns(shape4); } }; LOG.debug(shape); LOG.debug(shape.getLetter()); LOG.debug("Split into: "); TrainingCorpusShapeSplitter splitter = new TrainingCorpusShapeSplitter(); splitter.setGraphicsService(graphicsService); splitter.setBoundaryServiceInternal(boundaryService); List<ShapeSequence> result = splitter.split(shape); ShapeSequence shapeSequence = result.get(0); assertEquals(4, shapeSequence.size()); new Verifications() { { shape1.setLetter("?"); shape2.setLetter(""); shape3.setLetter(""); shape4.setLetter(""); } }; }
From source file:org.openxdata.server.servlet.ResetPasswordServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(this.getServletContext()); mailSender = (org.springframework.mail.javamail.JavaMailSenderImpl) ctx.getBean("mailSender"); userService = (UserService) ctx.getBean("userService"); userDetailsService = (UserDetailsService) ctx.getBean("userDetailsService"); messageSource = (ResourceBundleMessageSource) ctx.getBean("messageSource"); userLocale = new Locale((String) request.getSession().getAttribute("locale")); //new AcceptHeaderLocaleResolver().resolveLocale(request); log.debug("userLocale=" + userLocale.getLanguage()); String email = request.getParameter("email"); if (email == null) { //ajax response reference text out.println("noEmailSuppliedError"); }/*from ww w . ja va 2 s . c om*/ try { User user = userService.findUserByEmail(email); /* * Valid User with the correct e-mail. */ insertUserInSecurityContext(user); // this is so that it is possible to reset their password (security checks) Properties props = propertyPlaceholder.getResolvedProps(); String from = props.getProperty("mailSender.from"); try { //Reset the User password and send an email userService.resetPassword(user, 6); SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo(email); msg.setSubject(messageSource.getMessage("resetPasswordEmailSubject", new Object[] { user.getFullName() }, userLocale)); msg.setText(messageSource.getMessage("resetPasswordEmail", new Object[] { user.getName(), user.getClearTextPassword() }, userLocale)); msg.setFrom(from); try { mailSender.send(msg); //ajax response reference text out.println("passwordResetSuccessful"); } catch (MailException ex) { log.error("Error while sending an email to the user " + user.getName() + " in order to reset their password.", ex); log.error("Password reset email:" + msg.toString()); //ajax response reference text out.println("emailSendError"); } } catch (Exception e) { log.error("Error while resetting the user " + user.getName() + "'s password", e); //ajax response reference text out.println("passwordResetError"); } } catch (UserNotFoundException userNotFound) { /* * Invalid User or incorrect Email. */ //ajax response reference text out.println("validationError"); } }
From source file:at.alladin.rmbt.controlServer.ResultResource.java
@Post("json") public String request(final String entity) { final String secret = getContext().getParameters().getFirstValue("RMBT_SECRETKEY"); addAllowOrigin();/*from w w w . j a v a2s . co m*/ JSONObject request = null; final ErrorList errorList = new ErrorList(); final JSONObject answer = new JSONObject(); System.out.println(MessageFormat.format(labels.getString("NEW_RESULT"), getIP())); if (entity != null && !entity.isEmpty()) // try parse the string to a JSON object try { request = new JSONObject(entity); System.out.println(request); final String lang = request.optString("client_language"); // Load Language Files for Client final List<String> langs = Arrays .asList(settings.getString("RMBT_SUPPORTED_LANGUAGES").split(",\\s*")); if (langs.contains(lang)) { errorList.setLanguage(lang); labels = ResourceManager.getSysMsgBundle(new Locale(lang)); } // System.out.println(request.toString(4)); if (conn != null) { conn.setAutoCommit(false); final Test test = new Test(conn); if (request.optString("test_token").length() > 0) { final String[] token = request.getString("test_token").split("_"); try { // Check if UUID final UUID testUuid = UUID.fromString(token[0]); final String data = token[0] + "_" + token[1]; final String hmac = Helperfunctions.calculateHMAC(secret, data); if (hmac.length() == 0) errorList.addError("ERROR_TEST_TOKEN"); if (token[2].length() > 0 && hmac.equals(token[2])) { final List<String> clientNames = Arrays .asList(settings.getString("RMBT_CLIENT_NAME").split(",\\s*")); final List<String> clientVersions = Arrays .asList(settings.getString("RMBT_VERSION_NUMBER").split(",\\s*")); if (test.getTestByUuid(testUuid) > 0) if (clientNames.contains(request.optString("client_name")) && clientVersions.contains(request.optString("client_version"))) { test.setFields(request); final String networkOperator = request .optString("telephony_network_operator"); if (MCC_MNC_PATTERN.matcher(networkOperator).matches()) test.getField("network_operator").setString(networkOperator); else test.getField("network_operator").setString(null); final String networkSimOperator = request .optString("telephony_network_sim_operator"); if (MCC_MNC_PATTERN.matcher(networkSimOperator).matches()) test.getField("network_sim_operator").setString(networkSimOperator); else test.getField("network_sim_operator").setString(null); // RMBTClient Info final String ipLocalRaw = request.optString("test_ip_local", null); if (ipLocalRaw != null) { final InetAddress ipLocalAddress = InetAddresses.forString(ipLocalRaw); // original address (not filtered) test.getField("client_ip_local") .setString(InetAddresses.toAddrString(ipLocalAddress)); // anonymized local address final String ipLocalAnonymized = Helperfunctions .anonymizeIp(ipLocalAddress); test.getField("client_ip_local_anonymized") .setString(ipLocalAnonymized); // type of local ip test.getField("client_ip_local_type") .setString(Helperfunctions.IpType(ipLocalAddress)); // public ip final InetAddress ipPublicAddress = InetAddresses .forString(test.getField("client_public_ip").toString()); test.getField("nat_type").setString( Helperfunctions.getNatType(ipLocalAddress, ipPublicAddress)); } final String ipServer = request.optString("test_ip_server", null); if (ipServer != null) { final InetAddress testServerInetAddress = InetAddresses .forString(ipServer); test.getField("server_ip") .setString(InetAddresses.toAddrString(testServerInetAddress)); } //log IP address final String ipSource = getIP(); test.getField("source_ip").setString(ipSource); //log anonymized address try { final InetAddress ipSourceIP = InetAddress.getByName(ipSource); final String ipSourceAnonymized = Helperfunctions .anonymizeIp(ipSourceIP); test.getField("source_ip_anonymized").setString(ipSourceAnonymized); } catch (UnknownHostException e) { System.out.println("Exception thrown:" + e); } // Additional Info ////////////////////////////////////////////////// // extended test stats: ////////////////////////////////////////////////// final TestStat extendedTestStat = TestStat .checkForSubmittedTestStats(request, test.getUid()); if (extendedTestStat != null) { final TestStatDao testStatDao = new TestStatDao(conn); testStatDao.save(extendedTestStat); } ////////////////////////////////////////////////// JSONArray speedData = request.optJSONArray("speed_detail"); if (speedData != null && !test.hasError()) { final PreparedStatement psSpeed = conn.prepareStatement( "INSERT INTO test_speed (test_id, upload, thread, time, bytes) VALUES (?,?,?,?,?)"); psSpeed.setLong(1, test.getUid()); for (int i = 0; i < speedData.length(); i++) { final JSONObject item = speedData.getJSONObject(i); final String direction = item.optString("direction"); if (direction != null && (direction.equals("download") || direction.equals("upload"))) { psSpeed.setBoolean(2, direction.equals("upload")); psSpeed.setInt(3, item.optInt("thread")); psSpeed.setLong(4, item.optLong("time")); psSpeed.setLong(5, item.optLong("bytes")); psSpeed.executeUpdate(); } } } final JSONArray pingData = request.optJSONArray("pings"); if (pingData != null && !test.hasError()) { final PreparedStatement psPing = conn.prepareStatement( "INSERT INTO ping (test_id, value, value_server, time_ns) " + "VALUES(?,?,?,?)"); psPing.setLong(1, test.getUid()); for (int i = 0; i < pingData.length(); i++) { final JSONObject pingDataItem = pingData.getJSONObject(i); long valueClient = pingDataItem.optLong("value", -1); if (valueClient >= 0) psPing.setLong(2, valueClient); else psPing.setNull(2, Types.BIGINT); long valueServer = pingDataItem.optLong("value_server", -1); if (valueServer >= 0) psPing.setLong(3, valueServer); else psPing.setNull(3, Types.BIGINT); long timeNs = pingDataItem.optLong("time_ns", -1); if (timeNs >= 0) psPing.setLong(4, timeNs); else psPing.setNull(4, Types.BIGINT); psPing.executeUpdate(); } } final JSONArray geoData = request.optJSONArray("geoLocations"); if (geoData != null && !test.hasError()) for (int i = 0; i < geoData.length(); i++) { final JSONObject geoDataItem = geoData.getJSONObject(i); if (geoDataItem.optLong("tstamp", 0) != 0 && geoDataItem.optDouble("geo_lat", 0) != 0 && geoDataItem.optDouble("geo_long", 0) != 0) { final GeoLocation geoloc = new GeoLocation(conn); geoloc.setTest_id(test.getUid()); final long clientTime = geoDataItem.optLong("tstamp"); final Timestamp tstamp = java.sql.Timestamp .valueOf(new Timestamp(clientTime).toString()); geoloc.setTime(tstamp, test.getField("timezone").toString()); geoloc.setAccuracy( (float) geoDataItem.optDouble("accuracy", 0)); geoloc.setAltitude(geoDataItem.optDouble("altitude", 0)); geoloc.setBearing((float) geoDataItem.optDouble("bearing", 0)); geoloc.setSpeed((float) geoDataItem.optDouble("speed", 0)); geoloc.setProvider(geoDataItem.optString("provider", "")); geoloc.setGeo_lat(geoDataItem.optDouble("geo_lat", 0)); geoloc.setGeo_long(geoDataItem.optDouble("geo_long", 0)); geoloc.setTime_ns(geoDataItem.optLong("time_ns", 0)); geoloc.storeLocation(); // Store Last Geolocation as // Testlocation if (i == geoData.length() - 1) { if (geoDataItem.has("geo_lat")) test.getField("geo_lat").setField(geoDataItem); if (geoDataItem.has("geo_long")) test.getField("geo_long").setField(geoDataItem); if (geoDataItem.has("accuracy")) test.getField("geo_accuracy").setField(geoDataItem); if (geoDataItem.has("provider")) test.getField("geo_provider").setField(geoDataItem); } if (geoloc.hasError()) { errorList.addError(geoloc.getError()); break; } } } final JSONArray cellData = request.optJSONArray("cellLocations"); if (cellData != null && !test.hasError()) for (int i = 0; i < cellData.length(); i++) { final JSONObject cellDataItem = cellData.getJSONObject(i); final Cell_location cellloc = new Cell_location(conn); cellloc.setTest_id(test.getUid()); final long clientTime = cellDataItem.optLong("time"); final Timestamp tstamp = java.sql.Timestamp .valueOf(new Timestamp(clientTime).toString()); cellloc.setTime(tstamp, test.getField("timezone").toString()); cellloc.setTime_ns(cellDataItem.optLong("time_ns", 0)); cellloc.setLocation_id(cellDataItem.optInt("location_id", 0)); cellloc.setArea_code(cellDataItem.optInt("area_code", 0)); cellloc.setPrimary_scrambling_code( cellDataItem.optInt("primary_scrambling_code", 0)); cellloc.storeLocation(); if (cellloc.hasError()) { errorList.addError(cellloc.getError()); break; } } int signalStrength = Integer.MAX_VALUE; //measured as RSSI (GSM,UMTS,Wifi) int lteRsrp = Integer.MAX_VALUE; // signal strength measured as RSRP int lteRsrq = Integer.MAX_VALUE; // signal quality of LTE measured as RSRQ int linkSpeed = UNKNOWN; final int networkType = test.getField("network_type").intValue(); final JSONArray signalData = request.optJSONArray("signals"); if (signalData != null && !test.hasError()) { for (int i = 0; i < signalData.length(); i++) { final JSONObject signalDataItem = signalData.getJSONObject(i); final Signal signal = new Signal(conn); signal.setTest_id(test.getUid()); final long clientTime = signalDataItem.optLong("time"); final Timestamp tstamp = java.sql.Timestamp .valueOf(new Timestamp(clientTime).toString()); signal.setTime(tstamp, test.getField("timezone").toString()); final int thisNetworkType = signalDataItem.optInt("network_type_id", 0); signal.setNetwork_type_id(thisNetworkType); final int thisSignalStrength = signalDataItem .optInt("signal_strength", UNKNOWN); if (thisSignalStrength != UNKNOWN) signal.setSignal_strength(thisSignalStrength); signal.setGsm_bit_error_rate( signalDataItem.optInt("gsm_bit_error_rate", 0)); final int thisLinkSpeed = signalDataItem.optInt("wifi_link_speed", 0); signal.setWifi_link_speed(thisLinkSpeed); final int rssi = signalDataItem.optInt("wifi_rssi", UNKNOWN); if (rssi != UNKNOWN) signal.setWifi_rssi(rssi); lteRsrp = signalDataItem.optInt("lte_rsrp", UNKNOWN); lteRsrq = signalDataItem.optInt("lte_rsrq", UNKNOWN); final int lteRssnr = signalDataItem.optInt("lte_rssnr", UNKNOWN); final int lteCqi = signalDataItem.optInt("lte_cqi", UNKNOWN); final long timeNs = signalDataItem.optLong("time_ns", UNKNOWN); signal.setLte_rsrp(lteRsrp); signal.setLte_rsrq(lteRsrq); signal.setLte_rssnr(lteRssnr); signal.setLte_cqi(lteCqi); signal.setTime_ns(timeNs); signal.storeSignal(); if (networkType == 99) // wlan { if (rssi < signalStrength && rssi != UNKNOWN) signalStrength = rssi; } else if (thisSignalStrength < signalStrength && thisSignalStrength != UNKNOWN) signalStrength = thisSignalStrength; if (thisLinkSpeed != 0 && (linkSpeed == UNKNOWN || thisLinkSpeed < linkSpeed)) linkSpeed = thisLinkSpeed; if (signal.hasError()) { errorList.addError(signal.getError()); break; } } // set rssi value (typically GSM,UMTS, but also old LTE-phones) if (signalStrength != Integer.MAX_VALUE && signalStrength != UNKNOWN && signalStrength != 0) // 0 dBm is out of range ((IntField) test.getField("signal_strength")) .setValue(signalStrength); // set rsrp value (typically LTE) if (lteRsrp != Integer.MAX_VALUE && lteRsrp != UNKNOWN && lteRsrp != 0) // 0 dBm is out of range ((IntField) test.getField("lte_rsrp")).setValue(lteRsrp); // set rsrq value (LTE) if (lteRsrq != Integer.MAX_VALUE && lteRsrq != UNKNOWN) ((IntField) test.getField("lte_rsrq")).setValue(lteRsrq); if (linkSpeed != Integer.MAX_VALUE && linkSpeed != UNKNOWN) ((IntField) test.getField("wifi_link_speed")).setValue(linkSpeed); } // use max network type final String sqlMaxNetworkType = "SELECT nt.uid" + " FROM signal s" + " JOIN network_type nt" + " ON s.network_type_id=nt.uid" + " WHERE test_id=?" + " ORDER BY nt.technology_order DESC" + " LIMIT 1"; final PreparedStatement psMaxNetworkType = conn .prepareStatement(sqlMaxNetworkType); psMaxNetworkType.setLong(1, test.getUid()); if (psMaxNetworkType.execute()) { final ResultSet rs = psMaxNetworkType.getResultSet(); if (rs.next()) { final int maxNetworkType = rs.getInt("uid"); if (maxNetworkType != 0) ((IntField) test.getField("network_type")) .setValue(maxNetworkType); } } /* * check for different types (e.g. * 2G/3G) */ final String sqlAggSignal = "WITH agg AS" + " (SELECT array_agg(DISTINCT nt.group_name ORDER BY nt.group_name) agg" + " FROM signal s" + " JOIN network_type nt ON s.network_type_id=nt.uid WHERE test_id=?)" + " SELECT uid FROM agg JOIN network_type nt ON nt.aggregate=agg"; final PreparedStatement psAgg = conn.prepareStatement(sqlAggSignal); psAgg.setLong(1, test.getUid()); if (psAgg.execute()) { final ResultSet rs = psAgg.getResultSet(); if (rs.next()) { final int newNetworkType = rs.getInt("uid"); if (newNetworkType != 0) ((IntField) test.getField("network_type")) .setValue(newNetworkType); } } if (test.getField("network_type").intValue() <= 0) errorList.addError("ERROR_NETWORK_TYPE"); final IntField downloadField = (IntField) test.getField("speed_download"); if (downloadField.isNull() || downloadField.intValue() <= 0 || downloadField.intValue() > 10000000) // 10 gbit/s limit errorList.addError("ERROR_DOWNLOAD_INSANE"); final IntField upField = (IntField) test.getField("speed_upload"); if (upField.isNull() || upField.intValue() <= 0 || upField.intValue() > 10000000) // 10 gbit/s limit errorList.addError("ERROR_UPLOAD_INSANE"); //clients still report eg: "test_ping_shortest":9195040 (note the 'test_' prefix there!) final LongField pingField = (LongField) test.getField("ping_shortest"); if (pingField.isNull() || pingField.longValue() <= 0 || pingField.longValue() > 60000000000L) // 1 min limit errorList.addError("ERROR_PING_INSANE"); if (errorList.isEmpty()) test.getField("status").setString("FINISHED"); else test.getField("status").setString("ERROR"); test.storeTestResults(false); if (test.hasError()) errorList.addError(test.getError()); } else errorList.addError("ERROR_CLIENT_VERSION"); } else errorList.addError("ERROR_TEST_TOKEN_MALFORMED"); } catch (final IllegalArgumentException e) { e.printStackTrace(); errorList.addError("ERROR_TEST_TOKEN_MALFORMED"); } } else errorList.addError("ERROR_TEST_TOKEN_MISSING"); conn.commit(); } else errorList.addError("ERROR_DB_CONNECTION"); } catch (final JSONException e) { errorList.addError("ERROR_REQUEST_JSON"); System.out.println("Error parsing JSDON Data " + e.toString()); e.printStackTrace(); } catch (final SQLException e) { System.out.println("Error while storing data " + e.toString()); e.printStackTrace(); } else errorList.addErrorString("Expected request is missing."); try { answer.putOpt("error", errorList.getList()); } catch (final JSONException e) { System.out.println("Error saving ErrorList: " + e.toString()); } return answer.toString(); }
From source file:com.bt.aloha.eventing.EventDispatcher.java
public int dispatchEvent(List<?> rawListenerList, final Object event, boolean invokeAsynchronously, Integer maxNumberOfListenersToInvoke) { if (event == null) throw new UndefinedEventException("Cannot dispatch null event"); List<?> filteredListenerArray = filterListeners(rawListenerList, event); final Locale locale = new Locale(LOCALE); String eventName = event.getClass().getSimpleName().toLowerCase(locale); if (eventName.toLowerCase(locale).endsWith(EVENT_SUFFIX)) eventName = eventName.substring(0, eventName.length() - EVENT_SUFFIX.length()); int numberOfListenersInvoked = 0; for (final Object listener : filteredListenerArray) { if (maxNumberOfListenersToInvoke != null && numberOfListenersInvoked >= maxNumberOfListenersToInvoke.intValue()) { log.debug(String.format("Already invoked max number (%d) of listeners for event %s", maxNumberOfListenersToInvoke.intValue(), eventName)); break; }/* w w w. java 2 s.com*/ if (deliverEventToListener(listener, eventName, event, invokeAsynchronously)) { numberOfListenersInvoked++; } else { log.warn(String.format( "Unable to deliver event %s to listener %s - check that the listeners have method names corresponding to event names", eventName, listener.getClass().getName())); } } return numberOfListenersInvoked; }
From source file:com.celements.common.test.AbstractBridgedComponentTestCase.java
@SuppressWarnings("unchecked") public XWikiContext getContext() { if (this.context.getLanguage() == null) { this.context.setLanguage("de"); }//from w w w . ja va 2s . c o m if (this.context.get("msg") == null) { Locale locale = new Locale(this.context.getLanguage()); ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources", locale); if (bundle == null) { bundle = ResourceBundle.getBundle("ApplicationResources"); } XWikiMessageTool msg = new TestMessageTool(bundle, context); context.put("msg", msg); VelocityContext vcontext = ((VelocityContext) context.get("vcontext")); if (vcontext != null) { vcontext.put("msg", msg); vcontext.put("locale", locale); } Map gcontext = (Map) context.get("gcontext"); if (gcontext != null) { gcontext.put("msg", msg); gcontext.put("locale", locale); } } return this.context; }
From source file:net.pms.newgui.GeneralTab.java
public JComponent build() { // Apply the orientation for the locale Locale locale = new Locale(configuration.getLanguage()); ComponentOrientation orientation = ComponentOrientation.getOrientation(locale); String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation); FormLayout layout = new FormLayout(colSpec, ROW_SPEC); PanelBuilder builder = new PanelBuilder(layout); builder.setBorder(Borders.DLU4_BORDER); builder.setOpaque(true);/*from w w w. j a v a 2 s.c o m*/ CellConstraints cc = new CellConstraints(); smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3")); smcheckBox.setContentAreaFilled(false); smcheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setMinimized((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isMinimized()) { smcheckBox.setSelected(true); } JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); builder.addLabel(Messages.getString("NetworkTab.0"), FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation)); final KeyedComboBoxModel kcbm = new KeyedComboBoxModel( new Object[] { "ar", "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "iw", "is", "it", "ja", "ko", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv", "tr" }, new Object[] { "Arabic", "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech", "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Hebrew", "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)", "Romanian", "Russian", "Slovenian", "Spanish", "Swedish", "Turkish" }); langs = new JComboBox(kcbm); langs.setEditable(false); String defaultLang = null; if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) { defaultLang = configuration.getLanguage(); } else { defaultLang = Locale.getDefault().getLanguage(); } if (defaultLang == null) { defaultLang = "en"; } kcbm.setSelectedKey(defaultLang); if (langs.getSelectedIndex() == -1) { langs.setSelectedIndex(0); } langs.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setLanguage((String) kcbm.getSelectedKey()); } } }); builder.add(langs, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation)); builder.add(smcheckBox, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation)); JButton service = new JButton(Messages.getString("NetworkTab.4")); service.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (PMS.get().installWin32Service()) { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"), Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())), Messages.getString("NetworkTab.14"), Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } } }); builder.add(service, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation)); if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) { service.setEnabled(false); } JButton checkForUpdates = new JButton(Messages.getString("NetworkTab.8")); checkForUpdates.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LooksFrame frame = (LooksFrame) PMS.get().getFrame(); frame.checkForUpdates(); } }); builder.add(checkForUpdates, FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation)); autoUpdateCheckBox = new JCheckBox(Messages.getString("NetworkTab.9")); autoUpdateCheckBox.setContentAreaFilled(false); autoUpdateCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setAutoUpdate((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isAutoUpdate()) { autoUpdateCheckBox.setSelected(true); } builder.add(autoUpdateCheckBox, FormLayoutUtil.flip(cc.xyw(7, 13, 3), colSpec, orientation)); if (!Build.isUpdatable()) { checkForUpdates.setEnabled(false); autoUpdateCheckBox.setEnabled(false); } host = new JTextField(configuration.getServerHostname()); host.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setHostname(host.getText()); } }); port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : ""); port.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { try { String p = port.getText(); if (StringUtils.isEmpty(p)) { p = "5001"; } int ab = Integer.parseInt(p); configuration.setServerPort(ab); } catch (NumberFormatException nfe) { logger.debug("Could not parse port from \"" + port.getText() + "\""); } } }); cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), FormLayoutUtil.flip(cc.xyw(1, 21, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); final KeyedComboBoxModel networkInterfaces = createNetworkInterfacesModel(); networkinterfacesCBX = new JComboBox(networkInterfaces); networkInterfaces.setSelectedKey(configuration.getNetworkInterface()); networkinterfacesCBX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey()); } } }); ip_filter = new JTextField(configuration.getIpFilter()); ip_filter.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { configuration.setIpFilter(ip_filter.getText()); } }); maxbitrate = new JTextField(configuration.getMaximumBitrate()); maxbitrate.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { PMS.getConfiguration().setMaximumBitrate(maxbitrate.getText()); } }); builder.addLabel(Messages.getString("NetworkTab.20"), FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation)); builder.add(networkinterfacesCBX, FormLayoutUtil.flip(cc.xyw(3, 23, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.23"), FormLayoutUtil.flip(cc.xy(1, 25), colSpec, orientation)); builder.add(host, FormLayoutUtil.flip(cc.xyw(3, 25, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.24"), FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation)); builder.add(port, FormLayoutUtil.flip(cc.xyw(3, 27, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.30"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation)); builder.add(ip_filter, FormLayoutUtil.flip(cc.xyw(3, 29, 7), colSpec, orientation)); builder.addLabel(Messages.getString("NetworkTab.35"), FormLayoutUtil.flip(cc.xy(1, 31), colSpec, orientation)); builder.add(maxbitrate, FormLayoutUtil.flip(cc.xyw(3, 31, 7), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), FormLayoutUtil.flip(cc.xyw(1, 33, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32")); newHTTPEngine.setSelected(configuration.isHTTPEngineV2()); newHTTPEngine.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(newHTTPEngine, FormLayoutUtil.flip(cc.xyw(1, 35, 9), colSpec, orientation)); preventSleep = new JCheckBox(Messages.getString("NetworkTab.33")); preventSleep.setSelected(configuration.isPreventsSleep()); preventSleep.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED)); } }); builder.add(preventSleep, FormLayoutUtil.flip(cc.xyw(1, 37, 9), colSpec, orientation)); JCheckBox fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38")); fdCheckBox.setContentAreaFilled(false); fdCheckBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED)); } }); if (configuration.isRendererForceDefault()) { fdCheckBox.setSelected(true); } builder.addLabel(Messages.getString("NetworkTab.36"), FormLayoutUtil.flip(cc.xy(1, 39), colSpec, orientation)); ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations(); ArrayList<Object> keyValues = new ArrayList<Object>(); ArrayList<Object> nameValues = new ArrayList<Object>(); keyValues.add(""); nameValues.add(Messages.getString("NetworkTab.37")); if (allConfs != null) { for (RendererConfiguration renderer : allConfs) { if (renderer != null) { keyValues.add(renderer.getRendererName()); nameValues.add(renderer.getRendererName()); } } } final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel( (Object[]) keyValues.toArray(new Object[keyValues.size()]), (Object[]) nameValues.toArray(new Object[nameValues.size()])); renderers = new JComboBox(renderersKcbm); renderers.setEditable(false); String defaultRenderer = configuration.getRendererDefault(); renderersKcbm.setSelectedKey(defaultRenderer); if (renderers.getSelectedIndex() == -1) { renderers.setSelectedIndex(0); } builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, 39, 7), colSpec, orientation)); builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation)); cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), FormLayoutUtil.flip(cc.xyw(1, 43, 9), colSpec, orientation)); cmp = (JComponent) cmp.getComponent(0); cmp.setFont(cmp.getFont().deriveFont(Font.BOLD)); pPlugins = new JPanel(new GridLayout()); builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 45, 9), colSpec, orientation)); JPanel panel = builder.getPanel(); // Apply the orientation to the panel and all components in it panel.applyComponentOrientation(orientation); JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); return scrollPane; }
From source file:dk.dma.msiproxy.web.MessageDetailsServlet.java
/** * Main GET method//from ww w. j av a2 s. c om * @param request servlet request * @param response servlet response */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Never cache the response response = WebUtils.nocache(response); // Read the request parameters String providerId = request.getParameter("provider"); String lang = request.getParameter("lang"); String messageId = request.getParameter("messageId"); String activeNow = request.getParameter("activeNow"); String areaHeadingIds = request.getParameter("areaHeadings"); List<AbstractProviderService> providerServices = providers.getProviders(providerId); if (providerServices.size() == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid 'provider' parameter"); return; } // Ensure that the language is valid lang = providerServices.get(0).getLanguage(lang); // Force the encoding and the locale based on the lang parameter request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); final Locale locale = new Locale(lang); request = new HttpServletRequestWrapper(request) { @Override public Locale getLocale() { return locale; } }; // Get the messages in the given language for the requested provider MessageFilter filter = new MessageFilter().lang(lang); Date now = "true".equals(activeNow) ? new Date() : null; Integer id = StringUtils.isNumeric(messageId) ? Integer.valueOf(messageId) : null; Set<Integer> areaHeadings = StringUtils.isNotBlank(areaHeadingIds) ? Arrays .asList(areaHeadingIds.split(",")).stream().map(Integer::valueOf).collect(Collectors.toSet()) : null; List<Message> messages = providerServices.stream().flatMap(p -> p.getCachedMessages(filter).stream()) // Filter on message id .filter(msg -> (id == null || id.equals(msg.getId()))) // Filter on active messages .filter(msg -> (now == null || msg.getValidFrom() == null || msg.getValidFrom().before(now))) // Filter on area headings .filter(msg -> (areaHeadings == null || areaHeadings.contains(getAreaHeadingId(msg)))) .collect(Collectors.toList()); // Register the attributes to be used on the JSP apeg request.setAttribute("messages", messages); request.setAttribute("baseUri", app.getBaseUri()); request.setAttribute("lang", lang); request.setAttribute("locale", locale); request.setAttribute("provider", providerId); if (request.getServletPath().endsWith("pdf")) { generatePdfFile(request, response); } else { generateHtmlPage(request, response); } }
From source file:com.cami.spring.web.WebConfig.java
@Bean(name = "localeResolver") public LocaleResolver sessionLocaleResolver() { final SessionLocaleResolver localeResolver = new SessionLocaleResolver(); localeResolver.setDefaultLocale(new Locale("en")); return localeResolver; }
From source file:jp.terasoluna.fw.beans.jxpath.BeanPointerFactoryExTest.java
/** * testCreateNodePointerNodePointer01() <br> * <br>/* ww w . jav a 2s . c o m*/ * () <br> * C <br> * <br> * () parent:not null<br> * () name:not null<br> * () bean:null<br> * <br> * () NodePointer:new NullPointer {<br> * parent=?parent<br> * name=?name<br> * }<br> * <br> * ?null??? <br> * @throws Exception ????? */ @Test public void testCreateNodePointerNodePointer01() throws Exception { // ?? BeanPointerFactoryEx factory = new BeanPointerFactoryEx(); QName qName = new QName("name"); Locale locale = new Locale("ja"); NodePointer nodePointer = NodePointer.newNodePointer(qName, null, locale); // NodePointer result = factory.createNodePointer(nodePointer, qName, null); // assertSame(NullPointer.class, result.getClass()); assertSame(nodePointer, result.getParent()); assertSame(qName, result.getName()); }
From source file:org.accelerators.activiti.admin.AdminApp.java
/** Returns the bundle for the current locale. */ public ResourceBundle getBundle() { // Set to english by default if (i18nBundle == null) { setLocale(new Locale("en")); }/*from ww w .j ava2 s . c om*/ // Return resource bundle return i18nBundle; }