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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:info.mikaelsvensson.devtools.analysis.shared.AbstractAnalyzer.java

public static String getFormattedString(String pattern, File patternArgumentSourceFile) {
    // LinkedHashMap since the values should be returned in the order of insertion (for backwards compatibility)
    final LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
    values.put("logFileName", patternArgumentSourceFile.getName());
    values.put("logFileNameWithoutExt",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getName(), "."));
    values.put("logFilePath",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getAbsolutePath(), "."));
    values.put("logFilePathWithoutExt",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getAbsolutePath(), "."));
    values.put("parentName", patternArgumentSourceFile.getParentFile().getName());
    values.put("parentPath", patternArgumentSourceFile.getParentFile().getAbsolutePath());

    // Add numeric "key" for each "parameter" (for backwards compability)
    int i = 0;/*w w w.  j  a v  a 2  s  .  c o m*/
    for (Object value : values.values().toArray()) {
        values.put(String.valueOf(i++), value);
    }

    // Use {key} format instead of ${key}, thus providing backwards compatibility with previously used MessageFormat.
    return StrSubstitutor.replace(pattern, values, "{", "}");
}

From source file:de.blizzy.backup.vfs.RemoteFileOrFolder.java

@Override
public IFolder getParentFolder() {
    if (!file.equals("/")) { //$NON-NLS-1$
        String parentFolder = StringUtils.substringBeforeLast(file, "/"); //$NON-NLS-1$
        if (StringUtils.isBlank(parentFolder)) {
            parentFolder = "/"; //$NON-NLS-1$
        }//from   w w  w  . j  a va2s.  com
        return getFolder(parentFolder);
    }
    return null;
}

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/*  ww  w .  ja  v a 2 s  . c  o  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:de.blizzy.backup.vfs.sftp.SftpFileOrFolder.java

@Override
public IFolder getParentFolder() {
    if (!file.equals("/")) { //$NON-NLS-1$
        String parentFolder = StringUtils.substringBeforeLast(file, "/"); //$NON-NLS-1$
        if (StringUtils.isBlank(parentFolder)) {
            parentFolder = "/"; //$NON-NLS-1$
        }//from  w ww.  j  av a2  s .com
        return new SftpFileOrFolder(parentFolder, location);
    }
    return null;
}

From source file:com.neatresults.mgnltweaks.ui.field.TemplatePathConverter.java

@Override
public String convertToPresentation(String path, Class<? extends String> targetType, Locale locale)
        throws ConversionException {
    String res = StringUtils.EMPTY;
    if (StringUtils.isBlank(path)) {
        return res;
    }/*from w w  w .j  ava  2s  . c o m*/
    path = StringUtils.substringBeforeLast(path, ".ftl");
    res = path;
    return res;
}

From source file:net.sf.dynamicreports.site.ExamplesAspect.java

@Around("build()")
public void build(ProceedingJoinPoint pjp) throws Throwable {
    Class<?> design = pjp.getSignature().getDeclaringType();
    name = design.getSimpleName();//from  w w w . j  a  va2 s.c o  m
    if (StringUtils.endsWith(name, "Design")) {
        name = StringUtils.substringBeforeLast(name, "Design");
    }
    String path = design.getName().substring(Templates.class.getPackage().getName().length() + 1)
            .split("\\.")[0];
    GenerateSite.addExample(name, path, design);
    pjp.proceed();
}

From source file:edu.kit.dama.util.update.types.JavaLibrary.java

/**
 * Default constructor. During construction library name, version, snapshot
 * status and MD5 hash are obtained. If the filename does not match the
 * regular expression, name and version are set 'null' and {@link #isValid()}
 * will return 'false'.//from   w w  w . j av a2s  .  c  om
 *
 * @param pFile The jar file.
 */
public JavaLibrary(File pFile) {
    location = pFile;
    fullname = pFile.getName();
    try (FileInputStream fis = new FileInputStream(pFile)) {
        md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
    } catch (IOException ex) {
        md5 = "";
    }
    String nameVersion = StringUtils.substringBeforeLast(fullname, ".");

    Matcher m = Pattern.compile("(.*)[-]([0-9\\.]+)(-SNAPSHOT)?").matcher(nameVersion);
    if (m.find()) {
        name = m.group(1);
        version = m.group(2);
        snapshot = m.group(3) != null;
        valid = true;
    } else {
        //does not fit file pattern
        name = null;
        version = null;
        snapshot = false;
        valid = false;
    }
}

From source file:com.yqboots.security.access.RoleHierarchyImpl.java

/**
 * Retrieves the hierarchy roles.//from   w ww  . j av a2 s  .co  m
 *
 * @param role the granted authority
 * @return the roles from hierarchy
 */
protected Collection<? extends GrantedAuthority> retrieveHierarchyRoles(GrantedAuthority role) {
    final Set<GrantedAuthority> results = new HashSet<>();
    // /R001/R002/R003 ...
    String roleStr = role.getAuthority();

    if (StringUtils.startsWith(roleStr, "ROLE_") && StringUtils.contains(roleStr, "/")) {
        roleStr = StringUtils.substringAfter(roleStr, "ROLE_");
    }

    while (StringUtils.isNotBlank(roleStr)) {
        results.add(new SimpleGrantedAuthority(roleStr));
        if (!StringUtils.contains(roleStr, "/")) {
            break;
        }

        roleStr = StringUtils.substringBeforeLast(roleStr, "/");
    }

    return results;
}

From source file:de.tuberlin.uebb.jbop.access.ClassDescriptor.java

/**
 * Get the Package of the class.
 * 
 * @return the package
 */
public String getPackage() {
    return StringUtils.substringBeforeLast(name, ".");
}

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  w w .  j  av a 2  s. 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;
}