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:com.huateng.ebank.framework.util.ApplicationContextUtils.java

public static synchronized void init(String location) throws CommonException {
    try {//  w ww .  j a  v  a  2 s.  c  o  m
        if (null == context) {
            String[] locations = StringUtils.tokenizeToStringArray(location, ",");
            if (log.isInfoEnabled()) {
                for (int i = 0; i < locations.length; i++) {
                    log.info("Loading spring config from files:" + locations[i].trim());
                }
                log.info("Loading spring config from files:" + location);
            }
            context = new ClassPathXmlApplicationContext(locations);
            /** shen_antonio.*/
            ContextUtil.setContext(context);
        }
    } catch (Exception ex) {
        if (log.isErrorEnabled()) {
            log.error("?spring?", ex);
        }
        ExceptionUtil.throwCommonException("??(spring).",
                "errors.system.spring", ex);
    }
}

From source file:org.focusns.common.web.WebUtils.java

public static Map<String, String> getMatrixParameters(HttpServletRequest request) {
    ///*  ww w.  j av  a  2 s  . co  m*/
    Map<String, String> parameterMap = new LinkedHashMap<String, String>();
    //
    String requestUri = request.getRequestURI();
    if (requestUri.contains(";")) {
        String paramsString = requestUri.substring(requestUri.indexOf(";") + 1);
        String[] paramsPair = new String[] { paramsString };
        if (paramsString.contains(",")) {
            paramsPair = StringUtils.tokenizeToStringArray(paramsString, ",");
        }
        for (String paramPair : paramsPair) {
            String[] nameAndValue = StringUtils.split(paramPair, "=");
            parameterMap.put(nameAndValue[0], nameAndValue[1]);
        }
    }
    return parameterMap;
}

From source file:com.tooe.core.db.mongo.converters.StringConverter.java

@Override
public void write(Object source, DBObject target) {
    String strPerson = (String) source;
    String[] parsedStrPerson = StringUtils.tokenizeToStringArray(strPerson, ",");
    target.put("fname", parsedStrPerson[0]);
    target.put("lname", parsedStrPerson[1]);
    DBObject innerObject = new BasicDBObject();
    innerObject.put("city", parsedStrPerson[2]);
    innerObject.put("street", parsedStrPerson[3]);
    innerObject.put("zip", parsedStrPerson[4]);
    innerObject.put("state", parsedStrPerson[5]);
    target.put("address", innerObject);
}

From source file:org.eclipse.virgo.ide.beans.core.internal.locate.SpringOsgiConfigLocationUtils.java

/**
 * Similar to {@link #getHeaderLocations(Dictionary)} but looks at a specified header directly.
 *//* w ww .  j a v  a2s  .co m*/
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[] { defaultValue };
    }

    return ctxEntries;
}

From source file:com.ewcms.common.query.mongo.PropertyConvert.java

/**
 * ?{@link RuntimeException}//from  ww w.jav  a2  s.c o  m
 * 
 * @param name  ???{@literal null}
 * @return {@value Class<?>}
 */
public Class<?> getPropertyType(String propertyName) {
    if (!StringUtils.hasText(propertyName)) {
        throw new IllegalArgumentException("Property's name must not null or empty!");
    }

    String[] names = StringUtils.tokenizeToStringArray(propertyName, NESTED);
    Class<?> type = beanClass;
    PropertyDescriptor pd = null;
    for (String name : names) {
        pd = BeanUtils.getPropertyDescriptor(type, name);
        if (pd == null) {
            logger.error("\"{}\" property isn't exist.", propertyName);
            throw new RuntimeException(propertyName + " property isn't exist.");
        }
        type = pd.getPropertyType();
    }

    if (type.isArray()) {
        return type.getComponentType();
    }

    if (Collection.class.isAssignableFrom(type)) {
        Method method = pd.getReadMethod();
        if (method == null) {
            logger.error("\"{}\" property is not read method.", propertyName);
            throw new RuntimeException(propertyName + " property is not read method.");
        }
        ParameterizedType returnType = (ParameterizedType) method.getGenericReturnType();
        if (returnType.getActualTypeArguments().length > 0) {
            return (Class<?>) returnType.getActualTypeArguments()[0];
        }
        logger.error("\"{}\" property is collection,but it's not generic.", propertyName);
        throw new RuntimeException(propertyName + " property is collection,but it's not generic.");
    }

    return type;
}

From source file:hwolf.spring.boot.jsf.JsfConfiguration.java

private Collection<String> getBasePackages() {
    Set<String> basePackages = new LinkedHashSet<>();
    AnnotationAttributes attrs = new AnnotationAttributes(
            metaData.getAnnotationAttributes(EnableJsf.class.getName()));
    String[] basePackagesArray = attrs.getAliasedStringArray("basePackages", EnableJsf.class,
            metaData.getClassName());//w w  w.  ja v a2 s . com
    for (String pkg : basePackagesArray) {
        String[] tokenized = StringUtils.tokenizeToStringArray(environment.resolvePlaceholders(pkg),
                ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS);
        basePackages.addAll(Arrays.asList(tokenized));
    }
    for (Class<?> clazz : attrs.getClassArray("basePackageClasses")) {
        basePackages.add(ClassUtils.getPackageName(clazz));
    }
    if (basePackages.isEmpty()) {
        basePackages.add(ClassUtils.getPackageName(metaData.getClassName()));
    }
    return basePackages;
}

From source file:com.googlecode.flyway.core.dbsupport.mysql.MySQLSqlScript.java

@Override
protected boolean endsWithOpenMultilineStringLiteral(String statement) {
    //Ignore all special characters that naturally occur in SQL, but are not opening or closing string literals
    String[] tokens = StringUtils.tokenizeToStringArray(statement, " ;=|(),");

    List<Token> delimitingTokens = extractStringLiteralDelimitingTokens(tokens);

    boolean insideQuoteStringLiteral = false;
    boolean insideQStringLiteral = false;

    for (Token delimitingToken : delimitingTokens) {
        boolean moreTokensApplicable = true;
        for (TokenType tokenType : delimitingToken.tokenTypes) {
            if (!moreTokensApplicable) {
                continue;
            }//from www.j  a  v  a 2s.co  m

            if (!insideQStringLiteral && !insideQuoteStringLiteral && (tokenType == TokenType.SINGLE_OPEN)) {
                insideQuoteStringLiteral = true;
                if (delimitingToken.singleTypeApplicable) {
                    moreTokensApplicable = false;
                }
                continue;
            }
            if (insideQuoteStringLiteral && (tokenType == TokenType.SINGLE_CLOSE)) {
                insideQuoteStringLiteral = false;
                moreTokensApplicable = false;
                continue;
            }
            if (!insideQStringLiteral && !insideQuoteStringLiteral && (tokenType == TokenType.DOUBLE_OPEN)) {
                insideQStringLiteral = true;
                continue;
            }
            if (insideQStringLiteral && (tokenType == TokenType.DOUBLE_CLOSE)) {
                insideQStringLiteral = false;
                moreTokensApplicable = false;
            }
        }
    }

    return insideQuoteStringLiteral || insideQStringLiteral;
}

From source file:com.stormpath.spring.security.authz.permission.DomainPermission.java

public DomainPermission(String actions) {
    domain = getDomain(getClass());/*from  w w w.  j a  v a2 s  .  c o  m*/
    this.actions = CollectionUtils.asSet(StringUtils.tokenizeToStringArray(actions, SUBPART_DIVIDER_TOKEN));
    encodeParts(domain, actions, null);
}

From source file:org.psikeds.common.config.ConfigLocationOverrider.java

String getContextLocation(final String location) {
    String newloc = location;/*from  w  w  w .j a v a2  s .  co m*/
    final String[] contextFiles = StringUtils.tokenizeToStringArray(location, CONFIG_LOCATION_DELIMITERS);
    for (final String contextFile : contextFiles) {
        final String overridingFile = findOverridingFile(contextFile);
        if (overridingFile != null) {
            newloc = location.replaceAll(contextFile, overridingFile);
        }
    }
    return newloc;
}

From source file:com.googlecode.flyway.core.dbsupport.h2.H2SqlScript.java

/**
 * Checks whether the statement we have assembled so far ends with an open multi-line string literal (which will be
 * continued on the next line)./*from  w  ww . j a  v  a  2  s. c o  m*/
 *
 * @param statement The current statement, assembled from the lines we have parsed so far. May not yet be complete.
 *
 * @return {@code true} if the statement is unfinished and the end is currently in the middle of a multi-line string
 *         literal. {@code false} if not.
 */
@Override
protected boolean endsWithOpenMultilineStringLiteral(String statement) {
    //Ignore all special characters that naturally occur in SQL, but are not opening or closing string literals
    String[] tokens = StringUtils.tokenizeToStringArray(statement, " ;=|(),");

    List<Set<TokenType>> delimitingTokens = extractStringLiteralDelimitingTokens(tokens);

    boolean insideQuoteStringLiteral = false;
    boolean insideDollarStringLiteral = false;

    for (Set<TokenType> delimitingToken : delimitingTokens) {
        if (!insideDollarStringLiteral && !insideQuoteStringLiteral
                && delimitingToken.contains(TokenType.QUOTE_OPEN)) {
            insideQuoteStringLiteral = true;
            continue;
        }
        if (insideQuoteStringLiteral && delimitingToken.contains(TokenType.QUOTE_CLOSE)) {
            insideQuoteStringLiteral = false;
            continue;
        }
        if (!insideDollarStringLiteral && !insideQuoteStringLiteral
                && delimitingToken.contains(TokenType.DOLLAR_OPEN)) {
            insideDollarStringLiteral = true;
            continue;
        }
        if (insideDollarStringLiteral && delimitingToken.contains(TokenType.DOLLAR_CLOSE)) {
            insideDollarStringLiteral = false;
        }
    }

    return insideQuoteStringLiteral || insideDollarStringLiteral;
}