/** * Gets a resource bundle using the specified base name and locale, and the caller's class loader. * @param bundle the base name of the resource bundle, a fully qualified class name * @param locale the locale for which a resource bundle is desired * @return a resource bundle for the given base name and locale */ public static ListResourceBundle getResourceBundle(final String bundle, final Locale locale) { return AccessController.doPrivileged(new PrivilegedAction<ListResourceBundle>() { public ListResourceBundle run() { try { return (ListResourceBundle)ResourceBundle.getBundle(bundle, locale); } catch (MissingResourceException e) { try { return (ListResourceBundle)ResourceBundle.getBundle(bundle, new Locale("en", "US")); } catch (MissingResourceException e2) { throw new MissingResourceException( "Could not load any resource bundle by " + bundle, bundle, ""); } } } }); }
/** * Gets a resource bundle using the specified base name and locale, and the * caller's class loader. * * @param bundle the base name of the resource bundle, a fully qualified * class name * @param locale the locale for which a resource bundle is desired * @return a resource bundle for the given base name and locale */ public static ListResourceBundle getResourceBundle(final String bundle, final Locale locale) { return AccessController.doPrivileged(new PrivilegedAction<ListResourceBundle>() { public ListResourceBundle run() { try { return (ListResourceBundle) ResourceBundle.getBundle(bundle, locale); } catch (MissingResourceException e) { try { return (ListResourceBundle) ResourceBundle.getBundle(bundle, new Locale("en", "US")); } catch (MissingResourceException e2) { throw new MissingResourceException( "Could not load any resource bundle by " + bundle, bundle, ""); } } } }); }
/** * Loads a resources using JRE and returns the names */ private static Set<String> loadClass(String clazz) throws Exception { ListResourceBundle lrb = (ListResourceBundle)Class.forName(clazz).newInstance(); Set<String> keys = lrb.keySet(); Map<String,String> newold = new HashMap<String,String>(); boolean dup = false; // Check if normalize() creates dup entries. This is crucial. for (String k: keys) { String key = normalize(k); if (newold.containsKey(key)) { err("Dup found for " + key + ":"); err("["+newold.get(key)+"]"); err("["+k+"]"); dup = true; } newold.put(key, k); } if (dup) throw new Exception(); return keys; }
/** * @deprecated Construtor para AbstractConverter contendo os formatadores de * convers�o padr�o<br> * � altamente recomend�vel que se construa este objeto * informando o resourceBundle de internacionalizacao */ public AbstractConverter() { logger .warn("ATENCAO!! CONSTRUINDO UM RESOURCE BUNDLE COM A INTERNACIONALIZA��O DE " + "FORMATOS PADR�O!!!. ISTO PODE COMPROMETER A PORTABILIDADE DA APLICACAO"); ResourceBundle resourceBundle = new ListResourceBundle() { protected Object[][] getContents() { String valores[][] = { { PROPERTY_FORMATO_DATA_VIEW, DEFAULT_FORMATO_DATA }, { PROPERTY_DECIMAL_SEPARATOR, DEFAULT_DECIMAL_SEPARATOR }, { PROPERTY_GROUPING_SEPARATOR, DEFAULT_GROUPING_SEPARATOR }, { PROPERTY_FORMATO_SHORT, DEFAULT_FORMATO_SHORT }, { PROPERTY_FORMATO_INTEGER, DEFAULT_FORMATO_INTEGER }, { PROPERTY_FORMATO_LONG, DEFAULT_FORMATO_LONG }, { PROPERTY_FORMATO_FLOAT, DEFAULT_FORMATO_FLOAT }, { PROPERTY_FORMATO_DOUBLE, DEFAULT_FORMATO_DOUBLE } }; return valores; } }; setResourceBundle(resourceBundle); }
@POST @Path( "/wildcard" ) public ResourceBundle getResourceBundle( ResourceBundleRequest resourceBundleRequest ) { final List<ResourceBundle> resourceBundles = new ArrayList<ResourceBundle>( ); for ( ResourceBundleWildcard resourceBundleWildcard : resourceBundleRequest.getWildcards() ) { Pattern keyPattern = Pattern.compile( resourceBundleWildcard.getKeyRegex() ); resourceBundles.addAll( getResourceBundles( keyPattern, getLocale( resourceBundleRequest.getLocale() ) ) ); } return new ListResourceBundle() { @Override protected Object[][] getContents() { List<Object[]> entries = new ArrayList<Object[]>(); for ( ResourceBundle resourceBundle : resourceBundles ) { for ( String key : Collections.list( resourceBundle.getKeys() ) ) { entries.add( new Object[] { key, resourceBundle.getString( key ) } ); } } return entries.toArray( new Object[ entries.size() ][] ); } }; }
@Override public void onCreateActions(ListResourceBundle resources, final BaseEditor baseEditor, IProgressMonitor monitor) { PyEdit edit = (PyEdit) baseEditor; edit.addOfflineActionListener("--internal-test-modules", new Action() { @Override public void run() { List<IPythonNature> allPythonNatures = PythonNature.getAllPythonNatures(); StringBuffer buf = new StringBuffer(); try { for (IPythonNature nature : allPythonNatures) { buf.append(checkIntegrity(nature, new NullProgressMonitor(), true)); } } catch (MisconfigurationException e) { buf.append(e.getMessage()); } UIUtils.showString(buf.toString()); } }, "Used just for testing (do not use).", true); }
/** * Notifies listeners that the actions have just been created in the editor. */ public void notifyOnCreateActions(final ListResourceBundle resources) { final BaseEditor edit = pyEdit.get(); if (edit == null) { return; } INotifierRunnable runnable = new INotifierRunnable() { @Override public void run(final IProgressMonitor monitor) { for (IPyEditListener listener : edit.getAllListeners()) { try { if (!monitor.isCanceled()) { listener.onCreateActions(resources, edit, monitor); } } catch (Exception e) { //must not fail Log.log(e); } } } }; runIt(runnable); }
/** * This method associates Ctrl+new line with the evaluation of commands in the console. */ @Override public void onCreateActions(ListResourceBundle resources, final BaseEditor baseEditor, IProgressMonitor monitor) { final PyEdit edit = (PyEdit) baseEditor; final EvaluateAction evaluateAction = new EvaluateAction(edit); evaluateAction.setActionDefinitionId(IInteractiveConsoleConstants.EVALUATE_ACTION_ID); evaluateAction.setId(IInteractiveConsoleConstants.EVALUATE_ACTION_ID); Runnable runnable = new Runnable() { @Override public void run() { if (!edit.isDisposed()) { edit.setAction(IInteractiveConsoleConstants.EVALUATE_ACTION_ID, evaluateAction); } } }; Display.getDefault().syncExec(runnable); }
@Override public void onCreateActions(ListResourceBundle resources, BaseEditor baseEditor, IProgressMonitor monitor) { //Note: can be called multiple times (will only create handlers for the new actions). Map<String, InteractiveCommandCustomHandler> commandIdToHandler = InteractiveConsoleCommand .getCommandIdToHandler(); Set<Entry<String, InteractiveCommandCustomHandler>> entrySet = commandIdToHandler.entrySet(); for (Entry<String, InteractiveCommandCustomHandler> entry : entrySet) { if (idToAction.containsKey(entry.getKey())) { continue; } InteractiveConsoleUserCommandAction action = new InteractiveConsoleUserCommandAction(resources, "Pyedit.InteractiveConsoleUserCommand", baseEditor, entry.getKey()); action.setActionDefinitionId(entry.getKey()); action.setId(entry.getKey()); baseEditor.setAction(FullRepIterable.getLastPart(entry.getKey()), action); idToAction.put(entry.getKey(), action); } this.resources = resources; this.weakEditor = new WeakReference<>(baseEditor); InteractiveConsoleCommand.onCommandIdToHandlerChanged.registerListener(onCommandIdToHandlerChangedCallback); }
@Before public void setUp() { request = mock(HttpServletRequest.class); servletContext = mock(ServletContext.class); session = mock(HttpSession.class); localization = new JstlLocalization(request); ResourceBundle bundle = new ListResourceBundle() { @Override protected Object[][] getContents() { return new Object[][] { { "my.key", "abc" } }; } }; LocalizationContext context = new LocalizationContext(bundle); when(request.getAttribute(FMT_LOCALIZATION_CONTEXT + ".request")).thenReturn(context); when(request.getSession(false)).thenReturn(session); when(request.getServletContext()).thenReturn(servletContext); }
public Object call() throws Exception { LogRecord lg = new LogRecord(Level.ALL, getMessage()); lg.setResourceBundle(new ListResourceBundle() { protected Object[][] getContents() { return new Object[][] { {getMessage(), getMessage()} }; } }); return new LogRecord[] { lg }; }
/** * @deprecated Construtor para AbstractConverter contendo os formatadores de conversao padrAo<br> * e altamente recomendAvel que se construa este objeto informando o resourceBundle de internacionalizacao */ public AbstractConverter() { logger.warn("ATENCAO!! CONSTRUINDO UM RESOURCE BUNDLE COM A INTERNACIONALIZAcao DE " + "FORMATOS PADRAO!!!. ISTO PODE COMPROMETER A PORTABILIDADE DA APLICACAO"); ResourceBundle resourceBundle = new ListResourceBundle() { protected Object[][] getContents() { String valores[][] = { { PROPERTY_FORMATO_DATA_VIEW, DEFAULT_FORMATO_DATA }, { PROPERTY_DECIMAL_SEPARATOR, DEFAULT_DECIMAL_SEPARATOR }, { PROPERTY_GROUPING_SEPARATOR, DEFAULT_GROUPING_SEPARATOR }, { PROPERTY_FORMATO_SHORT, DEFAULT_FORMATO_SHORT }, { PROPERTY_FORMATO_INTEGER, DEFAULT_FORMATO_INTEGER }, { PROPERTY_FORMATO_LONG, DEFAULT_FORMATO_LONG }, { PROPERTY_FORMATO_FLOAT, DEFAULT_FORMATO_FLOAT }, { PROPERTY_FORMATO_DOUBLE, DEFAULT_FORMATO_DOUBLE } }; return valores; } }; setResourceBundle(resourceBundle); }
private static BuildInfo getDefaultBuildInfo() { return new BuildInfo( new ListResourceBundle() { @Override public Object[][] getContents() { return new Object[][] { { "svnVersion", "345M", }, { "timestamp", "January 1, 2007", }, }; } }); }
@org.junit.Test(timeout = 1000) public void testConvertResourceBundle_add2558() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testConvertResourceBundle_add2558"); final Map<java.lang.String, java.lang.String> in = new HashMap<java.lang.String, java.lang.String>(5 , 1); in.put("1", "A"); in.put("1", "A"); in.put("2", "B"); in.put("3", "C"); in.put("4", "D"); in.put("5", "E"); final ResourceBundle b = new ListResourceBundle() { @Override public Object[][] getContents() { final Object[][] contents = new Object[in.size()][2]; final Iterator<java.lang.String> i = in.keySet().iterator(); int n = 0; while (i.hasNext()) { final Object key = i.next(); final Object val = in.get(key); contents[n][0] = key; contents[n][1] = val; ++n; } return contents; } }; final Map<java.lang.String, java.lang.Object> out = org.apache.commons.collections4.MapUtils.toMap(b); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),7777,in,7776,in.equals(out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
@org.junit.Test(timeout = 1000) public void testConvertResourceBundle_add2559() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testConvertResourceBundle_add2559"); final Map<java.lang.String, java.lang.String> in = new HashMap<java.lang.String, java.lang.String>(5 , 1); in.put("1", "A"); in.put("2", "B"); in.put("2", "B"); in.put("3", "C"); in.put("4", "D"); in.put("5", "E"); final ResourceBundle b = new ListResourceBundle() { @Override public Object[][] getContents() { final Object[][] contents = new Object[in.size()][2]; final Iterator<java.lang.String> i = in.keySet().iterator(); int n = 0; while (i.hasNext()) { final Object key = i.next(); final Object val = in.get(key); contents[n][0] = key; contents[n][1] = val; ++n; } return contents; } }; final Map<java.lang.String, java.lang.Object> out = org.apache.commons.collections4.MapUtils.toMap(b); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),7777,in,7776,in.equals(out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }
@org.junit.Test(timeout = 1000) public void testConvertResourceBundle_add2560() { fr.inria.diversify.testamplification.logger.Logger.writeTestStart(Thread.currentThread(),this, "testConvertResourceBundle_add2560"); final Map<java.lang.String, java.lang.String> in = new HashMap<java.lang.String, java.lang.String>(5 , 1); in.put("1", "A"); in.put("2", "B"); in.put("3", "C"); in.put("3", "C"); in.put("4", "D"); in.put("5", "E"); final ResourceBundle b = new ListResourceBundle() { @Override public Object[][] getContents() { final Object[][] contents = new Object[in.size()][2]; final Iterator<java.lang.String> i = in.keySet().iterator(); int n = 0; while (i.hasNext()) { final Object key = i.next(); final Object val = in.get(key); contents[n][0] = key; contents[n][1] = val; ++n; } return contents; } }; final Map<java.lang.String, java.lang.Object> out = org.apache.commons.collections4.MapUtils.toMap(b); fr.inria.diversify.testamplification.logger.Logger.logAssertArgument(Thread.currentThread(),7777,in,7776,in.equals(out)); fr.inria.diversify.testamplification.logger.Logger.writeTestFinish(Thread.currentThread()); }