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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.phenotips.vocabulary.internal.solr.MendelianInheritanceInMan.java

private SolrQuery addDynamicQueryParameters(String originalQuery, Integer rows, String sort, String customFq,
        SolrQuery query) {// w  w  w  .  j a v  a  2  s . c o  m
    String queryString = originalQuery.trim();
    String escapedQuery = ClientUtils.escapeQueryChars(queryString);
    query.setFilterQueries(StringUtils.defaultIfBlank(customFq, "+type:disorder"));
    query.setQuery(escapedQuery);
    query.set(SpellingParams.SPELLCHECK_Q, queryString);
    String lastWord = StringUtils.substringAfterLast(escapedQuery, " ");
    if (StringUtils.isBlank(lastWord)) {
        lastWord = escapedQuery;
    }
    lastWord += "*";
    query.set(DisMaxParams.BQ,
            String.format(
                    "nameSpell:%1$s^20 short_name:%1$s^20 synonymSpell:%1$s^12 text:%1$s^1 textSpell:%1$s^2",
                    lastWord));
    query.setRows(rows);
    if (StringUtils.isNotBlank(sort)) {
        for (String sortItem : sort.split("\\s*,\\s*")) {
            query.addSort(StringUtils.substringBefore(sortItem, " "),
                    sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc);
        }
    }
    return query;
}

From source file:org.phenotips.vocabulary.internal.solr.OrphanetRareDiseaseOntology.java

/**
 * Adds dynamic solr query parameters to {@code query}, based on the received {@code rawQuery raw query string},
 * {@code rows the maximum number of results to return}, {@code sort the sorting order}, and {@code customFilter a
 * custom filter}.//from  www . j  a  v  a  2 s  . c  om
 *
 * @param rawQuery unprocessed query string
 * @param rows the maximum number of search items to return
 * @param sort the optional sort parameter
 * @param customFilter custom filter for the results
 * @param query a {@link SolrQuery solr query} object
 * @return the updated {@link SolrQuery solr query} object
 */
private SolrQuery addDynamicQueryParam(@Nonnull final String rawQuery, final Integer rows,
        @Nullable final String sort, @Nullable final String customFilter, @Nonnull SolrQuery query) {
    final String queryString = rawQuery.trim();
    final String escapedQuery = ClientUtils.escapeQueryChars(queryString);
    if (StringUtils.isNotBlank(customFilter)) {
        query.setFilterQueries(customFilter);
    }
    query.setQuery(escapedQuery);
    query.set(SpellingParams.SPELLCHECK_Q, queryString);
    final String lastWord = StringUtils.defaultIfBlank(StringUtils.substringAfterLast(escapedQuery, " "),
            escapedQuery) + "*";
    query.set(DisMaxParams.BQ,
            String.format("nameSpell:%1$s^20 defSpell:%1$s^3 text:%1$s^1 textSpell:%1$s^2", lastWord));
    query.setRows(rows);
    if (StringUtils.isNotBlank(sort)) {
        for (final String sortItem : sort.split("\\s*,\\s*")) {
            query.addSort(StringUtils.substringBefore(sortItem, " "),
                    sortItem.endsWith(" desc") || sortItem.startsWith("-") ? ORDER.desc : ORDER.asc);
        }
    }
    return query;
}

From source file:org.polymap.wbv.mdb.WvkImporter.java

public WvkImporter(UnitOfWork uow, ClientFile clientFile, InputStream in) {
        super("WVK-Daten importieren");
        this.uow = uow;
        this.in = in;
        this.clientFile = clientFile;

        this.revier = StringUtils.substringAfterLast(FilenameUtils.getBaseName(clientFile.getName()), "_");
        if (!Revier.all.get().containsKey(revier)) {
            throw new IllegalStateException("Das Revier gibt es nicht: " + revier);
        }/*from   w w  w  . j a  v a  2s  . co  m*/
    }

From source file:org.sakaiproject.rubrics.logic.impl.RubricsServiceImpl.java

private Map<String, Map<String, String>> extractCriterionDataFromParams(HashMap<String, String> params) {

    Map<String, Map<String, String>> criterionDataMap = new HashMap();

    for (Map.Entry<String, String> param : params.entrySet()) {
        String possibleCriterionId = StringUtils.substringAfterLast(param.getKey(), "-");
        String criterionDataLabel = StringUtils.substringBeforeLast(param.getKey(), "-");
        if (StringUtils.isNumeric(possibleCriterionId)) {
            if (!criterionDataMap.containsKey(possibleCriterionId)) {
                criterionDataMap.put(possibleCriterionId, new HashMap());
            }//from  w w  w .  j  av  a  2  s  . co m
            criterionDataMap.get(possibleCriterionId).put(criterionDataLabel, param.getValue());
        }
    }

    return criterionDataMap;
}

From source file:org.sakaiproject.rubrics.logic.RubricsServiceImpl.java

private Map<String, Map<String, String>> extractCriterionDataFromParams(Map<String, String> params) {

    Map<String, Map<String, String>> criterionDataMap = new HashMap<>();

    for (Map.Entry<String, String> param : params.entrySet()) {
        String possibleCriterionId = StringUtils.substringAfterLast(param.getKey(), "-");
        String criterionDataLabel = StringUtils.substringBeforeLast(param.getKey(), "-");
        if (StringUtils.isNumeric(possibleCriterionId)) {
            if (!criterionDataMap.containsKey(possibleCriterionId)) {
                criterionDataMap.put(possibleCriterionId, new HashMap<>());
            }//from  w  w  w.j a v a  2s  .com
            criterionDataMap.get(possibleCriterionId).put(criterionDataLabel, param.getValue());
        }
    }

    return criterionDataMap;
}

From source file:org.sbs.util.download.MultiThreadDownload.java

/**
 * /*from  ww w .  j a va2 s  .  co  m*/
 * @param url
 * @param path
 * @param fileName
 * @return
 * @throws DownLoadException
 */
@SuppressWarnings("unchecked")
public File downLoad(final URL url, String path, String fileName) throws DownLoadException {
    // ??
    this.downLen = -1;
    this.contentLen = 0;
    this.date = new Date();
    this.finished = false;
    try {
        URLConnection con = url.openConnection();
        //?
        this.contentLen = con.getContentLength();
        //??
        if (StringUtils.isBlank(fileName)) {
            fileName = StringUtils.substringAfterLast(url.getPath(), "/");
        }
        //
        File _path = new File(path);
        if (!_path.exists()) {
            _path.mkdirs();
        }
        final File file = new File(path + File.separator + fileName);
        if (file.exists())
            file.delete();
        if (this.threadNum == 0 && this.blockSize > 0) {
            this.threadNum = (int) (contentLen / blockSize);
            if (this.threadNum == 0) {
                this.threadNum = 1;
            }
        }
        long subLen = contentLen / threadNum;
        List<Future<DownLoadBean>> result = Lists.newArrayList();
        for (int i = 0; i < threadNum; i++) {
            final int pos = (int) (i * subLen);
            final int end = (int) ((i + 1) * subLen) - 1;
            final int current = pos;
            Future<DownLoadBean> f = (Future<DownLoadBean>) pool.submit(new Callable<DownLoadBean>() {
                int $pos = pos;
                int $end = end;
                int $current = current;

                @Override
                public DownLoadBean call() throws Exception {
                    //buff
                    BufferedInputStream bis = null;
                    RandomAccessFile fos = null;
                    byte[] buf = new byte[BUFFER_SIZE];
                    URLConnection con = null;
                    try {
                        con = url.openConnection();
                        con.setAllowUserInteraction(true);
                        //???startPosendPos
                        con.setRequestProperty("Range", "bytes=" + $pos + "-" + $end);
                        fos = new RandomAccessFile(file, "rw");
                        //startPos
                        fos.seek($pos);
                        //????curPos???endPos
                        //endPos?
                        bis = new BufferedInputStream(con.getInputStream());
                        while ($current < $end) {
                            int len = bis.read(buf, 0, BUFFER_SIZE);
                            if (len == -1) {
                                break;
                            }
                            fos.write(buf, 0, len);
                            $current = $current + len;
                            if ($current - 1 > $end) {
                                throw new DownLoadException(
                                        "????");
                            }
                            addLen(len);
                        }
                        bis.close();
                        fos.close();
                    } catch (IOException ex) {
                        /* ?????
                        StringBuffer sb = new StringBuffer();
                        sb.append($pos).append("\t").append($current).append("\t").append($end).append("\n");
                         FileUtils.write(new File(file.getAbsolutePath()+".pos"), sb, true);
                         */
                        throw new RuntimeException(ex);
                    }
                    log.debug(this.hashCode() + ":??[" + $pos + "," + $end + "]");
                    return new DownLoadBean($pos, $end, $current);
                }
            });
            result.add(f);
        }
        Long resultTotal = 0L;
        for (Future<DownLoadBean> f : result) {
            DownLoadBean dInfo = f.get();
            resultTotal += dInfo.getCurrent() - dInfo.getPos();
        }
        // ?
        if (contentLen > resultTotal + 1) {
            // ???
            FileUtils.write(new File(down_error_log_file), url.toString() + "\n", true);
            throw new DownLoadException("?");
        } else {
            finished = true;
            return file;
        }
    } catch (IOException | InterruptedException | ExecutionException e) {
        // 
        try {
            FileUtils.write(new File(down_error_log_file), url.toString() + "\n", true);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
        e.printStackTrace();
    }
    return null;
}

From source file:org.spicyurl.UrlParser.java

private void parseLoginHostPort(String loginHostPort) {
    if (StringUtils.isEmpty(loginHostPort)) {
        url.getValidationErrorsModifiable().add(UrlErrors.HOST_IS_MISSING);
        return;/*w  w  w  .  j  a  va2  s.c  om*/
    }
    if (loginHostPort.contains(LOGIN_SEP)) {
        parseLogin(StringUtils.substringBeforeLast(loginHostPort, LOGIN_SEP));
        parseHostPort(StringUtils.substringAfterLast(loginHostPort, LOGIN_SEP));
    } else {
        parseHostPort(loginHostPort);
    }
}

From source file:org.springside.examples.bootservice.functional.TaskRestServiceTest.java

@Test
public void createUpdateAndDeleteTask() {

    // create/*from  w  w  w  .  jav  a2  s . c o m*/
    Task task = randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.title).isEqualTo(task.title);

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.id = new Long(id);
    task.title = RandomData.randomName("Task");

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.title).isEqualTo(task.title);

    // delete
    restTemplate.delete(createdTaskUri);
    Task deletedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(deletedTask).isNull();
}

From source file:org.springside.samples.quickservice.functional.TaskRestServiceTest.java

@Test
public void createUpdateAndDeleteTask() {

    // create//from ww  w . ja v  a 2s  . c  om
    Task task = randomTask();

    URI createdTaskUri = restTemplate.postForLocation(resourceUrl, task);
    System.out.println(createdTaskUri.toString());
    Task createdTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(createdTask.getTitle()).isEqualTo(task.getTitle());

    // update
    String id = StringUtils.substringAfterLast(createdTaskUri.toString(), "/");
    task.setId(new Long(id));
    task.setTitle(RandomData.randomName("Task"));

    restTemplate.put(createdTaskUri, task);

    Task updatedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(updatedTask.getTitle()).isEqualTo(task.getTitle());

    // delete
    restTemplate.delete(createdTaskUri);
    Task deletedTask = restTemplate.getForObject(createdTaskUri, Task.class);
    assertThat(deletedTask).isNull();
}

From source file:org.structr.common.PathHelper.java

/**
 * Return last part of path after separator or the path if no path separator was found.
 * //from w  w  w.j  a v a 2  s  .  com
 * @param path
 * @return name
 */
public static String getName(final String path) {

    String cleanedPath = clean(path);

    if (cleanedPath != null && cleanedPath.contains(PATH_SEP)) {

        return StringUtils.substringAfterLast(cleanedPath, PATH_SEP);

    } else {

        return cleanedPath;

    }
}