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:org.broadleafcommerce.common.web.extensibility.MergeXmlWebApplicationContext.java

/**
 * Load the bean definitions with the given XmlBeanDefinitionReader.
 * <p>The lifecycle of the bean factory is handled by the refreshBeanFactory method;
 * therefore this method is just supposed to load and/or register bean definitions.
 * <p>Delegates to a ResourcePatternResolver for resolving location patterns
 * into Resource instances./*  w ww  .  jav a  2  s. c om*/
 * @throws org.springframework.beans.BeansException in case of bean registration errors
 * @throws java.io.IOException if the required XML document isn't found
 * @see #refreshBeanFactory
 * @see #getConfigLocations
 * @see #getResources
 * @see #getResourcePatternResolver
 */
protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {
    String[] broadleafConfigLocations = StandardConfigLocations.retrieveAll(standardLocationTypes);

    ArrayList<ResourceInputStream> sources = new ArrayList<ResourceInputStream>(20);
    for (String location : broadleafConfigLocations) {
        InputStream source = MergeXmlWebApplicationContext.class.getClassLoader().getResourceAsStream(location);
        if (source != null) {
            sources.add(new ResourceInputStream(source, location));
        }
    }
    ResourceInputStream[] filteredSources = new ResourceInputStream[] {};
    filteredSources = sources.toArray(filteredSources);
    String patchLocation = getPatchLocation();
    String[] patchLocations = StringUtils.tokenizeToStringArray(patchLocation,
            ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
    List<ResourceInputStream> patchList = new ArrayList<ResourceInputStream>();
    for (int i = 0; i < patchLocations.length; i++) {
        ResourceInputStream patch;
        if (patchLocations[i].startsWith("classpath")) {
            InputStream is = MergeXmlWebApplicationContext.class.getClassLoader().getResourceAsStream(
                    patchLocations[i].substring("classpath*:".length(), patchLocations[i].length()));
            patch = new ResourceInputStream(is, patchLocations[i]);
        } else {
            Resource resource = getResourceByPath(patchLocations[i]);
            patch = new ResourceInputStream(resource.getInputStream(), patchLocations[i]);
        }
        if (patch == null || patch.available() <= 0) {
            patchList.addAll(getResourcesFromPatternResolver(patchLocations[i]));
        } else {
            patchList.add(patch);
        }
    }

    ImportProcessor importProcessor = new ImportProcessor(this);
    ResourceInputStream[] patchArray;
    try {
        filteredSources = importProcessor.extract(filteredSources);
        patchArray = importProcessor.extract(patchList.toArray(new ResourceInputStream[patchList.size()]));
    } catch (MergeException e) {
        throw new FatalBeanException("Unable to merge source and patch locations", e);
    }

    Resource[] resources = new MergeApplicationContextXmlConfigResource().getConfigResources(filteredSources,
            patchArray);
    reader.loadBeanDefinitions(resources);
}

From source file:org.dbist.dml.impl.DmlJdbc.java

private void appendSelectSql(StringBuffer buf, Map<String, Object> paramMap, Table table, Query query,
        boolean groupBy, boolean ignoreOrderBy) {
    boolean joined = table.containsLinkedTable();
    @SuppressWarnings("unchecked")
    Map<String, Column> relColMap = joined ? new ListOrderedMap() : null;

    // Select//from  w  w  w .  j a  va  2s  . c o m
    buf.append("select");
    // Grouping fields
    if (groupBy) {
        if (!ValueUtils.isEmpty(query.getSelect())) {
            List<String> group = query.getGroup();
            for (String fieldName : query.getSelect()) {
                if (group.contains(fieldName))
                    continue;
                throw new DbistRuntimeException("Grouping query cannot be executed with some other fields: "
                        + table.getClazz().getName() + "." + fieldName);
            }
        }
        int i = 0;
        for (String group : query.getGroup()) {
            buf.append(i++ == 0 ? " " : ", ");
            if (joined)
                appendName(table, buf, table.getName()).append(".");
            appendName(table, buf, toColumnName(table, group));
        }
    }
    // All fields
    else if (ValueUtils.isEmpty(query.getSelect())) {
        int i = 0;
        if (ValueUtils.isEmpty(query.getUnselect())) {
            for (Column column : table.getColumnList())
                i = appendColumn(buf, table, column, relColMap, i);
        }
        // Except some fields
        else {
            List<String> unselects = new ArrayList<String>(query.getUnselect().size());
            for (String unselect : query.getUnselect())
                unselects.add(toColumnName(table, unselect));
            for (Column column : table.getColumnList()) {
                if (unselects.contains(column.getName()))
                    continue;
                i = appendColumn(buf, table, column, relColMap, i);
            }
        }
    }
    // Some fields
    else {
        int i = 0;
        for (String fieldName : query.getSelect()) {
            Column column = toColumn(table, fieldName);
            i = appendColumn(buf, table, column, relColMap, i);
        }
    }

    appendFromWhere(table, query, buf, paramMap, relColMap);

    // Group by
    if (groupBy) {
        buf.append(" group by");
        int i = 0;
        for (String group : query.getGroup()) {
            buf.append(i++ == 0 ? " " : ", ");
            if (joined)
                appendName(table, buf, table.getName()).append(".");
            appendName(table, buf, toColumnName(table, group));
        }
    }

    // Order by
    if (!ignoreOrderBy && !ValueUtils.isEmpty(query.getOrder())) {
        buf.append(" order by");
        int i = 0;
        for (Order order : query.getOrder()) {
            for (String fieldName : StringUtils.tokenizeToStringArray(order.getField(), ",")) {
                buf.append(i++ == 0 ? " " : ", ");
                if (joined)
                    appendName(table, buf, table.getName()).append(".");
                appendName(table, buf, toColumnName(table, fieldName))
                        .append(order.isAscending() ? " asc" : " desc");
            }
        }
    }

    appendLock(buf, query.getLock());
}

From source file:org.dbist.dml.impl.DmlJdbc.java

public void setDomain(String domain) {
    this.domain = domain;
    if (ValueUtils.isEmpty(domain)) {
        domainList.clear();//from   w w w  .j  a  v a 2s.co m
        return;
    }
    for (String d : StringUtils.tokenizeToStringArray(domain, ","))
        domainList.add(d);
}

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

/**
 * Parses the supplied <code>&lt;bean&gt;</code> element. May return <code>null</code> if there were errors during
 * parse. Errors are reported to the {@link org.springframework.beans.factory.parsing.ProblemReporter}.
 *///from  w  ww.j a  v a  2  s .  com
private BeanDefinitionHolder parseComponentDefinitionElement(Element ele, BeanDefinition containingBean) {

    // extract bean name
    String id = ele.getAttribute(BeanDefinitionParserDelegate.ID_ATTRIBUTE);
    String nameAttr = ele.getAttribute(BeanDefinitionParserDelegate.NAME_ATTRIBUTE);

    List<String> aliases = new ArrayList<String>(4);
    if (StringUtils.hasLength(nameAttr)) {
        String[] nameArr = StringUtils.tokenizeToStringArray(nameAttr,
                BeanDefinitionParserDelegate.BEAN_NAME_DELIMITERS);
        aliases.addAll(Arrays.asList(nameArr));
    }

    String beanName = id;

    if (!StringUtils.hasText(beanName) && !aliases.isEmpty()) {
        beanName = (String) aliases.remove(0);
        if (log.isDebugEnabled()) {
            log.debug("No XML 'id' specified - using '" + beanName + "' as bean name and " + aliases
                    + " as aliases");
        }
    }

    if (containingBean == null) {

        if (checkNameUniqueness(beanName, aliases, usedNames)) {
            error("Bean name '" + beanName + "' is already used in this file", ele);
        }

        if (ParsingUtils.isReservedName(beanName, ele, parserContext)) {
            error("Blueprint reserved name '" + beanName + "' cannot be used", ele);
        }
    }

    AbstractBeanDefinition beanDefinition = parseBeanDefinitionElement(ele, beanName, containingBean);
    if (beanDefinition != null) {
        if (!StringUtils.hasText(beanName)) {
            try {
                if (containingBean != null) {
                    beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition,
                            parserContext.getRegistry(), true);
                } else {
                    beanName = ParsingUtils.generateBlueprintBeanName(beanDefinition,
                            parserContext.getRegistry(), false);
                    // TODO: should we support 2.0 behaviour (see below):
                    // 
                    // Register an alias for the plain bean class name, if still possible,
                    // if the generator returned the class name plus a suffix.
                    // This is expected for Spring 1.2/2.0 backwards compatibility.
                }
                if (log.isDebugEnabled()) {
                    log.debug("Neither XML 'id' nor 'name' specified - " + "using generated bean name ["
                            + beanName + "]");
                }
            } catch (Exception ex) {
                error(ex.getMessage(), ele, ex);
                return null;
            }
        }
        return new BeanDefinitionHolder(beanDefinition, beanName);
    }

    return null;
}

From source file:org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils.java

/**
 * Return the directive value as a String. If the directive does not exist
 * or is invalid (wrong format) a null string will be returned.
 * /* w  w  w.  j  a  va2s . c  om*/
 * @param header
 * @param directive
 * @return
 */
public static String getDirectiveValue(String header, String directive) {
    Assert.notNull(header, "not-null header required");
    Assert.notNull(directive, "not-null directive required");
    String[] directives = StringUtils.tokenizeToStringArray(header, DIRECTIVE_SEPARATOR);

    for (int i = 0; i < directives.length; i++) {
        String[] splittedDirective = StringUtils.delimitedListToStringArray(directives[i].trim(), EQUALS);
        if (splittedDirective.length == 2 && splittedDirective[0].equals(directive))
            return splittedDirective[1];
    }

    return null;
}

From source file:org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils.java

/**
 * Similar to {@link #getHeaderLocations(Dictionary)} but looks at a
 * specified header directly.//from   ww w  . j  ava2  s  .  c o  m
 * 
 * @param header header to look at
 * @param defaultValue default locations if none is specified
 * @return
 */
public static String[] getLocationsFromHeader(String header, String defaultValue) {

    String[] ctxEntries;
    if (StringUtils.hasText(header) && !(';' == header.charAt(0))) {
        // get the config locations
        String locations = StringUtils.tokenizeToStringArray(header, DIRECTIVE_SEPARATOR)[0];
        // parse it into individual token
        ctxEntries = StringUtils.tokenizeToStringArray(locations, CONTEXT_LOCATION_SEPARATOR);

        // replace * with a 'digestable' location
        for (int i = 0; i < ctxEntries.length; i++) {
            if (CONFIG_WILDCARD.equals(ctxEntries[i]))
                ctxEntries[i] = defaultValue;
        }
    } else {
        ctxEntries = new String[0];
    }

    return ctxEntries;
}

From source file:org.impalaframework.module.source.BaseInternalModuleDefinitionSource.java

private void addDependentModuleProperties(String moduleName, Properties properties, List<String> added) {

    if (logger.isDebugEnabled()) {
        logger.debug("Checking dependencies for module " + moduleName);
    }//from   w  w w  . ja va  2 s.  co m

    String dependsOnString = properties.getProperty(DEPENDS_ON_PROPERTY);
    if (StringUtils.hasText(dependsOnString)) {
        String[] dependents = StringUtils.tokenizeToStringArray(dependsOnString, " ,");
        for (String dependent : dependents) {
            if (!moduleProperties.containsKey(dependent)) {
                Properties dependentProperties = getPropertiesForModule(dependent);
                moduleProperties.put(dependent, dependentProperties);
                added.add(dependent);

                //recursively add dependent properties

                if (logger.isDebugEnabled()) {
                    logger.debug("Adding dependent modules for " + dependent);
                }

                addDependentModuleProperties(dependent, dependentProperties, added);
            }
        }
    }
}

From source file:org.impalaframework.web.spring.config.WebMappingBeanDefinitionParser.java

String[] getFilterNames(String filterNamesAttribute) {
    String[] filterNames = StringUtils.hasText(filterNamesAttribute)
            ? StringUtils.tokenizeToStringArray(filterNamesAttribute, " ,")
            : null;/* ww w.  ja  va  2s  .  c  o m*/
    return filterNames;
}

From source file:org.lexgrid.loader.processor.support.BeanReflectionTruncator.java

/**
 * Gets the field path./*from w w  w .j a va  2s.co m*/
 * 
 * @param path the path
 * 
 * @return the field path
 */
protected String[] getFieldPath(String path) {
    return StringUtils.tokenizeToStringArray(path, pathDelimiter);
}

From source file:org.openspaces.pu.container.servicegrid.PUServiceBeanImpl.java

private List<URL> getManifestClassPathJars(String puName, InputStream manifestStream) {
    List<URL> exportedManifestUrls = new ArrayList<URL>();
    try {/*  w w  w  . j  ava2 s.  co m*/

        Manifest manifest = new Manifest(manifestStream);

        String manifestClasspathLibs = manifest.getMainAttributes().getValue("Class-Path");
        if (manifestClasspathLibs != null) {
            String[] manifestLibFiles = StringUtils.tokenizeToStringArray(manifestClasspathLibs, " ");
            for (String fileName : manifestLibFiles) {

                try {
                    fileName = PlaceholderReplacer.replacePlaceholders(System.getenv(), fileName);
                } catch (PlaceholderResolutionException e) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Could not resolve manifest classpath entry: " + fileName
                                + " of processing unit " + puName, e);
                    }
                    continue;
                }

                URL url = null;
                try {
                    url = new URL(fileName);
                    if (!"file".equals(url.getProtocol())) {
                        if (logger.isWarnEnabled()) {
                            logger.warn("Only file protocol is supported in urls, found : '" + fileName
                                    + "' in manifest classpath of processing unit " + puName);
                        }
                        continue;
                    }
                } catch (MalformedURLException e) {
                    // moving on, checking if file path has been provided
                }

                File file;
                if (url != null) {
                    try {
                        file = new File(url.toURI());
                    } catch (URISyntaxException e) {
                        if (logger.isWarnEnabled()) {
                            logger.warn("Invalid url: " + url + " provided in pu " + puName
                                    + " manifest classpath, ignoring entry", e);
                        }
                        continue;
                    }
                } else {
                    file = new File(fileName);
                }

                if (!file.isAbsolute()) {
                    file = new File(SystemInfo.singleton().getXapHome(), fileName);
                }

                if (!file.isFile()) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("Did not find manifest classpath entry: " + file.getAbsolutePath()
                                + " for processing unit: " + puName + ", ignoring entry.");
                    }
                    continue;
                }

                if (logger.isDebugEnabled()) {
                    logger.debug("Adding " + file.getAbsolutePath()
                            + " read from MANIFEST.MF to processing unit: " + puName + " classpath");
                }

                URL urlToAdd = file.toURI().toURL();
                exportedManifestUrls.add(urlToAdd);
            }
        }
    } catch (IOException e) {
        if (logger.isWarnEnabled()) {
            logger.warn(failedReadingManifest(puName), e);
        }
    } finally {
        try {
            manifestStream.close();
        } catch (IOException e) {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed closing manifest input stream.", e);
            }
        }
    }
    return exportedManifestUrls;
}