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:com.neatresults.mgnltweaks.ui.contentapp.browser.QueryableJcrContainer.java

@Override
protected QueryResult executeQuery(String statement, String language, long limit, long offset)
        throws RepositoryException {
    log.debug("ST: {}", statement);
    String[] segments = StringUtils.split(path, "/");
    // templates needs 2 queries - one for website and one for config
    if ("templates".equals(segments[2])) {
        // pages/*from   w  w  w . jav a  2 s .c  o m*/
        QueryResult res1 = super.executeQuery(statement, language, limit, offset);
        // config
        this.setWorkspace(RepositoryConstants.CONFIG);
        statement = StringUtils.substringBefore(statement, " where ") + " where"
        // id references (availability, autogeneration, ...)
                + " contains(t.*,'" + segments[1] + ":" + StringUtils.substringAfter(path, "/templates/") + "')"
                // extends
                + buildExtends(path);
        log.debug("ST2: {}", statement);
        QueryResult res2 = super.executeQuery(statement, language, limit, offset);
        return new AggregatedQueryResult(res1, res2);
    }
    this.setWorkspace(RepositoryConstants.CONFIG);
    return super.executeQuery(statement, language, limit, offset);
}

From source file:jodtemplate.pptx.postprocessor.StylePostprocessor.java

private void processComment(final Comment comment, final Element at, final Slide slide,
        final Configuration configuration) throws JODTemplateException {
    String commentText = comment.getText();
    if (commentText.startsWith(STYLIZED_KEYWORD)) {
        commentText = StringUtils.removeStart(commentText, STYLIZED_KEYWORD);
        final String className = StringUtils.substringBefore(commentText, ":");
        commentText = StringUtils.removeStart(commentText, className + ": ");
        final Stylizer stylizer = configuration.getStylizer(className);
        if (stylizer == null) {
            throw new JODTemplateException("Unable to find stylizer");
        }/*from  w w w  . j a va2  s.  c o  m*/
        final String text = StringUtils.removeStart(commentText, " stylized: ");
        final Element ar = at.getParentElement();
        final Element ap = ar.getParentElement();
        final int arIndex = ap.indexOf(ar);
        final Element arPr = getArPrElement(ar);
        final Element apPr = getApPrElement(ap);
        final Element sourceApPr = ObjectUtils.clone(apPr);
        cleanApPrElement(apPr);

        final List<Element> stylizedElements = stylizer.stylize(text, arPr, apPr, slide);

        ap.removeContent(ar);
        final List<Element> remains = getRemainingElements(arIndex, ap);
        for (Element el : remains) {
            ap.removeContent(el);
        }

        final int currentApIndex = injectElementsInDocument(stylizedElements, ap, apPr, arIndex);
        injectRemainsInDocument(remains, ap, sourceApPr, currentApIndex);
    }
}

From source file:de.jfachwert.post.Ort.java

private static String[] split(String name) {
    String input = StringUtils.trimToEmpty(name);
    String[] splitted = new String[] { "", input };
    if (input.contains(" ")) {
        try {/*from  ww  w.  ja v  a 2 s.  c  o  m*/
            String plz = PLZ.validate(StringUtils.substringBefore(input, " "));
            splitted[0] = plz;
            splitted[1] = StringUtils.substringAfter(input, " ").trim();
        } catch (ValidationException ex) {
            LOG.log(Level.FINE, "no PLZ inside '" + name + "' found:", ex);
        }
    }
    return splitted;
}

From source file:io.github.kitarek.elasthttpd.plugins.consumers.file.mapper.UriToFileMapper.java

public String getNormalizedUriRequestPathWithoutQueryString(String uriRequestPath) {
    return normalizeUrlRequestPath(
            StringUtils.substringBefore(uriRequestPath, QUERY_STRING_REQUEST_PATH_SEPARATOR));
}

From source file:com.norconex.commons.lang.time.YearMonthDay.java

/**
 * Constructs a YearMonthDay from a string of this format: 
 * <code>yyyy-MM-dd</code>./* w  w  w  . ja  va  2  s  .  c om*/
 * @param date a date string
 */
public YearMonthDay(String date) {
    this(Integer.valueOf(StringUtils.substringBefore(date, "-")),
            Integer.valueOf(StringUtils.substringBetween(date, "-")),
            Integer.valueOf(StringUtils.substringAfterLast(date, "-")));
}

From source file:com.jkoolcloud.tnt4j.streams.transform.FuncGetObjectName.java

private static String resolveObjectName(String objectName, List<?> args) {
    String option = args.size() > 1 ? (String) args.get(1) : null;
    Options opt;/*from w ww.  j a  v a  2 s  .  c o  m*/

    try {
        opt = StringUtils.isEmpty(option) ? Options.DEFAULT : Options.valueOf(option.toUpperCase());
    } catch (IllegalArgumentException exc) {
        opt = Options.DEFAULT;
    }

    switch (opt) {
    case FULL:
        break;
    case BEFORE:
        String sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringBefore(objectName, sSymbol);
        }
        break;
    case AFTER:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            objectName = StringUtils.substringAfter(objectName, sSymbol);
        }
        break;
    case REPLACE:
        sSymbol = args.size() > 2 ? (String) args.get(2) : null;
        if (StringUtils.isNotEmpty(sSymbol)) {
            String rSymbol = args.size() > 3 ? (String) args.get(3) : null;
            objectName = StringUtils.replaceChars(objectName, sSymbol, rSymbol == null ? "" : rSymbol);
        }
        break;
    case SECTION:
        String idxStr = args.size() > 2 ? (String) args.get(2) : null;
        int idx;
        try {
            idx = Integer.parseInt(idxStr);
        } catch (Exception exc) {
            idx = -1;
        }

        if (idx >= 0) {
            sSymbol = args.size() > 3 ? (String) args.get(3) : null;
            String[] onTokens = StringUtils.split(objectName,
                    StringUtils.isEmpty(sSymbol) ? OBJ_NAME_TOKEN_DELIMITERS : sSymbol);
            objectName = idx < ArrayUtils.getLength(onTokens) ? onTokens[idx] : objectName;
        }
        break;
    case DEFAULT:
    default:
        idx = StringUtils.indexOfAny(objectName, OBJ_NAME_TOKEN_DELIMITERS);
        if (idx > 0) {
            objectName = StringUtils.substring(objectName, 0, idx);
        }
        break;
    }

    return objectName;
}

From source file:de.vandermeer.skb.datatool.backend.BackendLatexAcrLog.java

/**
 * Loads and processes the the LaTeX, creates list of found acronyms.
 * @throws IOException if there is a problem with the file read
 */// w w  w .j  ava2  s. c o  m
public void loadLatexLog() throws IOException {
    Validate.validState(this.file != null);
    BufferedReader br = new BufferedReader(new FileReader(this.file));
    String line;
    while ((line = br.readLine()) != null) {
        if (StringUtils.contains(line, "Package acronym ")) {
            if (StringUtils.contains(line, "Info: ")) {
                String acro = StringUtils.substringAfter(line, "acro:");
                acro = StringUtils.substringBefore(acro, "'");
                this.acronymsLog.add(acro);
                this.acronymsUsed++;
            } else if (StringUtils.contains(line, "Warning: ")) {
                String acro = StringUtils.substringAfter(line, "`");
                acro = StringUtils.substringBefore(acro, "'");
                this.acronymsLog.add(acro);
                this.acronymsUsed++;
            } else {
                System.err.println("##########");
            }
        }
    }
    br.close();
}

From source file:edu.toronto.cs.phenotips.solr.HPOScriptService.java

/**
 * Get the HPO IDs of the specified phenotype and all its ancestors.
 * //w ww  .j a v  a 2 s. com
 * @param id the HPO identifier to search for, in the {@code HP:1234567} format
 * @return the full set of ancestors-or-self IDs, or an empty set if the requested ID was not found in the index
 */
public Set<String> getAllAncestorsAndSelfIDs(final String id) {
    Set<String> results = new HashSet<String>();
    Queue<SolrDocument> nodes = new LinkedList<SolrDocument>();
    SolrDocument crt = this.get(id);
    if (crt == null) {
        return results;
    }
    nodes.add(crt);
    while (!nodes.isEmpty()) {
        crt = nodes.poll();
        results.add(String.valueOf(crt.get(ID_FIELD_NAME)));
        @SuppressWarnings("unchecked")
        List<String> parents = (List<String>) crt.get("is_a");
        if (parents == null) {
            continue;
        }
        for (String pid : parents) {
            nodes.add(this.get(StringUtils.substringBefore(pid, " ")));
        }
    }
    return results;
}

From source file:com.cognifide.qa.bb.cumber.BobcumberListener.java

private boolean isScenario(String displayName) {
    boolean isScenario = false;
    if (displayName.contains(COLON)) {
        String testStep = StringUtils.substringBefore(displayName, COLON);
        isScenario = SCENARIO_STATEMENT.equals(testStep);
    }/*from  w  w  w .ja  va  2s .  co m*/
    return isScenario;
}

From source file:com.sonicle.webtop.core.app.servlet.ServletHelper.java

public static String sanitizeBaseUrl(String url) {
    url = StringUtils.substringBefore(url, Login.URL);
    url = StringUtils.substringBefore(url, Logout.URL);
    url = StringUtils.substringBefore(url, UIPrivate.URL);
    url = StringUtils.substringBefore(url, Otp.URL);
    url = StringUtils.substringBefore(url, ResourceRequest.URL);
    url = StringUtils.substringBefore(url, PrivateRequest.URL);
    url = StringUtils.substringBefore(url, PublicRequest.URL);
    url = StringUtils.substringBefore(url, RestApi.URL);
    return PathUtils.ensureTrailingSeparator(url);
}