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

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

Introduction

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

Prototype

public static String substringBefore(final String str, final String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:org.polymap.rhei.fulltext.address.AddressTokenFilter.java

@Override
public String apply(String term) {
    if (term.endsWith("str")) {
        return StringUtils.substringBefore(term, "str");
    } else if (term.endsWith("strasse")) {
        return StringUtils.substringBefore(term, "strasse");
    } else if (term.endsWith("strae")) {
        return StringUtils.substringBefore(term, "strae");
    }/*  w w w.  j  a va2  s.co  m*/
    return term;

    //                final char[] buffer = termAtt.termBuffer();
    //                final int length = termAtt.termLength();
    //                for (int i = 0; i < length; i++)
    //                    buffer[i] = Character.toLowerCase( buffer[i] );
}

From source file:org.rippleosi.common.util.DateFormatter.java

public static String combineDateTime(Date date, Date time) {

    String dateAsString = toString(date);
    String timeAsString = toString(time);

    if (dateAsString == null || timeAsString == null) {
        return null;
    }/*from  w w  w. j  a  v a 2  s  . co  m*/

    return StringUtils.substringBefore(dateAsString, "T") + "T" + StringUtils.substringAfter(timeAsString, "T");
}

From source file:org.sakuli.services.forwarder.icinga2.model.Icinga2Result.java

public Optional<Integer> getCodeOfFirstElement() {
    if (results != null) {
        return results.stream().filter(Objects::nonNull).findFirst().map(e -> e.get("code"))
                .map(s -> Integer.valueOf(StringUtils.substringBefore(s, ".")));
    }/*w  w  w .j a va  2s . c o  m*/
    return Optional.empty();
}

From source file:org.sbs.goodcrawler.extractor.selector.action.string.StringBeforeAction.java

/**
 * ?beforeString?/* w w w.jav  a 2s . c  om*/
 */
@Override
public String doAction(String content) {
    if (StringUtils.isNotBlank(content)) {
        return StringUtils.substringBefore(content, this.separator);
    }
    return "";
}

From source file:org.sleuthkit.autopsy.imageanalyzer.gui.navpanel.GroupTreeItem.java

/**
 * Recursive method to add a grouping at a given path.
 *
 * @param path Full path (or subset not yet added) to add
 * @param g Group to add/* w w w.  j a  va  2  s  . c  o  m*/
 * @param tree True if it is part of a tree (versus a list)
 */
void insert(String path, DrawableGroup g, Boolean tree) {
    if (tree) {
        String cleanPath = StringUtils.stripStart(path, "/");

        // get the first token
        String prefix = StringUtils.substringBefore(cleanPath, "/");

        // Are we at the end of the recursion?
        if ("".equals(prefix)) {
            getValue().setGroup(g);
        } else {
            GroupTreeItem prefixTreeItem = childMap.get(prefix);
            if (prefixTreeItem == null) {
                final GroupTreeItem newTreeItem = new GroupTreeItem(prefix, null, comp);

                prefixTreeItem = newTreeItem;
                childMap.put(prefix, prefixTreeItem);
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (getChildren()) {
                            getChildren().add(newTreeItem);
                        }
                    }
                });

            }

            // recursively go into the path
            prefixTreeItem.insert(StringUtils.stripStart(cleanPath, prefix), g, tree);
        }
    } else {
        GroupTreeItem treeItem = childMap.get(path);
        if (treeItem == null) {
            final GroupTreeItem newTreeItem = new GroupTreeItem(path, g, comp);
            newTreeItem.setExpanded(true);
            childMap.put(path, newTreeItem);

            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    synchronized (getChildren()) {
                        getChildren().add(newTreeItem);
                        if (comp != null) {
                            FXCollections.sort(getChildren(), comp);
                        }
                    }
                }
            });

        }
    }
}

From source file:org.sleuthkit.autopsy.imagegallery.gui.navpanel.GroupTreeItem.java

/**
 * Recursive method to add a grouping at a given path.
 *
 * @param path Full path (or subset not yet added) to add
 * @param g    Group to add/*from   ww w .  ja  v a  2s  .c o m*/
 * @param tree True if it is part of a tree (versus a list)
 */
void insert(String path, DrawableGroup g, Boolean tree) {
    if (tree) {
        String cleanPath = StringUtils.stripStart(path, "/");

        // get the first token
        String prefix = StringUtils.substringBefore(cleanPath, "/");

        // Are we at the end of the recursion?
        if ("".equals(prefix)) {
            getValue().setGroup(g);
        } else {
            GroupTreeItem prefixTreeItem = childMap.get(prefix);
            if (prefixTreeItem == null) {
                final GroupTreeItem newTreeItem = new GroupTreeItem(prefix, null, comp);

                prefixTreeItem = newTreeItem;
                childMap.put(prefix, prefixTreeItem);
                Platform.runLater(() -> {
                    synchronized (getChildren()) {
                        getChildren().add(newTreeItem);
                    }
                });

            }

            // recursively go into the path
            prefixTreeItem.insert(StringUtils.stripStart(cleanPath, prefix), g, tree);
        }
    } else {
        GroupTreeItem treeItem = childMap.get(path);
        if (treeItem == null) {
            final GroupTreeItem newTreeItem = new GroupTreeItem(path, g, comp);
            newTreeItem.setExpanded(true);
            childMap.put(path, newTreeItem);

            Platform.runLater(() -> {
                synchronized (getChildren()) {
                    getChildren().add(newTreeItem);
                    if (comp != null) {
                        FXCollections.sort(getChildren(), comp);
                    }
                }
            });

        }
    }
}

From source file:org.spdx.rdfparser.license.ListedLicenses.java

private void loadListedLicenseIDs() {
    listedLicenseModificationLock.writeLock().lock();
    try {/*from  www.  ja v a 2 s.  c om*/
        listedLicenseCache = Maps.newHashMap(); // clear the cache
        listdLicenseIds = Sets.newHashSet(); //Clear the listed license IDs to avoid stale licenses.
        //TODO: Can the keys of listedLicenseCache be used instead of this set?
        //NOTE: THis includes deprecated licenses - should this be changed to only return non-deprecated licenses?
        Model stdLicenseModel = getListedLicenseModel();
        Node p = stdLicenseModel.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_ID)
                .asNode();
        Triple m = Triple.createMatch(null, p, null);
        ExtendedIterator<Triple> tripleIter = stdLicenseModel.getGraph().find(m);
        while (tripleIter.hasNext()) {
            Triple t = tripleIter.next();
            listdLicenseIds.add(t.getObject().toString(false));
        }
        p = stdLicenseModel
                .getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_LIST_VERSION)
                .asNode();
        m = Triple.createMatch(null, p, null);
        tripleIter = stdLicenseModel.getGraph().find(m);
        if (tripleIter.hasNext()) {
            Triple t = tripleIter.next();
            String licenseListVersionPropertyValue = t.getObject().toString(false);
            licenseListVersion = StringUtils.substringBefore(licenseListVersionPropertyValue, " "); //Omit any superfluous data, such as a date
        }
    } catch (Exception ex) {
        logger.error("Error loading SPDX listed license ID's from model.");
    } finally {
        listedLicenseModificationLock.writeLock().unlock();
    }
}

From source file:org.spdx.rdfparser.license.TestListedLicenses.java

@Test
public void testLicenseListVersionFormat() {
    String licenseListversion = ListedLicenses.getListedLicenses().getLicenseListVersion();

    Assert.assertEquals("Expected one point in license list version. ", 1,
            StringUtils.countMatches(licenseListversion, "."));
    Assert.assertTrue("Number expected before the point in license list version (" + licenseListversion + ")",
            StringUtils.isNumeric(StringUtils.substringBefore(licenseListversion, ".")));
    Assert.assertTrue("Number expected after the point in license list version (" + licenseListversion + ")",
            StringUtils.isNumeric(StringUtils.substringAfter(licenseListversion, ".")));
}

From source file:org.spicyurl.UrlParser.java

private void parseLogin(String login) {
    if (StringUtils.contains(login, USER_PASS_SEP)) {
        url.setUsername(StringUtils.substringBefore(login, USER_PASS_SEP));
        url.setPassword(StringUtils.substringAfter(login, USER_PASS_SEP));
    } else {/*from  ww w  . j av a 2 s.  co m*/
        url.setUsername(login);
    }
}

From source file:org.structr.console.rest.AsRestCommand.java

@Override
public boolean parseNext(final String line, final Writable writable) throws IOException {

    final String trimmed = line.trim();
    final String userString = StringUtils.substringBefore(trimmed, " ");
    final String remaining = StringUtils.substringAfter(trimmed, " ");

    if (StringUtils.isNoneBlank(userString, remaining)) {

        command = RestCommand.parse(remaining, writable);
        if (command != null) {

            final String[] parts = userString.split("[:]+");
            if (parts.length == 2) {

                command.authenticate(parts[0], parts[1]);

                // success
                return true;

            } else {

                writable.println("Syntax error, user string must be <username>:<password>.");
            }/*from   w w  w .  j a v  a 2s . c  om*/
        }

    } else {

        writable.println("Syntax error, user string must be <username>:<password>.");
    }

    return false;
}