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.eryansky.common.orm.core.PropertyFilters.java

/**
 * ?/*from  w w w .java2 s  .co  m*/
 * <p>
 *    
 * </p>
 * <code>
 *    PropertyFilters.get("EQS_propertyName","maurice")
 * </code>
 * 
 * @param expression ?
 * @param matchValue 
 * 
 * @return {@link PropertyFilter}
 */
@SuppressWarnings("static-access")
public static PropertyFilter get(String expression, String matchValue) {

    Assert.hasText(expression, "??");

    String restrictionsNameAndClassType = StringUtils.substringBefore(expression, "_");

    String restrictionsName = StringUtils.substring(restrictionsNameAndClassType, 0,
            restrictionsNameAndClassType.length() - 1);
    String classType = StringUtils.substring(restrictionsNameAndClassType,
            restrictionsNameAndClassType.length() - 1, restrictionsNameAndClassType.length());

    FieldType FieldType = null;
    try {
        FieldType = FieldType.valueOf(classType);
    } catch (Exception e) {
        throw new IllegalAccessError(
                "[" + expression + "]??,?:" + classType);
    }

    String[] propertyNames = null;

    if (StringUtils.contains(expression, "_OR_")) {
        String temp = StringUtils.substringAfter(expression, restrictionsNameAndClassType + "_");
        propertyNames = StringUtils.splitByWholeSeparator(temp, "_OR_");
    } else {
        propertyNames = new String[1];
        propertyNames[0] = StringUtils.substringAfterLast(expression, "_");
    }

    return new PropertyFilter(restrictionsName, FieldType, propertyNames, matchValue);
}

From source file:com.thinkbiganalytics.nifi.rest.support.NifiTemplateNameUtil.java

/**
 * Return the process group name, removing the versioned timestamp if one exists
 *
 * @param name a process group name//from ww w.  ja  v a  2s. c  o  m
 * @return the process group name, removing the versioned timestamp if one exists
 */
public static String parseVersionedProcessGroupName(String name) {
    if (isVersionedProcessGroup(name)) {
        return StringUtils.substringBefore(name, " - ");
    }
    return name;
}

From source file:com.u2apple.rt.util.AndroidDeviceUtils.java

public static String getBrandByProductId(String productId) {
    String brand = null;/*  www  .j  a  va  2  s . c om*/
    if (StringUtils.isNotBlank(productId)) {
        brand = StringUtils.substringBefore(productId, "-");
    }
    return brand;
}

From source file:com.github.dactiv.orm.core.PropertyFilters.java

/**
 * ?/*w w w. j a v a2 s .  c  o  m*/
 * <p>
 *    
 * </p>
 * <code>
 *    PropertyFilters.build("EQS_propertyName","maurice")
 * </code>
 * 
 * @param expression ?
 * @param matchValue 
 * 
 * @return {@link PropertyFilter}
 */
@SuppressWarnings("static-access")
public static PropertyFilter build(String expression, String matchValue) {

    Assert.hasText(expression, "??");

    String restrictionsNameAndClassType = StringUtils.substringBefore(expression, "_");

    String restrictionsName = StringUtils.substring(restrictionsNameAndClassType, 0,
            restrictionsNameAndClassType.length() - 1);
    String classType = StringUtils.substring(restrictionsNameAndClassType,
            restrictionsNameAndClassType.length() - 1, restrictionsNameAndClassType.length());

    FieldType FieldType = null;
    try {
        FieldType = FieldType.valueOf(classType);
    } catch (Exception e) {
        throw new IllegalAccessError(
                "[" + expression + "]??,?:" + classType);
    }

    String[] propertyNames = null;

    if (StringUtils.contains(expression, "_OR_")) {
        String temp = StringUtils.substringAfter(expression, restrictionsNameAndClassType + "_");
        propertyNames = StringUtils.splitByWholeSeparator(temp, "_OR_");
    } else {
        propertyNames = new String[1];
        propertyNames[0] = StringUtils.substringAfterLast(expression, "_");
    }

    return new PropertyFilter(restrictionsName, FieldType, propertyNames, matchValue);
}

From source file:com.gargoylesoftware.htmlunit.html.IEConditionalCommentExpressionEvaluator.java

/**
 * Evaluates the condition./*from w  w  w  .  j  a v  a  2 s. com*/
 * @param condition the condition like "lt IE 7"
 * @param browserVersion the browser version. Note that currently it can only be an IE browser.
 * @return the evaluation result
 */
public static boolean evaluate(String condition, final BrowserVersion browserVersion) {
    condition = condition.trim();
    if ("IE".equals(condition)) {
        return true;
    } else if ("true".equals(condition)) {
        return true;
    } else if ("false".equals(condition)) {
        return false;
    } else if (condition.contains("&")) {
        return evaluate(StringUtils.substringBefore(condition, "&"), browserVersion)
                && evaluate(StringUtils.substringAfter(condition, "&"), browserVersion);
    } else if (condition.contains("|")) {
        return evaluate(StringUtils.substringBefore(condition, "|"), browserVersion)
                || evaluate(StringUtils.substringAfter(condition, "|"), browserVersion);
    } else if (condition.startsWith("!")) {
        return !evaluate(condition.substring(1), browserVersion);
    } else if (condition.startsWith("IE")) {
        final String currentVersion = Float.toString(browserVersion.getBrowserVersionNumeric());
        return currentVersion.startsWith(condition.substring(2).trim());
    } else if (condition.startsWith("lte IE")) {
        return browserVersion.getBrowserVersionNumeric() <= parseVersion(condition.substring(6));
    } else if (condition.startsWith("lt IE")) {
        return browserVersion.getBrowserVersionNumeric() < parseVersion(condition.substring(5));
    } else if (condition.startsWith("gt IE")) {
        return browserVersion.getBrowserVersionNumeric() > parseVersion(condition.substring(5));
    } else if (condition.startsWith("gte IE")) {
        return browserVersion.getBrowserVersionNumeric() >= parseVersion(condition.substring(6));
    } else if (condition.startsWith("lt")) {
        return true;
    } else if (condition.startsWith("gt")) {
        return false;
    } else if (condition.startsWith("(")) {
        // in fact not fully correct if () can be nested
        return evaluate(StringUtils.substringBetween(condition, "(", ")"), browserVersion);
    } else {
        return false;
    }
}

From source file:io.wcm.handler.url.rewriter.impl.UrlExternalizerTransformerConfig.java

private static Map<String, String> toElementAttributeNamesMap(String[] elementAttributeNames) {
    Map<String, String> map = new HashMap<>();
    for (String item : elementAttributeNames) {
        String elementName = StringUtils.trim(StringUtils.substringBefore(item, ELEMENT_ATTRIBUTE_SEPARATOR));
        String attributeName = StringUtils.trim(StringUtils.substringAfter(item, ELEMENT_ATTRIBUTE_SEPARATOR));
        if (StringUtils.isBlank(elementName) || StringUtils.isBlank(attributeName)) {
            log.info("Invalid URL externalizier transformer configuration - skipping invalid element entry: "
                    + item);/* www. j a v a  2 s .  c o  m*/
        } else if (map.containsKey(elementName)) {
            log.info("Invalid URL externalizier transformer configuration - skipping duplicate element name: "
                    + item);
        } else {
            map.put(elementName, attributeName);
        }
    }
    return map;
}

From source file:de.micromata.genome.util.text.StandardHeaderSplitter.java

/**
 * Split.//from   w  w w .  j a  v a  2 s  .  c om
 *
 * @param text the text
 * @return the pair
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static Pair<String, Map<String, String>> split(String text) throws IOException {
    LineNumberReader lnr = new LineNumberReader(new StringReader(text));
    Map<String, String> headers = new HashMap<String, String>();
    String line = null;
    boolean leedingNewlines = true;
    while ((line = lnr.readLine()) != null) {
        if (StringUtils.isBlank(line)) {
            if (leedingNewlines == true) {// es kann sein, dass am Anfang die Newlines sind(wegen Code, etc)
                continue;
            } else {
                break;
            }
        }
        String key = StringUtils.substringBefore(line, ":");
        String value = StringUtils.substringAfter(line, ":");
        headers.put(StringUtils.trim(key), StringUtils.trim(value));
        leedingNewlines = false;
    }
    if (headers.size() == 0) {
        return new Pair<String, Map<String, String>>(text, headers);
    }
    return new Pair<String, Map<String, String>>(slurp(lnr), headers);
}

From source file:com.thinkbiganalytics.spark.shell.SparkClientUtil.java

/**
 * Gets the major version number from the Spark client.
 *///from  w  w  w  .  jav  a2  s .c o m
public static String getMajorVersion() {
    if (majorVersion == null) {
        try {
            majorVersion = StringUtils.substringBefore(getVersion(), ".");
        } catch (final IOException e) {
            throw new IllegalStateException("Unable to determine Spark version");
        }
    }
    return majorVersion;
}

From source file:com.thinkbiganalytics.nifi.feedmgr.NifiEnvironmentProperties.java

/**
 * for a given property return the serviceName
 */// w  w w .j  a v  a2  s .co  m
public static String serviceNameForEnvironmentProperty(String envProperty) {
    String prop = envProperty;
    prop = StringUtils.substringAfter(prop, getPrefix());
    String serviceName = StringUtils.substringBefore(prop, ".");
    return serviceName;
}

From source file:io.knotx.adapter.common.placeholders.UriTransformer.java

protected static List<String> getPlaceholders(String serviceUri) {
    return Arrays.asList(serviceUri.split("\\{")).stream().filter(str -> str.contains("}"))
            .map(str -> StringUtils.substringBefore(str, "}")).collect(Collectors.toList());
}