Example usage for org.springframework.util StringUtils tokenizeToStringArray

List of usage examples for org.springframework.util StringUtils tokenizeToStringArray

Introduction

In this page you can find the example usage for org.springframework.util StringUtils tokenizeToStringArray.

Prototype

public static String[] tokenizeToStringArray(@Nullable String str, String delimiters) 

Source Link

Document

Tokenize the given String into a String array via a StringTokenizer .

Usage

From source file:info.sargis.eventbus.config.EventBusHandlerBeanDefinitionParser.java

protected Set<RuntimeBeanReference> getHandlers(Element element, ParserContext parserContext) {

    String[] basePackages = StringUtils.tokenizeToStringArray(element.getAttribute(BASE_PACKAGE_ATTRIBUTE),
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);

    ClassPathBeanDefinitionScanner scanner = configureScanner(parserContext, element);
    Set<RuntimeBeanReference> candidates = new ManagedSet<RuntimeBeanReference>(32);

    for (String basePackage : basePackages) {
        Set<BeanDefinition> components = scanner.findCandidateComponents(basePackage);
        for (BeanDefinition component : components) {
            if (isEventBusHandlerCandidate(component, parserContext)) {
                candidates.add(defineRuntimeBeanReference(parserContext, component));
            } else {
                logger.warn(String.format(
                        "Found EventBus handler candidate: %s, but without @Subscribe annotation on any public method",
                        component));/*from w w  w .ja va2  s  .c o m*/
            }
        }
    }

    return candidates;
}

From source file:com.github.persapiens.jsfboot.security.AuthorizeFaceletsTag.java

void setIfNotGranted(String ifNotGranted) {
    String[] roles = StringUtils.tokenizeToStringArray(ifNotGranted, ",");
    if (!ObjectUtils.isEmpty(roles)) {
        String expression = toHasAnyRoleExpression(roles, true);
        setAccess(getAccess() != null ? getAccess() + AND + expression : expression);
    }//from  ww  w .  ja v  a  2  s . c  o  m
}

From source file:org.sakaiproject.login.springframework.SakaiHomeContextLoader.java

/**
 * Initialize the local ApplicationContext, link it to the shared context, and load shared definitions into the shared context.
 *
 * @param servletContext current servlet context
 * @return the new WebApplicationContext
 * @throws org.springframework.beans.BeansException
 *          if the context couldn't be initialized
 *///from  ww  w  .j  a  v a 2  s  .co m
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) throws BeansException {

    WebApplicationContext rv = super.initWebApplicationContext(servletContext);
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) rv;

    if (configurableApplicationContext != null) {
        String sakaiHomeLocation = servletContext.getInitParameter(SAKAI_HOME_LOCATION_PARAM);
        String servletContextName = rv.getServletContext().getServletContextName();
        if (sakaiHomeLocation == null || sakaiHomeLocation.length() == 0) {
            sakaiHomeLocation = servletContextName + SAKAI_HOME_CONTEXT_SUFFIX;
        }
        if (sakaiHomeLocation != null) {
            final String sakaiHomePath = ServerConfigurationService.getSakaiHomePath();

            String[] locations = StringUtils.tokenizeToStringArray(sakaiHomeLocation,
                    ConfigurableWebApplicationContext.CONFIG_LOCATION_DELIMITERS);
            if (locations != null) {

                XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(
                        (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory());

                for (int i = 0; i < locations.length; i++) {
                    String resourcePath = sakaiHomePath + locations[i];
                    M_log.debug(
                            servletContextName + " is attempting to load Spring beans from: " + resourcePath);
                    if (new File(resourcePath).exists()) {
                        reader.loadBeanDefinitions(new FileSystemResource(resourcePath));
                    } else {
                        M_log.info(servletContext + " startup is skipping introspection of the resource: "
                                + resourcePath + " because it does not exist.");
                    }
                }
            }
        }
    }

    return rv;
}

From source file:org.javelin.sws.ext.bind.SweJaxbContextFactory.java

/**
 * <p>Determines mapped classes in the context path and invokes {@link #createContext(Class[], Map)}</p>
 * <p>JAXB-RI uses {@code ObjectFactory} class and/or {@code jaxb.index} file</p>
 * <p>see: com.sun.xml.bind.v2.ContextFactory.createContext(String, ClassLoader, Map<String, Object>)</p>
 * /*from   w w  w  .ja  va 2 s  .c  o m*/
 * @param contextPath
 * @param classLoader
 * @param properties
 * @return
 * @throws IOException 
 */
public static JAXBContext createContext(String contextPath, ClassLoader classLoader, Map<String, ?> properties)
        throws IOException {
    Assert.notNull(contextPath, "The contextPath should not be null");

    PathMatchingResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(
            classLoader);
    MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resourcePatternResolver);

    List<Class<?>> classes = new LinkedList<Class<?>>();
    // scan the package(s)
    String[] packages = StringUtils.tokenizeToStringArray(contextPath, ":");
    for (String pkg : packages) {
        log.trace("Scanning package: {}", pkg);
        Resource[] resources = resourcePatternResolver
                .getResources(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX
                        + ClassUtils.convertClassNameToResourcePath(pkg) + "/*.class");
        for (Resource classResource : resources) {
            MetadataReader mdReader = metadataReaderFactory.getMetadataReader(classResource);
            Class<?> cls = ClassUtils.resolveClassName(mdReader.getClassMetadata().getClassName(), classLoader);
            if (cls.getSimpleName().equals("package-info")) {
                XmlSchema xmlSchema = AnnotationUtils.getAnnotation(cls.getPackage(), XmlSchema.class);
                String namespace = xmlSchema == null || xmlSchema.namespace() == null
                        ? NamespaceUtils.packageNameToNamespace(cls.getPackage())
                        : xmlSchema.namespace();
                log.trace(" - found package-info: {}, namespace: {}", cls.getPackage().getName(), namespace);
            } else {
                log.trace(" - found class: {}", mdReader.getClassMetadata().getClassName());
                classes.add(cls);
            }
        }
    }

    return createContext(classes.toArray(new Class[0]), properties);
}

From source file:com.freebox.engeneering.application.web.common.ApplicationContextListener.java

/**
 * Reads config locations from initParameter.
 * @param context the web application context.
 * @param initParameter the init parameter.
 * @return the array of config locations.
 *//*from   w  ww.  jav a 2s .c  o  m*/
private String[] getConfigLocations(WebApplicationContext context, String initParameter) {
    String[] configLocations = null;
    if (initParameter != null) {
        final String[] locations = StringUtils.tokenizeToStringArray(initParameter, CONFIG_LOCATION_DELIMITERS);
        if (locations != null) {
            Assert.noNullElements(locations, "Config locations must not be null");
            configLocations = new String[locations.length];
            for (int i = 0; i < locations.length; i++) {
                configLocations[i] = context.getEnvironment().resolveRequiredPlaceholders(locations[i]).trim();
            }
        }
    }
    return configLocations != null ? configLocations : getDefaultConfigLocations();
}

From source file:org.jasig.ssp.util.importer.job.tasklet.BatchInitializer.java

private void removeInvalidFiles()
        throws UnsupportedEncodingException, IOException, PartialUploadGuardException {
    TableColumnMetaDataRepository repo = metadataRepository.getRepository().getColumnMetadataRepository();
    Boolean missingKeysFound = false;
    String exceptionMessage = "";
    String EOL = System.getProperty("line.separator");
    List<String> tableNames = new ArrayList<String>();
    for (Resource resource : resources) {
        String fileName = resource.getFilename();
        String[] tableName = fileName.split("\\.");

        BufferedReader reader = bufferedReaderFactory.create(resource, encoding);
        String[] headers = StringUtils.tokenizeToStringArray(reader.readLine(), ",");
        TableReference tableReference = new TableReference(tableName[0]);
        tableNames.add(EOL + tableName[0]);
        TableMetadata tableMetadato = repo.getTableMetadata(tableReference);
        Map<String, String> tableMap = new HashMap<String, String>();
        for (String header : headers)
            tableMap.put(header, header);

        if (!tableMetadato.hasKeys(tableMap)) {
            missingKeysFound = true;//from   w w  w. j av a 2s. c  om
            List<String> missingKeys = tableMetadato.missingKeys(tableMap);
            exceptionMessage = exceptionMessage + "Table: " + tableName[0]
                    + " can not be processed. Missing headers: "
                    + StringUtils.collectionToCommaDelimitedString(missingKeys) + EOL;
        }
    }

    if (missingKeysFound) {
        exceptionMessage = exceptionMessage + "All Tables Not Processed: "
                + StringUtils.collectionToCommaDelimitedString(tableNames) + EOL;
        throw new PartialUploadGuardException(exceptionMessage);
    }
}

From source file:com.riptide.plugins.jenkins.cloudfront.utils.AntPathMatcher.java

/**
 * Actually match the given <code>path</code> against the given <code>pattern</code>.
 *
 * @param pattern   the pattern to match against
 * @param path      the path String to test
 * @param fullMatch whether a full pattern match is required (else a pattern match as far as the given base path goes
 *                  is sufficient)/*from  w w w .j  a  v  a2s. c o  m*/
 * @return <code>true</code> if the supplied <code>path</code> matched, <code>false</code> if it didn't
 */
protected boolean doMatch(String pattern, String path, boolean fullMatch,
        Map<String, String> uriTemplateVariables) {
    if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
        return false;
    }

    String[] pattDirs = StringUtils.tokenizeToStringArray(pattern, this.pathSeparator);
    String[] pathDirs = StringUtils.tokenizeToStringArray(path, this.pathSeparator);

    int pattIdxStart = 0;
    int pattIdxEnd = pattDirs.length - 1;
    int pathIdxStart = 0;
    int pathIdxEnd = pathDirs.length - 1;

    // Match all elements up to the first **
    while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
        String patDir = pattDirs[pattIdxStart];
        if ("**".equals(patDir)) {
            break;
        }
        if (!matchStrings(patDir, pathDirs[pathIdxStart], uriTemplateVariables)) {
            return false;
        }
        pattIdxStart++;
        pathIdxStart++;
    }

    if (pathIdxStart > pathIdxEnd) {
        // Path is exhausted, only match if rest of pattern is * or **'s
        if (pattIdxStart > pattIdxEnd) {
            return (pattern.endsWith(this.pathSeparator) ? path.endsWith(this.pathSeparator)
                    : !path.endsWith(this.pathSeparator));
        }
        if (!fullMatch) {
            return true;
        }
        if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*")
                && path.endsWith(this.pathSeparator)) {
            return true;
        }
        for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
            if (!pattDirs[i].equals("**")) {
                return false;
            }
        }
        return true;
    } else if (pattIdxStart > pattIdxEnd) {
        // String not exhausted, but pattern is. Failure.
        return false;
    } else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
        // Path start definitely matches due to "**" part in pattern.
        return true;
    }

    // up to last '**'
    while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
        String patDir = pattDirs[pattIdxEnd];
        if (patDir.equals("**")) {
            break;
        }
        if (!matchStrings(patDir, pathDirs[pathIdxEnd], uriTemplateVariables)) {
            return false;
        }
        pattIdxEnd--;
        pathIdxEnd--;
    }
    if (pathIdxStart > pathIdxEnd) {
        // String is exhausted
        for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
            if (!pattDirs[i].equals("**")) {
                return false;
            }
        }
        return true;
    }

    while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
        int patIdxTmp = -1;
        for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
            if (pattDirs[i].equals("**")) {
                patIdxTmp = i;
                break;
            }
        }
        if (patIdxTmp == pattIdxStart + 1) {
            // '**/**' situation, so skip one
            pattIdxStart++;
            continue;
        }
        // Find the pattern between padIdxStart & padIdxTmp in str between
        // strIdxStart & strIdxEnd
        int patLength = (patIdxTmp - pattIdxStart - 1);
        int strLength = (pathIdxEnd - pathIdxStart + 1);
        int foundIdx = -1;

        strLoop: for (int i = 0; i <= strLength - patLength; i++) {
            for (int j = 0; j < patLength; j++) {
                String subPat = pattDirs[pattIdxStart + j + 1];
                String subStr = pathDirs[pathIdxStart + i + j];
                if (!matchStrings(subPat, subStr, uriTemplateVariables)) {
                    continue strLoop;
                }
            }
            foundIdx = pathIdxStart + i;
            break;
        }

        if (foundIdx == -1) {
            return false;
        }

        pattIdxStart = patIdxTmp;
        pathIdxStart = foundIdx + patLength;
    }

    for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
        if (!pattDirs[i].equals("**")) {
            return false;
        }
    }

    return true;
}

From source file:org.mybatis.spring.config.MapperScannerBeanDefinitionParser.java

/**
 * {@inheritDoc}/*from w  w w. j a  va 2  s .  c  o  m*/
 */
@Override
public synchronized BeanDefinition parse(Element element, ParserContext parserContext) {
    ClassPathMapperScanner scanner = new ClassPathMapperScanner(parserContext.getRegistry());
    ClassLoader classLoader = scanner.getResourceLoader().getClassLoader();
    XmlReaderContext readerContext = parserContext.getReaderContext();
    scanner.setResourceLoader(readerContext.getResourceLoader());
    try {
        String annotationClassName = element.getAttribute(ATTRIBUTE_ANNOTATION);
        if (StringUtils.hasText(annotationClassName)) {
            @SuppressWarnings("unchecked")
            Class<? extends Annotation> markerInterface = (Class<? extends Annotation>) classLoader
                    .loadClass(annotationClassName);
            scanner.setAnnotationClass(markerInterface);
        }
        String markerInterfaceClassName = element.getAttribute(ATTRIBUTE_MARKER_INTERFACE);
        if (StringUtils.hasText(markerInterfaceClassName)) {
            Class<?> markerInterface = classLoader.loadClass(markerInterfaceClassName);
            scanner.setMarkerInterface(markerInterface);
        }
        String nameGeneratorClassName = element.getAttribute(ATTRIBUTE_NAME_GENERATOR);
        if (StringUtils.hasText(nameGeneratorClassName)) {
            Class<?> nameGeneratorClass = classLoader.loadClass(nameGeneratorClassName);
            BeanNameGenerator nameGenerator = BeanUtils.instantiateClass(nameGeneratorClass,
                    BeanNameGenerator.class);
            scanner.setBeanNameGenerator(nameGenerator);
        }
    } catch (Exception ex) {
        readerContext.error(ex.getMessage(), readerContext.extractSource(element), ex.getCause());
    }
    String sqlSessionTemplateBeanName = element.getAttribute(ATTRIBUTE_TEMPLATE_REF);
    scanner.setSqlSessionTemplateBeanName(sqlSessionTemplateBeanName);
    String sqlSessionFactoryBeanName = element.getAttribute(ATTRIBUTE_FACTORY_REF);
    scanner.setSqlSessionFactoryBeanName(sqlSessionFactoryBeanName);
    scanner.registerFilters();
    String basePackage = element.getAttribute(ATTRIBUTE_BASE_PACKAGE);
    scanner.scan(StringUtils.tokenizeToStringArray(basePackage,
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));
    return null;
}

From source file:com.googlecode.objectify.spring.ObjectifyFactoryBean.java

protected List<Class<?>> doScan() {
    List<Class<?>> classes = new ArrayList<Class<?>>();
    String[] basePackages = StringUtils.tokenizeToStringArray(this.basePackage,
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
    for (String basePackage : basePackages) {
        if (this.logger.isInfoEnabled()) {
            this.logger.info("Scanning package [" + basePackage + "]");
        }//  www .j  a  v  a 2 s  . c  o m
        ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
                false);
        scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Entity.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class));
        Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage);
        for (BeanDefinition candidate : candidates) {
            Class<?> clazz = ClassUtils.resolveClassName(candidate.getBeanClassName(),
                    ClassUtils.getDefaultClassLoader());
            classes.add(clazz);
        }
    }
    return classes;
}

From source file:com.deq.spring.ObjectifyFactoryBean.java

protected List<Class<?>> doScan() {
    final List<Class<?>> classes = new ArrayList<Class<?>>();
    final String[] basePackages = StringUtils.tokenizeToStringArray(basePackage,
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
    for (final String basePackage : basePackages) {
        if (logger.isInfoEnabled()) {
            logger.info("Scanning package [" + basePackage + "]");
        }/*ww w.j a v  a 2 s  . co m*/
        final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(
                false);

        scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Entity.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(com.googlecode.objectify.annotation.Subclass.class));
        scanner.addIncludeFilter(new AnnotationTypeFilter(javax.persistence.Entity.class));

        final Set<BeanDefinition> candidates = scanner.findCandidateComponents(basePackage);
        for (final BeanDefinition candidate : candidates) {
            final Class<?> clazz = ClassUtils.resolveClassName(candidate.getBeanClassName(),
                    ClassUtils.getDefaultClassLoader());
            classes.add(clazz);
        }
    }
    return classes;
}