List of usage examples for java.util Collections enumeration
public static <T> Enumeration<T> enumeration(final Collection<T> c)
From source file:de.micromata.genome.tpsb.httpmockup.MockServletContext.java
/** Returns an enumeration of all the initialization parameters in the context. */ @Override/*from w ww.ja v a 2s.co m*/ public Enumeration getInitParameterNames() { return Collections.enumeration(this.initParameters.keySet()); }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java
/** * <p>//from ww w .j a v a 2s . c om * This expands wild cards properties.<br /><br /> * Both wildcard expressions and expressions to expand are present in the * same properties object.<br /><br /> * <i>Example</i> * <ul> * <li><b>property with wildcard</b>: /root/element[*]/key=new_value</li> * <li><b>property matching</b>: /root/element[my_name]/key=old_value</li> * </ul> * will expand to:<br /> * <ul> * <li><b>property after expansion</b>: * /root/element[my_name]/key=new_value</li> * </ul> * </p> * * @param properties, the properties object with wildcard expressions and * expressions to expand * @return properties with expanded expressions, but without wildcard * expressions */ protected Properties expandWildCards(Properties properties) { Properties propertiesWithWildCards = new Properties() { // sorted properties private static final long serialVersionUID = 7793482336210629858L; @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; String key; // retrieve the keys with WildCards Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { key = (String) e.nextElement(); if (isAWildCard(key)) { propertiesWithWildCards.setProperty(key, properties.getProperty(key)); properties.remove(key); } } // try to replace the values of other keys matching the keys with WildCards Enumeration<Object> w = propertiesWithWildCards.keys(); while (w.hasMoreElements()) { String keyWithWildCards = (String) w.nextElement(); String regex = wildcardToRegex(keyWithWildCards); String ignoreWildcardInVariablesPattern = "(.*)variables\\\\\\[(.*)\\\\\\]\\/variable\\\\\\[(.*)\\\\\\](.*)"; Pattern p = Pattern.compile(ignoreWildcardInVariablesPattern); Matcher m = p.matcher(regex); if (m.matches()) { String variables = m.group(2); String variable = m.group(3); variables = variables.replace(".*", "\\*"); variable = variable.replace(".*", "\\*"); regex = m.group(1) + "variables\\[" + variables + "\\]/variable\\[" + variable + "\\]" + m.group(4); } Boolean found = false; e = properties.keys(); while (e.hasMoreElements()) { key = (String) e.nextElement(); if (Pattern.matches(regex, key)) { found = true; String value = (String) propertiesWithWildCards.getProperty(keyWithWildCards); properties.setProperty(key, value); } } // not found, we put back the expression with wild cards in the original list (false positive) // this way the wildcard can still be used in a next pass and will be removed at the end by AbstractPackagingMojo.removeWildCards if (!found) { properties.setProperty(keyWithWildCards, propertiesWithWildCards.getProperty(keyWithWildCards)); } } return properties; }
From source file:org.apache.myfaces.webapp.filter.MultipartRequestWrapper.java
public Enumeration getParameterNames() { if (parametersMap == null) parseRequest();/*from w w w . j av a2 s .c o m*/ //return Collections.enumeration( parametersMap.keySet() ); HashSet mergedNames = new HashSet(request.getParameterMap().keySet()); mergedNames.addAll(parametersMap.keySet()); return Collections.enumeration(mergedNames); }
From source file:com.nmote.io.ByteArrayOutputStream.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 2s.c om * @return the current contents of this output stream. * @see java.io.ByteArrayOutputStream#toByteArray() * @see #reset() * @since Commons IO 2.0 */ public 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:jp.terasoluna.fw.util.PropertyUtil.java
/** * ????? ??//from w w w . j ava2 s. c o m * @param localProps * @param keyPrefix * @return ??? */ public static Enumeration<String> getPropertyNames(Properties localProps, String keyPrefix) { if (localProps == null || keyPrefix == null) { return null; } Collection<String> matchedNames = new ArrayList<String>(); Enumeration<?> propNames = localProps.propertyNames(); while (propNames.hasMoreElements()) { String name = (String) propNames.nextElement(); if (name.startsWith(keyPrefix)) { matchedNames.add(name); } } return Collections.enumeration(matchedNames); }
From source file:com.adobe.acs.commons.http.headers.impl.AbstractDispatcherCacheHeaderFilterTest.java
@Test public void testDoFilterInvalidServerAgent() throws Exception { agents.add("Not-Day-Communique-Dispatcher"); when(request.getHeaders(AbstractDispatcherCacheHeaderFilter.SERVER_AGENT_NAME)) .thenReturn(Collections.enumeration(agents)); filter.doFilter(request, response, chain); verify(chain).doFilter(request, response); verify(request).getHeaders(AbstractDispatcherCacheHeaderFilter.SERVER_AGENT_NAME); verify(request).getMethod();/*from w ww . j a va2 s.co m*/ verify(request).getParameterMap(); verifyNoMoreInteractions(request, this.request, response, chain); }
From source file:org.debux.webmotion.server.call.ClientSession.java
@Override public Enumeration<String> getAttributeNames() { String[] names = getValueNames(); List<String> list = Arrays.asList(names); return Collections.enumeration(list); }
From source file:com.app.framework.web.MultipartFilter.java
/** * Wrap the given HttpServletRequest with the given parameterMap. * * @param request The HttpServletRequest of which the given parameterMap * have to be wrapped in./*from w w w . j a v a2 s . c om*/ * @param parameterMap The parameterMap to be wrapped in the given * HttpServletRequest. * @return The HttpServletRequest with the parameterMap wrapped in. */ private static HttpServletRequest wrapRequest(HttpServletRequest request, final Map<String, String[]> parameterMap) { return new HttpServletRequestWrapper(request) { public Map<String, String[]> getParameterMap() { return parameterMap; } public String[] getParameterValues(String name) { return parameterMap.get(name); } public String getParameter(String name) { String[] params = getParameterValues(name); return params != null && params.length > 0 ? params[0] : null; } public Enumeration<String> getParameterNames() { return Collections.enumeration(parameterMap.keySet()); } }; }
From source file:org.jaffa.presentation.portlet.CustomRequestProcessor.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>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 * * @exception ServletException if an exception is thrown while setting * property values// w w w. j ava 2s . co m */ protected static void customRequestUtilsPopulate(Object bean, String prefix, String suffix, HttpServletRequest request, ActionMapping mapping) 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 ((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 MultipartRequestHandler multipartHandler = getMultipartHandler(request); // 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); 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())) { // *** Jaffa-customization: Do not just terminate form population. Instead throw a ServletException *** //return; throw new ServletException( "The size of the file being uploaded exceeds the maximum allowed " + ModuleUtils .getInstance().getModuleConfig(request).getControllerConfig().getMaxFileSize()); } //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); } 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); } } // *** Jaffa-customization: Reset the bean *** try { if (log.isDebugEnabled()) log.debug("Calling FormBean reset()"); ((ActionForm) bean).reset(mapping, request); } catch (Exception e) { throw new ServletException("FormBean.reset", e); } // Set the corresponding properties of our bean try { BeanUtils.populate(bean, properties); } catch (Exception e) { throw new ServletException("BeanUtils.populate", e); } }
From source file:org.apache.wicket.protocol.http.mock.MockHttpServletRequest.java
/** * Get the names of all of the values.//from w w w .ja va 2 s . c o m * * @return The names */ @Override public Enumeration<String> getAttributeNames() { return Collections.enumeration(attributes.keySet()); }