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.apache.oltu.oauth2.ext.dynamicreg.server.request.JSONHttpServletRequestWrapper.java

public Enumeration<String> getParameterNames() {
    return Collections.enumeration(getParameterMap().keySet());
}

From source file:uk.ac.lancs.e_science.fileUpload.UploadFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;//  w  ww  . j a v a  2  s.co m
    }

    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contentLength = httpRequest.getHeader("Content-Length");
    try {
        if (sizeMax != -1 && contentLength != null && Long.parseLong(contentLength) > sizeMax) {
            ServletException servletEx = new ServletException("Uploaded file size excess maximun legal");
            throw servletEx;
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
        //nothing
    }

    boolean isMultipartContent = FileUpload.isMultipartContent(httpRequest);
    if (!isMultipartContent) {
        chain.doFilter(request, response);
        return;
    }

    DiskFileUpload upload = new DiskFileUpload();
    if (repositoryPath != null)
        upload.setRepositoryPath(repositoryPath);

    try {

        // SAK-13408 - Websphere cannot properly read the request if it has already been parsed and
        // marked by the Apache Commons FileUpload library. The request needs to be buffered so that 
        // it can be reset for subsequent processing
        if ("websphere".equals(ServerConfigurationService.getString("servlet.container"))) {
            HttpServletRequest bufferedInputRequest = new BufferedHttpServletRequestWrapper(httpRequest);
            httpRequest = bufferedInputRequest;
        }

        List list = upload.parseRequest(httpRequest);

        if ("websphere".equals(ServerConfigurationService.getString("servlet.container"))) {
            httpRequest.getInputStream().reset();
        }

        final Map map = new HashMap();
        for (int i = 0; i < list.size(); i++) {
            FileItem item = (FileItem) list.get(i);
            String str = item.getString("UTF-8");
            if (item.isFormField())
                map.put(item.getFieldName(), new String[] { str });
            else
                httpRequest.setAttribute(item.getFieldName(), item);
        }

        chain.doFilter(new HttpServletRequestWrapper(httpRequest) {
            public Map getParameterMap() {
                return map;
            }

            public String[] getParameterValues(String name) {
                Map map = getParameterMap();
                return (String[]) map.get(name);
            }

            public String getParameter(String name) {
                String[] params = getParameterValues(name);
                if (params == null)
                    return null;
                return params[0];
            }

            public Enumeration getParameterNames() {
                Map map = getParameterMap();
                return Collections.enumeration(map.keySet());
            }
        }, response);
    } catch (FileUploadException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
}

From source file:org.mskcc.cbio.portal.util.SessionServiceRequestWrapper.java

@Override
public Enumeration<String> getParameterNames() {
    if (storedParameters != null) {
        LOG.debug(// w ww.j a  v  a 2s .  c  o  m
                "SessionServiceRequestWrapper.getParameterNames(): accessing parameters from stored session with id '"
                        + sessionId + "'");
        return Collections.enumeration(storedParameters.keySet());
    }
    LOG.debug("SessionServiceRequestWrapper.getParameterNames(): accessing current request parameters");
    return super.getParameterNames();
}

From source file:grails.plugin.springsecurity.web.access.GrailsWebInvocationPrivilegeEvaluator.java

static HttpServletRequest createInstance(final String contextPath, final String httpMethod,
        final String requestURI) {
    final Map<String, Object> attributes = new HashMap<String, Object>();

    return (HttpServletRequest) Proxy.newProxyInstance(HttpServletRequest.class.getClassLoader(),
            new Class[] { HttpServletRequest.class }, new InvocationHandler() {
                public Object invoke(Object proxy, Method method, Object[] args) {

                    String methodName = method.getName();

                    if ("getContextPath".equals(methodName))
                        return contextPath;
                    if ("getMethod".equals(methodName))
                        return httpMethod;
                    if ("getRequestURI".equals(methodName))
                        return requestURI;
                    if ("setAttribute".equals(methodName)) {
                        attributes.put((String) args[0], args[1]);
                        return null;
                    }//  ww  w.  j  a  va  2 s. c  o  m
                    if ("getAttribute".equals(methodName)) {
                        return attributes.get(args[0]);
                    }

                    if ("getProtocol".equals(methodName) || "getScheme".equals(methodName))
                        return "http";
                    if ("getServerName".equals(methodName))
                        return "localhost";
                    if ("getServerPort".equals(methodName))
                        return 8080;

                    if (methodName.startsWith("is"))
                        return false;

                    if ("getParameterMap".equals(methodName))
                        return Collections.emptyMap();

                    if ("getAttributeNames".equals(methodName) || "getHeaderNames".equals(methodName)
                            || "getHeaders".equals(methodName) || "getLocales".equals(methodName)
                            || "getParameterNames".equals(methodName)) {
                        return Collections.enumeration(Collections.emptySet());
                    }

                    return null;
                }
            });
}

From source file:org.hdiv.filter.RequestWrapper.java

/**
 * Returns the names of the parameters for this request. The enumeration consists of the normal request parameter
 * names plus the parameters read from the multipart request.
 */// w ww .  j  a  va  2s  .  c  o  m
public Enumeration getParameterNames() {

    Enumeration baseParams = super.getParameterNames();

    if (!this.isMultipart)
        return baseParams;

    Vector list = new Vector();

    while (baseParams.hasMoreElements()) {
        list.add(baseParams.nextElement());
    }

    Collection multipartParams = this.parameters.keySet();
    Iterator iterator = multipartParams.iterator();

    while (iterator.hasNext()) {
        list.add(iterator.next());
    }

    return Collections.enumeration(list);
}

From source file:com.esri.gpt.control.filter.MultipartWrapper.java

/**
 * Gets the form parameter names.//from  w ww .  j  a v a 2  s.com
 * @return the form parameter names
 */
@Override
public Enumeration getParameterNames() {
    return Collections.enumeration(_formParameters.keySet());
}

From source file:eu.planets_project.tb.gui.backing.ListExp.java

public Collection<Experiment> getAllMatchingExperiments() {
    // Otherwise, search for the string toFind:
    log.debug("Searching experiments for: " + toFind);
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    Collection<Experiment> allExps = null;
    // Only go if there is a string to search for:
    if (toFind == null || "".equals(toFind)) {
        allExps = testbedMan.getAllExperiments();
    } else {/*from  w w  w .  j  av a 2s . co  m*/
        allExps = testbedMan.searchAllExperiments(toFind);
    }
    log.debug("Found " + allExps.size() + " matching experiment(s).");
    currExps = Collections.list(Collections.enumeration(allExps));
    sort(getSort(), isAscending());
    return currExps;
}

From source file:org.apache.pdfbox.pdmodel.PDPage.java

@Override
public InputStream getContents() throws IOException {
    COSBase base = page.getDictionaryObject(COSName.CONTENTS);
    if (base instanceof COSStream) {
        return ((COSStream) base).createInputStream();
    } else if (base instanceof COSArray && ((COSArray) base).size() > 0) {
        COSArray streams = (COSArray) base;
        byte[] delimiter = new byte[] { '\n' };
        List<InputStream> inputStreams = new ArrayList<InputStream>();
        for (int i = 0; i < streams.size(); i++) {
            COSStream stream = (COSStream) streams.getObject(i);
            inputStreams.add(stream.createInputStream());
            inputStreams.add(new ByteArrayInputStream(delimiter));
        }/*  w  w w. j a v  a2 s.c  o  m*/
        return new SequenceInputStream(Collections.enumeration(inputStreams));
    }
    return null;
}

From source file:mobac.program.model.Atlas.java

public Enumeration<?> children() {
    return Collections.enumeration(layers);
}

From source file:org.jasig.portal.url.PortalHttpServletRequestWrapperImpl.java

@Override
public Enumeration<?> getHeaders(String name) {
    final Object value = this.additionalHeaders.get(name);
    if (value == null) {
        return super.getHeaders(name);
    }//from  w  w  w  .java 2  s  .c  om

    return Collections.enumeration(Collections.singleton(value));
}