Example usage for org.apache.commons.collections4.iterators IteratorEnumeration IteratorEnumeration

List of usage examples for org.apache.commons.collections4.iterators IteratorEnumeration IteratorEnumeration

Introduction

In this page you can find the example usage for org.apache.commons.collections4.iterators IteratorEnumeration IteratorEnumeration.

Prototype

public IteratorEnumeration(final Iterator<? extends E> iterator) 

Source Link

Document

Constructs a new IteratorEnumeration that will use the given iterator.

Usage

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getHeaderNames() {
    return new IteratorEnumeration(headers.keySet().iterator());
}

From source file:de.micromata.genome.gwiki.plugin.GWikiPluginJavaClassLoader.java

@Override
public Enumeration<URL> getResources(String name) throws IOException {
    return new IteratorEnumeration<URL>(getResourceList(name, false).iterator());
}

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getHeaders(String name) {
    List<String> hl = headers.get(name);
    if (hl == null) {
        return new IteratorEnumeration(Collections.EMPTY_LIST.iterator());
    }/*from  w  w  w.j  a  v a  2 s  .  c  o m*/
    return new IteratorEnumeration(hl.iterator());
}

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getAttributeNames() {
    return new IteratorEnumeration(attributes.keySet().iterator());
}

From source file:com.ethercis.vehr.parser.EhrScapeURIParserTest.java

@Test
public void testTemplateQueryParser() throws ServiceManagerException {

    // get a template with templateId = 'template_id'
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id");
    Map<String, String[]> parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    Map<String, String[]> headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);//w w w .  j  ava2s  .c  o  m
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //get an example for a templateId = 'template_id'
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id/example");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template/example", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //get the list of templates
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("GET");
    uriParser.parse(request);
    assertEquals("GET", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());

    //delete a template
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template/template_id");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("DELETE");
    uriParser.parse(request);
    assertEquals("DELETE", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());
    assertEquals("template_id",
            uriParser.identifyParametersAsProperties().getClientProperty("templateId").toString());

    //post a template
    request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn("/rest/v1/template");
    parameters = new HashMap<String, String[]>();
    parameters.put("format", new String[] { "XML" });
    when(request.getParameterMap()).thenReturn(parameters);
    headers = new HashMap<String, String[]>();
    headers.put("Content-Type", new String[] { "application/xml" });
    when(request.getHeaderNames()).thenReturn(new IteratorEnumeration<String>(headers.keySet().iterator()));
    when(request.getHeader("Content-Type")).thenReturn("application/xml");
    when(request.getMethod()).thenReturn("POST");
    uriParser.parse(request);
    assertEquals("POST", uriParser.identifyMethod().toUpperCase());
    assertEquals("rest/v1/template", uriParser.identifyPath());

}

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getLocales() {
    return new IteratorEnumeration(locales.iterator());
}

From source file:de.micromata.genome.test.web.SimHttpServletRequest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public Enumeration getParameterNames() {
    return new IteratorEnumeration(parameters.keySet().iterator());
}

From source file:nl.meg.propertiesutility.Properties.java

public Enumeration<?> propertyNames() {
    Enumeration enumeration = new IteratorEnumeration(stringPropertyNames().iterator());
    return enumeration;
}

From source file:nl.salp.warcraft4j.dev.ui.CascFileTreeNode.java

@Override
public Enumeration children() {
    return new IteratorEnumeration<>(children.iterator());
}

From source file:org.broadleafcommerce.openadmin.web.filter.BroadleafAdminTypedEntityRequestFilter.java

@SuppressWarnings("unchecked")
public boolean isRequestForTypedEntity(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    String servletPath = request.getServletPath();
    if (!servletPath.contains(":")) {
        return false;
    }//  w  w w  . j  a  v a 2 s  .com

    // Find the Admin Section for the typed entity.
    String sectionKey = getSectionKeyFromRequest(request);
    AdminSection typedEntitySection = adminNavigationService.findAdminSectionByURI(sectionKey);

    // If the Typed Entity Section does not exist, continue with the filter chain.
    if (typedEntitySection == null) {
        return false;
    }

    // Check if admin user has access to this section.
    if (!adminUserHasAccess(typedEntitySection)) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access is denied");
        return true;
    }

    // Add the typed entity admin section to the request.
    request.setAttribute("typedEntitySection", typedEntitySection);

    // Find the type and build the new path.
    String type = getEntityTypeFromRequest(request);
    final String forwardPath = servletPath.replace(type, "");

    // Get the type field name on the Entity for the given section.
    String typedFieldName = getTypeFieldName(typedEntitySection);

    // Build out the new parameter map to be forwarded.
    final Map parameters = new LinkedHashMap(request.getParameterMap());
    if (typedFieldName != null) {
        parameters.put(typedFieldName, new String[] { type.substring(1).toUpperCase() });
    }

    // Build our request wrapper.
    final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
        @Override
        public String getParameter(String name) {
            Object temp = parameters.get(name);
            Object[] response = new Object[0];
            if (temp != null) {
                ArrayUtils.addAll(response, temp);
            }
            if (ArrayUtils.isEmpty(response)) {
                return null;
            } else {
                return (String) response[0];
            }
        }

        @Override
        public Map getParameterMap() {
            return parameters;
        }

        @Override
        public Enumeration getParameterNames() {
            return new IteratorEnumeration(parameters.keySet().iterator());
        }

        @Override
        public String[] getParameterValues(String name) {
            return (String[]) parameters.get(name);
        }

        @Override
        public String getServletPath() {
            return forwardPath;
        }
    };
    requestProcessor.process(new ServletWebRequest(wrapper, response));

    // Forward the wrapper to the appropriate path
    wrapper.getRequestDispatcher(wrapper.getServletPath()).forward(wrapper, response);
    return true;
}