List of usage examples for java.util ResourceBundle getBundle
@CallerSensitive public static ResourceBundle getBundle(String baseName, Module module)
From source file:org.fornax.cartridges.sculptor.framework.web.errorhandling.ErrorBindingPhaseListener.java
/** * Pull out the Spring Errors object from context and convert each error into * a FacesMessage.//from www .ja v a2s. c om * @see javax.faces.event.PhaseListener#afterPhase(javax.faces.event.PhaseEvent) */ public void afterPhase(PhaseEvent event) { FacesContext context = event.getFacesContext(); RequestContext requestContext = RequestContextHolder.getRequestContext(); if (requestContext == null) return; Map<?, ?> model; try { model = requestContext.getFlashScope().asMap(); } catch (IllegalStateException e) { return; } Locale locale = context.getExternalContext().getRequestLocale(); for (Iterator<?> iter = model.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); Object value = model.get(key); // If we have an Errors object and it is not the duplicate currentFormObject // one (always provided for compatibility with single object forms) if (value instanceof Errors && !key.endsWith("currentFormObject")) { Errors errors = (Errors) value; for (Iterator<?> eter = errors.getAllErrors().iterator(); eter.hasNext();) { ObjectError error = (ObjectError) eter.next(); String summary = null; try { ResourceBundle bundle = ResourceBundle.getBundle("i18n.messages", context.getViewRoot().getLocale()); summary = bundle.getString(error.getCode()); /* another way of getting the error code resolved */ /* it might be better to use this one */ /*FacesContext fc = FacesContext.getCurrentInstance(); ELContext elc = fc.getELContext(); ExpressionFactory ef = fc.getApplication().getExpressionFactory(); ValueExpression ve = ef.createValueExpression(elc, "#{msg}", PropertyResourceBundle.class); PropertyResourceBundle msg = (PropertyResourceBundle) ve.getValue(elc); if (msg != null) { summary = msg.getString(error.getCode()); }*/ summary = MessageFormat.format(summary, error.getArguments()); // if it's a field error we prepend the name of the field to the message if (error instanceof FieldError) { FieldError fieldError = (FieldError) error; summary = fieldError.getField() + " - " + summary; } } catch (MissingResourceException mrexception) { summary = error.getDefaultMessage(); // try to translate the message if (messageSource != null) { summary = messageSource.getMessage(error, locale); } if (summary != null) { summary = MessageFormat.format(summary, error.getArguments()); } } if (summary != null) { String detail = summary; FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail); context.addMessage(null, message); } } } } }
From source file:mekhq.campaign.finances.Finances.java
public Finances() { transactions = new ArrayList<Transaction>(); loans = new ArrayList<Loan>(); assets = new ArrayList<Asset>(); loanDefaults = 0;// www . ja v a 2 s. c om failCollateral = 0; wentIntoDebt = null; // Init the resource map resourceMap = ResourceBundle.getBundle("mekhq.resources.Finances", new EncodeControl()); //$NON-NLS-1$ }
From source file:com.xmage.launcher.XMageLauncher.java
private XMageLauncher() { locale = Locale.getDefault(); //locale = new Locale("it", "IT"); messages = ResourceBundle.getBundle("MessagesBundle", locale); localize();// www .jav a2s. co m serverConsole = new XMageConsole("XMage Server console"); clientConsole = new XMageConsole("XMage Client console"); frame = new JFrame(messages.getString("frameTitle") + " " + Config.getVersion()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setPreferredSize(new Dimension(800, 500)); frame.setResizable(false); createToolbar(); ImageIcon icon = new ImageIcon(XMageLauncher.class.getResource("/icon-mage-flashed.png")); frame.setIconImage(icon.getImage()); Random r = new Random(); int imageNum = 1 + r.nextInt(17); ImageIcon background = new ImageIcon(new ImageIcon( XMageLauncher.class.getResource("/backgrounds/" + Integer.toString(imageNum) + ".jpg")).getImage() .getScaledInstance(800, 480, Image.SCALE_SMOOTH)); mainPanel = new JLabel(background) { @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); Dimension lmPrefSize = getLayout().preferredLayoutSize(this); size.width = Math.max(size.width, lmPrefSize.width); size.height = Math.max(size.height, lmPrefSize.height); return size; } }; mainPanel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { grabPoint = e.getPoint(); mainPanel.getComponentAt(grabPoint); } }); mainPanel.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseDragged(MouseEvent e) { // get location of Window int thisX = frame.getLocation().x; int thisY = frame.getLocation().y; // Determine how much the mouse moved since the initial click int xMoved = (thisX + e.getX()) - (thisX + grabPoint.x); int yMoved = (thisY + e.getY()) - (thisY + grabPoint.y); // Move window to this position int X = thisX + xMoved; int Y = thisY + yMoved; frame.setLocation(X, Y); } }); mainPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.insets = new Insets(10, 10, 10, 10); Font font16 = new Font("Arial", Font.BOLD, 16); Font font12 = new Font("Arial", Font.PLAIN, 12); Font font12b = new Font("Arial", Font.BOLD, 12); mainPanel.add(Box.createRigidArea(new Dimension(250, 50))); ImageIcon logo = new ImageIcon(new ImageIcon(XMageLauncher.class.getResource("/label-xmage.png")).getImage() .getScaledInstance(150, 75, Image.SCALE_SMOOTH)); xmageLogo = new JLabel(logo); constraints.gridx = 3; constraints.gridy = 0; constraints.gridheight = 1; constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.anchor = GridBagConstraints.EAST; mainPanel.add(xmageLogo, constraints); textArea = new JTextArea(5, 40); textArea.setEditable(false); textArea.setForeground(Color.WHITE); textArea.setBackground(Color.BLACK); DefaultCaret caret = (DefaultCaret) textArea.getCaret(); caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); constraints.gridx = 2; constraints.gridy = 1; constraints.weightx = 1.0; constraints.weighty = 1.0; constraints.fill = GridBagConstraints.BOTH; mainPanel.add(scrollPane, constraints); labelProgress = new JLabel(messages.getString("progress")); labelProgress.setFont(font12); labelProgress.setForeground(Color.WHITE); constraints.gridy = 2; constraints.weightx = 0.0; constraints.weighty = 0.0; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.WEST; mainPanel.add(labelProgress, constraints); progressBar = new JProgressBar(0, 100); constraints.gridx = 3; constraints.weightx = 1.0; constraints.gridwidth = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.HORIZONTAL; mainPanel.add(progressBar, constraints); JPanel pnlButtons = new JPanel(); pnlButtons.setLayout(new GridBagLayout()); pnlButtons.setOpaque(false); constraints.gridx = 0; constraints.gridy = 3; constraints.gridheight = GridBagConstraints.REMAINDER; constraints.fill = GridBagConstraints.BOTH; mainPanel.add(pnlButtons, constraints); btnLaunchClient = new JButton(messages.getString("launchClient")); btnLaunchClient.setToolTipText(messages.getString("launchClient.tooltip")); btnLaunchClient.setFont(font16); btnLaunchClient.setForeground(Color.GRAY); btnLaunchClient.setEnabled(false); btnLaunchClient.setPreferredSize(new Dimension(180, 60)); btnLaunchClient.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleClient(); } }); constraints.gridx = GridBagConstraints.RELATIVE; constraints.gridy = 0; constraints.gridwidth = 1; constraints.fill = GridBagConstraints.BOTH; pnlButtons.add(btnLaunchClient, constraints); btnLaunchClientServer = new JButton(messages.getString("launchClientServer")); btnLaunchClientServer.setToolTipText(messages.getString("launchClientServer.tooltip")); btnLaunchClientServer.setFont(font12b); btnLaunchClientServer.setEnabled(false); btnLaunchClientServer.setForeground(Color.GRAY); btnLaunchClientServer.setPreferredSize(new Dimension(80, 40)); btnLaunchClientServer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleServer(); handleClient(); } }); constraints.fill = GridBagConstraints.HORIZONTAL; pnlButtons.add(btnLaunchClientServer, constraints); btnLaunchServer = new JButton(messages.getString("launchServer")); btnLaunchServer.setToolTipText(messages.getString("launchServer.tooltip")); btnLaunchServer.setFont(font12b); btnLaunchServer.setEnabled(false); btnLaunchServer.setForeground(Color.GRAY); btnLaunchServer.setPreferredSize(new Dimension(80, 40)); btnLaunchServer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleServer(); } }); pnlButtons.add(btnLaunchServer, constraints); btnUpdate = new JButton(messages.getString("update.xmage")); btnUpdate.setToolTipText(messages.getString("update.xmage.tooltip")); btnUpdate.setFont(font12b); btnUpdate.setForeground(Color.BLACK); btnUpdate.setPreferredSize(new Dimension(80, 40)); btnUpdate.setEnabled(true); btnUpdate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleUpdate(); } }); pnlButtons.add(btnUpdate, constraints); btnCheck = new JButton(messages.getString("check.xmage")); btnCheck.setToolTipText(messages.getString("check.xmage.tooltip")); btnCheck.setFont(font12b); btnCheck.setForeground(Color.BLACK); btnCheck.setPreferredSize(new Dimension(80, 40)); btnCheck.setEnabled(true); btnCheck.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { handleCheckUpdates(); } }); pnlButtons.add(btnCheck, constraints); frame.add(mainPanel); frame.pack(); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(dim.width / 2 - frame.getSize().width / 2, dim.height / 2 - frame.getSize().height / 2); }
From source file:com.globalsight.reports.JobTableModel.java
/** * Creates a new JobTableModel holding the relevant data about a job * excluding workflow information <br> * /*from www . j a v a 2 s .c om*/ * @param p_job * -- the job to get data from * @param p_uilocale * -- the UI locale * @return JobTableModel */ public JobTableModel(List<Job> p_jobs, Locale p_uilocale, Currency p_currency) { m_uilocale = p_uilocale; m_bundle = ResourceBundle.getBundle(MY_MESSAGES, m_uilocale); m_datarows = new LinkedList<List<Object>>(); m_currency = p_currency; // don't use job costing values even if it's turned on because the // particular report // doesn't care about the costing if (m_currency != null) m_jobCosting = true; fillAllData(p_jobs); }
From source file:it.cnr.icar.eric.client.ui.swing.metal.MetalThemeMenu.java
/** * Constucts a JMenu named 'name' with a a RadioButton for each * object in 'themeArray'.//from w w w . j a v a 2s. c o m * * @param name the visible name for the Menu. * @param themeArray the array of themes to put in the menu. */ public MetalThemeMenu(String name, MetalTheme[] themeArray) { super(name); themeNames = ResourceBundle.getBundle(BASE_NAME, Locale.getDefault()); themes = themeArray; ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem defaultItem = null; for (int i = 0; i < themes.length; i++) { String themeName; try { themeName = themeNames.getString(themes[i].getName().replaceAll("\\s", "")); } catch (MissingResourceException mre) { themeName = themes[i].getName(); Object[] noResourceArgs = { themes[i].getName(), getLocale() }; MessageFormat form = new MessageFormat(themeNames.getString("message.error.noResource")); log.error(form.format(noResourceArgs)); } JRadioButtonMenuItem item = new JRadioButtonMenuItem(themeName); group.add(item); add(item); item.setActionCommand(i + ""); item.addActionListener(this); // Theme name without spaces is the key for looking up localized item text. item.setName(themes[i].getName().replaceAll(" ", "")); if (i == 0) { item.setSelected(true); defaultItem = item; } } //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); defaultItem.doClick(); }
From source file:org.accelerators.activiti.admin.AdminApp.java
@Override public void setLocale(Locale locale) { super.setLocale(locale); i18nBundle = ResourceBundle.getBundle(Messages.class.getName(), getLocale()); }
From source file:io.github.swagger2markup.internal.document.builder.MarkupDocumentBuilder.java
MarkupDocumentBuilder(Swagger2MarkupConverter.Context globalContext, Swagger2MarkupExtensionRegistry extensionRegistry, Path outputPath) { this.globalContext = globalContext; this.extensionRegistry = extensionRegistry; this.config = globalContext.getConfig(); this.outputPath = outputPath; this.markupDocBuilder = MarkupDocBuilders .documentBuilder(config.getMarkupLanguage(), config.getLineSeparator()) .withAnchorPrefix(config.getAnchorPrefix()); ResourceBundle labels = ResourceBundle.getBundle("io/github/swagger2markup/lang/labels", config.getOutputLanguage().toLocale()); DEFAULT_COLUMN = labels.getString("default_column"); EXAMPLE_COLUMN = labels.getString("example_column"); FLAGS_COLUMN = labels.getString("flags.column"); FLAGS_REQUIRED = labels.getString("flags.required"); FLAGS_OPTIONAL = labels.getString("flags.optional"); FLAGS_READ_ONLY = labels.getString("flags.read_only"); SCHEMA_COLUMN = labels.getString("schema_column"); NAME_COLUMN = labels.getString("name_column"); DESCRIPTION_COLUMN = labels.getString("description_column"); SCOPES_COLUMN = labels.getString("scopes_column"); DESCRIPTION = DESCRIPTION_COLUMN;//from w ww .j av a 2 s . co m PRODUCES = labels.getString("produces"); CONSUMES = labels.getString("consumes"); TAGS = labels.getString("tags"); NO_CONTENT = labels.getString("no_content"); }
From source file:es.pode.empaquetador.presentacion.avanzado.recursos.crear.elementos.CrearRecursoAvanzadoElementosControllerImpl.java
@Override public final void submitDependencias(ActionMapping mapping, es.pode.empaquetador.presentacion.avanzado.recursos.crear.elementos.SubmitDependenciasForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { java.util.Locale locale = (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE); ResourceBundle i18n = ResourceBundle.getBundle("application-resources", locale); String accion = form.getAction(); if (accion/* w w w .j a v a2 s .com*/ .equals(i18n.getString("portalempaquetado.avanzado.recursos.crear.paso2.dependencias.eliminar"))) { if (form.getIdentifierRowSelection() != null && form.getIdentifierRowSelection().size() > 0) { form.setIdentificadores(form.getIdentifierRowSelection()); } else { throw new ValidatorException("{portal_empaquetado.exception}"); } } }
From source file:com.googlecode.noweco.webmail.lotus.LotusWebmailConnection.java
@SuppressWarnings("unchecked") public LotusWebmailConnection(final HttpClient httpclient, final HttpHost host, final String prefix) throws IOException { this.prefix = prefix; HttpGet httpGet;// w w w . ja v a2 s.c om HttpResponse rsp; HttpEntity entity; String baseName = getClass().getPackage().getName().replace('.', '/') + "/lotus"; ResourceBundle bundleBrowser = null; for (Header header : (Collection<Header>) httpclient.getParams() .getParameter(ClientPNames.DEFAULT_HEADERS)) { if (header.getName().equals("Accept-Language")) { Matcher matcher = LANGUAGE_PATTERN.matcher(header.getValue()); if (matcher.find()) { String region = matcher.group(2); if (region != null && region.length() != 0) { bundleBrowser = ResourceBundle.getBundle(baseName, new Locale(matcher.group(1), region)); } else { bundleBrowser = ResourceBundle.getBundle(baseName, new Locale(matcher.group(1))); } } } } ResourceBundle bundleEnglish = ResourceBundle.getBundle(baseName, new Locale("en")); String deletePattern = "(?:" + Pattern.quote(bundleEnglish.getString("Delete")); if (bundleBrowser != null) { deletePattern = deletePattern + "|" + Pattern.quote(bundleBrowser.getString("Delete")) + ")"; } String emptyTrashPattern = "(?:" + Pattern.quote(bundleEnglish.getString("EmptyTrash")); if (bundleBrowser != null) { emptyTrashPattern = emptyTrashPattern + "|" + Pattern.quote(bundleBrowser.getString("EmptyTrash")) + ")"; } deleteDeletePattern = Pattern.compile( "_doClick\\('([^/]*/\\$V\\d+ACTIONS/[^']*)'[^>]*>" + deletePattern + "\\\\" + deletePattern); deleteEmptyTrashPattern = Pattern.compile( "_doClick\\('([^/]*/\\$V\\d+ACTIONS/[^']*)'[^>]*>" + deletePattern + "\\\\" + emptyTrashPattern); httpGet = new HttpGet(prefix + "/($Inbox)?OpenView"); rsp = httpclient.execute(host, httpGet); entity = rsp.getEntity(); String string = EntityUtils.toString(entity); if (entity != null) { LOGGER.trace("inbox content : {}", string); EntityUtils.consume(entity); } Matcher matcher = MAIN_PAGE_PATTERN.matcher(string); if (!matcher.find()) { throw new IOException("Unable to parse main page"); } pagePrefix = matcher.group(1); this.httpclient = httpclient; this.host = host; }
From source file:com.norconex.commons.lang.time.DurationUtil.java
private static String getString(Locale locale, long unitValue, final String key, boolean islong) { String k = key;/*from ww w . java2s . c o m*/ if (islong && unitValue > 1) { k += "s"; } String pkg = ClassUtils.getPackageName(DurationUtil.class); ResourceBundle time; if (locale != null && Locale.FRENCH.getLanguage().equals(locale.getLanguage())) { time = ResourceBundle.getBundle(pkg + ".time", Locale.FRENCH); } else { time = ResourceBundle.getBundle(pkg + ".time"); } if (islong) { return " " + unitValue + " " + time.getString("timeunit.long." + k); } return unitValue + time.getString("timeunit.short." + k); }