Example usage for org.springframework.util StringUtils delimitedListToStringArray

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

Introduction

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

Prototype

public static String[] delimitedListToStringArray(@Nullable String str, @Nullable String delimiter) 

Source Link

Document

Take a String that is a delimited list and convert it into a String array.

Usage

From source file:fr.xebia.management.statistics.ProfileAspect.java

/**
 * <p>//from  w  w  w.  j  a v a 2  s. c  o  m
 * Formats the given <code>fullyQualifiedName</code> according to the given
 * <code>classNameStyle</code>.
 * </p>
 * <p>
 * Samples with <code>java.lang.String</code>:
 * <ul>
 * <li>{@link ClassNameStyle#FULLY_QUALIFIED_NAME} :
 * <code>java.lang.String</code></li>
 * <li>{@link ClassNameStyle#COMPACT_FULLY_QUALIFIED_NAME} :
 * <code>j.l.String</code></li>
 * <li>{@link ClassNameStyle#SHORT_NAME} : <code>String</code></li>
 * </ul>
 * </p>
 */
protected static String getFullyQualifiedMethodName(String fullyQualifiedClassName, String methodName,
        ClassNameStyle classNameStyle) {
    StringBuilder fullyQualifiedMethodName = new StringBuilder(
            fullyQualifiedClassName.length() + methodName.length() + 1);
    switch (classNameStyle) {
    case FULLY_QUALIFIED_NAME:
        fullyQualifiedMethodName.append(fullyQualifiedClassName);
        break;
    case COMPACT_FULLY_QUALIFIED_NAME:
        String[] splittedFullyQualifiedName = StringUtils.delimitedListToStringArray(fullyQualifiedClassName,
                ".");
        for (int i = 0; i < splittedFullyQualifiedName.length - 1; i++) {
            fullyQualifiedMethodName.append(splittedFullyQualifiedName[i].charAt(0)).append(".");
        }
        fullyQualifiedMethodName.append(splittedFullyQualifiedName[splittedFullyQualifiedName.length - 1]);
        break;
    case SHORT_NAME:
        fullyQualifiedMethodName.append(StringUtils.unqualify(fullyQualifiedClassName));
        break;
    default:
        // should not occur
        fullyQualifiedMethodName.append(fullyQualifiedClassName);
        break;
    }
    fullyQualifiedMethodName.append(".").append(methodName);
    return fullyQualifiedMethodName.toString();
}

From source file:org.web4thejob.orm.RenderElementImpl.java

@Override
public PathMetadata getPropertyPath() {
    if (propertyPath == null && flatPropertyPath != null) {
        if (getRenderScheme() == null) {
            throw new IllegalStateException("renderScheme cannot be null.");
        }// w  w  w.  ja va  2  s  .  com

        propertyPath = ContextUtil.getMRS().getPropertyPath(getRenderScheme().getTargetType(),
                StringUtils.delimitedListToStringArray(flatPropertyPath, Path.DELIMITER));
    }
    return propertyPath;
}

From source file:org.works.common.data.layer.datasource.InitializingDataSourceFactoryBean.java

private void doExecuteScript(final Resource scriptResource) {
    if (scriptResource == null || !scriptResource.exists())
        return;//from w  w  w  .  jav  a2  s .  c  om
    TransactionTemplate transactionTemplate = new TransactionTemplate(
            new DataSourceTransactionManager(dataSource));
    transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            String[] scripts;
            try {
                scripts = StringUtils.delimitedListToStringArray(
                        stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";");
            } catch (IOException e) {
                throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
            }
            for (int i = 0; i < scripts.length; i++) {
                String script = scripts[i].trim();
                if (StringUtils.hasText(script)) {
                    try {
                        jdbcTemplate.execute(script);
                    } catch (DataAccessException e) {
                        if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) {
                            logger.debug("DROP script failed (ignoring): " + script);
                        } else {
                            throw e;
                        }
                    }
                }
            }
            return null;
        }

    });

}

From source file:com.khs.test.jdbc.datasource.DSInitializer.java

private void doExecuteScript(final Resource scriptResource) {
    if (scriptResource == null || !scriptResource.exists())
        return;/*from w ww  .ja va2 s .c o m*/
    TransactionTemplate transactionTemplate = new TransactionTemplate(
            new DataSourceTransactionManager(dataSource));
    transactionTemplate.execute(new TransactionCallback() {

        @SuppressWarnings("unchecked")
        public Object doInTransaction(TransactionStatus status) {
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            String[] scripts;
            try {
                scripts = StringUtils.delimitedListToStringArray(
                        stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";");
            } catch (IOException e) {
                throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
            }
            for (int i = 0; i < scripts.length; i++) {
                String script = scripts[i].trim();
                if (StringUtils.hasText(script)) {
                    try {
                        jdbcTemplate.execute(script);
                    } catch (DataAccessException e) {
                        if (ignoreFailedDrop && script.toLowerCase().startsWith("drop")) {
                            logger.debug("DROP script failed (ignoring): " + script);
                        } else {
                            throw e;
                        }
                    }
                }
            }
            return null;
        }

    });

}

From source file:springbatch.test.jdbc.datasource.DataSourceInitializer.java

private void doExecuteScript(final Resource scriptResource) {
    if (scriptResource == null || !scriptResource.exists())
        return;/*from   ww w . j  a  v  a2s . c om*/
    TransactionTemplate transactionTemplate = new TransactionTemplate(
            new DataSourceTransactionManager(dataSource));
    transactionTemplate.execute(new TransactionCallback() {

        @SuppressWarnings("unchecked")
        public Object doInTransaction(TransactionStatus status) {
            JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
            String[] scripts;
            try {
                scripts = StringUtils.delimitedListToStringArray(
                        stripComments(IOUtils.readLines(scriptResource.getInputStream())), ";");
            } catch (IOException e) {
                throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
            }
            for (int i = 0; i < scripts.length; i++) {
                String script = scripts[i].trim();
                if (StringUtils.hasText(script)) {
                    try {
                        jdbcTemplate.execute(scripts[i]);
                    } catch (DataAccessException e) {
                        if (!script.toUpperCase().startsWith("DROP")) {
                            throw e;
                        }
                    }
                }
            }
            return null;
        }

    });

}

From source file:se.alingsas.alfresco.repo.utils.byggreda.ReadMetadataDocument.java

/**
 * Parse and validate a single line in a metadata document for ByggReda
 * //  w ww .j  a va  2 s  .c om
 * @param line
 * @return
 */
private static ByggRedaDocument parseAndValidate(String line) {
    ByggRedaDocument document = new ByggRedaDocument();
    String[] parts = StringUtils.delimitedListToStringArray(line, "\";\"");
    if (parts.length <= 1) {
        //If parts were not found, try without quotes
        parts = StringUtils.delimitedListToStringArray(line, ";");
    }
    document.setReadSuccessfully(false);

    for (String part : parts) {
        if (part.indexOf(";") != -1) {
            document.setStatusMsg("Semikolon ptrffades i ngot av flten p raden");
            return document;
        }
    }

    // Verify that all parts were extracted
    if (parts.length != 14) {
        document.setStatusMsg("Fel antal delar i rad. Antal delar funna:" + parts.length
                + " Frvntat antal delar: " + EXPECTED_NUM_PARTS + " Rad: " + line);
    } else {
        // All parts were extracted successfully
        int i = 0;
        document.setReadSuccessfully(true);
        document.setFilm(parts[i++]);
        if (document.getFilm().indexOf("\"") == 0) {
            // Remove prefix "
            document.setFilm(document.getFilm().substring(1));
        }
        document.setSerialNumber(parts[i++]);
        try {
            document.setRecordYear((Integer) Integer.parseInt(parts[i++]));
        } catch (NumberFormatException e) {
            document.setReadSuccessfully(false);
            document.setStatusMsg("Ogiltigt diarier");
            return document;
        }
        document.setRecordNumber(parts[i++]);
        if (!StringUtils.hasText(document.getRecordNumber())) {
            document.setReadSuccessfully(false);
            document.setStatusMsg("Diarienummer saknas");
            return document;
        }
        document.setRecordDisplay(
                document.getRecordYear() + RECORD_DISPLAY_SEPARATOR + document.getRecordNumber());
        document.setBuildingDescription(parts[i++]);
        if (!StringUtils.hasText(document.getBuildingDescription())) {
            document.setReadSuccessfully(false);
            document.setStatusMsg("Fastighetsbeteckning saknas");
            return document;
        }
        document.setLastBuildingDescription(parts[i++]);
        document.setAddress(parts[i++]);
        document.setLastAddress(parts[i++]);
        document.setDecision(parts[i++]);
        document.setForA(parts[i++]);
        document.setIssuePurpose(parts[i++]);
        document.setNote(parts[i++]);
        document.setRecords(parts[i++]);
        document.setFileName(parts[i]);
        if (!StringUtils.hasText(document.getFileName())) {
            document.setReadSuccessfully(false);
            document.setStatusMsg("Filnamn saknas");
            return document;
        }
        if (document.getFileName().indexOf("\"") == (document.getFileName().length() - 1)) {
            // Remove postfix " from last part
            document.setFileName(document.getFileName().substring(0, document.getFileName().length() - 1));
        }
        document.setFileName(CommonFileUtil.parseValidFileName(document.getFileName()));
        document.setMimetype(
                CommonFileUtil.getMimetypeByExtension(FilenameUtils.getExtension(document.getFileName())));
        String originalPart1 = document.getBuildingDescription().substring(0, 1).toUpperCase();
        String part1 = CommonFileUtil.parseValidFileName(originalPart1);
        String originalPart2 = document.getBuildingDescription().toUpperCase();
        String part2 = CommonFileUtil.parseValidFileName(originalPart2);
        String originalPart3 = document.getRecordDisplay() + " " + document.getIssuePurpose().toUpperCase();
        String part3 = CommonFileUtil.parseValidFileName(originalPart3);
        document.setPath(part1 + "/" + part2 + "/" + part3);
        document.setOriginalPath(originalPart1 + "#/#" + originalPart2 + "#/#" + originalPart3);
        document.setTitle(document.getRecordDisplay() + " " + document.getIssuePurpose());
    }
    return document;
}

From source file:org.fishwife.jrugged.spring.config.MonitorMethodInterceptorDefinitionDecorator.java

/**
 * Parse a comma-delimited list of method names into a List of strings.
 * Whitespace is ignored./* w w w .java  2  s  .  c om*/
 *
 * @param methods the comma delimited list of methods from the spring configuration
 *
 * @return List<String>
 */
public List<String> parseMethodList(String methods) {

    String[] methodArray = StringUtils.delimitedListToStringArray(methods, ",");

    List<String> methodList = new ArrayList<String>();

    for (String methodName : methodArray) {
        methodList.add(methodName.trim());
    }
    return methodList;
}

From source file:pl.chilldev.facelets.taglib.spring.web.MessageTag.java

/**
 * Builds interpolation arguments list./*w w w  .  j a  v  a 2s . c  o  m*/
 *
 * @param arguments Arguments list.
 * @param separator Argulemts separator.
 * @return Arguments list.
 * @since 0.0.1
 */
protected Object[] resolveArguments(Object arguments, String separator) {
    // this methos is taken from original Spring MessageTag implementation for JSP
    if (arguments instanceof String) {
        return StringUtils.delimitedListToStringArray((String) arguments, separator);
    } 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 new Object[0];
    }
}

From source file:org.mmonti.entitygraph.repository.CustomGenericJpaRepository.java

private void buildEntityGraph(EntityGraph<T> entityGraph, String[] attributeGraph) {
    List<String> attributePaths = Arrays.asList(attributeGraph);

    // Sort to ensure that the intermediate entity subgraphs are created accordingly.
    Collections.sort(attributePaths);
    Collections.reverse(attributePaths);

    // We build the entity graph based on the paths with highest depth first
    for (String path : attributePaths) {

        // Fast path - just single attribute
        if (!path.contains(".")) {
            entityGraph.addAttributeNodes(path);
            continue;
        }/*from   w w  w. ja va2 s . c om*/

        // We need to build nested sub fetch graphs
        String[] pathComponents = StringUtils.delimitedListToStringArray(path, ".");
        Subgraph<?> parent = null;

        for (int c = 0; c < pathComponents.length - 1; c++) {
            parent = c == 0 ? entityGraph.addSubgraph(pathComponents[c])
                    : parent.addSubgraph(pathComponents[c]);
        }

        parent.addAttributeNodes(pathComponents[pathComponents.length - 1]);
    }
}

From source file:org.web4thejob.orm.CriterionImpl.java

@Override
public PathMetadata getPropertyPath() {
    if (propertyPath == null && flatPropertyPath != null) {
        if (getQuery() == null) {
            throw new IllegalStateException("query cannot be null.");
        }/*  w  w  w  .  j a v  a2 s. c  o m*/

        propertyPath = ContextUtil.getMRS().getPropertyPath(query.getTargetType(),
                StringUtils.delimitedListToStringArray(flatPropertyPath, Path.DELIMITER));
    }
    return propertyPath;
}