List of usage examples for org.apache.commons.collections EnumerationUtils toList
public static List toList(Enumeration enumeration)
From source file:com.silverpeas.look.Ticker.java
public Ticker(List<PublicationDetail> pubs, ResourceLocator settings) { items = new ArrayList<TickerItem>(); for (PublicationDetail pub : pubs) { items.add(new TickerItem(pub)); }// w w w . ja v a2 s. c o m for (String key : (List<String>) EnumerationUtils.toList(settings.getKeys())) { if (key.startsWith("ticker.plugin")) { String param = settings.getString(key, null); if (param != null) { params.put(key.substring(key.lastIndexOf(".") + 1), param); } } } linkOnItem = settings.getBoolean("ticker.linkOnItem", false); }
From source file:com.mkl.websuites.internal.tests.ScenarioFolderTest.java
@SuppressWarnings("unchecked") @Override/*from www . j av a 2s . com*/ protected List<Test> defineTests() { // extracted "smuggled" parameters String stringPath = (String) genericParams[0]; ignoreSubfolders = (boolean) genericParams[1]; // SortingStrategy sortingStrategy = (SortingStrategy) genericParams[2]; Path path = Paths.get(stringPath); List<Test> topLevelFolderTests = new ArrayList<Test>(); TestSuite tempRootSuite = new TestSuite(stringPath); isTopTest = true; processRecursivelyFolder(path, tempRootSuite); // fix for duplicated top folder topLevelFolderTests.addAll(EnumerationUtils.toList(tempRootSuite.tests())); return topLevelFolderTests; }
From source file:info.magnolia.ui.framework.command.ImportZipCommand.java
@Override public boolean execute(Context context) throws Exception { this.context = context; File tmpFile = null;/* w ww . ja v a 2 s. com*/ FileOutputStream tmpStream = null; try { tmpFile = File.createTempFile(ZIP_TMP_FILE_PREFIX, ZIP_TMP_FILE_SUFFIX); tmpStream = new FileOutputStream(tmpFile); IOUtils.copy(inputStream, tmpStream); } catch (IOException e) { log.error("Failed to dump zip file to temp file: ", e); throw e; } finally { IOUtils.closeQuietly(tmpStream); IOUtils.closeQuietly(inputStream); } if (isValid(tmpFile)) { ZipFile zip = new ZipFile(tmpFile, getEncoding()); // We use the ant-1.6.5 zip package to workaround encoding issues of the sun implementation (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499) // For some reason, entries are not in the opposite order as how they appear in most tools - reversing here. // Note that java.util.zip does not show this behaviour, and ant-1.7.1 seems to enumerate entries in alphabetical or random order. // Another alternative might be http://truezip.dev.java.net final List zipEntries = EnumerationUtils.toList(zip.getEntries()); Collections.sort(zipEntries, new Comparator() { @Override public int compare(Object first, Object second) { ZipArchiveEntry firstEntry = ((ZipArchiveEntry) first); ZipArchiveEntry secondEntry = ((ZipArchiveEntry) second); if (firstEntry.isDirectory() != secondEntry.isDirectory()) { // order folders first return Boolean.compare(secondEntry.isDirectory(), firstEntry.isDirectory()); } // order alphabetically return firstEntry.getName().compareTo(secondEntry.getName()); } }); final Iterator it = zipEntries.iterator(); while (it.hasNext()) { ZipArchiveEntry entry = (ZipArchiveEntry) it.next(); processEntry(zip, entry); } context.getJCRSession(getRepository()).save(); } return false; }
From source file:com.mkl.websuites.internal.tests.ScenarioFolderTestTest.java
@Test public void shouldFixRunOnlyOneRootFolderSuite() throws Throwable { //given/*from ww w .j a va2 s . c o m*/ ScenarioFolderTest sut = new ScenarioFolderTest(FOLDERS_BASE + "1", true, SortingStrategy.APLHABETICAL); //when List<junit.framework.Test> definedTests = sut.defineTests(); //then assertThat(definedTests).hasSize(1); assertThat(definedTests.get(0)).isInstanceOf(TestSuite.class); TestSuite root = (TestSuite) definedTests.get(0); assertThat(root.getName()).endsWith("1"); List<?> tests = EnumerationUtils.toList(root.tests()); assertThat(tests).hasSize(4); }
From source file:edu.cornell.mannlib.vitro.webapp.filters.CachingResponseFilter.java
/** * The ETAG from the search index is not specific enough, since we may have * different versions for different languages. Add the Locales from the * request to make it unique.// ww w. j a v a2 s.c o m */ private String produceLanguageSpecificEtag(HttpServletRequest req, String rawEtag) { if (rawEtag == null) { return null; } @SuppressWarnings("unchecked") List<Locale> locales = EnumerationUtils.toList(req.getLocales()); StringBuilder buffer = new StringBuilder("\"").append(rawEtag); for (Locale locale : locales) { buffer.append(locale.toString()); } buffer.append("\""); String etag = buffer.toString().replaceAll("\\s", ""); log.debug("Language-specific ETAG = " + etag); return etag; }
From source file:org.ajax4jsf.tests.MockExternalContext.java
public Map getRequestHeaderValuesMap() { if (null == requestHeaderValuesMap) { requestHeaderValuesMap = new TreeMap(CASE_INSENSITIVE_COMPARATOR); HttpServletRequest request = (HttpServletRequest) getRequest(); for (Enumeration e = request.getHeaderNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); requestHeaderValuesMap.put(name, EnumerationUtils.toList(request.getHeaders(name)).toArray()); }//from w w w . ja v a 2s . co m } return Collections.unmodifiableMap(requestHeaderValuesMap); }
From source file:org.ambraproject.action.FeedbackAction.java
@SuppressWarnings("unchecked") public Map<String, String> getUserSessionAttributes() { final Map<String, String> headers = new LinkedHashMap<String, String>(); final HttpServletRequest request = ServletActionContext.getRequest(); {/* w w w . java 2s. c om*/ final Enumeration headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = (String) headerNames.nextElement(); final List<String> headerValues = EnumerationUtils.toList(request.getHeaders(headerName)); headers.put(headerName, StringUtils.join(headerValues.iterator(), ",")); } } headers.put("server-name", request.getServerName() + ":" + request.getServerPort()); headers.put("remote-addr", request.getRemoteAddr()); headers.put("local-addr", request.getLocalAddr() + ":" + request.getLocalPort()); /* * Keeping this in case more values get passed from the client other than just the visible form * fields */ { final Enumeration parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { final String paramName = (String) parameterNames.nextElement(); final String[] paramValues = request.getParameterValues(paramName); headers.put(paramName, StringUtils.join(paramValues, ",")); } } return headers; }
From source file:org.apache.brooklyn.rest.filter.CsrfTokenFilter.java
@Override public void filter(ContainerRequestContext requestContext) throws IOException { // if header supplied, check it is valid String requiredWhenS = request.getHeader(CSRF_TOKEN_REQUIRED_HEADER); if (Strings.isNonBlank(requiredWhenS) && getRequiredForRequests(requiredWhenS, null) == null) { fail(requestContext,/*from w w w . j av a2s . c o m*/ ApiError.builder().errorCode(Response.Status.BAD_REQUEST) .message(HEADER_OF_COOKIE(CSRF_TOKEN_REQUIRED_HEADER) + " header if supplied must be one of " + Arrays.asList(CsrfTokenRequiredForRequests.values())) .build()); return; } if (!request.isRequestedSessionIdValid()) { // no session; just return return; } @SuppressWarnings("unchecked") List<String> suppliedTokensDefault = EnumerationUtils.toList(request.getHeaders(CSRF_TOKEN_VALUE_HEADER)); @SuppressWarnings("unchecked") List<String> suppliedTokensAngular = EnumerationUtils .toList(request.getHeaders(CSRF_TOKEN_VALUE_HEADER_ANGULAR_NAME)); List<String> suppliedTokens = Lists.newArrayList(suppliedTokensDefault); suppliedTokens.addAll(suppliedTokensAngular); Object requiredToken = request.getSession().getAttribute(CSRF_TOKEN_VALUE_ATTR); CsrfTokenRequiredForRequests whenRequired = (CsrfTokenRequiredForRequests) request.getSession() .getAttribute(CSRF_TOKEN_REQUIRED_ATTR); boolean isRequired; if (whenRequired == null) { if (suppliedTokens.isEmpty()) { log.warn( "No CSRF token expected or supplied but a cookie-session is active: client should be updated" + " (in future CSRF tokens or instructions may be required for session-based clients)" + " - " + Entitlements.getEntitlementContext()); whenRequired = CsrfTokenRequiredForRequests.NONE; } else { // default whenRequired = DEFAULT_REQUIRED_FOR_REQUESTS; } // remember it to suppress warnings subsequently request.getSession().setAttribute(CSRF_TOKEN_REQUIRED_ATTR, whenRequired); } switch (whenRequired) { case NONE: isRequired = false; break; case WRITE: isRequired = !org.eclipse.jetty.http.HttpMethod.GET.toString().equals(requestContext.getMethod()); break; case ALL: isRequired = true; break; default: log.warn("Unexpected " + CSRF_TOKEN_REQUIRED_ATTR + " value " + whenRequired); isRequired = true; } if (Iterables.any(suppliedTokens, Predicates.equalTo(requiredToken))) { // matching token supplied, or not being used return; } if (!isRequired) { // csrf not required, but it doesn't match if (requiredToken != null) { log.trace( "CSRF optional token mismatch: client did not send valid token, but it isn't required so proceeding"); } return; } if (suppliedTokens.isEmpty()) { fail(requestContext, ApiError.builder().errorCode(Response.Status.UNAUTHORIZED) .message(HEADER_OF_COOKIE(CSRF_TOKEN_VALUE_COOKIE) + " header is required, containing token previously returned from server in cookie") .build()); } else { fail(requestContext, ApiError.builder().errorCode(Response.Status.UNAUTHORIZED).message( HEADER_OF_COOKIE(CSRF_TOKEN_VALUE_COOKIE) + " header did not match expected CSRF token") .build()); } }
From source file:org.apache.cocoon.jxpath.CocoonContextHandler.java
public String[] getPropertyNames(Object context) { final Enumeration e = ((Context) context).getAttributeNames(); return (String[]) EnumerationUtils.toList(e).toArray(); }
From source file:org.apache.cocoon.jxpath.CocoonRequestHandler.java
public String[] getPropertyNames(Object request) { final Enumeration e = ((Request) request).getAttributeNames(); return (String[]) EnumerationUtils.toList(e).toArray(); }