List of usage examples for org.springframework.util StringUtils trimArrayElements
public static String[] trimArrayElements(String[] array)
From source file:org.cloudfoundry.identity.uaa.authentication.login.Prompt.java
public static Prompt valueOf(String text) { if (!StringUtils.hasText(text)) { return null; }//from w ww. j a v a2 s . com String[] parts = text.split(":"); if (parts.length < 2) { return null; } String name = parts[0].replaceAll("\"", ""); String[] values = parts[1].replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", "").split(","); values = StringUtils.trimArrayElements(values); return new Prompt(name, values[0], values[1]); }
From source file:net.phoenix.thrift.xml.ArgBeanDefinitionParser.java
/** * register to the bean factory;//from w w w .j a v a2 s .c om * * @param element * @param parserContext * @param current */ private void registerBeanDefinition(Element element, ParserContext parserContext, AbstractBeanDefinition current) { try { Element parent = (Element) element.getParentNode(); String argsBeanDefinitionName = parent.getAttribute("id"); String name = argsBeanDefinitionName + "-" + element.getAttribute("name"); String[] alias = null; if (StringUtils.hasLength(name)) { alias = StringUtils.trimArrayElements(StringUtils.commaDelimitedListToStringArray(name)); } BeanDefinitionHolder holder = new BeanDefinitionHolder(current, name, alias); registerBeanDefinition(holder, parserContext.getRegistry()); } catch (BeanDefinitionStoreException ex) { parserContext.getReaderContext().error(ex.getMessage(), element); } }
From source file:org.jmxtrans.embedded.spring.EmbeddedJmxTransFactory.java
@Override public SpringEmbeddedJmxTrans getObject() throws Exception { logger.info("Load JmxTrans with configuration '{}'", configurationUrls); if (embeddedJmxTrans == null) { if (configurationUrls == null) { configurationUrls = Collections.singletonList(DEFAULT_CONFIGURATION_URL); }// w w w. j av a 2 s .c o m ConfigurationParser parser = new ConfigurationParser(); SpringEmbeddedJmxTrans newJmxTrans = new SpringEmbeddedJmxTrans(); newJmxTrans.setObjectName("org.jmxtrans.embedded:type=EmbeddedJmxTrans,name=" + beanName); for (String delimitedConfigurationUrl : configurationUrls) { String[] tokens = StringUtils.commaDelimitedListToStringArray(delimitedConfigurationUrl); tokens = StringUtils.trimArrayElements(tokens); for (String configurationUrl : tokens) { configurationUrl = configurationUrl.trim(); logger.debug("Load configuration {}", configurationUrl); Resource configuration = resourceLoader.getResource(configurationUrl); if (configuration.exists()) { try { parser.mergeEmbeddedJmxTransConfiguration(configuration.getInputStream(), newJmxTrans); } catch (Exception e) { throw new EmbeddedJmxTransException("Exception loading configuration " + configuration, e); } } else if (ignoreConfigurationNotFound) { logger.debug("Ignore missing configuration file {}", configuration); } else { throw new EmbeddedJmxTransException("Configuration file " + configuration + " not found"); } } } embeddedJmxTrans = newJmxTrans; logger.info("Created EmbeddedJmxTrans with configuration {})", configurationUrls); embeddedJmxTrans.start(); } return embeddedJmxTrans; }
From source file:cyrille.xml.xsd.XsomXsdParserSample.java
/** * Dump//from w w w.ja v a 2 s . c o m * * @param dataSourceElementDecl * @param indentation */ private void dumpDbcpDatasource(XSElementDecl dataSourceElementDecl) { XSType dataSourceElementType = dataSourceElementDecl.getType(); Assert.isTrue(dataSourceElementType.isComplexType()); XSComplexType dataSourceComplexType = dataSourceElementType.asComplexType(); XSContentType dataSourceContentType = dataSourceComplexType.getContentType(); Assert.isTrue(dataSourceContentType instanceof XSParticle); XSParticle dataSourceParticle = dataSourceContentType.asParticle(); XSTerm dataSourceTerm = dataSourceParticle.getTerm(); Assert.isTrue(dataSourceTerm.isModelGroup()); XSModelGroup dataSourceModelGroup = dataSourceTerm.asModelGroup(); for (XSParticle configurationElementParticle : dataSourceModelGroup.getChildren()) { XSTerm configurationElementTerm = configurationElementParticle.getTerm(); Assert.isTrue(configurationElementTerm.isElementDecl()); XSElementDecl configurationElementDecl = configurationElementTerm.asElementDecl(); XSType configurationElementType = configurationElementDecl.getType(); Assert.isTrue(configurationElementType.isComplexType()); XSComplexType configurationElementComplexType = configurationElementType.asComplexType(); XSAttributeUse valueAttributeUse = configurationElementComplexType.getAttributeUse("", "value"); Assert.notNull(valueAttributeUse, "'value' attribute not found for " + configurationElementDecl); XSAttributeDecl valueAttributeDeclaration = valueAttributeUse.getDecl(); String valueType = valueAttributeDeclaration.getType().getName(); boolean required = configurationElementParticle.getMinOccurs() == 1; String defaultValue = valueAttributeUse.getDefaultValue() == null ? "" : valueAttributeUse.getDefaultValue().toString(); String documentation = getDocumentation(configurationElementDecl); documentation = documentation.trim(); String[] splittedDocumentation = org.apache.commons.lang.StringUtils.split(documentation, "\n"); splittedDocumentation = StringUtils.trimArrayElements(splittedDocumentation); documentation = StringUtils.arrayToDelimitedString(splittedDocumentation, "<br/>"); System.out.println("|| *{{{" + configurationElementDecl.getName() + "}}}* || " + valueType + " || " + required + " || " + defaultValue + " || " + documentation + " ||"); } }
From source file:org.finra.dm.service.impl.EmrServiceImpl.java
/** * Validates the add groups to EMR cluster master create request. This method also trims request parameters. * * @param request the request.//ww w.j a v a2 s. c o m * * @throws IllegalArgumentException if any validation errors were found. */ private void validateAddSecurityGroupsToClusterMasterRequest(EmrMasterSecurityGroupAddRequest request) throws IllegalArgumentException { // Validate required elements Assert.hasText(request.getNamespace(), "A namespace must be specified."); Assert.hasText(request.getEmrClusterDefinitionName(), "An EMR cluster definition name must be specified."); Assert.hasText(request.getEmrClusterName(), "An EMR cluster name must be specified."); Assert.notEmpty(request.getSecurityGroupIds(), "At least one security group must be specified."); for (String securityGroup : request.getSecurityGroupIds()) { Assert.hasText(securityGroup, "A security group value must be specified."); } // Remove leading and trailing spaces. request.setNamespace(request.getNamespace().trim()); request.setEmrClusterDefinitionName(request.getEmrClusterDefinitionName().trim()); request.setEmrClusterName(request.getEmrClusterName().trim()); String[] trimmedGroups = new String[request.getSecurityGroupIds().size()]; trimmedGroups = StringUtils.trimArrayElements(request.getSecurityGroupIds().toArray(trimmedGroups)); request.setSecurityGroupIds(Arrays.asList(trimmedGroups)); }
From source file:org.openvpms.web.jobs.docload.DocumentLoaderJob.java
/** * Called by the {@link Scheduler} when a {@link Trigger} fires that is associated with the {@code Job}. * * @throws JobExecutionException if there is an exception while executing the job. *//* w ww .j av a 2 s.c o m*/ @Override public void execute(JobExecutionContext context) throws JobExecutionException { Listener listener = null; try { stop = false; IMObjectBean bean = new IMObjectBean(configuration, service); File source = getDir(bean.getString("sourceDir")); if (source == null || !source.exists()) { throw new IllegalStateException("Invalid source directory: " + source); } File target = getDir(bean.getString("targetDir")); if (target == null || !target.exists()) { throw new IllegalStateException("Invalid destination directory: " + target); } String idPattern = bean.getString("idPattern"); boolean overwrite = bean.getBoolean("overwrite"); boolean recurse = bean.getBoolean("recurse"); String[] types = bean.getString("archetypes", "").split(","); types = StringUtils.trimArrayElements(types); boolean logLoad = bean.getBoolean("log"); boolean stopOnError = bean.getBoolean("stopOnError"); IdLoader loader = new IdLoader(source, types, service, transactionManager, recurse, overwrite, Pattern.compile(idPattern)); LoaderListener delegate = logLoad ? new LoggingLoaderListener(log, target) : new DefaultLoaderListener(target); listener = new Listener(delegate); loader.setListener(listener); while (!stop && loader.hasNext()) { if (!loader.loadNext() && stopOnError) { break; } } complete(listener, null); } catch (Throwable exception) { log.error(exception, exception); complete(listener, exception); } }
From source file:org.springframework.flex.config.RemotingAnnotationPostProcessor.java
/** * /*from w ww . j av a 2s .c om*/ * {@inheritDoc} */ public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Set<RemotingDestinationMetadata> remoteBeans = findRemotingDestinations(beanFactory); if (remoteBeans.size() > 0) { Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, "In order for services to be exported via the @RemotingDestination annotation, the current BeanFactory must be a BeanDefinitionRegistry."); } BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory; for (RemotingDestinationMetadata remotingDestinationConfig : remoteBeans) { BeanDefinitionBuilder exporterBuilder = BeanDefinitionBuilder .rootBeanDefinition(RemotingDestinationExporter.class); exporterBuilder.getRawBeanDefinition().setRole(BeanDefinition.ROLE_INFRASTRUCTURE); RemotingDestination remotingDestination = remotingDestinationConfig.getRemotingDestination(); String messageBrokerId = StringUtils.hasText(remotingDestination.messageBroker()) ? remotingDestination.messageBroker() : BeanIds.MESSAGE_BROKER; String destinationId = StringUtils.hasText(remotingDestination.value()) ? remotingDestination.value() : remotingDestinationConfig.getBeanName(); String[] channels = null; for (String channelValue : remotingDestination.channels()) { channelValue = beanFactory.resolveEmbeddedValue(channelValue); String[] parsedChannels = StringUtils .trimArrayElements(StringUtils.commaDelimitedListToStringArray(channelValue)); channels = StringUtils.mergeStringArrays(channels, parsedChannels); } exporterBuilder.addPropertyReference(MESSAGE_BROKER_PROPERTY, messageBrokerId); exporterBuilder.addPropertyValue(SERVICE_PROPERTY, remotingDestinationConfig.getBeanName()); exporterBuilder.addDependsOn(remotingDestinationConfig.getBeanName()); exporterBuilder.addPropertyValue(DESTINATION_ID_PROPERTY, destinationId); exporterBuilder.addPropertyValue(CHANNELS_PROPERTY, channels); exporterBuilder.addPropertyValue(INCLUDE_METHODS_PROPERTY, remotingDestinationConfig.getIncludeMethods()); exporterBuilder.addPropertyValue(EXCLUDE_METHODS_PROPERTY, remotingDestinationConfig.getExcludeMethods()); exporterBuilder.addPropertyValue(SERVICE_ADAPTER_PROPERTY, remotingDestination.serviceAdapter()); BeanDefinitionReaderUtils.registerWithGeneratedName(exporterBuilder.getBeanDefinition(), registry); } }
From source file:org.springframework.flex.remoting.RemotingDestinationExporter.java
/** * Sets the methods to be excluded from the bean being exported * // w w w . ja v a 2 s. com * @param excludeMethods the methods to exclude */ public void setExcludeMethods(String[] excludeMethods) { this.excludeMethods = StringUtils.trimArrayElements(excludeMethods); }
From source file:org.springframework.flex.remoting.RemotingDestinationExporter.java
/** * Sets the methods to included from the bean being exported * /*from w w w .j av a2 s . co m*/ * @param includeMethods the methods to include */ public void setIncludeMethods(String[] includeMethods) { this.includeMethods = StringUtils.trimArrayElements(includeMethods); }
From source file:org.springframework.integration.channel.interceptor.GlobalChannelInterceptorBeanPostProcessor.java
/** * Adds any interceptor whose pattern matches against the channel's name. *//*from ww w . ja v a 2 s . co m*/ private void addMatchingInterceptors(MessageChannel channel, String beanName) { List<ChannelInterceptor> interceptors = this.getExistingInterceptors(channel); if (interceptors != null) { List<GlobalChannelInterceptorWrapper> tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>(); for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.positiveOrderInterceptors) { String[] patterns = globalChannelInterceptorWrapper.getPatterns(); patterns = StringUtils.trimArrayElements(patterns); if (PatternMatchUtils.simpleMatch(patterns, beanName)) { tempInterceptors.add(globalChannelInterceptorWrapper); } } Collections.sort(tempInterceptors, this.comparator); for (GlobalChannelInterceptorWrapper next : tempInterceptors) { interceptors.add(next.getChannelInterceptor()); } tempInterceptors = new ArrayList<GlobalChannelInterceptorWrapper>(); for (GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper : this.negativeOrderInterceptors) { String[] patterns = globalChannelInterceptorWrapper.getPatterns(); patterns = StringUtils.trimArrayElements(patterns); if (PatternMatchUtils.simpleMatch(patterns, beanName)) { tempInterceptors.add(globalChannelInterceptorWrapper); } } Collections.sort(tempInterceptors, comparator); if (!tempInterceptors.isEmpty()) { for (int i = tempInterceptors.size() - 1; i >= 0; i--) { interceptors.add(0, tempInterceptors.get(i).getChannelInterceptor()); } } } else if (logger.isDebugEnabled()) { logger.debug("Global Channel interceptors will not be applied to Channel: " + beanName); } }