Example usage for org.apache.commons.lang StringUtils substringBefore

List of usage examples for org.apache.commons.lang StringUtils substringBefore

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringBefore.

Prototype

public static String substringBefore(String str, String separator) 

Source Link

Document

Gets the substring before the first occurrence of a separator.

Usage

From source file:net.contextfw.web.application.internal.development.ReloadingClassLoaderConf.java

private void addReloadablePackage(String str) {
    String name = StringUtils.substringBefore(str, ":");
    boolean recursive = Boolean.parseBoolean(StringUtils.substringAfter(str, ":"));

    String postfix = recursive ? "\\..+" : "\\.[^\\.]+";

    reloadablePackageNames.add(name);/*  w w  w . j  ava2s.c  o m*/
    reloadablePackages.add(Pattern.compile("^" + name.replaceAll("\\.", "\\.") + postfix));
}

From source file:jetbrick.tools.chm.reader.IndexesReader.java

private void addIndex(Map<String, String> indexMaps, String text, String url) throws FileNotFoundException {
    String key;// ww  w  .  j  a  va  2  s .  com
    String urlToUse = url;
    urlToUse = StringUtils.remove(urlToUse, "../");
    urlToUse = StringUtils.remove(urlToUse, "./");

    if (url.indexOf('#') < 0) {
        key = text + " class";
    } else {
        key = StringUtils.substringBefore(text, "(");
        if (text.indexOf('(') != -1) {
            key = key + "()";
        }

        String textToUse = StringUtils.substringBefore(urlToUse, ".html");
        textToUse = textToUse.replace('/', '.') + "." + text;
        KeyManager keyManager = keyManagerMaps.get(key);
        String urlRedir = "../" + urlToUse;
        if (keyManager == null) {
            keyManager = new KeyManager(key);
            keyManager.add(textToUse, AnchorNameManager.replaceAnchor(urlRedir));
            keyManagerMaps.put(key, keyManager);
        } else { // repeat
            keyManager.add(textToUse, AnchorNameManager.replaceAnchor(urlRedir));
            // redirect
            urlToUse = keyManager.getUrl();
        }
    }
    indexMaps.put(key, AnchorNameManager.replaceAnchor(urlToUse));
}

From source file:fr.dutra.tools.maven.deptree.core.TgfParser.java

/**
 * sample line structure://  w w w  .j  a  v  a2 s. c o m
 * <pre>
 * -1437430659 com.ibm:mqjms:jar:6.0.0:runtime
 * #
 * 1770590530 96632433 compile
 * </pre>
 */
private void parseLine() {
    String line = this.lines.get(this.lineIndex);
    if ("#".equals(line)) {
        this.phase = ParsePhase.EDGE;
    } else if (this.phase == ParsePhase.NODE) {
        String id = StringUtils.substringBefore(line, " ");
        String artifact;
        if (line.contains("active project artifact:")) {
            artifact = extractActiveProjectArtifact();
        } else {
            artifact = StringUtils.substringAfter(line, " ");
        }
        Node node = parseArtifactString(artifact);
        if (root == null) {
            this.root = node;
        }
        nodes.put(id, node);
    } else {
        String parentId = StringUtils.substringBefore(line, " ");
        String childId = StringUtils.substringBetween(line, " ");
        Node parent = nodes.get(parentId);
        Node child = nodes.get(childId);
        parent.addChildNode(child);
    }
}

From source file:cn.hxh.springside.orm.PropertyFilter.java

/**
 * @param filterName ,???. /*from   w w  w .  j  a va  2s . c om*/
 *                   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, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr),
            "filter??" + filterName + ",??.");
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:cn.newtouch.util.orm.PropertyFilter.java

/**
 * @param filterName/*  w w  w. ja  va 2s  .co  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 {
        this.matchType = Enum.valueOf(MatchType.class, matchTypeCode);
    } catch (RuntimeException e) {
        throw new IllegalArgumentException(
                "filter??" + filterName + ",.", e);
    }

    try {
        this.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 + ",??.");
    this.propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

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

From source file:com.bjwg.back.util.PropertyFilter.java

/**
 *                   eg. LIKES_NAME_OR_LOGIN_NAME
 * @param value//w ww.j  a  va2 s .c o m
 */
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(filterName, e);
    }

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

    String propertyNameStr = StringUtils.substringAfter(filterName, "_");
    AssertUtils.isTrue(StringUtils.isNotBlank(propertyNameStr), filterName);
    propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR);

    this.matchValue = ObjectMapper.convertToObject(value, propertyClass);
}

From source file:com.hs.mail.imap.user.User.java

public String getUserName() {
    return StringUtils.substringBefore(userID, "@");
}

From source file:info.magnolia.module.delta.BootstrapSingleResourceAndOrderBefore.java

public BootstrapSingleResourceAndOrderBefore(String name, String description, String resource,
        String orderBeforeName) {
    super(name, description);
    // TODO : these values should be provided by the BootstrapUtil/Helper once MAGNOLIA-1806 is done.
    String filename = StringUtils.substringAfterLast(resource, "/");
    String repository = StringUtils.substringBefore(filename, ".");
    String path = StringUtils.substringAfter(StringUtils.substringBeforeLast(filename, "."), ".");
    path = "/" + StringUtils.replace(path, ".", "/");

    addTask(new BootstrapSingleResource(name, description, resource));
    addTask(new OrderNodeBeforeTask(name, description, repository, path, orderBeforeName));
}

From source file:com.igrow.mall.common.util.Struts2Utils.java

/**
 * ./*w  ww. j  a v  a 2 s  .com*/
        
 * eg.
 * render("text/plain", "hello", "encoding:GBK");
 * render("text/plain", "hello", "no-cache:false");
 * render("text/plain", "hello", "encoding:GBK", "no-cache:false");
 * 
 * @param headers ??header??"encoding:""no-cache:",UTF-8true.
 */
public static void render(final String contentType, final String content, final String... headers) {
    try {
        //?headers?
        String encoding = ENCODING_DEFAULT;
        boolean noCache = NOCACHE_DEFAULT;
        for (String header : headers) {
            String headerName = StringUtils.substringBefore(header, ":");
            String headerValue = StringUtils.substringAfter(header, ":");

            if (StringUtils.equalsIgnoreCase(headerName, ENCODING_PREFIX)) {
                encoding = headerValue;
            } else if (StringUtils.equalsIgnoreCase(headerName, NOCACHE_PREFIX)) {
                noCache = Boolean.parseBoolean(headerValue);
            } else
                throw new IllegalArgumentException(headerName + "??header");
        }

        HttpServletResponse response = ServletActionContext.getResponse();

        //headers?
        String fullContentType = contentType + ";charset=" + encoding;
        response.setContentType(fullContentType);
        if (noCache) {
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
        }

        response.getWriter().write(content);
        response.getWriter().flush();

    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
}

From source file:com.blue.ssh.core.orm.PropertyFilter.java

/**
 * @param filterName//from  w  ww.jav a 2s.  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);
}