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

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

Introduction

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

Prototype

public static String[] splitPreserveAllTokens(final String str, final 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:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

private boolean containsKeyImpl(String key) {
    return this.containsKeyImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR));
}

From source file:org.diorite.config.serialization.comments.CommentsWriter.java

private void writeComment(String comment) throws IOException {
    if (comment.isEmpty()) {
        return;/*from  www .  j  a  v  a  2 s  .c  om*/
    }
    String[] strings = StringUtils.splitPreserveAllTokens(comment, '\n');
    int i = 1;
    int size = strings.length;
    for (String string : strings) {
        this.writer.write(this.cachedIndent);
        this.writer.write("# ");
        this.writer.write(string);
        this.writeNewLine(true);
    }
    this.lineLock = false;
}

From source file:org.diorite.config.serialization.snakeyaml.emitter.Emitter.java

void writeComment(String comment, int firstNewLine, int lastNewLine) throws IOException {
    while (firstNewLine-- > 0) {
        this.writeLineBreak(null);
    }/* ww  w. ja v  a  2 s  .c o m*/
    this.printComments(StringUtils.splitPreserveAllTokens(comment, '\n'));
    while (lastNewLine-- > 0) {
        this.writeLineBreak(null);
    }
}

From source file:org.docx4j.template.utils.WMLPackageUtils.java

public static void replaceParagraph(String placeholder, String textToAdd, WordprocessingMLPackage template,
        ContentAccessor addTo) {/*  w  w w  .  j av  a 2  s.  com*/
    // 1. get the paragraph  
    List<P> paragraphs = getTargetElements(template.getMainDocumentPart(), P.class);
    P toReplace = null;
    for (P p : paragraphs) {
        List<Text> texts = getTargetElements(p, Text.class);
        for (Text t : texts) {
            Text content = (Text) t;
            if (content.getValue().equals(placeholder)) {
                toReplace = (P) p;
                break;
            }
        }
    }

    // we now have the paragraph that contains our placeholder: toReplace  
    // 2. split into seperate lines  
    String as[] = StringUtils.splitPreserveAllTokens(textToAdd, '\n');

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

        // 3. copy the found paragraph to keep styling correct  
        P copy = (P) XmlUtils.deepCopy(toReplace);

        // replace the text elements from the copy  
        List<?> texts = getTargetElements(copy, Text.class);
        if (texts.size() > 0) {
            Text textToReplace = (Text) texts.get(0);
            textToReplace.setValue(ptext);
        }

        // add the paragraph to the document  
        addTo.getContent().add(copy);
    }

    // 4. remove the original one  
    ((ContentAccessor) toReplace.getParent()).getContent().remove(toReplace);

}

From source file:org.kalypso.model.wspm.ewawi.data.reader.AbstractEwawiReader.java

private void readLine(final String line) throws ParseException {
    try {/*ww w  . ja  va 2s .co  m*/
        final String[] tabs = StringUtils.splitPreserveAllTokens(line, '\t'); //$NON-NLS-1$
        readTabs(tabs);
    } catch (final NumberFormatException e) {
        e.printStackTrace();
        throw new ParseException(line, 0);
    }
}

From source file:org.kalypso.model.wspm.ui.featureview.ChartFeatureControlFactory.java

private CommandWithStyle[] parseCommands(final String cmdIds, final String cmdStyles) {
    final String[] commandIds = StringUtils.splitPreserveAllTokens(cmdIds, ';');
    final String[] commandStyles = StringUtils.splitPreserveAllTokens(cmdStyles, ';');

    final Collection<CommandWithStyle> commands = new ArrayList<>();

    if (commandIds.length != commandStyles.length) {
        final String msg = Messages.getString(
                "org.kalypso.model.wspm.ui.featureview.ChartFeatureControlFactory.0", commandIds, //$NON-NLS-1$
                commandIds.length, cmdStyles, commandStyles.length);
        final IStatus status = new Status(IStatus.WARNING, KalypsoModelWspmUIPlugin.ID, msg);
        KalypsoCorePlugin.getDefault().getLog().log(status);
    } else {/*  www  .  j a v a  2s .  c  om*/
        for (int i = 0; i < commandIds.length; i++) {
            final String cmdId = commandIds[i].trim();
            final String cmdStyle = commandStyles[i].trim();

            final int styleFromString = SWTUtilities.createStyleFromString(cmdStyle);
            final int style = styleFromString == 0 ? SWT.PUSH : styleFromString;
            commands.add(new CommandWithStyle(cmdId, style));
        }
    }

    return commands.toArray(new CommandWithStyle[commands.size()]);
}

From source file:org.omnaest.utils.table.impl.serializer.CsvUnmarshallerImpl.java

private String[] extractCellTokensFromLine(String line) {
    ////from w  ww .j ava  2s . c o m
    String[] retvals = null;

    if (line != null) {
        //
        if (StringUtils.isNotEmpty(this.configuration.getQuotationCharacter())) {
            //
            final List<String> retlist = new ArrayList<String>();
            QuotationTextParser quotationTextParser = new QuotationTextParser(line,
                    this.configuration.getDelimiter(), this.configuration.getQuotationCharacter());
            for (String next = null; (next = quotationTextParser.next()) != null;) {
                retlist.add(next);
            }
            retvals = retlist.toArray(new String[retlist.size()]);
        } else {
            retvals = StringUtils.splitPreserveAllTokens(line, this.configuration.getDelimiter());
        }
    }

    //
    return retvals;
}

From source file:org.omnaest.utils.table.impl.serializer.PlainTextUnmarshaller.java

@SuppressWarnings("unchecked")
@Override//from w  ww.  j  a  v  a2  s .c  o  m
public Table<E> from(Reader reader) {
    /*
    ===Table1===
    !  !c0 !c1 !
    !r0!0:0|0:1|
    !r1!1:0|1:1|
    !r2!2:0|2:1|
    ------------
    */

    //
    if (reader != null) {
        //
        this.table.clear();

        //
        final Scanner scanner = new Scanner(reader);

        //
        {
            //
            String firstLine = scanner.hasNextLine() ? scanner.nextLine() : null;
            if (firstLine != null && firstLine.startsWith(delimiterTableTitle)) {
                //
                String tableName = firstLine.replaceAll(delimiterTableTitle, "");
                this.table.setTableName(tableName);
            }
        }

        //
        boolean hasRowTitles = false;
        String line = scanner.hasNextLine() ? scanner.nextLine() : null;
        if (line != null && line.startsWith(delimiterTitleColumn) && line.endsWith(delimiterTitleColumn)) {
            //
            String[] columnTokens = StringUtils.splitPreserveAllTokens(line, delimiterTitleColumn);
            if (columnTokens.length > 1) {
                //
                columnTokens = ArrayUtils.remove(columnTokens, columnTokens.length - 1);
                columnTokens = ArrayUtils.remove(columnTokens, 0);
            }

            //
            line = scanner.hasNextLine() ? scanner.nextLine() : null;

            //
            if (line != null && line.startsWith(delimiterTitleColumn)) {
                //
                if (columnTokens.length > 0) {
                    //
                    columnTokens = ArrayUtils.remove(columnTokens, 0);
                }
            }

            //
            columnTokens = org.omnaest.utils.structure.array.ArrayUtils.trimStringArrayTokens(columnTokens);

            //
            this.table.setColumnTitles(Arrays.asList(columnTokens));
        }

        //
        hasRowTitles = line != null && line.startsWith(delimiterTitleColumn);

        //
        int rowIndexPosition = 0;
        while (line != null) {
            //
            if (!line.startsWith(delimiterRow)) {
                //
                String[] cellTokens = StringUtils.splitPreserveAllTokens(line, delimiterColumn);
                if (cellTokens.length > 0) {
                    //
                    cellTokens = ArrayUtils.remove(cellTokens, cellTokens.length - 1);
                }

                //
                if (cellTokens.length > 0 && hasRowTitles) {
                    //
                    String[] firstCellTokens = StringUtils.splitPreserveAllTokens(cellTokens[0],
                            delimiterTitleColumn);

                    //
                    firstCellTokens = org.omnaest.utils.structure.array.ArrayUtils
                            .trimStringArrayTokens(firstCellTokens);

                    //
                    if (firstCellTokens.length >= 2) {
                        //
                        final String titleValue = firstCellTokens[1];
                        this.table.setRowTitle(rowIndexPosition, titleValue);
                    }

                    //
                    cellTokens[0] = "";
                    if (firstCellTokens.length >= 3) {
                        cellTokens[0] = firstCellTokens[2];
                    }
                } else if (cellTokens.length > 0) {
                    //
                    cellTokens = ArrayUtils.remove(cellTokens, 0);
                }

                //
                cellTokens = org.omnaest.utils.structure.array.ArrayUtils.trimStringArrayTokens(cellTokens);

                //
                final Class<E> elementType = this.table.elementType();
                E[] elements = (E[]) Array.newInstance(elementType, cellTokens.length);
                for (int ii = 0; ii < elements.length; ii++) {
                    elements[ii] = ObjectUtils.castTo(elementType, cellTokens[ii]);
                }
                this.table.setRowElements(rowIndexPosition++, elements);
            }

            //
            line = scanner.hasNextLine() ? scanner.nextLine() : null;
        }

    }

    // 
    return this.table;
}

From source file:org.sakaiproject.assignment.api.AssignmentReferenceReckoner.java

/**
 * This is a builder for an AssignmentReference
 *
 * @param container/*from  ww w.j a va2s .  c  o m*/
 * @param context
 * @param id
 * @param reference
 * @param subtype
 * @return
 */
@Builder(builderMethodName = "reckoner", buildMethodName = "reckon")
public static AssignmentReference newAssignmentReferenceReckoner(Assignment assignment,
        AssignmentSubmission submission, String container, String context, String id, String reference,
        String subtype) {
    if (StringUtils.startsWith(reference, REFERENCE_ROOT)) {
        // we will get null, assignment, [a|c|s|grades|submissions], context, [auid], id
        String[] parts = StringUtils.splitPreserveAllTokens(reference, Entity.SEPARATOR);
        if (parts.length > 2) {
            if (subtype == null)
                subtype = parts[2];

            if (parts.length > 3) {
                // context is the container
                if (context == null)
                    context = parts[3];

                // submissions have the assignment unique id as a container
                if ("s".equals(subtype) && parts.length > 5) {
                    if (container == null)
                        container = parts[4];
                    if (id == null)
                        id = parts[5];
                } else {
                    // others don't
                    if (parts.length > 4) {
                        if (id == null)
                            id = parts[4];
                    }
                }
            }
        }
    } else if (assignment != null) {
        context = assignment.getContext();
        id = assignment.getId();
        subtype = "a";
    } else if (submission != null) {
        Assignment submissionAssignment = submission.getAssignment();
        if (submissionAssignment != null) {
            context = submission.getAssignment().getContext();
            container = submission.getAssignment().getId();
            id = submission.getId();
            subtype = "s";
        } else {
            log.warn("no assignment while constructing submission reference");
        }
    }
    return new AssignmentReference((container == null) ? "" : container, (context == null) ? "" : context,
            (id == null) ? "" : id, (reference == null) ? "" : reference, (subtype == null) ? "" : subtype);
}

From source file:org.spicyurl.UrlParser.java

private void parseHostPort(String hostPort) {
    String[] stage0 = StringUtils.splitPreserveAllTokens(hostPort, PORT_SEP);
    if (stage0.length > 2) {
        url.getValidationErrorsModifiable().add(UrlErrors.INVALID_PORT_VALUE);
        return;/*from   w ww  .  j  a  v  a 2 s.  com*/
    }
    url.setHost(stage0[0]);
    if (stage0.length == 2) {
        parsePort(stage0[1]);
    }
}