Example usage for org.springframework.util StringUtils replace

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

Introduction

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

Prototype

public static String replace(String inString, String oldPattern, @Nullable String newPattern) 

Source Link

Document

Replace all occurrences of a substring within a string with another string.

Usage

From source file:org.focusns.common.web.page.config.WidgetConfig.java

private String generateId() {
    String uuidString = UUID.randomUUID().toString();
    return StringUtils.replace(uuidString, "-", "");
}

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

/**
 * Extract the type of all tokens that potentially delimit string literals.
 *
 * @param tokens The tokens to analyse./*ww w. j  av a 2  s .  co  m*/
 *
 * @return The list of potentially delimiting string literals token types per token. Tokens that do not have any
 *         impact on string delimiting are discarded.
 */
private List<Set<TokenType>> extractStringLiteralDelimitingTokens(String[] tokens) {
    List<Set<TokenType>> delimitingTokens = new ArrayList<Set<TokenType>>();
    for (String token : tokens) {
        //Remove escaped quotes as they do not form a string literal delimiter
        String cleanToken = StringUtils.replace(token, "''", "");

        Set<TokenType> tokenTypes = new HashSet<TokenType>();

        if (cleanToken.startsWith("'")) {
            if ((cleanToken.length() > 1) && cleanToken.endsWith("'")) {
                // Ignore. ' string literal is opened and closed inside the same token.
                continue;
            }
            tokenTypes.add(TokenType.QUOTE_OPEN);
        }

        if (cleanToken.endsWith("'")) {
            tokenTypes.add(TokenType.QUOTE_CLOSE);
        }

        if (cleanToken.startsWith("$$")) {
            if ((cleanToken.length() > 2) && cleanToken.endsWith("$$")) {
                // Ignore. $$ string literal is opened and closed inside the same token.
                continue;
            }
            tokenTypes.add(TokenType.DOLLAR_OPEN);
        }

        if (cleanToken.endsWith("$$")) {
            tokenTypes.add(TokenType.DOLLAR_CLOSE);
        }

        if (!tokenTypes.isEmpty()) {
            delimitingTokens.add(tokenTypes);
        }
    }

    return delimitingTokens;
}

From source file:org.web4thejob.web.composer.SafeModeWindow.java

private static String repalce(String in) {
    String out = in;/*from  www .  j  ava 2  s.  c o  m*/
    out = StringUtils.replace(out, "org.w4tj.panel.", "org.web4thejob.web.panel.");
    out = StringUtils.replace(out, "org.w4tj.dialog.", "org.web4thejob.web.dialog.");
    out = StringUtils.replace(out, "org.w4tj.composer.", "org.web4thejob.web.composer.");
    out = StringUtils.replace(out, "org.web4thejob.web.panel.DefaultEntityViewPanel",
            "org.web4thejob.web.panel.DefaultMutableEntityViewPanel");
    return out;
}

From source file:nu.localhost.tapestry5.springsecurity.components.IfRole.java

private Collection<GrantedAuthority> parseAuthoritiesString(String authorizationsString) {
    final Collection<GrantedAuthority> requiredAuthorities = new ArrayList<GrantedAuthority>();
    final String[] authorities = StringUtils.commaDelimitedListToStringArray(authorizationsString);

    for (int i = 0; i < authorities.length; i++) {
        String authority = authorities[i];

        // Remove the role's whitespace characters without depending on JDK 1.4+
        // Includes space, tab, new line, carriage return and form feed.
        String role = StringUtils.replace(authority, " ", "");
        role = StringUtils.replace(role, "\t", "");
        role = StringUtils.replace(role, "\r", "");
        role = StringUtils.replace(role, "\n", "");
        role = StringUtils.replace(role, "\f", "");

        requiredAuthorities.add(new SimpleGrantedAuthority(role));
    }//from w w w  .j  av a  2  s  .co m
    return requiredAuthorities;
}

From source file:com.digitalgeneralists.assurance.model.entities.ApplicationConfiguration.java

private List<String> transformStringPropertyToListProperty(String property, boolean removeExtensionPatterns) {
    StrTokenizer tokenizer = new StrTokenizer(property, ',');
    List<String> tokenizedList = tokenizer.getTokenList();
    // NOTE: May want to reconsider the toLowercase conversion.
    ListIterator<String> iterator = tokenizedList.listIterator();
    while (iterator.hasNext()) {
        String extension = iterator.next();
        // NOTE: This is probably a bit overly-aggressive and less-sophisticated than it could be,
        // but it should handle 99% of the input that will be entered.
        if (removeExtensionPatterns) {
            extension = StringUtils.replace(extension, "*.", "");
            extension = StringUtils.replace(extension, "*", "");
            extension = StringUtils.replace(extension, ".", "");
        }/* w  w w  .java 2  s  .  co  m*/
        iterator.set(extension.toLowerCase().trim());
    }
    return tokenizedList;
}

From source file:ch.astina.hesperid.web.components.security.IfRole.java

@SuppressWarnings("unchecked")
private Set parseAuthoritiesString(String authorizationsString) {
    final Set requiredAuthorities = new HashSet();
    final String[] authorities = StringUtils.commaDelimitedListToStringArray(authorizationsString);

    for (int i = 0; i < authorities.length; i++) {
        String authority = authorities[i];

        // Remove the role's whitespace characters without depending on JDK 1.4+
        // Includes space, tab, new line, carriage return and form feed.
        String role = StringUtils.replace(authority, " ", "");
        role = StringUtils.replace(role, "\t", "");
        role = StringUtils.replace(role, "\r", "");
        role = StringUtils.replace(role, "\n", "");
        role = StringUtils.replace(role, "\f", "");

        requiredAuthorities.add(new GrantedAuthorityImpl(role));
    }//ww w .  ja  v  a2s.co m

    return requiredAuthorities;
}

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

/**
 * Extract the type of all tokens that potentially delimit string literals.
 *
 * @param tokens The tokens to analyse.// w ww. j a  v a  2 s.  co  m
 * @return The list of potentially delimiting string literals token types per token. Tokens that do not have any
 *         impact on string delimiting are discarded.
 */
private List<Token> extractStringLiteralDelimitingTokens(String[] tokens) {
    List<Token> delimitingTokens = new ArrayList<Token>();
    for (String token : tokens) {
        //Remove escaped quotes as they do not form a string literal delimiter
        String cleanToken = StringUtils.replace(token, "''", "");

        List<TokenType> tokenTypes = new ArrayList<TokenType>();

        if (cleanToken.startsWith("'")) {
            tokenTypes.add(TokenType.SINGLE_OPEN);
        }

        if (cleanToken.endsWith("'")) {
            tokenTypes.add(TokenType.SINGLE_CLOSE);
        }

        if (cleanToken.startsWith("\"")) {
            tokenTypes.add(TokenType.DOUBLE_OPEN);
        }

        if (cleanToken.endsWith("\"")) {
            tokenTypes.add(TokenType.DOUBLE_CLOSE);
        }

        if (!tokenTypes.isEmpty()) {
            Token parsedToken = new Token();
            parsedToken.tokenTypes = tokenTypes;
            parsedToken.singleTypeApplicable = token.length() == 1;
            delimitingTokens.add(parsedToken);
        }
    }

    return delimitingTokens;
}

From source file:org.testng.spring.test.AbstractTransactionalDataSourceSpringContextTests.java

/**
 * Execute the given SQL script. Will be rolled back by default,
 * according to the fate of the current transaction.
 * @param sqlResourcePath Spring resource path for the SQL script.
 * Should normally be loaded by classpath. There should be one statement
 * per line. Any semicolons will be removed.
 * <b>Do not use this method to execute DDL if you expect rollback.</b>
 * @param continueOnError whether or not to continue without throwing
 * an exception in the event of an error
 * @throws DataAccessException if there is an error executing a statement
 * and continueOnError was false//from ww  w. j a  va2s  . c  o m
 */
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
    if (logger.isInfoEnabled()) {
        logger.info("Executing SQL script '" + sqlResourcePath + "'");
    }

    long startTime = System.currentTimeMillis();
    List statements = new LinkedList();
    Resource res = getApplicationContext().getResource(sqlResourcePath);
    try {
        LineNumberReader lnr = new LineNumberReader(new InputStreamReader(res.getInputStream()));
        String currentStatement = lnr.readLine();
        while (currentStatement != null) {
            currentStatement = StringUtils.replace(currentStatement, ";", "");
            statements.add(currentStatement);
            currentStatement = lnr.readLine();
        }

        for (Iterator itr = statements.iterator(); itr.hasNext();) {
            String statement = (String) itr.next();
            try {
                int rowsAffected = this.jdbcTemplate.update(statement);
                if (logger.isDebugEnabled()) {
                    logger.debug(rowsAffected + " rows affected by SQL: " + statement);
                }
            } catch (DataAccessException ex) {
                if (continueOnError) {
                    if (logger.isWarnEnabled()) {
                        logger.warn("SQL: " + statement + " failed", ex);
                    }
                } else {
                    throw ex;
                }
            }
        }
        long elapsedTime = System.currentTimeMillis() - startTime;
        logger.info("Done executing SQL script '" + sqlResourcePath + "' in " + elapsedTime + " ms");
    } catch (IOException ex) {
        throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResourcePath + "'", ex);
    }
}

From source file:com.googlecode.flyway.core.dbsupport.oracle.OracleSqlScript.java

/**
 * Extract the type of all tokens that potentially delimit string literals.
 *
 * @param tokens The tokens to analyse./*w  w w .  j a v  a 2s .  c  om*/
 * @return The list of potentially delimiting string literals token types per token. Tokens that do not have any
 *         impact on string delimiting are discarded.
 */
private List<Token> extractStringLiteralDelimitingTokens(String[] tokens) {
    String qCloseToken = "]'";

    List<Token> delimitingTokens = new ArrayList<Token>();
    for (String token : tokens) {
        //Remove escaped quotes as they do not form a string literal delimiter
        String cleanToken = StringUtils.replace(token, "''", "");

        List<TokenType> tokenTypes = new ArrayList<TokenType>();

        if (cleanToken.startsWith("'")) {
            tokenTypes.add(TokenType.QUOTE_OPEN);
        }

        if (cleanToken.endsWith("'")) {
            tokenTypes.add(TokenType.QUOTE_CLOSE);
        }

        if (cleanToken.startsWith("q'") && (cleanToken.length() >= 3)) {
            String qOpenToken = cleanToken.substring(0, 3);
            qCloseToken = computeQCloseToken(qOpenToken);

            tokenTypes.add(TokenType.Q_OPEN);
        }

        if (cleanToken.endsWith(qCloseToken)) {
            tokenTypes.add(TokenType.Q_CLOSE);
        }

        if (!tokenTypes.isEmpty()) {
            Token parsedToken = new Token();
            parsedToken.tokenTypes = tokenTypes;
            parsedToken.singleTypeApplicable = token.length() == 1;
            delimitingTokens.add(parsedToken);
        }
    }

    return delimitingTokens;
}

From source file:org.openspaces.maven.plugin.CreatePUProjectMojo.java

/**
 * Extracts the project files to the project directory.
 *//*from   w ww.jav a2s .c  o  m*/
private void extract(URL url) throws Exception {
    packageDirs = packageName.replaceAll("\\.", "/");
    String puTemplate = DIR_TEMPLATES + "/" + template + "/";
    int length = puTemplate.length() - 1;
    BufferedInputStream bis = new BufferedInputStream(url.openStream());
    JarInputStream jis = new JarInputStream(bis);
    JarEntry je;
    byte[] buf = new byte[1024];
    int n;
    while ((je = jis.getNextJarEntry()) != null) {
        String jarEntryName = je.getName();
        PluginLog.getLog().debug("JAR entry: " + jarEntryName);
        if (je.isDirectory() || !jarEntryName.startsWith(puTemplate)) {
            continue;
        }
        String targetFileName = projectDir + jarEntryName.substring(length);

        // convert the ${gsGroupPath} to directory
        targetFileName = StringUtils.replace(targetFileName, FILTER_GROUP_PATH, packageDirs);
        PluginLog.getLog().debug("Extracting entry " + jarEntryName + " to " + targetFileName);

        // read the bytes to the buffer
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        while ((n = jis.read(buf, 0, 1024)) > -1) {
            byteStream.write(buf, 0, n);
        }

        // replace property references with the syntax ${property_name}
        // to their respective property values.
        String data = byteStream.toString();
        data = StringUtils.replace(data, FILTER_GROUP_ID, packageName);
        data = StringUtils.replace(data, FILTER_ARTIFACT_ID, projectDir.getName());
        data = StringUtils.replace(data, FILTER_GROUP_PATH, packageDirs);

        // write the entire converted file content to the destination file.
        File f = new File(targetFileName);
        File dir = f.getParentFile();
        if (!dir.exists()) {
            dir.mkdirs();
        }
        FileWriter writer = new FileWriter(f);
        writer.write(data);
        jis.closeEntry();
        writer.close();
    }
    jis.close();
}