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:com.norconex.importer.parser.AbstractParserTest.java

protected File getFile(String resourcePath) throws IOException {
    File file = folder.newFile(StringUtils.substringAfterLast(resourcePath, "/"));
    FileUtils.copyInputStreamToFile(getInputStream(resourcePath), file);
    return file;/*from  w ww . j ava 2 s  .  c om*/
}

From source file:io.wcm.sling.commons.util.Escape.java

/**
 * Create valid filename by applying method {@link Escape#validName(String)} on filename and extension.
 * @param value Filename//from   www .j  a va2s  .  co m
 * @return Valid filename
 */
public static String validFilename(String value) {
    String fileExtension = StringUtils.substringAfterLast(value, ".");
    String fileName = StringUtils.substringBeforeLast(value, ".");
    if (StringUtils.isEmpty(fileExtension)) {
        return validName(fileName);
    }
    return validName(fileName) + "." + validName(fileExtension);
}

From source file:com.zht.common.codegen.excute.impl.AbstractGenerator.java

/**
 * // w w  w  . ja v  a  2 s .  c o m
 * @param filePath
 * @return
 */
protected String getFileName(String filePath) {
    String fileName = StringUtils.substringAfterLast(filePath, "/");
    if (fileName.equals("") || fileName == null) {
        fileName = StringUtils.substringAfterLast(filePath, "\\");
    }
    return fileName;
}

From source file:com.savoirfairelinux.jmeter.openstack.test.AbstractOpenstackSamplerTest.java

protected void runJMeter(String className) throws Exception {
    int iterations = Integer.valueOf(getTestConfiguration(className, "iterations", "1"));
    int threads = Integer.valueOf(getTestConfiguration(className, "threads", "1"));

    log.info("starting test " + StringUtils.substringAfterLast(className, "."));

    // loop controller
    LoopController loopController = new LoopController();
    loopController.setLoops(iterations);
    loopController.setFirst(true);/*from  ww w .j a v  a 2s  .  co  m*/
    loopController.initialize();

    // thread group
    ThreadGroup threadGroup = new ThreadGroup();
    threadGroup.setNumThreads(threads);
    threadGroup.setRampUp(1);
    threadGroup.setSamplerController(loopController);

    // JavaSampler
    JavaSampler javaSampler = new JavaSampler();
    javaSampler.setClassname(className);
    javaSampler.setArguments(arguments);

    // summary
    Summariser summariser = new Summariser("summary");
    ResultCollector logger = new ResultCollector(summariser);

    // simple listener to track if at least one test failed
    GlobalResult globalResult = new GlobalResult();

    // create test plan
    TestPlan testPlan = new TestPlan();

    // assemble the test plan from previously initialized elements
    HashTree testPlanHashTree = new HashTree();
    testPlanHashTree.add(testPlan);
    HashTree threadGroupHashTree = new HashTree();
    threadGroupHashTree = testPlanHashTree.add(testPlan, threadGroup);
    HashTree javaSamplerHashTree = new HashTree();
    javaSamplerHashTree = threadGroupHashTree.add(javaSampler);
    javaSamplerHashTree.add(logger);
    javaSamplerHashTree.add(globalResult);

    // start JMeter test
    StandardJMeterEngine jmeter = new StandardJMeterEngine();
    jmeter.configure(testPlanHashTree);
    jmeter.run();

    // increase log level to display the final summary
    LoggingManager.setPriority(Priority.INFO, "jmeter.reporters.Summariser");
    logger.testEnded();
    LoggingManager.setPriority(Priority.WARN, "jmeter.reporters.Summariser");

    // set the JUnit test result
    assertTrue(!globalResult.isFailed());
}

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

@Override
public void parse(String result, Task task) throws Exception {
    if (StringUtils.isBlank(result)) {
        return;/*from  ww  w.  j av  a  2  s . c  o  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.netflix.spinnaker.clouddriver.ecs.provider.agent.ServiceCachingAgent.java

public static Map<String, Object> convertServiceToAttributes(String accountName, String region,
        Service service) {//from   w ww  .  ja  va 2  s  .c o m
    Map<String, Object> attributes = new HashMap<>();
    String applicationName = service.getServiceName().contains("-")
            ? StringUtils.substringBefore(service.getServiceName(), "-")
            : service.getServiceName();
    String clusterName = StringUtils.substringAfterLast(service.getClusterArn(), "/");

    attributes.put("account", accountName);
    attributes.put("region", region);
    attributes.put("applicationName", applicationName);
    attributes.put("serviceName", service.getServiceName());
    attributes.put("serviceArn", service.getServiceArn());
    attributes.put("clusterName", clusterName);
    attributes.put("clusterArn", service.getClusterArn());
    attributes.put("roleArn", service.getRoleArn());
    attributes.put("taskDefinition", service.getTaskDefinition());
    attributes.put("desiredCount", service.getDesiredCount());
    attributes.put("maximumPercent", service.getDeploymentConfiguration().getMaximumPercent());
    attributes.put("minimumHealthyPercent", service.getDeploymentConfiguration().getMinimumHealthyPercent());
    attributes.put("loadBalancers", service.getLoadBalancers());
    attributes.put("createdAt", service.getCreatedAt().getTime());

    return attributes;
}

From source file:de.micromata.genome.chronos.spi.jdbc.TriggerJobDisplayDO.java

public String getJobDefinitionStringShortShort() {
    String s = getJobDefinitionStringShort();
    return StringUtils.substringAfterLast(s, ".");
}

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

/**
 * return the application.properties property key for the specific property using the proocessor type as the key reference
 *
 * @param property the nifi property//  www.  jav  a2s  .co m
 * @return the property key prepended with the "nifi.<processor type>[<processor name>]."
 */
public static String getProcessorNamePropertyConfigName(NifiProperty property) {
    String processorTypeName = "nifi."
            + toPropertyName(StringUtils.substringAfterLast(property.getProcessorType(), ".") + "["
                    + property.getProcessorName() + "]." + property.getKey());
    return processorTypeName;
}

From source file:de.crowdcode.movmvn.core.ContextImpl.java

/**
 * {@inheritDoc}//from   w ww  . ja  va 2 s .co  m
 */
@Override
public String getProjectName() {
    if (zipFile != null && !zipFile.equals("")) {
        String nameWithoutZip = StringUtils.substringBefore(zipFile, ".zip");
        String nameResult = StringUtils.substringAfterLast(nameWithoutZip, "/");
        if (nameResult.equals("")) {
            // We have no "/" instead "\\"
            nameResult = StringUtils.substringAfterLast(nameWithoutZip, "\\");
        }
        return nameResult;
    } else if (directory != null && !directory.equals("")) {
        String nameResult = StringUtils.substringAfterLast(directory, "/");
        if (nameResult.equals("")) {
            // We have no "/" instead "\\"
            nameResult = StringUtils.substringAfterLast(directory, "\\");
        }
        return nameResult;
    } else {
        return "";
    }
}

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

/**
 * Constructs a YearMonthDayInterval out of a string.  The recommended
 * string format is <code>yyyy-MM-dd - yyyy-MM-dd</code>, but any 
 * characters in between the start and end are accepted as long as there 
 * is a space after the start YearMontDay and before the end YearMonthDay.
 * @param interval the interval to parse
 *//*from  w  w w.  j  a v a2  s . co  m*/
public YearMonthDayInterval(String interval) {
    String trimmed = StringUtils.trim(interval);
    String startStr = StringUtils.substringBefore(trimmed, " ");
    String endStr = StringUtils.substringAfterLast(trimmed, " ");
    if (StringUtils.isBlank(startStr) || StringUtils.isBlank(endStr)) {
        throw new IllegalArgumentException("String YearMonthDay interval cannot be null or empty.");
    }
    this.start = new YearMonthDay(startStr);
    this.end = new YearMonthDay(endStr);
}