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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:io.treefarm.plugins.haxe.components.HaxeCompiler.java

public void compileHxml(MavenProject project, File hxml, File workingDirectory) throws Exception {
    List<String> args;
    int returnValue;

    // get the list of libs in the hxml        
    String haxelibToInstall;//from www. j  av a2  s.  com
    Set<String> haxelibsToInstall = new HashSet<String>();
    BufferedReader reader = new BufferedReader(new FileReader(hxml.getAbsolutePath()));
    String line = null;
    while ((line = reader.readLine()) != null) {
        haxelibToInstall = StringUtils.substringAfter(line, "-lib ");
        if (!StringUtils.startsWith(line, "#") && haxelibToInstall.length() > 0) {
            haxelibsToInstall.add(haxelibToInstall);
        }
    }

    // go through the list and if they are not installed, install them now
    Iterator<String> it = haxelibsToInstall.iterator();
    while (it.hasNext()) {
        haxelibToInstall = it.next();

        args = new ArrayList<String>();
        args.add("path");
        args.add(haxelibToInstall);
        returnValue = haxelib.execute(args);

        if (returnValue > 0) {
            args = new ArrayList<String>();
            args.add("install");
            args.add(haxelibToInstall);
            logger.info("Installing haxelib '" + haxelibToInstall + "'");
            returnValue = haxelib.execute(args, logger);
            if (returnValue > 0) {
                throw new Exception("Haxelib was installing '" + haxelibToInstall
                        + "', but has encountered an error and cannot proceed.");
            }
        }
    }

    // now that the libs are installed, compile the project
    args = new ArrayList<String>();
    args.add(hxml.getAbsolutePath());

    logger.info("Building '" + hxml.getName() + "'");
    returnValue = haxe.execute(args, workingDirectory);
    if (returnValue > 0) {
        throw new Exception("Haxe compiler was building '" + hxml.getName()
                + "', but has encountered an error and cannot proceed.");
    }
}

From source file:io.github.moosbusch.lumpi.gui.impl.Expression.java

public String getSubExpression(int startIndex, int tokenCount) {
    String separator = new String(new char[] { getSeparatorChar() });
    String result = "";
    if (tokenCount == 0) {
        return get(startIndex);
    } else {/*w ww .  ja v  a 2s  . c  o  m*/
        StringBuilder buf = new StringBuilder();
        buf.append(result);
        for (int cnt = 0; cnt < tokenCount; cnt++) {
            String token = get(startIndex + cnt);
            buf.append(getSeparatorChar());
            buf.append(token);
        }
        if (StringUtils.startsWith(result, separator)) {
            result = StringUtils.substringAfter(result, separator);
        }
        if (StringUtils.endsWith(result, separator)) {
            result = StringUtils.substringBeforeLast(result, separator);
        }
    }
    return result;
}

From source file:com.im.web.base.PropertyFilter.java

/**
 * @param filterName ,???. /*from   w w w .  j  a  v a2s . c  o m*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String firstPart = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1);
    String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length());

    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    //      Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    //      this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass);
}

From source file:de.jfachwert.bank.Bankverbindung.java

private static Object[] split(String bankverbindung) {
    String[] splitted = new String[3];
    splitted[0] = stripSeparator(StringUtils.substringBefore(bankverbindung, "IBAN"));
    splitted[1] = stripSeparator(StringUtils.substringAfter(bankverbindung, "IBAN"));
    if (StringUtils.isBlank(splitted[1])) {
        throw new LocalizedIllegalArgumentException(bankverbindung, "bank_account");
    }//from   ww w  .  j ava  2s.  c o m
    if (splitted[1].contains("BIC")) {
        splitted[2] = stripSeparator(StringUtils.substringAfter(splitted[1], "BIC"));
        splitted[1] = stripSeparator(StringUtils.substringBefore(splitted[1], "BIC"));
    } else {
        splitted[2] = "";
    }
    Object[] values = new Object[3];
    values[0] = splitted[0];
    values[1] = new IBAN(splitted[1]);
    values[2] = splitted[2].isEmpty() ? null : new BIC(splitted[2]);
    return values;
}

From source file:com.norconex.importer.handler.tagger.AbstractCharStreamTagger.java

@Override
protected final void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata,
        boolean parsed) throws ImporterHandlerException {

    String contentType = metadata.getString("Content-Type", "");
    contentType = StringUtils.substringBefore(contentType, ";");

    String charset = metadata.getString("Content-Encoding", null);
    if (charset == null) {
        charset = metadata.getString("charset", null);
    }/*  ww  w.  j a  va  2 s.c o m*/
    if (charset == null) {
        for (String type : metadata.getStrings("Content-Type")) {
            if (type.contains("charset")) {
                charset = StringUtils.trimToNull(StringUtils.substringAfter(type, "charset="));
                break;
            }
        }
    }
    if (StringUtils.isBlank(charset) || !CharEncoding.isSupported(charset)) {
        charset = CharEncoding.UTF_8;
    }
    try {
        InputStreamReader is = new InputStreamReader(document, charset);
        tagTextDocument(reference, is, metadata, parsed);
    } catch (UnsupportedEncodingException e) {
        throw new ImporterHandlerException(e);
    }
}

From source file:com.iorga.iraj.json.ObjectContextCaller.java

public ObjectContextCaller(final Class<?> currentClass, final String currentContextPath)
        throws SecurityException {
    final String firstContextPathPart = StringUtils.substringBefore(currentContextPath, ".");

    try {/*from   w w  w . j a v a  2 s .co  m*/
        getter = currentClass.getMethod("get" + StringUtils.capitalize(firstContextPathPart));
    } catch (final NoSuchMethodException e) {
        try {
            getter = currentClass.getMethod("is" + StringUtils.capitalize(firstContextPathPart));
        } catch (final NoSuchMethodException e1) {
            throw new IllegalArgumentException("No getter for " + firstContextPathPart + " on " + currentClass);
        }
    }

    if (!firstContextPathPart.equals(currentContextPath)) {
        // the path is not finished to handle
        nextContextCaller = new ObjectContextCaller(getter.getReturnType(),
                StringUtils.substringAfter(currentContextPath, "."));
    } else {
        nextContextCaller = null;
    }
}

From source file:lolth.autohome.buy.AutohomeBuyInfoListTaskFetch.java

@Override
protected void parsePage(Document doc, FetchTask task) throws Exception {
    Elements lis = doc.select("li.price-item");

    for (Element li : lis) {
        AutohomeBuyInfoBean bean = new AutohomeBuyInfoBean();
        bean.setUrl(task.getUrl());// ww  w  .  java 2 s  .c o m
        bean.setForumId(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 postTime = li.select("div.user-name span");
        if (!postTime.isEmpty()) {
            bean.setPostTime(StringUtils.trim(StringUtils.substringBefore(postTime.first().text(), "?")));
        }

        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, "")));
            }
        }

        log.debug("Bean : {}", bean);

        bean.persistOnNotExist();
    }
}

From source file:com.thinkmore.framework.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*from   w w w  .  j  a v  a2  s .com*/
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value .
 */
public PropertyFilter(final String filterName, final String value) {

    String matchTypeStr = StringUtils.substringBefore(filterName, "_");
    String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1);
    String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1,
            matchTypeStr.length());
    try {
        matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue();
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    propertyNames = StringUtils.split(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    Assert.isTrue(propertyNames.length > 0,
            "filter??" + filterName + ",??.");
    //entity property.
    this.propertyValue = ReflectionUtil.convertStringToObject(value, propertyType);
}

From source file:net.sf.dynamicreports.design.transformation.chartcustomizer.SeriesColorsByNameCustomizer.java

@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
    if (chart.getPlot() instanceof CategoryPlot) {
        CategoryItemRenderer renderer = chart.getCategoryPlot().getRenderer();
        CategoryDataset dataset = chart.getCategoryPlot().getDataset();
        Set<String> legend = new LinkedHashSet<String>();
        if (dataset != null) {
            for (int i = 0; i < dataset.getRowCount(); i++) {
                String key = (String) dataset.getRowKey(i);
                if (renderer instanceof GroupedStackedBarRenderer) {
                    key = StringUtils.substringAfter(key, GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY);
                    legend.add(key);/* w w w  .ja va  2  s. c o m*/
                }
                renderer.setSeriesPaint(i, seriesColorsByName.get(key));
            }
        }
        if (!legend.isEmpty()) {
            LegendItemCollection legendItems = new LegendItemCollection();
            for (String item : legend) {
                legendItems.add(new LegendItem(item, seriesColorsByName.get(item)));
            }
            chart.getCategoryPlot().setFixedLegendItems(legendItems);
        }
    } else if (chart.getPlot() instanceof PiePlot) {
        PiePlot plot = (PiePlot) chart.getPlot();
        PieDataset dataset = plot.getDataset();
        for (int i = 0; i < dataset.getItemCount(); i++) {
            String key = (String) dataset.getKey(i);
            plot.setSectionPaint(key, seriesColorsByName.get(key));
        }
    } else if (chart.getPlot() instanceof XYPlot) {
        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        XYDataset dataset = chart.getXYPlot().getDataset();
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            String key = (String) dataset.getSeriesKey(i);
            renderer.setSeriesPaint(i, seriesColorsByName.get(key));
        }
    }
}

From source file:com.linkedin.mitm.proxy.connectionflow.ConnectionFlowProcessor.java

/**
 * Resolve remote address// www . j a v  a 2 s.c  om
 * */
private static InetSocketAddress getRemoteAddress(HttpRequest httpRequest) {
    String uri = httpRequest.getUri();
    String uriWithoutProtocol;
    if (HTTP_PREFIX.matcher(uri).matches()) {
        uriWithoutProtocol = StringUtils.substringAfter(uri, "://");
    } else {
        uriWithoutProtocol = uri;
    }
    String hostAndPort;
    if (uriWithoutProtocol.contains("/")) {
        hostAndPort = uriWithoutProtocol.substring(0, uriWithoutProtocol.indexOf("/"));
    } else {
        hostAndPort = uriWithoutProtocol;
    }
    String hostName;
    int port;
    if (hostAndPort.contains(":")) {
        int index = hostAndPort.indexOf(":");
        hostName = hostAndPort.substring(0, index);
        port = Integer.parseInt(hostAndPort.substring(index + 1));
    } else {
        hostName = hostAndPort;
        port = 80;
    }
    return new InetSocketAddress(hostName, port);
}