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:czlab.wabbit.CljPodLoader.java

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    boolean sys = isSystem(name);
    Enumeration<URL> p = !sys ? null : _parent.getResources(name);
    Enumeration<URL> t = (sys && !p.hasMoreElements()) ? null : this.findResources(name);
    List<URL> s = toList(t);
    s.addAll(toList(p));/*from   w w w .  j  av  a  2  s .  c o m*/
    return Collections.enumeration(s);
}

From source file:org.springframework.session.web.http.HttpSessionAdapter.java

@Override
public Enumeration<String> getAttributeNames() {
    checkState();
    return Collections.enumeration(this.session.getAttributeNames());
}

From source file:net.ontopia.utils.ontojsp.FakeServletContext.java

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

From source file:com.pearson.developer.xapi.proxy.AuthFilter.java

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

    HttpServletRequest req = (HttpServletRequest) request;

    // AJAX will preflight xAPI request with OPTIONS request without Authorization header
    if ("OPTIONS".equals(req.getMethod())) {
        chain.doFilter(request, response);
        return;//from w ww  .jav  a  2s  . c o  m
    }

    boolean authorized = false;
    try { // decode and verify the basic auth credentials
        String authHeader = req.getHeader("Authorization");
        authHeader = authHeader.substring("Basic ".length());
        String decodedAuthHeader = new String(Base64.decodeBase64(authHeader), "UTF-8");
        String[] credentials = decodedAuthHeader.split(":");
        if (credentials.length == 2) {
            String username = credentials[0];
            String password = credentials[1];
            authorized = SessionDatabase.verify(username, password);
        }
    } catch (Exception e) {
        // do nothing
    }

    // proceed to xAPI if session was authorized
    if (authorized) {
        final String targetBasicAuth = config.getInitParameter("targetBasicAuth");

        // need to give the LRS it's expected Authorization value
        HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(req) {
            @Override
            public String getHeader(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    return targetBasicAuth;
                }
                return super.getHeader(name);
            }

            @Override
            public Enumeration<String> getHeaders(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    List<String> values = new ArrayList<String>();
                    values.add(targetBasicAuth);
                    return Collections.enumeration(values);
                }
                return super.getHeaders(name);
            }
        };
        chain.doFilter(requestWrapper, response);
        return;
    }

    // respond with a 401 if missing auth
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.reset();
    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    resp.getWriter().println("401 - Unauthorized");
}

From source file:com.jkoolcloud.tnt4j.streams.format.FactPathValueFormatter.java

private static <T> Collection<T> getSortedCollection(Collection<T> col, Comparator<T> comp) {
    List<T> cList;/* www  . ja v  a  2  s. co m*/
    if (col instanceof List<?>) {
        cList = (List<T>) col;
    } else {
        cList = Collections.list(Collections.enumeration(col));
    }
    Collections.sort(cList, comp);

    return cList;
}

From source file:fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest.java

/**
 * Gets the list of filenames attached to the request
 * @return The list as an enumeration/*from www  . jav  a  2s  .co  m*/
 */
public Enumeration getFileNames() {
    return Collections.enumeration(_multipartFiles.keySet());
}

From source file:com.adobe.aem.demomachine.gui.AemDemoUtils.java

public static int[] getDemoAddons(File buildFile) {

    List<Integer> listIndices = new ArrayList<Integer>();

    Properties defaultProps = loadProperties(
            buildFile.getParentFile().getAbsolutePath() + File.separator + "build.properties");
    Properties personalProps = loadProperties(buildFile.getParentFile().getAbsolutePath() + File.separator
            + "conf" + File.separator + "build-personal.properties");

    @SuppressWarnings("serial")
    Properties sortedProps = new Properties() {
        @Override/*from   ww  w. java  2s.c om*/
        public synchronized Enumeration<Object> keys() {
            return Collections.enumeration(new TreeSet<Object>(super.keySet()));
        }
    };
    sortedProps.putAll(defaultProps);

    // Looping through all possible options
    Enumeration<?> e = sortedProps.keys();

    int currentIndice = 0;
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (key.startsWith("demo.addons.") & !(key.endsWith("help") || key.endsWith("label"))) {
            String value = sortedProps.getProperty(key);
            if (personalProps.containsKey(key)) {
                value = personalProps.getProperty(key);
            }
            if (value.equals("true")) {
                listIndices.add(currentIndice);
            }
            currentIndice = currentIndice + 1;
        }
    }
    int[] array = new int[listIndices.size()];
    for (int i = 0; i < listIndices.size(); i++)
        array[i] = listIndices.get(i);
    return array;

}

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

@Test
public void shouldSetRequestInfoAttributeWithIpAddressIfNoSessionCookiePresent() throws Exception {
    List<String> cookies = Arrays.asList("SOME_COOKIE=\"gkdsjlsdijg\"", "ANOTHER_COOKIE=\"soihgweitj\"");
    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.empty(), requestInfo.getCookieValue());
    assertEquals(ipAddress, requestInfo.getRemoteAddress());
    assertEquals(Optional.empty(), requestInfo.getUser());
}

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

public Collection<Experiment> getExperimentsOfUser() {
    // Get all experiments created/owned by the current user  
    // get user id from MB facility
    // get UserBean - grab userid   
    /*List<Experiment> usersExpList = new ArrayList<Experiment>();*/
    UserBean managedUserBean = (UserBean) JSFUtil.getManagedObject("UserBean");
    String userid = managedUserBean.getUserid();
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    /*Iterator<Experiment> iter = testbedMan.getAllExperiments().iterator();        
    while (iter.hasNext()) {/* w w w  . j  ava 2  s.  c om*/
       Experiment exp = iter.next();
       if (userid.equals(exp.getExperimentSetup().getBasicProperties().getExperimenter()))
      usersExpList.add(exp);
    }
    myExps = usersExpList; */
    Collection<Experiment> myExps = testbedMan.getAllExperimentsOfUsers(userid, true);
    currExps = Collections.list(Collections.enumeration(myExps));
    sort(getSort(), isAscending());
    return currExps;
}

From source file:org.opennms.netmgt.config.datacollection.Rrd.java

/**
 * Method enumerateRra./*from  w ww . j a  v  a2 s .  c  om*/
 * 
 * @return an Enumeration over all possible elements of this
 * collection
 */
public Enumeration<String> enumerateRra() {
    return Collections.enumeration(m_rras);
}