List of usage examples for org.springframework.util StringUtils delimitedListToStringArray
public static String[] delimitedListToStringArray(@Nullable String str, @Nullable String delimiter)
From source file:org.openmrs.web.taglib.OpenmrsMessageTag.java
/** * @see MessageTag#resolveArguments(Object) *//*from www .j av a 2s. c om*/ protected Object[] resolveArguments(Object arguments) throws JspException { if (arguments instanceof String) { return StringUtils.delimitedListToStringArray((String) arguments, this.argumentSeparator); } else if (arguments instanceof Object[]) { return (Object[]) arguments; } else if (arguments instanceof Collection) { return ((Collection<?>) arguments).toArray(); } else if (arguments != null) { // Assume a single argument object. return new Object[] { arguments }; } else { return null; } }
From source file:fr.openwide.talendalfresco.alfresco.importer.ContentImporterComponentBase.java
/** * Create a valid path// ww w . ja v a2 s. com * * @param path * @return */ protected String createValidPath(String path) { StringBuffer validPath = new StringBuffer(path.length()); String[] segments = StringUtils.delimitedListToStringArray(path, "/"); for (int i = 0; i < segments.length; i++) { if (segments[i] != null && segments[i].length() > 0) { String[] qnameComponents = QName.splitPrefixedQName(segments[i]); QName segmentQName = QName.createQName(qnameComponents[0], QName.createValidLocalName(qnameComponents[1]), namespaceService); validPath.append(segmentQName.toPrefixString()); } if (i < (segments.length - 1)) { validPath.append("/"); } } return validPath.toString(); }
From source file:com.baidu.rigel.biplatform.tesseract.isservice.search.service.impl.CallbackSearchServiceImpl.java
private SearchIndexResultSet packageResultRecords(QueryRequest query, SqlQuery sqlQuery, Map<CallbackExecutor, CallbackResponse> response) { List<String> groupby = new ArrayList<String>(query.getGroupBy().getGroups()); // Confirm meta sequence List<Entry<CallbackExecutor, CallbackResponse>> fieldValuesHolderList = new ArrayList<Entry<CallbackExecutor, CallbackResponse>>( response.size());// w w w. ja v a2 s .c o m for (Entry<CallbackExecutor, CallbackResponse> e : response.entrySet()) { groupby.addAll(e.getKey().getCallbackMeasures()); fieldValuesHolderList.add(e); } Meta meta = new Meta(groupby.toArray(new String[0])); // default result size 500 SearchIndexResultSet result = new SearchIndexResultSet(meta, 500); // Use first response as base SEQ. Weak implementation. FIXME: WANGYUXUE. List<String> fieldValues = null; for (int index = 0; index < fieldValuesHolderList.get(0).getValue().getData().size(); index++) { fieldValues = new ArrayList<String>(groupby.size()); CallbackMeasureVaue mv = (CallbackMeasureVaue) fieldValuesHolderList.get(0).getValue().getData() .get(index); String key = mv.keySet().iterator().next(); fieldValues.addAll(Arrays.asList(StringUtils.delimitedListToStringArray(key, RESPONSE_VALUE_SPLIT))); fieldValues.addAll(mv.get(key)); for (int i = 1; i < fieldValuesHolderList.size(); i++) { CallbackMeasureVaue callbackMeasureValue = (CallbackMeasureVaue) fieldValuesHolderList.get(i) .getValue().getData().get(index); if (key.equals(callbackMeasureValue.keySet().iterator().next())) { fieldValues.addAll(callbackMeasureValue.get(key)); } else { LOGGER.error("Wrong SEQ of callback response of {} : {}", fieldValuesHolderList.get(i).getKey().group.getKey(), callbackMeasureValue); } } SearchIndexResultRecord record = new SearchIndexResultRecord(fieldValues.toArray(new Serializable[0]), StringUtils.collectionToCommaDelimitedString(fieldValues)); result.addRecord(record); } return result; }
From source file:fr.mby.portal.coreimpl.context.PropertiesAppConfigFactory.java
/** * Process default OPA permissions from config. * //from w w w . java2 s . c om * @param appConfig * @param opaConfig * @throws AppConfigNotFoundException */ protected void processPreferences(final BasicAppConfig appConfig, final Properties opaConfig) { final String preferencesKeysVal = this.getOptionalValue(opaConfig, OpaConfigKeys.PREFERENCES.getKey()); final String[] preferencesKeysArray = StringUtils.delimitedListToStringArray(preferencesKeysVal, IAppConfigFactory.OPA_CONFIG_LIST_SPLITER); if (preferencesKeysArray != null) { final Map<String, String[]> preferencesMap = new HashMap<String, String[]>(preferencesKeysArray.length); for (final String prefKey : preferencesKeysArray) { // Search prefValue final String preferenceVal = this.getOptionalValue(opaConfig, prefKey); final String[] preferenceValArray = StringUtils.delimitedListToStringArray(preferenceVal, IAppConfigFactory.OPA_CONFIG_LIST_SPLITER); preferencesMap.put(prefKey, preferenceValArray); } this.appPreferencesManager.init(appConfig, preferencesMap); } }
From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtil.java
/** * Get a file or folder from the Repository * /* w ww . ja v a 2 s. com*/ * @param site * @param path * @return */ private FileInfo getRepoFileFolder(SiteInfo site, String path) { // Check Alfresco for folder final String[] parts = StringUtils.delimitedListToStringArray(path, "/"); List<String> list = new ArrayList<String>(); for (String part : parts) { list.add(part); } NodeRef rootNodeRef = fileFolderService.searchSimple(site.getNodeRef(), SiteService.DOCUMENT_LIBRARY); try { return fileFolderService.resolveNamePath(rootNodeRef, list, false); } catch (FileNotFoundException e) { return null; } }
From source file:se.alingsas.alfresco.repo.utils.byggreda.ByggRedaUtil.java
/** * Create new or return existing folder/*from w ww .jav a 2 s .c o m*/ * * @param filepath * @param site * @return */ private NodeRef createFolder(final String basePath, final String folderPath, final String folderTitles, final SiteInfo site) { NodeRef rootNodeRef = fileFolderService.searchSimple(site.getNodeRef(), SiteService.DOCUMENT_LIBRARY); String[] parts = StringUtils.delimitedListToStringArray(basePath, "/"); for (String part : parts) { part = StringUtils.trimWhitespace(part); NodeRef folder = fileFolderService.searchSimple(rootNodeRef, part); while (folder == null) { folder = fileFolderService.create(rootNodeRef, part, ContentModel.TYPE_FOLDER).getNodeRef(); nodeService.setProperty(folder, ContentModel.PROP_TITLE, part); } rootNodeRef = folder; } if (folderPath != null) { parts = StringUtils.delimitedListToStringArray(folderPath, "/"); String[] titles; if (folderTitles != null) { titles = StringUtils.delimitedListToStringArray(folderTitles, "#/#"); } else { titles = new String[0]; } for (int i = 0; i < parts.length; i++) { String part = parts[i]; String title; if (titles.length >= i + 1) { title = titles[i]; } else { title = part; } part = StringUtils.trimWhitespace(part); NodeRef folder = fileFolderService.searchSimple(rootNodeRef, part); while (folder == null) { folder = fileFolderService.create(rootNodeRef, part, ContentModel.TYPE_FOLDER).getNodeRef(); nodeService.setProperty(folder, ContentModel.PROP_TITLE, title); } rootNodeRef = folder; } } return rootNodeRef; }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.web.StaticContentServlet.java
private URL[] getRequestResourceURLs(HttpServletRequest request) throws MalformedURLException { final String rawResourcePath = request.getServletPath() + request.getPathInfo(); //The Spring ResourceServlet allowed for combined resource url delimited by ',' as you can see //below but we're not using it since we have one call to the server for each resource by default. //Still I left that code there in case in the future we want to use the feature. final String[] localResourcePaths = StringUtils.delimitedListToStringArray(rawResourcePath, ","); final URL[] resources = new URL[localResourcePaths.length]; for (int i = 0; i < localResourcePaths.length; i++) { final URL resource = getServletContext().getResource(localResourcePaths[i]); if (resource == null) { return null; } else {// ww w . j a va 2 s .com resources[i] = resource; } } return resources; }
From source file:net.solarnetwork.node.setup.obr.OBRProvisionTask.java
private Set<Bundle> findFragmentHostsForBundles(Collection<Bundle> toRefresh) { Set<Bundle> fragmentHosts = new HashSet<Bundle>(); Bundle[] bundles = bundleContext.getBundles(); for (Bundle b : toRefresh) { if (b.getState() == Bundle.UNINSTALLED) { continue; }//ww w . j a v a 2s.c o m String hostHeader = b.getHeaders().get(Constants.FRAGMENT_HOST); if (hostHeader == null) { continue; } String[] clauses = StringUtils.delimitedListToStringArray(hostHeader, ";"); if (clauses == null || clauses.length < 1) { continue; } String hostSymbolicName = clauses[0]; for (Bundle hostBundle : bundles) { if (hostBundle.getSymbolicName() != null && hostBundle.getSymbolicName().equals(hostSymbolicName)) { VersionRange hostVersionRange = null; if (clauses.length > 1) { for (String clause : clauses) { Matcher m = BUNDLE_VERSION_PATTERN.matcher(clause); if (m.find()) { String ver = m.group(1); try { hostVersionRange = new org.osgi.framework.VersionRange(ver); } catch (IllegalArgumentException e) { LOG.warn("Ignoring fragment bundle {} version range syntax error: {}", hostSymbolicName, e.getMessage()); } break; } } } if (hostVersionRange == null || hostVersionRange.includes(hostBundle.getVersion())) { LOG.debug("Found fragment {} host {} to refresh", b, hostBundle); fragmentHosts.add(hostBundle); } continue; } } } return fragmentHosts; }
From source file:org.acegisecurity.ui.digestauth.DigestProcessingFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { throw new ServletException("Can only process HttpServletRequest"); }// ww w .j a v a 2 s . co m if (!(response instanceof HttpServletResponse)) { throw new ServletException("Can only process HttpServletResponse"); } HttpServletRequest httpRequest = (HttpServletRequest) request; String header = httpRequest.getHeader("Authorization"); if (logger.isDebugEnabled()) { logger.debug("Authorization header received from user agent: " + header); } if ((header != null) && header.startsWith("Digest ")) { String section212response = header.substring(7); String[] headerEntries = StringSplitUtils.splitIgnoringQuotes(section212response, ','); Map headerMap = StringSplitUtils.splitEachArrayElementAndCreateMap(headerEntries, "=", "\""); String username = (String) headerMap.get("username"); String realm = (String) headerMap.get("realm"); String nonce = (String) headerMap.get("nonce"); String uri = (String) headerMap.get("uri"); String responseDigest = (String) headerMap.get("response"); String qop = (String) headerMap.get("qop"); // RFC 2617 extension String nc = (String) headerMap.get("nc"); // RFC 2617 extension String cnonce = (String) headerMap.get("cnonce"); // RFC 2617 extension // Check all required parameters were supplied (ie RFC 2069) if ((username == null) || (realm == null) || (nonce == null) || (uri == null) || (response == null)) { if (logger.isDebugEnabled()) { logger.debug("extracted username: '" + username + "'; realm: '" + username + "'; nonce: '" + username + "'; uri: '" + username + "'; response: '" + username + "'"); } fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.missingMandatory", new Object[] { section212response }, "Missing mandatory digest value; received header {0}"))); return; } // Check all required parameters for an "auth" qop were supplied (ie RFC 2617) if ("auth".equals(qop)) { if ((nc == null) || (cnonce == null)) { if (logger.isDebugEnabled()) { logger.debug("extracted nc: '" + nc + "'; cnonce: '" + cnonce + "'"); } fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.missingAuth", new Object[] { section212response }, "Missing mandatory digest value; received header {0}"))); return; } } // Check realm name equals what we expected if (!this.getAuthenticationEntryPoint().getRealmName().equals(realm)) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.incorrectRealm", new Object[] { realm, this.getAuthenticationEntryPoint().getRealmName() }, "Response realm name '{0}' does not match system realm name of '{1}'"))); return; } // Check nonce was a Base64 encoded (as sent by DigestProcessingFilterEntryPoint) if (!Base64.isArrayByteBase64(nonce.getBytes())) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.nonceEncoding", new Object[] { nonce }, "Nonce is not encoded in Base64; received nonce {0}"))); return; } // Decode nonce from Base64 // format of nonce is: // base64(expirationTime + ":" + md5Hex(expirationTime + ":" + key)) String nonceAsPlainText = new String(Base64.decodeBase64(nonce.getBytes())); String[] nonceTokens = StringUtils.delimitedListToStringArray(nonceAsPlainText, ":"); if (nonceTokens.length != 2) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.nonceNotTwoTokens", new Object[] { nonceAsPlainText }, "Nonce should have yielded two tokens but was {0}"))); return; } // Extract expiry time from nonce long nonceExpiryTime; try { nonceExpiryTime = new Long(nonceTokens[0]).longValue(); } catch (NumberFormatException nfe) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.nonceNotNumeric", new Object[] { nonceAsPlainText }, "Nonce token should have yielded a numeric first token, but was {0}"))); return; } // Check signature of nonce matches this expiry time String expectedNonceSignature = DigestUtils .md5Hex(nonceExpiryTime + ":" + this.getAuthenticationEntryPoint().getKey()); if (!expectedNonceSignature.equals(nonceTokens[1])) { fail(request, response, new BadCredentialsException(messages.getMessage("DigestProcessingFilter.nonceCompromised", new Object[] { nonceAsPlainText }, "Nonce token compromised {0}"))); return; } // Lookup password for presented username // NB: DAO-provided password MUST be clear text - not encoded/salted // (unless this instance's passwordAlreadyEncoded property is 'false') boolean loadedFromDao = false; UserDetails user = userCache.getUserFromCache(username); if (user == null) { loadedFromDao = true; try { user = userDetailsService.loadUserByUsername(username); } catch (UsernameNotFoundException notFound) { fail(request, response, new BadCredentialsException( messages.getMessage("DigestProcessingFilter.usernameNotFound", new Object[] { username }, "Username {0} not found"))); return; } if (user == null) { throw new AuthenticationServiceException( "AuthenticationDao returned null, which is an interface contract violation"); } userCache.putUserInCache(user); } // Compute the expected response-digest (will be in hex form) String serverDigestMd5; // Don't catch IllegalArgumentException (already checked validity) serverDigestMd5 = generateDigest(passwordAlreadyEncoded, username, realm, user.getPassword(), ((HttpServletRequest) request).getMethod(), uri, qop, nonce, nc, cnonce); // If digest is incorrect, try refreshing from backend and recomputing if (!serverDigestMd5.equals(responseDigest) && !loadedFromDao) { if (logger.isDebugEnabled()) { logger.debug( "Digest comparison failure; trying to refresh user from DAO in case password had changed"); } try { user = userDetailsService.loadUserByUsername(username); } catch (UsernameNotFoundException notFound) { // Would very rarely happen, as user existed earlier fail(request, response, new BadCredentialsException( messages.getMessage("DigestProcessingFilter.usernameNotFound", new Object[] { username }, "Username {0} not found"))); } userCache.putUserInCache(user); // Don't catch IllegalArgumentException (already checked validity) serverDigestMd5 = generateDigest(passwordAlreadyEncoded, username, realm, user.getPassword(), ((HttpServletRequest) request).getMethod(), uri, qop, nonce, nc, cnonce); } // If digest is still incorrect, definitely reject authentication attempt if (!serverDigestMd5.equals(responseDigest)) { if (logger.isDebugEnabled()) { logger.debug("Expected response: '" + serverDigestMd5 + "' but received: '" + responseDigest + "'; is AuthenticationDao returning clear text passwords?"); } fail(request, response, new BadCredentialsException( messages.getMessage("DigestProcessingFilter.incorrectResponse", "Incorrect response"))); return; } // To get this far, the digest must have been valid // Check the nonce has not expired // We do this last so we can direct the user agent its nonce is stale // but the request was otherwise appearing to be valid if (nonceExpiryTime < System.currentTimeMillis()) { fail(request, response, new NonceExpiredException( messages.getMessage("DigestProcessingFilter.nonceExpired", "Nonce has expired/timed out"))); return; } if (logger.isDebugEnabled()) { logger.debug("Authentication success for user: '" + username + "' with response: '" + responseDigest + "'"); } UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(user, user.getPassword()); authRequest.setDetails(authenticationDetailsSource.buildDetails((HttpServletRequest) request)); SecurityContextHolder.getContext().setAuthentication(authRequest); } chain.doFilter(request, response); }