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:io.wcm.devops.maven.nodejsproxy.resource.Checksums.java

/**
 * @param data Checksums file content/*w  ww.j  a  va 2s  . c o  m*/
 */
public Checksums(String data) {
    String[] lines = StringUtils.split(data, "\n");
    for (String line : lines) {
        String checksum = StringUtils.substringBefore(line, "  ");
        String filename = StringUtils.substringAfter(line, "  ");
        if (StringUtils.isNoneBlank(checksum, filename)) {
            checksums.put(filename, checksum);
        }
    }
}

From source file:com.google.dart.java2dart.processor.JUnitSemanticProcessorTest.java

public void test_Assert() throws Exception {
    translateSingleFile("// filler filler filler filler filler filler filler filler filler filler",
            "package test;", "import junit.framework.Assert;", "import junit.framework.TestCase;",
            "public class Test extends TestCase {", "  public void test_x() {", "    fail(\"msg\");",
            "    Assert.fail(\"msg\");", "  }", "}");
    runProcessor();//from  ww w  . j  av  a  2 s  . c  om
    String resultSource = getFormattedSource(unit);
    resultSource = StringUtils.substringBefore(resultSource, "static dartSuite() {");
    assertEquals(toString(//
            "class Test extends JUnitTestCase {", "  void test_x() {", "    JUnitTestCase.fail(\"msg\");",
            "    JUnitTestCase.fail(\"msg\");", "  }", "  "), resultSource);
}

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

/**
 * resolve the Nifi Property from the  env controllerServiceProperty
 *//* w  ww.j  a v a  2 s.  co m*/
public static String environmentPropertyToControllerServiceProperty(String envProperty) {
    String prop = envProperty;
    prop = StringUtils.substringAfter(prop, getPrefix());
    String serviceName = StringUtils.substringBefore(prop, ".");
    prop = StringUtils.substringAfter(prop, ".");
    prop = environmentPropertyToNifi(prop);
    return prop;
}

From source file:com.thinkbiganalytics.metadata.api.sla.FeedExecutedSinceFeed.java

public FeedExecutedSinceFeed(@JsonProperty("sinceCategoryAndFeedName") String sinceCategoryAndFeed,
        @JsonProperty("categoryAndFeed") String categoryAndFeed) {
    super(categoryAndFeed);
    this.sinceCategoryAndFeedName = sinceCategoryAndFeed;
    this.sinceCategoryName = StringUtils.substringBefore(sinceCategoryAndFeedName, ".");
    this.sinceFeedName = StringUtils.substringAfter(sinceCategoryAndFeedName, ".");
}

From source file:com.sketchy.drawing.DrawingSize.java

public static DrawingSize parse(String string) {
    double width = 0;
    double height = 0;

    String upperCasedString = StringUtils.upperCase(string);
    String widthString = StringUtils.substringBefore(upperCasedString, "X").trim();
    String heightString = StringUtils.substringAfter(upperCasedString, "X").trim();

    widthString = StringUtils.substringBeforeLast(widthString, "MM");
    heightString = StringUtils.substringBefore(heightString, " ");
    heightString = StringUtils.substringBeforeLast(heightString, "MM");

    try {/*ww w . j av  a 2  s  .  c  o  m*/
        width = Double.parseDouble(widthString);
        height = Double.parseDouble(heightString);
    } catch (Exception e) {
        throw new RuntimeException("Invalid Drawing Size! '" + string + "'");
    }

    if ((width <= 0) || (height <= 0)) {
        throw new RuntimeException("Invalid Drawing Size! '" + string + "'");
    }
    return new DrawingSize(width, height);
}

From source file:com.sonar.maven.it.suite.AbstractMavenTest.java

protected static Version mojoVersion() {
    if (mojoVersion == null) {
        try {/*from   www  .j a v  a2  s.  c  o m*/
            for (String line : Files.readAllLines(Paths.get("../pom.xml"), StandardCharsets.UTF_8)) {
                if (line.startsWith("  <version>")) {
                    String version = StringUtils.substringAfter(line, "<version>");
                    version = StringUtils.substringBefore(version, "</version>");
                    mojoVersion = Version.create(version);
                    return mojoVersion;
                }
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        throw new IllegalStateException("Unable to find version of the Maven plugin to be used by ITs");
    }
    return mojoVersion;
}

From source file:com.netflix.spinnaker.fiat.model.resources.ServiceAccount.java

@JsonIgnore
public List<String> getRequiredGroupMembership() {
    // There is a potential here for a naming collision where service account
    // "my-svc-account@abc.com" and "my-svc-account@xyz.com" each allow one another's users to use
    // their service account. In practice, though, I don't think this will be an issue.
    return Collections.singletonList(StringUtils.substringBefore(name, "@"));
}

From source file:io.wcm.dam.assetservice.impl.AssetRequestParser.java

private static List<AssetRequest> getAssetRequestsFromSuffix(String assetPath,
        SlingHttpServletRequest request) {
    List<AssetRequest> requests = new ArrayList<>();

    String suffixWithoutExtension = StringUtils.substringBefore(request.getRequestPathInfo().getSuffix(), ".");
    String[] suffixParts = StringUtils.split(suffixWithoutExtension, "/");
    if (suffixParts != null) {
        for (String suffixPart : suffixParts) {
            Map<String, String> params = parseSuffixPart(suffixPart);
            String mediaFormat = params.get(RP_MEDIAFORMAT);
            long width = NumberUtils.toLong(params.get(RP_WIDTH));
            long height = NumberUtils.toLong(params.get(RP_HEIGHT));
            if (StringUtils.isNotEmpty(mediaFormat) || width > 0 || height > 0) {
                requests.add(new AssetRequest(assetPath, mediaFormat, width, height));
            }/*from   w w  w . ja  v  a2s.  c  o  m*/
        }
    }

    return requests;
}

From source file:lolthx.autohome.buy.AutohomePriceListFetch.java

@Override
public void parse(String result, Task task) throws Exception {
    if (StringUtils.isBlank(result)) {
        return;//from  www . j a  v  a2  s.co  m
    }

    Date start = task.getStartDate();
    Date end = task.getEndDate();

    Document doc = Jsoup.parse(result);
    Elements lis = doc.select("li.price-item");

    AutohomePriceInfoBean bean = new AutohomePriceInfoBean();

    for (Element li : lis) {

        try {
            Elements postTimeEl = li.select("div.user-name span");
            String postTime = "";
            if (!postTimeEl.isEmpty()) {
                postTime = StringUtils.trim(
                        StringUtils.substringBefore(postTimeEl.first().text(), "?").replaceAll("", ""));

                if (!isTime(postTime, start, end)) {
                    continue;
                }
            }
            bean.setPostTime(postTime);
            bean.setUrl(task.getUrl());
            bean.setForumId(StringUtils.substringBefore(task.getExtra(), ":"));
            bean.setProjectName(task.getProjectName());
            bean.setKeyword(StringUtils.substringAfter(task.getExtra(), ":"));

            // post id
            Elements id = li.select("div.price-share a.share");
            if (!id.isEmpty()) {
                String idStr = id.first().attr("data-target");
                idStr = StringUtils.substringAfterLast(idStr, "_");
                if (StringUtils.isBlank(idStr)) {
                    continue;
                }

                bean.setId(idStr);
            }

            // 
            Elements user = li.select("div.user-name a");
            if (!user.isEmpty()) {
                String userUrl = user.first().absUrl("href");
                String userId = StringUtils.substringAfterLast(userUrl, "/");
                String userName = user.first().text();

                bean.setUserId(userId);
                bean.setUserUrl(userUrl);
                bean.setUserName(userName);
            }

            Elements dataLis = li.select("div.price-item-bd li");
            for (Element dataLi : dataLis) {
                String data = dataLi.text();

                if (StringUtils.startsWith(data, "")) {
                    bean.setCar(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setGuidePrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setTotalPrice(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setPurchaseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "?")) {
                    bean.setCommercialInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }

                if (StringUtils.startsWith(data, "")) {
                    bean.setVehicleUseTax(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setCompulsoryInsurance(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setLicenseFee(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setPromotion(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    bean.setBuyTime(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
                if (StringUtils.startsWith(data, "")) {
                    String area = StringUtils.trim(StringUtils.substringAfter(data, ""));
                    String[] pAndC = StringUtils.splitByWholeSeparator(area, ",", 2);

                    if (pAndC.length == 1) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[0]);
                    }

                    if (pAndC.length == 2) {
                        bean.setBuyProvince(pAndC[0]);
                        bean.setBuyCity(pAndC[1]);
                    }

                }
                if (StringUtils.startsWith(data, "")) {
                    Elements level = dataLi.select("span.level");
                    // 
                    if (!level.isEmpty()) {
                        bean.setSellerComment(level.first().text());
                    }

                    // ?
                    Elements seller = dataLi.select("a.title");
                    if (!seller.isEmpty()) {
                        String sellerUrl = seller.first().absUrl("href");
                        String sellerName = seller.first().text();
                        String sellerId = StringUtils.substringAfterLast(sellerUrl, "/");

                        bean.setSellerId(sellerId);
                        bean.setSellerName(sellerName);
                        bean.setSellerUrl(sellerUrl);
                    }

                    // ?
                    Elements sellerPhone = dataLi.select("em.phone-num");
                    if (!sellerPhone.isEmpty()) {
                        bean.setSellerPhone(sellerPhone.first().text());
                    }

                    // ?
                    // Elements sellerAddress =
                    // dataLi.select("em.phone-num");

                }
                if (StringUtils.startsWith(data, "?")) {
                    bean.setBuyFeeling(StringUtils.trim(StringUtils.substringAfter(data, "")));
                }
            }
            bean.saveOnNotExist();
        } catch (Exception e) {
            e.printStackTrace();
            continue;
        }
    }
}

From source file:com.monarchapis.driver.hash.HawkV1RequestHasher.java

/**
 * Creates a Hawk payload hash.//  w w w .  j a  va2s  .c o m
 */
@Override
public String getRequestHash(ApiRequest request, String algorithm) {
    try {
        String digestAlgorithm = HasherUtils.getMessageDigestAlgorithm(algorithm);
        String mimeType = StringUtils.substringBefore(request.getContentType(), ";");

        MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        baos.write("hawk.1.payload\n".getBytes("UTF-8"));

        if (mimeType != null) {
            baos.write(mimeType.getBytes("UTF-8"));
        }

        baos.write('\n');
        baos.write(request.getBody());
        baos.write('\n');
        byte[] hash = digest.digest(baos.toByteArray());

        return Base64.encodeBase64String(hash);
    } catch (Exception e) {
        throw new ApiException("Could not generate request hash", e);
    }
}