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) 

Source Link

Document

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

Usage

From source file:bazaar4idea.command.BzrRevisionsCommand.java

public final List<BzrFileRevision> execute(BzrFile hgFile, int limit) {
    if (limit <= REVISION_INDEX || hgFile == null || hgFile.getRepo() == null) {
        return Collections.emptyList();
    }//from   w  w w. ja  v a  2s  .  co m

    ShellCommandService hgCommandService = ShellCommandService.getInstance(project);

    BzrStandardResult result = execute(hgCommandService, hgFile.getRepo(), TEMPLATE, limit, hgFile);

    List<BzrFileRevision> revisions = new LinkedList<BzrFileRevision>();
    for (String line : result.getStdOutAsLines()) {
        try {
            String[] attributes = StringUtils.splitPreserveAllTokens(line, '|');
            if (attributes.length != ITEM_COUNT) {
                LOG.warn("Wrong format. Skipping line " + line);
                continue;
            }
            BzrRevisionNumber vcsRevisionNumber = BzrRevisionNumber.getInstance(attributes[REVISION_INDEX],
                    attributes[CHANGESET_INDEX]);
            Date revisionDate = DATE_FORMAT.parse(attributes[DATE_INDEX]);
            String author = attributes[AUTHOR_INDEX];
            String branchName = attributes[BRANCH_INDEX];
            String commitMessage = attributes[MESSAGE_INDEX];
            revisions.add(new BzrFileRevision(project, hgFile, vcsRevisionNumber, branchName, revisionDate,
                    author, commitMessage));
        } catch (NumberFormatException e) {
            LOG.warn("Error parsing rev in line " + line);
        } catch (ParseException e) {
            LOG.warn("Error parsing date in line " + line);
        }
    }
    return revisions;
}

From source file:com.npower.dm.setup.task.TacItemParser.java

/**
 * @return//  ww w. j a  v  a 2s.c  o  m
 * @throws Exception
 */
public TacItem getNext() throws Exception {
    String line = this.getNextLine();

    if (StringUtils.isEmpty(line)) {
        return null;
    }
    String[] cols = StringUtils.splitPreserveAllTokens(line, ";");
    if (cols.length != 20) {
        throw new Exception("More columns in line#" + this.lineNumber + ":" + line);
    }
    TacItem item = new TacItem(this.lineNumber);
    item.setTac(this.trim(cols[0]));
    item.setHandsetBrand(this.trim(cols[1]));
    item.setHandsetModel(this.trim(cols[2]));
    item.setReportingBody(this.trim(cols[3]));
    item.setApprovedIn(this.trim(cols[4]));
    item.setGsm450(this.boolValue(this.trim(cols[5])));
    item.setGsm850(this.boolValue(this.trim(cols[6])));
    item.setGsm900(this.boolValue(this.trim(cols[7])));
    item.setGsm1800(this.boolValue(this.trim(cols[8])));
    item.setGsm1900(this.boolValue(this.trim(cols[9])));
    item.setGsmr(this.boolValue(this.trim(cols[10])));
    item.setGsm3(this.boolValue(this.trim(cols[11])));
    item.setFoma(this.boolValue(this.trim(cols[12])));
    item.setIden800(this.boolValue(this.trim(cols[13])));
    item.setCdma800(this.boolValue(this.trim(cols[14])));
    item.setCdma1800(this.boolValue(this.trim(cols[15])));
    item.setCdma1900(this.boolValue(this.trim(cols[16])));
    item.setTdma(this.boolValue(this.trim(cols[17])));
    item.setSatellite(this.boolValue(this.trim(cols[18])));
    return item;
}

From source file:com.ning.maven.plugins.dependencyversionscheck.version.Version.java

public Version(final String rawVersion, final String selectedVersion) {
    if (StringUtils.isBlank(rawVersion) || StringUtils.isBlank(selectedVersion)) {
        throw new NullPointerException("Version cannot be null");
    }/* ww  w.  jav  a 2  s .c  o m*/

    this.selectedVersion = selectedVersion;
    this.rawVersion = rawVersion;

    rawElements = StringUtils.splitPreserveAllTokens(selectedVersion, "-._");
    versionElements = new VersionElement[rawElements.length];

    // Position of the next splitter to look at.
    int charPos = 0;

    // Position to store the result in.
    int resultPos = 0;

    for (int i = 0; i < rawElements.length; i++) {
        final String rawElement = rawElements[i];

        long divider = 0L;
        final char dividerChar;

        charPos += rawElement.length();
        if (charPos < selectedVersion.length()) {
            dividerChar = selectedVersion.charAt(charPos);
            charPos++;

            if (dividerChar == '.') {
                divider |= DOT_DIVIDER;
            } else if (dividerChar == '-') {
                divider |= MINUS_DIVIDER;
            } else if (dividerChar == '_') {
                divider |= UNDERSCORE_DIVIDER;
            } else {
                divider |= OTHER_DIVIDER;
            }

        } else {
            dividerChar = 0;
            divider |= END_OF_VERSION;
        }

        final String element = StringUtils.trimToEmpty(rawElement);

        if (!StringUtils.isBlank(element)) {
            long flags = ALL_NUMBERS | ALL_LETTERS | ALL_OTHER;
            final char firstChar = element.charAt(0);
            final char lastChar = element.charAt(element.length() - 1);

            if (Character.isDigit(firstChar)) {
                flags |= STARTS_WITH_NUMBERS;
            } else if (Character.isLetter(firstChar)) {
                flags |= STARTS_WITH_LETTERS;
            } else {
                flags |= STARTS_WITH_OTHER;
            }

            if (Character.isDigit(lastChar)) {
                flags |= ENDS_WITH_NUMBERS;
            } else if (Character.isLetter(lastChar)) {
                flags |= ENDS_WITH_LETTERS;
            } else {
                flags |= ENDS_WITH_OTHER;
            }

            for (int j = 0; j < element.length(); j++) {

                if (Character.isDigit(element.charAt(j))) {
                    flags &= ~(ALL_LETTERS | ALL_OTHER);
                    flags |= NUMBERS;
                } else if (Character.isLetter(element.charAt(j))) {
                    flags &= ~(ALL_NUMBERS | ALL_OTHER);
                    flags |= LETTERS;
                } else {
                    flags &= ~(ALL_LETTERS | ALL_NUMBERS);
                    flags |= OTHER;
                }
            }

            versionElements[resultPos++] = new VersionElement(element, flags, divider, dividerChar);
        }
    }

    this.elementCount = resultPos;
}

From source file:com.dianping.lion.vo.OperationLogCriteria.java

public void setOpType(String opType) {
    this.opType = opType;
    String[] tokens = StringUtils.splitPreserveAllTokens(opType, '|');
    if (StringUtils.isNotBlank(tokens[0])) {
        opTypeStart = Integer.parseInt(tokens[0]);
    }//from   w  ww.  ja  v  a 2 s.co  m
    if (StringUtils.isNotBlank(tokens[1])) {
        opTypeEnd = Integer.parseInt(tokens[1]);
    }
    projectRelated = Boolean.parseBoolean(tokens[2]);
}

From source file:eulermind.importer.LineNode.java

private static List<LineNode> splitTextToLines(String text) {
    String lines[] = StringUtils.splitPreserveAllTokens(text, '\n');

    ArrayList<LineNode> compressedLines = new ArrayList<>();

    //? ?// w  w w.  j a va 2  s.c o m
    for (String line : lines) {
        LineNode curNode = new LineNode(line);

        if (curNode.isBlank()) {
            if (compressedLines.size() == 0) {
                continue;
            }

            LineNode last = compressedLines.get(compressedLines.size() - 1);
            if (last.isBlank()) {
                last.m_blankLines++;
            } else {
                compressedLines.add(curNode);
            }

        } else {
            compressedLines.add(curNode);
        }
    }

    return compressedLines;
}

From source file:com.seer.datacruncher.spring.SchemasReadController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    UserEntity user = (UserEntity) session.getAttribute("user");
    if (user == null) {
        return null;
    }/*from ww w . j a  va 2 s  .  c  om*/
    String start = request.getParameter("start");
    String limit = request.getParameter("limit");

    if (start == null || limit == null) {
        start = "-1";
        limit = "-1";
    }
    ObjectMapper mapper = new ObjectMapper();
    long appId = -1;
    String appIds = request.getParameter("appIds");
    String paramIdSchemaType = null;
    List<String> idSchemaTypeList = null;
    int idSchemaType = -1;

    if (appIds != null && (appIds.trim().length() == 0 || appIds.equals("-1"))) {
        appIds = null;
    }

    if (request.getParameter("idSchemaType") != null) {
        idSchemaType = -1;
        paramIdSchemaType = request.getParameter("idSchemaType");
        if ((paramIdSchemaType.indexOf(",", 0)) < 0) {
            // 1 condition
            idSchemaType = Integer.parseInt(request.getParameter("idSchemaType"));
        } else {
            //more condition
            idSchemaTypeList = Arrays.asList(StringUtils.splitPreserveAllTokens(paramIdSchemaType, ","));
        }
    }
    String strAppId = request.getParameter("appId");
    if (strAppId != null && !strAppId.trim().isEmpty()) {
        appId = Integer.valueOf(strAppId);
        if (appId == 0)
            appId = -1;
    }
    mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
    ServletOutputStream out = null;
    response.setContentType("application/json");
    out = response.getOutputStream();
    ReadList readList = null;

    if (user.getIdRole() == Roles.ADMINISTRATOR.getDbCode()) {
        if (idSchemaTypeList != null) {
            readList = schemasDao.readBySchemaTypeId(Integer.parseInt(start), Integer.parseInt(limit),
                    idSchemaTypeList, appIds);
        } else {
            readList = schemasDao.readBySchemaTypeId(Integer.parseInt(start), Integer.parseInt(limit),
                    idSchemaType, appIds);
        }
    } else {
        readList = schemasDao.read(Integer.parseInt(start), Integer.parseInt(limit), user.getIdUser());
    }

    //FIXME: Check with Mario

    @SuppressWarnings("unchecked")
    List<SchemaEntity> SchemaEntities = (List<SchemaEntity>) readList.getResults();
    if (SchemaEntities != null && SchemaEntities.size() > 0) {
        for (SchemaEntity schemaEntity : SchemaEntities) {
            ReadList readTriggersList = schemaTriggerStatusDao.findByIdSchema(schemaEntity.getIdSchema());
            if (CollectionUtils.isNotEmpty(readTriggersList.getResults())) {
                SchemaTriggerStatusEntity schemaTriggerStatusEntity = (SchemaTriggerStatusEntity) readTriggersList
                        .getResults().get(0);
                schemaEntity.setSchemaEvents(schemaTriggerStatusEntity);
            }
        }
    }

    out.write(mapper.writeValueAsBytes(readList));
    out.flush();
    out.close();
    return null;
}

From source file:com.ewcms.publication.uri.UriRule.java

/**
 * ??//from w  w w.j  a  va  2s. c  om
 * 
 * @param variable ????
 * @param parameters ??
 * @return ??
 * @throws PublishException
 */
Object getVariableValue(String variable, Map<String, Object> parameters) throws PublishException {
    logger.debug("Variable is {}", variable);
    String p = StringUtils.splitPreserveAllTokens(variable, ".")[0];
    logger.debug("Parameter name is {}", p);

    String parameter = ALIAS_PARAMETERS.get(p);
    if (parameter == null) {
        logger.warn("\"{}\" parameter is not exist", p);
        parameter = p;
    }
    Object object = parameters.get(parameter);
    if (object == null) {
        logger.error("\"{}\" parameter is not exist", parameter);
        throw new PublishException(variable + " is not exist");
    }
    try {
        if (!p.equals(variable)) {
            String property = StringUtils.removeStart(variable, p + ".");
            logger.debug("Property name is {}", property);
            return PropertyUtils.getProperty(object, property);
        } else {
            return object;
        }
    } catch (Exception e) {
        logger.error("Get variable value is error:{}", e.toString());
        throw new PublishException(e);
    }
}

From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQLNew.java

/**
 * @param line/*from  w w w. j  a  v  a2  s.  co m*/
 * @return
 */
private Vector<String> split(final String line) {
    toks.clear();

    String[] tokens = StringUtils.splitPreserveAllTokens(line, '|');
    for (String s : tokens) {
        toks.add(s);
    }

    /*if (false)
    {
    System.out.println(toks.size());
    if (toks.size() != 199)
    {
        System.out.println("Line["+line+"] is "+toks.size());
    }
    }*/
    return toks;
}

From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQL.java

/**
 * @param line/*w  w  w  .j  a v  a2 s  .c o m*/
 * @return
 */
private Vector<String> split(final String line, final char c) {
    toks.clear();

    String[] tokens = StringUtils.splitPreserveAllTokens(line, c);
    for (String s : tokens) {
        toks.add(s);
    }
    return toks;
}

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.converter.impl.DefaultImpexConverter.java

protected String escapeQuotes(final String input) {
    final String[] splitedInput = StringUtils.splitPreserveAllTokens(input, SEMICOLON_CHAR);
    final List<String> tmp = new ArrayList<String>();
    for (final String string : splitedInput) {
        if (doesNotContainNewLine(string)) {
            tmp.add(StringEscapeUtils.escapeCsv(string));
        } else {/*from   w  w  w.  ja  v a2s  .  com*/
            tmp.add(string);
        }
    }
    return StringUtils.join(tmp, SEMICOLON_CHAR);
}