List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospector.java
/** * Applies the given properties to the cached DatastoreContext and yields a new DatastoreContext * instance which can be obtained via {@link getContext}. * * @param properties the properties to apply * @return true if the cached DatastoreContext was updated, false otherwise. *//*from w w w. j ava 2 s . c o m*/ public synchronized boolean update(Dictionary<String, Object> properties) { currentProperties = null; if (properties == null || properties.isEmpty()) { return false; } LOG.debug("In update: properties: {}", properties); ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder(); Builder builder = DatastoreContext.newBuilderFrom(context); final String dataStoreTypePrefix = context.getDataStoreName() + '.'; List<String> keys = getSortedKeysByDatastoreType(Collections.list(properties.keys()), dataStoreTypePrefix); boolean updated = false; for (String key : keys) { Object value = properties.get(key); mapBuilder.put(key, value); // If the key is prefixed with the data store type, strip it off. if (key.startsWith(dataStoreTypePrefix)) { key = key.replaceFirst(dataStoreTypePrefix, ""); } if (convertValueAndInvokeSetter(key, value, builder)) { updated = true; } } currentProperties = mapBuilder.build(); if (updated) { context = builder.build(); } return updated; }
From source file:org.apache.openjpa.persistence.PersistenceProductDerivation.java
private static List<URL> getResourceURLs(String rsrc, ClassLoader loader) throws IOException { List<URL> answer = null; if (RSRC_DEFAULT.equals(rsrc) && defaultPersistenceFiles != null) { answer = new ArrayList(); answer.addAll(defaultPersistenceFiles); }/*from www . j a va 2s . com*/ Enumeration<URL> urls = null; try { urls = (Enumeration) AccessController.doPrivileged(J2DoPrivHelper.getResourcesAction(loader, rsrc)); if (!urls.hasMoreElements()) { if (!rsrc.startsWith("META-INF")) urls = (Enumeration) AccessController .doPrivileged(J2DoPrivHelper.getResourcesAction(loader, "META-INF/" + rsrc)); } } catch (PrivilegedActionException pae) { throw (IOException) pae.getException(); } if (urls.hasMoreElements()) { if (answer == null) { answer = Collections.list(urls); } else { answer.addAll(Collections.list(urls)); } } return answer; }
From source file:com.zz.globalsession.GlobalHttpSession.java
@Override public String toString() { StringBuilder attributes = new StringBuilder(); for (Object attr : Collections.list(getAttributeNames())) { attributes.append(attr);// www.j av a2 s . c o m attributes.append(","); } return "com.m3.globalsession.GlobalHttpSession(id: " + getId() + ", attributes: [" + attributes.toString().replaceFirst(",$", "") + "], creationTime: " + getCreationTime() + ", lastAccessedTime: " + getLastAccessedTime() + ", maxInactiveInterval: " + getMaxInactiveInterval() + ")"; }
From source file:io.cos.cas.authentication.handler.support.OpenScienceFrameworkPrincipalFromRequestRemoteUserNonInteractiveCredentialsAction.java
/** * Abstract method to implement to construct the credential from the * request object.//from w w w.j av a 2 s . c o m * * @param context the context for this request. * @return the constructed credential or null if none could be constructed * from the request. * @throws AccountException a account exception */ protected Credential constructCredentialsFromRequest(final RequestContext context) throws AccountException { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); final OpenScienceFrameworkCredential credential = (OpenScienceFrameworkCredential) context.getFlowScope() .get("credential"); // WARNING: Do not assume this works w/o acceptance testing in a Production environment. // The call is made to trust these headers only because we assume the Apache Shibboleth Service Provider module // rejects any conflicting / forged headers. final String shibbolethSession = request.getHeader(SHIBBOLETH_SESSION_HEADER); if (StringUtils.hasText(shibbolethSession)) { final String remoteUser = request.getHeader(REMOTE_USER); if (StringUtils.isEmpty(remoteUser)) { logger.error("Invalid Remote User specified as Empty"); throw new RemoteUserFailedLoginException("Invalid Remote User specified as Empty"); } logger.info("Remote User from HttpServletRequest '{}'", remoteUser); credential.setRemotePrincipal(Boolean.TRUE); for (final String headerName : Collections.list(request.getHeaderNames())) { if (headerName.startsWith(ATTRIBUTE_PREFIX)) { final String headerValue = request.getHeader(headerName); logger.debug("Remote User [{}] Auth Header '{}': '{}'", remoteUser, headerName, headerValue); credential.getAuthenticationHeaders().put(headerName.substring(ATTRIBUTE_PREFIX.length()), headerValue); } } // Notify the OSF of the remote principal authentication. final PrincipalAuthenticationResult remoteUserInfo = notifyRemotePrincipalAuthenticated(credential); credential.setUsername(remoteUserInfo.getUsername()); credential.setInstitutionId(remoteUserInfo.getInstitutionId()); return credential; } else if (request.getParameter("username") != null && request.getParameter("verification_key") != null) { // Construct credential if presented with (username, verification_key) // This is used when: // 1. User creates an account // 2. User resets the password through forgot_password // 3. User sets password when added as an unregistered contribution // Note: Two-factor sign in works and remain unchanged credential.setUsername(request.getParameter("username")); credential.setVerificationKey(request.getParameter("verification_key")); return credential; } return null; }
From source file:ro.nextreports.designer.wizpublish.DownloadListWizardPanel.java
public void onFinish() { Thread executorThread = new Thread(new Runnable() { public void run() { JDialog parent = (JDialog) context.getAttribute(PublishWizard.MAIN_FRAME); String destinationPath = (String) context.getAttribute(DownloadBulkWizard.DESTINATION); UIActivator activator = new UIActivator(Globals.getMainFrame(), I18NSupport.getString("download"), listModel.size());//www. j a va 2s . co m activator.start(); WebServiceClient client = (WebServiceClient) context.getAttribute(PublishWizard.CLIENT); String entity = (String) context.getAttribute(WizardConstants.ENTITY); try { StringBuilder sbError = new StringBuilder(); StringBuilder sbInfo = new StringBuilder(); if (WizardConstants.ENTITY_REPORT.equals(entity)) { for (Object path : Collections.list(listModel.elements())) { String serverPath = (String) path; String name = getName(serverPath) + FormSaver.REPORT_FULL_EXTENSION; try { ReportMetaData reportMetaData = client.getReport(serverPath); XStream xstream = XStreamFactory.createXStream(); Report report = (Report) xstream.fromXML( new String(reportMetaData.getMainFile().getFileContent(), "UTF-8")); boolean ok = FormSaver.getInstance().save(new File(destinationPath, name), report); sbInfo.append(name).append(" : ").append(I18NSupport.getString("downloaded")) .append("\n"); if (ok) { // save images List<FileMetaData> list = reportMetaData.getImages(); if (list != null) { for (FileMetaData image : list) { FileUtil.createFile( destinationPath + File.separator + image.getFileName(), image.getFileContent()); } } // save template FileMetaData fmd = reportMetaData.getTemplate(); if (fmd != null) { FileUtil.createFile(destinationPath + File.separator + fmd.getFileName(), fmd.getFileContent()); } } } catch (Exception e) { sbError.append(name).append(" : ").append(e.getMessage()).append("\n"); } activator.updateProgress(); } } else { for (Object path : Collections.list(listModel.elements())) { String serverPath = (String) path; String name = getName(serverPath) + ChartUtil.CHART_FULL_EXTENSION; try { ChartMetaData chartMetaData = client.getChart(serverPath); XStream xstream = XStreamFactory.createXStream(); Chart chart = (Chart) xstream .fromXML(new String(chartMetaData.getMainFile().getFileContent(), "UTF-8")); ChartUtil.save(new File(destinationPath, name), chart); sbInfo.append(name).append(" : ").append(I18NSupport.getString("downloaded")) .append("\n"); } catch (Exception e) { sbError.append(name).append(" : ").append(e.getMessage()).append("\n"); } activator.updateProgress(); } } if (sbError.length() > 0) { Show.error(parent, sbInfo.toString() + "\n" + sbError.toString()); } else { Show.info(parent, sbInfo.toString()); } } finally { if (activator != null) { activator.stop(); activator = null; } } } }, "NEXT : " + getClass().getSimpleName()); executorThread.start(); }
From source file:license.ExtraTestWakeLicense.java
/** * ?mac?/*from ww w. j a va2 s. co m*/ * @param sb * @throws Exception */ private static void mac(StringBuilder sb) throws Exception { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); int i = 12; Base64 base64 = new Base64(); for (NetworkInterface ni : Collections.list(interfaces)) { if (ni.getName().substring(0, 1).equalsIgnoreCase("e")) { sb.append(String.valueOf(i)).append('=').append(ni.getName()).append('\n'); i++; byte[] mac = ni.getHardwareAddress(); sb.append(String.valueOf(i)).append('=').append(base64.encodeAsString(mac)).append('\n'); i++; } } }
From source file:org.openhab.ui.cometvisu.internal.util.ClientInstaller.java
/** * Extract the content of the zip file to the target folder * * @param folderName {String} subfolder inside the zip file that should be extracted * @param zipFile {ZipFile} zip-file to extract * @param destDir {String} destination for the extracted files */// ww w.ja va 2s .co m private void extractFolder(String folderName, ZipFile zipFile, String destDir) { for (ZipEntry entry : Collections.list(zipFile.entries())) { if (entry.getName().startsWith(folderName)) { String target = entry.getName().substring(folderName.length()); File file = new File(destDir, target); if (entry.isDirectory()) { file.mkdirs(); } else { if (file.exists() && file.getPath().matches(".*/config/visu_config.*\\.xml")) { // never ever overwrite existing config files continue; } new File(file.getParent()).mkdirs(); try (InputStream is = zipFile.getInputStream(entry); OutputStream os = new FileOutputStream(file);) { for (int len; (len = is.read(buffer)) != -1;) { os.write(buffer, 0, len); } logger.info("extracted zip file {} to folder {}", zipFile.getName(), destDir); } catch (IOException e) { logger.error("error extracting file {}", e.getMessage(), e); } } } } }
From source file:com.technophobia.substeps.report.DefaultExecutionReportBuilder.java
public void copyJarResourcesRecursively(final File destination, final JarURLConnection jarConnection) throws IOException { final JarFile jarFile = jarConnection.getJarFile(); for (final JarEntry entry : Collections.list(jarFile.entries())) { if (entry.getName().startsWith(jarConnection.getEntryName())) { final String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName()); if (!entry.isDirectory()) { InputStream entryInputStream = null; try { entryInputStream = jarFile.getInputStream(entry); FileUtils.copyInputStreamToFile(entryInputStream, new File(destination, fileName)); } finally { IOUtils.closeQuietly(entryInputStream); }//from w w w .ja va 2 s . c om } else { new File(destination, fileName).mkdirs(); } } } }
From source file:psiprobe.tools.ApplicationUtils.java
/** * Gets the application attributes./*from ww w .j ava 2 s . c o m*/ * * @param context the context * @return the application attributes */ public static List<Attribute> getApplicationAttributes(Context context) { List<Attribute> attrs = new ArrayList<>(); ServletContext servletCtx = context.getServletContext(); for (String attrName : Collections.list(servletCtx.getAttributeNames())) { Object attrValue = servletCtx.getAttribute(attrName); Attribute attr = new Attribute(); attr.setName(attrName); attr.setValue(attrValue); attr.setType(ClassUtils.getQualifiedName(attrValue.getClass())); attrs.add(attr); } return attrs; }
From source file:org.apache.jackrabbit.core.TransientRepository.java
/** * Returns the available descriptor keys. If the underlying repository * is initialized, then the call is proxied to it, otherwise the static * descriptor keys are returned./*from ww w.java 2s. c om*/ * * @return descriptor keys */ public synchronized String[] getDescriptorKeys() { if (repository != null) { return repository.getDescriptorKeys(); } else { String[] keys = Collections.list(descriptors.propertyNames()).toArray(new String[0]); Arrays.sort(keys); return keys; } }