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:jp.terasoluna.fw.util.PropertyUtil.java

/**
 * ????? ? &quot;-D&quot; ??? ????
 *//*from  w w w .  j  a v  a 2  s  . c om*/
private static void overrideProperties() {
    Enumeration<String> enumeration = Collections.enumeration(props.keySet());
    while (enumeration.hasMoreElements()) {
        String name = enumeration.nextElement();
        String value = System.getProperty(name);
        if (value != null) {
            props.put(name, value);
        }
    }
}

From source file:org.ovirt.engine.api.common.security.CORSSupportFilter.java

private void lazyInit() throws ServletException {
    // Check if the CORS support is enabled:
    final Boolean enabled = (Boolean) getBackendParameter(ConfigurationValues.CORSSupport);
    if (enabled == null || !enabled) {
        log.info("CORS support is disabled.");
        return;/*from  w w  w  . j  a  va  2s.c  o  m*/
    }

    // Get the allowed origins from the backend configuration:
    final String allowedOrigins = (String) getBackendParameter(ConfigurationValues.CORSAllowedOrigins);
    if (StringUtils.isEmpty(allowedOrigins)) {
        log.warn(
                "The CORS support has been enabled, but the list of allowed origins is empty. This means that CORS "
                        + "support will actually be disabled.");
        return;
    }
    log.info("CORS support is enabled for origins \"{}\".", allowedOrigins);

    // Populate the parameters for the delegate:
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(CORSFilter.PARAM_CORS_ALLOWED_METHODS, "GET,POST,PUT,DELETE");
    parameters.put(CORSFilter.PARAM_CORS_ALLOWED_HEADERS, "Accept,Authorization,Content-Type");
    parameters.put(CORSFilter.PARAM_CORS_ALLOWED_ORIGINS, allowedOrigins);

    // Add all the parameters of this filter to those passed to the delegate, so that the user can override the
    // configuration modifying the web.xml file:
    final Enumeration<String> names = config.getInitParameterNames();
    while (names.hasMoreElements()) {
        final String name = names.nextElement();
        final String value = config.getInitParameter(name);
        parameters.put(name, value);
    }

    // Create the delegate and initialize with the prepared parameters:
    delegate = new CORSFilter();
    delegate.init(new FilterConfig() {
        @Override
        public String getFilterName() {
            return config.getFilterName();
        }

        @Override
        public ServletContext getServletContext() {
            return config.getServletContext();
        }

        @Override
        public String getInitParameter(String name) {
            return parameters.get(name);
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return Collections.enumeration(parameters.keySet());
        }
    });
}

From source file:spring.travel.site.request.RequestInfoInterceptorTest.java

@Test
public void shouldSetRequestInfoAttributeIfSessionCookieIsPresentButEmpty() throws Exception {
    List<String> cookies = Arrays.asList(cookieName + "=");
    when(request.getHeaders("Cookie")).thenReturn(Collections.enumeration(cookies));

    assertTrue(interceptor.preHandle(request, response, new Object()));

    verify(request, times(1)).setAttribute(eq(attributeName), requestCaptor.capture());
    Request requestInfo = requestCaptor.getValue();

    assertEquals(Optional.of(""), requestInfo.getCookieValue());
    assertEquals(ipAddress, requestInfo.getRemoteAddress());
    assertEquals(Optional.empty(), requestInfo.getUser());
}

From source file:org.znerd.yaff.MultipartServletRequestWrapper.java

@Override
public Enumeration getParameterNames() {
    return Collections.enumeration(_parameters.keySet());
}

From source file:org.orbeon.oxf.processor.JFreeChartProcessor.java

protected ChartInfo createChart(org.orbeon.oxf.pipeline.api.PipelineContext context,
        JFreeChartSerializer.ChartConfig chartConfig) {

    Document data = readInputAsDOM4J(context, getInputByName(INPUT_DATA));

    Dataset ds;/*w  w  w .j  a v  a 2 s.  c  o  m*/
    if (chartConfig.getType() == JFreeChartSerializer.ChartConfig.PIE_TYPE
            || chartConfig.getType() == JFreeChartSerializer.ChartConfig.PIE3D_TYPE)
        ds = createPieDataset(chartConfig, data);
    else if (chartConfig.getType() == ChartConfig.XY_LINE_TYPE)
        ds = createXYDataset(chartConfig, data);
    else if (chartConfig.getType() == ChartConfig.TIME_SERIES_TYPE)
        ds = createTimeSeriesDataset(chartConfig, data);
    else
        ds = createDataset(chartConfig, data);

    JFreeChart chart = drawChart(chartConfig, ds);
    ChartRenderingInfo info = new ChartRenderingInfo();

    String file;
    try {
        final ExternalContext.Session session = ((ExternalContext) context
                .getAttribute(PipelineContext.EXTERNAL_CONTEXT)).getSession(true);
        file = ServletUtilities.saveChartAsPNG(chart, chartConfig.getxSize(), chartConfig.getySize(), info,
                new HttpSession() {
                    public Object getAttribute(String s) {
                        return session.getAttributesMap(PortletSession.APPLICATION_SCOPE).get(s);
                    }

                    public Enumeration getAttributeNames() {
                        return Collections.enumeration(
                                session.getAttributesMap(PortletSession.APPLICATION_SCOPE).keySet());
                    }

                    public long getCreationTime() {
                        return session.getCreationTime();
                    }

                    public String getId() {
                        return session.getId();
                    }

                    public long getLastAccessedTime() {
                        return session.getLastAccessedTime();
                    }

                    public int getMaxInactiveInterval() {
                        return session.getMaxInactiveInterval();
                    }

                    public ServletContext getServletContext() {
                        return null;
                    }

                    public HttpSessionContext getSessionContext() {
                        return null;
                    }

                    public Object getValue(String s) {
                        return getAttribute(s);
                    }

                    public String[] getValueNames() {
                        List list = new ArrayList();
                        for (Enumeration e = getAttributeNames(); e.hasMoreElements();) {
                            list.add(e.nextElement());
                        }
                        String[] array = new String[list.size()];
                        list.toArray(array);
                        return array;
                    }

                    public void invalidate() {
                        session.invalidate();
                    }

                    public boolean isNew() {
                        return session.isNew();
                    }

                    public void putValue(String s, Object o) {
                        setAttribute(s, o);
                    }

                    public void removeAttribute(String s) {
                        session.getAttributesMap(PortletSession.APPLICATION_SCOPE).remove(s);
                    }

                    public void removeValue(String s) {
                        removeAttribute(s);
                    }

                    public void setAttribute(String s, Object o) {
                        session.getAttributesMap(PortletSession.APPLICATION_SCOPE).put(s, o);
                    }

                    public void setMaxInactiveInterval(int i) {
                        session.setMaxInactiveInterval(i);
                    }
                });
    } catch (Exception e) {
        throw new OXFException(e);
    }
    return new ChartInfo(info, file);
}

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

public Collection<Experiment> getAllExpAwaitingAuth() {
    // Get the experiments-to-approve list:
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    Collection<Experiment> myExps = testbedMan.getAllExperimentsAwaitingApproval();
    currExps = Collections.list(Collections.enumeration(myExps));
    sort(getSort(), isAscending());/* ww  w.j  ava2  s  . co m*/
    return currExps;
}

From source file:org.opennms.netmgt.config.snmp.Definition.java

/**
 * Method enumerateIpMatch./*w  w w. ja  v a2  s.  c om*/
 * 
 * @return an Enumeration over all possible elements of this
 * collection
 */
public Enumeration<String> enumerateIpMatch() {
    return Collections.enumeration(this._ipMatchList);
}

From source file:org.apache.river.container.classloading.VirtualFileSystemClassLoader.java

@Override
public Enumeration<URL> findResources(final String name) throws IOException {

    Enumeration result = (Enumeration) Security.doPrivileged(new PrivilegedAction<Enumeration>() {

        public Enumeration run() {
            List<URL> urlList = new ArrayList<URL>();
            try {

                List<FileObject> foList = findResourceFileObjects(name);
                for (FileObject fo : foList) {
                    urlList.add(fo.getURL());
                }//from   w  ww . j av  a  2s . c  o m
            } catch (FileSystemException ex) {
                Logger.getLogger(VirtualFileSystemClassLoader.class.getName()).log(Level.SEVERE, null, ex);
            }
            return Collections.enumeration(urlList);
        }
    });
    return result;
}

From source file:com.corejsf.UploadFilter.java

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

    //System.out.println("**** doFilter #1");
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*www .j  a  va2  s. c  o  m*/
    }

    //System.out.println("**** doFilter #2");
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    boolean isMultipartContent = FileUpload.isMultipartContent(httpRequest);
    if (!isMultipartContent) {
        chain.doFilter(request, response);
        return;
    }

    //System.out.println("**** doFilter #3");
    DiskFileUpload upload = new DiskFileUpload();
    if (repositoryPath != null)
        upload.setRepositoryPath(repositoryPath);

    try {
        List list = upload.parseRequest(httpRequest);
        final Map map = new HashMap();
        for (int i = 0; i < list.size(); i++) {
            FileItem item = (FileItem) list.get(i);
            //System.out.println("form filed="+item.getFieldName()+" : "+str);
            if (item.isFormField()) {
                String str = item.getString("UTF-8");
                map.put(item.getFieldName(), new String[] { str });
            } else {
                httpRequest.setAttribute(item.getFieldName(), item);
            }
        }

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

            // busywork follows ... should have been part of the wrapper
            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) {
        log.error(ex.getMessage());
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
}

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

@Override
public Enumeration<?> getHeaderNames() {
    final Set<Object> headerNames = new LinkedHashSet<Object>();

    for (final Enumeration<?> headerNamesEnum = super.getHeaderNames(); headerNamesEnum.hasMoreElements();) {
        final Object name = headerNamesEnum.nextElement();
        headerNames.add(name);//w  w w. jav a  2  s .  c  om
    }

    headerNames.addAll(this.additionalHeaders.keySet());

    return Collections.enumeration(headerNames);
}