Example usage for java.util Collections enumeration

List of usage examples for java.util Collections enumeration

Introduction

In this page you can find the example usage for java.util Collections enumeration.

Prototype

public static <T> Enumeration<T> enumeration(final Collection<T> c) 

Source Link

Document

Returns an enumeration over the specified collection.

Usage

From source file:org.directwebremoting.util.FakeHttpServletRequest.java

public Enumeration<Locale> getLocales() {
    return Collections.enumeration(Arrays.asList(Locale.getDefault()));
}

From source file:com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.java

@Override
public Enumeration<String> getParameterNames() {
    List<String> paramNames = new ArrayList<>();
    paramNames.addAll(request.getQueryStringParameters().keySet());
    paramNames.addAll(urlEncodedFormParameters.keySet());
    return Collections.enumeration(paramNames);
}

From source file:org.darkstar.batch.utils.DarkstarUtils.java

/**
 * Method to Load the Npc Id Mapping Properties
 * @return Mapping Properties//from  w  w  w  . j a  va  2  s.c o  m
 */
public static Properties loadMappingProperties(final Properties configProperties) {
    final Properties mappingProperties = new Properties() {
        private static final long serialVersionUID = 665397466355935210L;

        @Override
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }

        @Override
        public Set<Object> keySet() {
            return Collections.unmodifiableSet(new TreeSet<Object>(super.keySet()));
        }
    };

    try {
        final File mappingFile = new File(
                configProperties.getProperty("mapping_file", "./npcid-mapping.properties"));
        if (mappingFile.exists()) {
            final FileInputStream mappingStream = new FileInputStream(mappingFile);
            mappingProperties.load(mappingStream);
            IOUtils.closeQuietly(mappingStream);
        }
    } catch (final Exception e) {
        throw new RuntimeException("Error Reading Mapping File!", e);
    }

    return mappingProperties;
}

From source file:org.apache.wicket.protocol.http.mock.MockHttpServletRequest.java

/**
 * Get the names of all of the headers.//from   w  w w.  ja v a2s .co  m
 * 
 * @return The header names
 */
@Override
public Enumeration<String> getHeaderNames() {
    return Collections.enumeration(headers.keySet());
}

From source file:org.sakaiproject.entitybroker.util.http.EntityHttpServletRequest.java

public Enumeration getAttributeNames() {
    return Collections.enumeration(attributes.keySet());
}

From source file:org.tinygroup.jspengine.runtime.PageContextImpl.java

private Enumeration<String> doGetAttributeNamesInScope(int scope) {
    switch (scope) {
    case PAGE_SCOPE:
        if (!isNametableInitialized) {
            initializePageScopeNameTable();
        }//from  www  . ja  v a  2 s .com
        return Collections.enumeration(attributes.keySet());

    case REQUEST_SCOPE:
        return request.getAttributeNames();

    case SESSION_SCOPE:
        if (session == null) {
            throw new IllegalStateException(Localizer.getMessage("jsp.error.page.noSession"));
        }
        return session.getAttributeNames();

    case APPLICATION_SCOPE:
        return context.getAttributeNames();

    default:
        throw new IllegalArgumentException("Invalid scope");
    }
}

From source file:org.xwoot.jxta.mock.MockJxtaPeer.java

/** {@inheritDoc} **/
public Enumeration<PeerGroupAdvertisement> getKnownGroups() {

    if (!this.isConnectedToNetwork()) {
        logger.warn("Not connected to network.");
        // return empty enumeration.
        return Collections.enumeration(new ArrayList<PeerGroupAdvertisement>());
    }// w  w w. j  a  v a 2s  .c  o  m

    discoverGroups(null, null);

    return Collections.enumeration(this.localGroupAdvRegistry);
}

From source file:me.tatetian.hs.io.SamplableByteArrayOutputStream.java

/**
 * Gets the current contents of this byte stream as a Input Stream. The
 * returned stream is backed by buffers of <code>this</code> stream,
 * avoiding memory allocation and copy, thus saving space and time.<br>
 * //from   w w  w  .ja v a 2 s.  c o  m
 * @return the current contents of this output stream.
 * @see java.io.ByteArrayOutputStream#toByteArray()
 * @see #reset()
 * @since Commons IO 2.0
 */
private InputStream toBufferedInputStream() {
    int remaining = count;
    if (remaining == 0) {
        return new ClosedInputStream();
    }
    List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
    for (byte[] buf : buffers) {
        int c = Math.min(buf.length, remaining);
        list.add(new ByteArrayInputStream(buf, 0, c));
        remaining -= c;
        if (remaining == 0) {
            break;
        }
    }
    return new SequenceInputStream(Collections.enumeration(list));
}

From source file:org.apache.wicket.protocol.http.mock.MockHttpServletRequest.java

/**
 * Get enumeration of all header values with the given name.
 * /*from w ww.j av  a  2s .co  m*/
 * @param name
 *            The name
 * @return The header values
 */
@Override
public Enumeration<String> getHeaders(final String name) {
    @SuppressWarnings("unchecked")
    List<String> list = (List<String>) headers.get(name);
    if (list == null) {
        list = new ArrayList<String>();
    }
    return Collections.enumeration(list);
}

From source file:org.apache.struts.util.RequestUtils.java

/**
 * <p>Populate the properties of the specified JavaBean from the specified
 * HTTP request, based on matching each parameter name (plus an optional
 * prefix and/or suffix) against the corresponding JavaBeans "property
 * setter" methods in the bean's class. Suitable conversion is done for
 * argument types as described under <code>setProperties</code>.</p>
 * <p/>//from ww w.  j a  v  a 2s . c  o m
 * <p>If you specify a non-null <code>prefix</code> and a non-null
 * <code>suffix</code>, the parameter name must match
 * <strong>both</strong> conditions for its value(s) to be used in
 * populating bean properties. If the request's content type is
 * "multipart/form-data" and the method is "POST", the
 * <code>HttpServletRequest</code> object will be wrapped in a
 * <code>MultipartRequestWrapper</code object.</p>
 *
 * @param bean    The JavaBean whose properties are to be set
 * @param prefix  The prefix (if any) to be prepend to bean property names
 *                when looking for matching parameters
 * @param suffix  The suffix (if any) to be appended to bean property
 *                names when looking for matching parameters
 * @param request The HTTP request whose parameters are to be used to
 *                populate bean properties
 * @throws ServletException if an exception is thrown while setting
 *                          property values
 */
public static void populate(Object bean, String prefix, String suffix, HttpServletRequest request)
        throws ServletException {
    // Build a list of relevant request parameters from this request
    HashMap properties = new HashMap();

    // Iterator of parameter names
    Enumeration names = null;

    // Map for multipart parameters
    Map multipartParameters = null;

    String contentType = request.getContentType();
    String method = request.getMethod();
    boolean isMultipart = false;

    if (bean instanceof ActionForm) {
        ((ActionForm) bean).setMultipartRequestHandler(null);
    }

    MultipartRequestHandler multipartHandler = null;
    if ((contentType != null) && (contentType.startsWith("multipart/form-data"))
            && (method.equalsIgnoreCase("POST"))) {
        // Get the ActionServletWrapper from the form bean
        ActionServletWrapper servlet;

        if (bean instanceof ActionForm) {
            servlet = ((ActionForm) bean).getServletWrapper();
        } else {
            throw new ServletException(
                    "bean that's supposed to be " + "populated from a multipart request is not of type "
                            + "\"org.apache.struts.action.ActionForm\", but type " + "\""
                            + bean.getClass().getName() + "\"");
        }

        // Obtain a MultipartRequestHandler
        multipartHandler = getMultipartHandler(request);

        if (multipartHandler != null) {
            isMultipart = true;

            // Set servlet and mapping info
            servlet.setServletFor(multipartHandler);
            multipartHandler.setMapping((ActionMapping) request.getAttribute(Globals.MAPPING_KEY));

            // Initialize multipart request class handler
            multipartHandler.handleRequest(request);

            //stop here if the maximum length has been exceeded
            Boolean maxLengthExceeded = (Boolean) request
                    .getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);

            if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
                ((ActionForm) bean).setMultipartRequestHandler(multipartHandler);
                return;
            }

            //retrieve form values and put into properties
            multipartParameters = getAllParametersForMultipartRequest(request, multipartHandler);
            names = Collections.enumeration(multipartParameters.keySet());
        }
    }

    if (!isMultipart) {
        names = request.getParameterNames();
    }

    while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        String stripped = name;

        if (prefix != null) {
            if (!stripped.startsWith(prefix)) {
                continue;
            }

            stripped = stripped.substring(prefix.length());
        }

        if (suffix != null) {
            if (!stripped.endsWith(suffix)) {
                continue;
            }

            stripped = stripped.substring(0, stripped.length() - suffix.length());
        }

        Object parameterValue = null;

        if (isMultipart) {
            parameterValue = multipartParameters.get(name);
            parameterValue = rationalizeMultipleFileProperty(bean, name, parameterValue);
        } else {
            parameterValue = request.getParameterValues(name);
        }

        // Populate parameters, except "standard" struts attributes
        // such as 'org.apache.struts.action.CANCEL'
        if (!(stripped.startsWith("org.apache.struts."))) {
            properties.put(stripped, parameterValue);
        }
    }

    // Set the corresponding properties of our bean
    try {
        BeanUtils.populate(bean, properties);
    } catch (Exception e) {
        throw new ServletException("BeanUtils.populate", e);
    } finally {
        if (multipartHandler != null) {
            // Set the multipart request handler for our ActionForm.
            // If the bean isn't an ActionForm, an exception would have been
            // thrown earlier, so it's safe to assume that our bean is
            // in fact an ActionForm.
            ((ActionForm) bean).setMultipartRequestHandler(multipartHandler);
        }
    }
}