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.shallop.codedrill.common.persistence.hibernate.HibernateDao.java

private String prepareCountHql(String orgHql) {
    String fromHql = orgHql;/*www. j  a v a2s  .c o  m*/
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;
    return countHql;
}

From source file:com.adobe.acs.commons.data.Spreadsheet.java

public String convertHeaderName(String str) {
    if (enableHeaderNameConversion) {
        if (str.contains("@")) {
            str = StringUtils.substringBefore(str, "@");
        }//from   w w  w . j a v a2s . c o m
        return String.valueOf(str).toLowerCase().replaceAll("[^0-9a-zA-Z:\\-]+", "_");
    } else {
        return String.valueOf(str);
    }
}

From source file:cc.recommenders.names.CoReNames.java

public static String src2vmType(String type) {
    ensureIsNotNull(type, "type");
    ///*w  ww  .  j  av  a2 s .  c  o  m*/
    final PrimitiveType p = PrimitiveType.fromSrc(type);
    if (p != null) {
        return String.valueOf(p.vm());
    }
    int dimensions = 0;
    if (type.endsWith("]")) {
        dimensions = StringUtils.countMatches(type, "[]");
        type = StringUtils.substringBefore(type, "[") + ";";
    }
    return StringUtils.repeat("[", dimensions) + "L" + type.replaceAll("\\.", "/");
}

From source file:com.project.framework.dao.BaseDao.java

/**
 * count.// w  w  w . j  a  v  a  2  s  .  c om
 * 
 * ????,???count?.
 */
public long countResult(final String queryString, final Map<String, ?> values) {
    String fromHql = queryString;
    //select??order by???count,?.
    fromHql = "from " + StringUtils.substringAfter(fromHql, "from");
    fromHql = StringUtils.substringBefore(fromHql, "order by");

    String countHql = "select count(*) " + fromHql;

    try {
        Long count = executeUniqueQuery(countHql, values);
        return count;
    } catch (Exception e) {
        throw new RuntimeException("queryString can't be auto count, queryString is:" + countHql, e);
    }
}

From source file:com.opensymphony.xwork2.util.finder.UrlSet.java

private List<URL> getUrls(ClassLoaderInterface classLoader) throws IOException {
    List<URL> list = new ArrayList<URL>();

    //find jars// w  ww.  ja  va2 s. co m
    ArrayList<URL> urls = Collections.list(classLoader.getResources("META-INF"));

    for (URL url : urls) {
        if ("jar".equalsIgnoreCase(url.getProtocol())) {
            String externalForm = url.toExternalForm();
            //build a URL pointing to the jar, instead of the META-INF dir
            url = new URL(StringUtils.substringBefore(externalForm, "META-INF"));
            list.add(url);
        } else if (LOG.isDebugEnabled())
            LOG.debug("Ignoring URL [#0] because it is not a jar", url.toExternalForm());

    }

    //usually the "classes" dir
    list.addAll(Collections.list(classLoader.getResources("")));
    return list;
}

From source file:com.neatresults.mgnltweaks.neatu2b.ui.form.field.composite.CompositeU2BFieldTransformer.java

public String getVideoId(Property<?> prop) {
    if (prop == null) {
        throw new NullPointerException(
                "Video is not set or name of the required field for this dialog is not correctly configured.");
    }//w  w  w . j  ava  2 s  .co m
    String maybeId = (String) prop.getValue();
    if (maybeId == null) {
        return null;
    }
    if (maybeId.startsWith("http")) {
        maybeId = StringUtils.substringBefore(StringUtils.substringAfter(maybeId, "?v="), "&");
    }
    return maybeId;
}

From source file:com.cognifide.aet.vs.mongodb.MongoDBClient.java

public static String getCompanyNameFromDbName(String dbName) {
    return StringUtils.substringBefore(dbName, DB_NAME_SEPARATOR);
}

From source file:com.adguard.android.commons.RawResources.java

/**
 * Cleans up language code, leaves only first part of it
 *
 * @param language Language code (like en_US)
 * @return language (like en)/*from w  ww.  jav  a2s.  co  m*/
 */
private static String cleanUpLanguageCode(String language) {
    String languageCode = StringUtils.substringBefore(language, "_");
    return StringUtils.lowerCase(languageCode);
}

From source file:de.crowdcode.kissmda.maven.plugin.KissMdaMojo.java

private void useTransformerNamesWithOrder(Injector parentInjector)
        throws MojoExecutionException, InstantiationException, IllegalAccessException, ClassNotFoundException {
    // Read the list and parse:
    // 1:de.crowdcode.kissmda.cartridges.extensions.ExtensionExamplesTransformer
    // Put it in a map and sort the content after the order
    Map<Integer, String> sortedtTransformerNameWithOrders = new TreeMap<Integer, String>();

    for (String content : transformerNameWithOrders) {
        String order = StringUtils.substringBefore(content, ":");
        Integer orderAsInt = Integer.decode(order);
        String transformerClazz = StringUtils.substringAfter(content, ":");
        sortedtTransformerNameWithOrders.put(orderAsInt, transformerClazz);
    }//from   ww  w. ja v a 2s  .  c o  m

    for (Map.Entry<Integer, String> entry : sortedtTransformerNameWithOrders.entrySet()) {
        // We need the counterpart Guice module for this transformer
        // In the same package but with Module as suffix
        String transformerClazzName = entry.getValue();
        String guiceModuleClazzName = getGuiceModuleName(transformerClazzName);
        Class<? extends Transformer> transformerClazz = Class.forName(transformerClazzName)
                .asSubclass(Transformer.class);
        Class<? extends Module> guiceModuleClazz = Class.forName(guiceModuleClazzName).asSubclass(Module.class);

        logger.info("Start the transformation with following Transformer: " + transformerClazzName
                + " - order: " + entry.getKey());
        // Create the transformer class with Guice module as child
        // injector and execute
        Injector injector = parentInjector.createChildInjector(guiceModuleClazz.newInstance());
        Transformer transformer = injector.getInstance(transformerClazz);
        transformer.transform(context);

        logger.info("Stop the transformation with following Transformer:" + transformerClazzName);
    }
}

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

/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * Gets the request for a submission of this form with the specified SubmittableElement.
 * @param submitElement the element that caused the submit to occur
 * @return the request/*from  w  w w.  ja  v  a  2  s  .  co  m*/
 */
public WebRequest getWebRequest(final SubmittableElement submitElement) {
    final HtmlPage htmlPage = (HtmlPage) getPage();
    final List<NameValuePair> parameters = getParameterListForSubmit(submitElement);
    final HttpMethod method;
    final String methodAttribute = getMethodAttribute();
    if ("post".equalsIgnoreCase(methodAttribute)) {
        method = HttpMethod.POST;
    } else {
        if (!"get".equalsIgnoreCase(methodAttribute) && StringUtils.isNotBlank(methodAttribute)) {
            notifyIncorrectness("Incorrect submit method >" + getMethodAttribute() + "<. Using >GET<.");
        }
        method = HttpMethod.GET;
    }

    final BrowserVersion browser = getPage().getWebClient().getBrowserVersion();
    String actionUrl = getActionAttribute();
    String anchor = null;
    String queryFromFields = "";
    if (HttpMethod.GET == method) {
        if (actionUrl.contains("#")) {
            anchor = StringUtils.substringAfter(actionUrl, "#");
        }
        final String enc = getPage().getPageEncoding();
        queryFromFields = URLEncodedUtils.format(Arrays.asList(NameValuePair.toHttpClient(parameters)), enc);

        // action may already contain some query parameters: they have to be removed
        actionUrl = StringUtils.substringBefore(actionUrl, "#");
        actionUrl = StringUtils.substringBefore(actionUrl, "?");
        parameters.clear(); // parameters have been added to query
    }
    URL url;
    try {
        if (actionUrl.isEmpty()) {
            url = WebClient.expandUrl(htmlPage.getUrl(), actionUrl);
        } else {
            url = htmlPage.getFullyQualifiedUrl(actionUrl);
        }

        if (!queryFromFields.isEmpty()) {
            url = UrlUtils.getUrlWithNewQuery(url, queryFromFields);
        }

        if (HttpMethod.GET == method && browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
                && WebClient.URL_ABOUT_BLANK != url) {
            url = UrlUtils.getUrlWithNewRef(url, null);
        } else if (HttpMethod.POST == method && browser.hasFeature(FORM_SUBMISSION_URL_WITHOUT_HASH)
                && WebClient.URL_ABOUT_BLANK != url && StringUtils.isEmpty(actionUrl)) {
            url = UrlUtils.getUrlWithNewRef(url, null);
        } else if (anchor != null && WebClient.URL_ABOUT_BLANK != url) {
            url = UrlUtils.getUrlWithNewRef(url, anchor);
        }
    } catch (final MalformedURLException e) {
        throw new IllegalArgumentException("Not a valid url: " + actionUrl);
    }

    final WebRequest request = new WebRequest(url, method);
    request.setRequestParameters(parameters);
    if (HttpMethod.POST == method) {
        request.setEncodingType(FormEncodingType.getInstance(getEnctypeAttribute()));
    }
    request.setCharset(getSubmitCharset());
    request.setAdditionalHeader("Referer", htmlPage.getUrl().toExternalForm());
    return request;
}