List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.opencms.workplace.tools.workplace.logging.CmsLog4JAdminDialog.java
/** * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() *//*from ww w . j a va 2s .com*/ @Override public void executeListSingleActions() throws CmsRuntimeException { // switch a single log-channel to an other logging-level if (getSelectedItem() == null) { return; } // get the log-channel to change the level String logchannnelName = getSelectedItem().getId(); Logger logchannel = LogManager.getLogger(logchannnelName); if (logchannel == null) { return; } // get the selected logging-level with the help of the row Level newLogchannelLevel = null; if (ACTION_LOGGING_LEVEL_DEBUG.equals(getParamListAction())) { newLogchannelLevel = Level.DEBUG; } else if (ACTION_LOGGING_LEVEL_INFO.equals(getParamListAction())) { newLogchannelLevel = Level.INFO; } else if (ACTION_LOGGING_LEVEL_WARN.equals(getParamListAction())) { newLogchannelLevel = Level.WARN; } else if (ACTION_LOGGING_LEVEL_ERROR.equals(getParamListAction())) { newLogchannelLevel = Level.ERROR; } else if (ACTION_LOGGING_LEVEL_FATAL.equals(getParamListAction())) { newLogchannelLevel = Level.FATAL; } else if (ACTION_LOGGING_LEVEL_OFF.equals(getParamListAction())) { newLogchannelLevel = Level.OFF; } if (newLogchannelLevel != null) { isparentlogger(logchannel); if (newLogchannelLevel.equals(logchannel.getParent().getLevel())) { logchannel.setLevel(null); } else { logchannel.setLevel(newLogchannelLevel); } } if (ACTION_ACTIVATE_LOGFILE.equals(getParamListAction())) { String filepath = ""; Layout layout = null; // if the button is activated check the value of the button // the button was active if (isloggingactivated(logchannel)) { // remove the private Appender from logger logchannel.removeAllAppenders(); // activate the heredity so the logger get the appender from parent logger logchannel.setAdditivity(true); } // the button was inactive else { @SuppressWarnings("unchecked") List<Appender> rootAppenders = Collections.list(Logger.getRootLogger().getAllAppenders()); // get the layout and file path from root logger for (Appender appender : rootAppenders) { if (appender instanceof FileAppender) { FileAppender fapp = (FileAppender) appender; filepath = fapp.getFile().substring(0, fapp.getFile().lastIndexOf(File.separatorChar)); layout = fapp.getLayout(); break; } } @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logchannel.getAllAppenders()); // check if the logger has an Appender get his layout for (Appender appender : appenders) { if (appender instanceof FileAppender) { FileAppender fapp = (FileAppender) appender; layout = fapp.getLayout(); break; } } String logfilename = ""; String temp = logchannel.getName(); // check if the logger name begins with "org.opencms" if (logchannel.getName().contains(OPENCMS_CLASS_PREFIX)) { // remove the prefix "org.opencms" from logger name to generate the file name temp = temp.replace(OPENCMS_CLASS_PREFIX, ""); // if the name has suffix if (temp.length() >= 1) { logfilename = filepath + File.separator + "opencms-" + temp.substring(1).replace(".", "-") + ".log"; } // if the name has no suffix else { logfilename = filepath + File.separator + "opencms" + temp.replace(".", "-") + ".log"; } } // if the logger name not begins with "org.opencms" else { logfilename = filepath + File.separator + "opencms-" + temp.replace(".", "-") + ".log"; } FileAppender fapp = null; try { // create new FileAppender for separate log file fapp = new FileAppender(layout, logfilename, true); // set the log file e.g.: "C:\tomcat6\webapps\opencms\WEB-INF\logs" fapp.setName(logchannnelName); } catch (IOException e) { LOG.error(Messages.get().container(Messages.LOG_CREATING_APPENDER_0), e); } // deactivate the heredity so the logger get no longer the appender from parent logger logchannel.setAdditivity(false); // remove all active Appenders from logger logchannel.removeAllAppenders(); // add the new created Appender to the logger logchannel.addAppender(fapp); } } refreshList(); }
From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTests.java
@Test public void buildRequestLocaleMulti() { webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8, da, en;q=0.7"); MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext); List<Locale> expected = asList(new Locale("da"), new Locale("en", "gb"), new Locale("en", "")); assertThat(Collections.list(actualRequest.getLocales()), equalTo(expected)); }
From source file:org.grouplens.lenskit.eval.script.EvalScriptEngine.java
/** * Register a default set of external methods. *//*from w ww . j a v a 2s .c o m*/ @SuppressWarnings({ "rawtypes", "unchecked" }) protected void loadExternalMethods() { Properties props = new Properties(); try { for (URL url : Collections .list(classLoader.getResources("META-INF/lenskit-eval/builders.properties"))) { InputStream istr = url.openStream(); try { props.load(istr); } finally { istr.close(); } } } catch (IOException e) { throw new RuntimeException(e); } for (Map.Entry<Object, Object> prop : props.entrySet()) { String name = prop.getKey().toString(); String command = prop.getValue().toString(); Class cls; try { cls = classLoader.loadClass(name); } catch (ClassNotFoundException e) { logger.warn("command registered for nonexistent class {}", name); continue; } Class cmd; try { cmd = Class.forName(command).asSubclass(Builder.class); } catch (ClassNotFoundException e) { logger.error("command class {} not builder", command); continue; } catch (ClassCastException e) { logger.error("class {} is not a builder", command); continue; } logger.debug("registering {} as builder for {}", command, cls); registerCommand(cls, cmd); } }
From source file:org.apache.felix.webconsole.internal.compendium.ComponentsServlet.java
private void listComponentProperties(JSONWriter jsonWriter, Component inputComponent) { Dictionary propsBook = inputComponent.getProperties(); if (propsBook != null) { JSONArray myBuf = new JSONArray(); TreeSet bookKeys = new TreeSet(Collections.list(propsBook.keys())); for (Iterator keyIter = bookKeys.iterator(); keyIter.hasNext();) { final String key = (String) keyIter.next(); final StringBuffer strBuffer = new StringBuffer(); strBuffer.append(key).append(" = "); Object prop = propsBook.get(key); if (prop.getClass().isArray()) { prop = Arrays.asList((Object[]) prop); }//www . ja v a 2 s .co m strBuffer.append(prop); myBuf.put(strBuffer.toString()); } printKeyVal(jsonWriter, "Properties", myBuf); } }
From source file:com.adamkruger.myipaddressinfo.NetworkInfoFragment.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) private static List<NetworkInterfaceInfo> getNetworkInterfaceInfos() { List<NetworkInterfaceInfo> networkInterfaceInfos = new ArrayList<NetworkInterfaceInfo>(); try {// w w w . ja v a2s.c o m List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface networkInterface : interfaces) { NetworkInterfaceInfo networkInterfaceInfo = new NetworkInterfaceInfo(); networkInterfaceInfo.name = networkInterface.getDisplayName(); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) { byte[] MAC = networkInterface.getHardwareAddress(); if (MAC != null) { StringBuilder stringBuilder = new StringBuilder(18); for (byte b : MAC) { if (stringBuilder.length() > 0) { stringBuilder.append(':'); } stringBuilder.append(String.format("%02x", b)); } networkInterfaceInfo.MAC = stringBuilder.toString(); } networkInterfaceInfo.MTU = networkInterface.getMTU(); } List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses()); for (InetAddress address : addresses) { if (!address.isLoopbackAddress()) { networkInterfaceInfo.ipAddresses.add(InetAddressToString(address)); } } if (networkInterfaceInfo.ipAddresses.size() > 0) { networkInterfaceInfos.add(networkInterfaceInfo); } } } catch (SocketException e) { } return networkInterfaceInfos; }
From source file:com.cloud.agent.AgentShell.java
public void init(String[] args) throws ConfigurationException { final ComponentLocator locator = ComponentLocator.getLocator("agent"); final Class<?> c = this.getClass(); _version = c.getPackage().getImplementationVersion(); if (_version == null) { throw new CloudRuntimeException("Unable to find the implementation version of this agent"); }/* w w w .j av a2 s.c o m*/ s_logger.info("Implementation Version is " + _version); loadProperties(); parseCommand(args); List<String> properties = Collections.list((Enumeration<String>) _properties.propertyNames()); for (String property : properties) { s_logger.debug("Found property: " + property); } _storage = locator.getManager(StorageComponent.class); if (_storage == null) { s_logger.info("Defaulting to using properties file for storage"); _storage = new PropertiesStorage(); _storage.configure("Storage", new HashMap<String, Object>()); } // merge with properties from command line to let resource access // command line parameters for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties().entrySet()) { _properties.put(cmdLineProp.getKey(), cmdLineProp.getValue()); } final Adapters adapters = locator.getAdapters(BackoffAlgorithm.class); final Enumeration en = adapters.enumeration(); while (en.hasMoreElements()) { _backoff = (BackoffAlgorithm) en.nextElement(); break; } if (en.hasMoreElements()) { s_logger.info("More than one backoff algorithm specified. Using the first one "); } if (_backoff == null) { s_logger.info("Defaulting to the constant time backoff algorithm"); _backoff = new ConstantTimeBackoff(); _backoff.configure("ConstantTimeBackoff", new HashMap<String, Object>()); } }
From source file:org.xdi.oxauth.model.crypto.OxAuthCryptoProvider.java
public List<String> getKeyAliases() throws KeyStoreException { return Collections.list(this.keyStore.aliases()); }
From source file:net.sf.jabref.JabRefGUI.java
private void setLookAndFeel() { try {/*from ww w. ja v a 2s . c o m*/ String lookFeel; String systemLookFeel = UIManager.getSystemLookAndFeelClassName(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) { // FIXME: Problems with OpenJDK and GTK L&F // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638 if (System.getProperty("java.runtime.name").contains("OpenJDK")) { // Metal L&F lookFeel = UIManager.getCrossPlatformLookAndFeelClassName(); LOGGER.warn( "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution."); } else { lookFeel = systemLookFeel; } } else { lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL); } // FIXME: Open JDK problem if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel) && !System.getProperty("java.runtime.name").contains("OpenJDK")) { // try to avoid ending up with the ugly Metal L&F Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel(); Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer()); com.jgoodies.looks.Options.setPopupDropShadowEnabled(true); UIManager.setLookAndFeel(lnf); } else { try { UIManager.setLookAndFeel(lookFeel); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // specified look and feel does not exist on the classpath, so use system l&f UIManager.setLookAndFeel(systemLookFeel); // also set system l&f as default Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel); // notify the user JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), Localization.lang( "Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); LOGGER.warn("Unable to find requested look and feel", e); } } } catch (Exception e) { LOGGER.warn("Look and feel could not be set", e); } // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS); if (overrideDefaultFonts) { int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE); UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); for (Object key : Collections.list(keys)) { if ((key instanceof String) && ((String) key).endsWith(".font")) { FontUIResource font = (FontUIResource) UIManager.get(key); font = new FontUIResource(font.getName(), font.getStyle(), fontSize); defaults.put(key, font); } } } }
From source file:org.nuxeo.runtime.datasource.BasicManagedDataSourceFactory.java
/** * Creates and configures a {@link BasicManagedDataSource} instance based on * the given properties.//from ww w . j a v a2s. c o m * * @param properties the datasource configuration properties * @throws Exception if an error occurs creating the data source */ public static DataSource createDataSource(Properties properties) throws Exception { BasicManagedDataSource dataSource = new BasicManagedDataSource(); String value = properties.getProperty(PROP_DEFAULTAUTOCOMMIT); if (value != null) { dataSource.setDefaultAutoCommit(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_DEFAULTREADONLY); if (value != null) { dataSource.setDefaultReadOnly(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_DEFAULTTRANSACTIONISOLATION); if (value != null) { int level = UNKNOWN_TRANSACTIONISOLATION; if ("NONE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_NONE; } else if ("READ_COMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_COMMITTED; } else if ("READ_UNCOMMITTED".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_READ_UNCOMMITTED; } else if ("REPEATABLE_READ".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_REPEATABLE_READ; } else if ("SERIALIZABLE".equalsIgnoreCase(value)) { level = Connection.TRANSACTION_SERIALIZABLE; } else { try { level = Integer.parseInt(value); } catch (NumberFormatException e) { System.err.println("Could not parse defaultTransactionIsolation: " + value); System.err.println("WARNING: defaultTransactionIsolation not set"); System.err.println("using default value of database driver"); level = UNKNOWN_TRANSACTIONISOLATION; } } dataSource.setDefaultTransactionIsolation(level); } value = properties.getProperty(PROP_DEFAULTCATALOG); if (value != null) { dataSource.setDefaultCatalog(value); } value = properties.getProperty(PROP_DRIVERCLASSNAME); if (value != null) { dataSource.setDriverClassName(value); } value = properties.getProperty(PROP_MAXACTIVE); if (value != null) { dataSource.setMaxActive(Integer.parseInt(value)); } value = properties.getProperty(PROP_MAXIDLE); if (value != null) { dataSource.setMaxIdle(Integer.parseInt(value)); } value = properties.getProperty(PROP_MINIDLE); if (value != null) { dataSource.setMinIdle(Integer.parseInt(value)); } value = properties.getProperty(PROP_INITIALSIZE); if (value != null) { dataSource.setInitialSize(Integer.parseInt(value)); } value = properties.getProperty(PROP_MAXWAIT); if (value != null) { dataSource.setMaxWait(Long.parseLong(value)); } value = properties.getProperty(PROP_TESTONBORROW); if (value != null) { dataSource.setTestOnBorrow(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_TESTONRETURN); if (value != null) { dataSource.setTestOnReturn(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_TIMEBETWEENEVICTIONRUNSMILLIS); if (value != null) { dataSource.setTimeBetweenEvictionRunsMillis(Long.parseLong(value)); } value = properties.getProperty(PROP_NUMTESTSPEREVICTIONRUN); if (value != null) { dataSource.setNumTestsPerEvictionRun(Integer.parseInt(value)); } value = properties.getProperty(PROP_MINEVICTABLEIDLETIMEMILLIS); if (value != null) { dataSource.setMinEvictableIdleTimeMillis(Long.parseLong(value)); } value = properties.getProperty(PROP_TESTWHILEIDLE); if (value != null) { dataSource.setTestWhileIdle(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_PASSWORD); if (value != null) { dataSource.setPassword(value); } value = properties.getProperty(PROP_URL); if (value != null) { dataSource.setUrl(value); } value = properties.getProperty(PROP_USERNAME); if (value != null) { dataSource.setUsername(value); } value = properties.getProperty(PROP_VALIDATIONQUERY); if (value != null) { dataSource.setValidationQuery(value); } value = properties.getProperty(PROP_VALIDATIONQUERY_TIMEOUT); if (value != null) { dataSource.setValidationQueryTimeout(Integer.parseInt(value)); } value = properties.getProperty(PROP_ACCESSTOUNDERLYINGCONNECTIONALLOWED); if (value != null) { dataSource.setAccessToUnderlyingConnectionAllowed(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_REMOVEABANDONED); if (value != null) { dataSource.setRemoveAbandoned(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_REMOVEABANDONEDTIMEOUT); if (value != null) { dataSource.setRemoveAbandonedTimeout(Integer.parseInt(value)); } value = properties.getProperty(PROP_LOGABANDONED); if (value != null) { dataSource.setLogAbandoned(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_POOLPREPAREDSTATEMENTS); if (value != null) { dataSource.setPoolPreparedStatements(Boolean.valueOf(value).booleanValue()); } value = properties.getProperty(PROP_MAXOPENPREPAREDSTATEMENTS); if (value != null) { dataSource.setMaxOpenPreparedStatements(Integer.parseInt(value)); } value = properties.getProperty(PROP_INITCONNECTIONSQLS); if (value != null) { StringTokenizer tokenizer = new StringTokenizer(value, ";"); dataSource.setConnectionInitSqls(Collections.list(tokenizer)); } value = properties.getProperty(PROP_CONNECTIONPROPERTIES); if (value != null) { Properties p = getProperties(value); Enumeration<?> e = p.propertyNames(); while (e.hasMoreElements()) { String propertyName = (String) e.nextElement(); dataSource.addConnectionProperty(propertyName, p.getProperty(propertyName)); } } // Managed: initialize XADataSource value = properties.getProperty(PROP_XADATASOURCE); if (value != null) { Class<?> xaDataSourceClass; try { xaDataSourceClass = Class.forName(value); } catch (Throwable t) { throw (SQLException) new SQLException("Cannot load XA data source class '" + value + "'") .initCause(t); } XADataSource xaDataSource; try { xaDataSource = (XADataSource) xaDataSourceClass.newInstance(); } catch (Throwable t) { throw (SQLException) new SQLException("Cannot create XA data source of class '" + value + "'") .initCause(t); } dataSource.setXaDataSourceInstance(xaDataSource); } // DBCP-215 // Trick to make sure that initialSize connections are created if (dataSource.getInitialSize() > 0) { dataSource.getLogWriter(); } // Return the configured DataSource instance return dataSource; }