Example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens

List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitPreserveAllTokens.

Prototype

public static String[] splitPreserveAllTokens(String str, String separatorChars, int max) 

Source Link

Document

Splits the provided text into an array with a maximum length, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:com.google.code.configprocessor.processing.properties.model.PropertyMapping.java

public void parse(String text, boolean trim) {
    String[] splitted = StringUtils.splitPreserveAllTokens(text, SEPARATOR_1 + SEPARATOR_2, 2);

    if (splitted.length > 1) {
        String name = splitted[0];
        String value = splitted[1];
        while (StringUtils.endsWith(name, SEPARATOR_ESCAPE)) {
            String[] aux = StringUtils.splitPreserveAllTokens(value, SEPARATOR_1 + SEPARATOR_2, 2);
            String charToAdd = Character.toString(text.charAt(name.length()));
            name += charToAdd;//  w  w w  .j  a  v  a 2 s  .  co m
            if (aux.length > 1) {
                name += aux[0];
                value = aux[1];
            } else if ((charToAdd.equals(SEPARATOR_1)) || (charToAdd.equals(SEPARATOR_2))) {
                name += value;
                value = null;
            } else {
                value = aux[0];
            }
        }

        splitted[0] = name;
        splitted[1] = value;
    }

    if (trim) {
        propertyName = splitted[0].trim();
    } else {
        propertyName = splitted[0];
    }

    if (splitted.length == 1) {
        propertyValue = null;
    } else {
        propertyValue = splitted[1];
    }
}

From source file:com.moz.fiji.schema.hbase.FijiManagedHBaseTableName.java

/**
 * Constructs using an HBase HTable name.
 *
 * @param hbaseTableName The HBase HTable name.
 * @return A new fiji-managed HBase table name.
 * @throws NotAFijiManagedTableException If the HBase table is not managed by fiji.
 *///from   w  w w.j av a 2s.  c  o  m
public static FijiManagedHBaseTableName get(String hbaseTableName) throws NotAFijiManagedTableException {
    // Split it into components.
    String[] components = StringUtils.splitPreserveAllTokens(hbaseTableName, Character.toString(DELIMITER), 4);

    // Make sure the first component is 'fiji'.
    if (!components[0].equals(FIJI_COMPONENT)) {
        throw new NotAFijiManagedTableException(hbaseTableName, "Doesn't start with fiji name component.");
    }

    if (components.length == 3) {
        // It's a managed fiji meta/schema/system table.
        return new FijiManagedHBaseTableName(components[1], components[2]);
    } else if (components.length == 4) {
        // It's a user-space fiji table.
        return new FijiManagedHBaseTableName(components[1], components[2], components[3]);
    } else {
        // Wrong number of components... must not be a fiji table.
        throw new NotAFijiManagedTableException(hbaseTableName, "Invalid number of name components.");
    }
}

From source file:org.codehaus.plexus.redback.struts2.interceptor.SecureActionInterceptor.java

private void executeReferrerSecurityCheck() {
    String referrer = ServletActionContext.getRequest().getHeader(HTTP_HEADER_REFERER);

    logger.debug("HTTP Referer header: {}", referrer);

    String[] tokens = StringUtils.splitPreserveAllTokens(referrer, "/", 3);

    if (tokens != null) {
        String path;/*from   www .j a  v a2 s.  c  om*/
        if (tokens.length < 3) {
            path = referrer;
        } else {
            path = tokens[tokens.length - 1];
        }

        logger.debug("Calculated virtual path: {}", path);

        ServletContext servletContext = ServletActionContext.getServletContext();

        String realPath = servletContext.getRealPath(path);

        if (StringUtils.isNotEmpty(realPath)) {
            // on windows realPath can return full path c:\\bla\\bla\....
            // so transforming \\ to /
            if (SystemUtils.IS_OS_WINDOWS) {
                realPath = StringUtils.replace(realPath, "\\", "/");
            }
            if (!realPath.endsWith(path)) {
                String errorMsg = "Failed referrer security check: Request did not come from the same server. "
                        + "Detected HTTP Referer header is '" + referrer + "'.";
                logger.error(errorMsg);
                throw new RuntimeException(errorMsg);
            } else {
                logger.debug("HTTP Referer header path found in server.");
            }
        }
    } else {
        logger.warn("HTTP Referer header is null.");
    }
}

From source file:org.eclipse.uomo.util.impl.Iso8601Date.java

private String checkSections(String content, String whole, String mask) {
    String workingMask = StringUtils.strip(mask, Messages.Iso8601Date_63);
    String[] parts = { "", workingMask }; //$NON-NLS-1$
    boolean first = true;
    inFraction = false;//from www  .j a  va  2s  . c  o m

    do {
        parts = StringUtils.splitPreserveAllTokens(parts[1], Messages.Iso8601Date_65, 2);
        String token = parts[0];
        if (token != null) { // support use of [ at first point to make
                             // everything optional
            String section = content == null || content.length() < token.length() ? null
                    : content.substring(0, token.length()); // sSection =
            // copy(sContent, 1,
            // length(sToken));
            if (section == null) { // if sSection = '' then
                if (!first) {
                    if (content != null && content.length() < token.length())
                        return Messages.Iso8601Date_66 + content + Messages.Iso8601Date_67 + token;
                    else
                        return Messages.Iso8601Date_68 + token + Messages.Iso8601Date_69 + mask
                                + Messages.Iso8601Date_70 + whole;
                }
            } else if (section.length() < token.length()) {
                return Messages.Iso8601Date_71 + token + Messages.Iso8601Date_72 + mask
                        + Messages.Iso8601Date_73 + whole + Messages.Iso8601Date_74 + section;
            } else {
                String error = checkSection(token, section);
                if (error != null)
                    return error;
                else if (section.length() >= content.length())
                    content = null;
                else
                    content = content.substring(section.length());
            }
        }
        first = false;
    } while (parts.length > 1 && content != null); // until not result or
    // (sFormat = '') or
    // (sContent = '');
    if (content != null) {
        return Messages.Iso8601Date_75 + content + Messages.Iso8601Date_76 + whole + Messages.Iso8601Date_77
                + mask;
    } else
        return null;
}

From source file:org.kiji.schema.hbase.KijiManagedHBaseTableName.java

/**
 * Constructs using an HBase HTable name.
 *
 * @param hbaseTableName The HBase HTable name.
 * @return A new kiji-managed HBase table name.
 * @throws NotAKijiManagedTableException If the HBase table is not managed by kiji.
 *//*from  w  w w .jav  a2s  .  c o m*/
public static KijiManagedHBaseTableName get(String hbaseTableName) throws NotAKijiManagedTableException {
    // Split it into components.
    String[] components = StringUtils.splitPreserveAllTokens(hbaseTableName, Character.toString(DELIMITER), 4);

    // Make sure the first component is 'kiji'.
    if (!components[0].equals(KIJI_COMPONENT)) {
        throw new NotAKijiManagedTableException(hbaseTableName, "Doesn't start with kiji name component.");
    }

    if (components.length == 3) {
        // It's a managed kiji meta/schema/system table.
        return new KijiManagedHBaseTableName(components[1], components[2]);
    } else if (components.length == 4) {
        // It's a user-space kiji table.
        return new KijiManagedHBaseTableName(components[1], components[2], components[3]);
    } else {
        // Wrong number of components... must not be a kiji table.
        throw new NotAKijiManagedTableException(hbaseTableName, "Invalid number of name components.");
    }
}