Java Examples for org.apache.commons.lang.StringUtils.substringBeforeLast

The following java examples will help you to understand the usage of org.apache.commons.lang.StringUtils.substringBeforeLast. These source code samples are taken from different open source projects.

Example 1
Project: jbehave-core-master  File: UnderscoredToCapitalized.java View source code
public String resolveName(String path) {
    String name = path;
    if (contains(name, extension)) {
        name = substringBeforeLast(name, extension);
    }
    if (contains(name, '/')) {
        name = substringAfterLast(name, "/");
    }
    if (contains(name, '.')) {
        name = substringAfterLast(name, ".");
    }
    return capitalize(name.replace("_", " "));
}
Example 2
Project: sputnik-master  File: AbstractBuildDirLocator.java View source code
@Nullable
@Override
public String apply(ReviewFile file) {
    if (file.getReviewFilename().contains(sourceDir)) {
        return substringBeforeLast(file.getReviewFilename(), sourceDir).concat(getMainBuildDir());
    }
    if (file.getReviewFilename().contains(testDir)) {
        return substringBeforeLast(file.getReviewFilename(), testDir).concat(getTestBuildDir());
    }
    return file.getSourceDir();
}
Example 3
Project: gradle-master  File: AbstractUriScriptSource.java View source code
private String classNameFromPath(String path) {
    String name = substringBeforeLast(substringAfterLast(path, "/"), ".");
    StringBuilder className = new StringBuilder(name.length());
    for (int i = 0; i < name.length(); i++) {
        char ch = name.charAt(i);
        className.append(isJavaIdentifierPart(ch) ? ch : '_');
    }
    if (!isJavaIdentifierStart(className.charAt(0))) {
        className.insert(0, '_');
    }
    className.setLength(Math.min(className.length(), 30));
    className.append('_');
    className.append(HashUtil.createCompactMD5(path));
    return className.toString();
}
Example 4
Project: tessell-master  File: ResourcesGenerator.java View source code
/** Finds {@code url(...)} in the css and replaces it with GWT @url declarations. */
private static String doUrlSubstitution(String cssContent) throws Exception {
    // keep track of urls we've already defined so we don't redefine them
    Set<String> defined = new HashSet<String>();
    // buffer for @url definitions, to be prepended at the end
    StringBuffer defs = new StringBuffer();
    // buffer to hold the transformed css, to be appended at the end
    StringBuffer sb = new StringBuffer();
    Matcher m = urlPattern.matcher(cssContent);
    while (m.find()) {
        String path = m.group(1);
        String methodName = GenUtils.toMethodName(substringBeforeLast(new File(path).getName(), "."));
        String aliasName = "_" + methodName + "Url";
        // for the DataResource
        String resourceName = methodName + "Data";
        if (defined.add(aliasName)) {
            defs.append("@url " + aliasName + " " + resourceName + ";\n");
        }
        m.appendReplacement(sb, aliasName);
    }
    m.appendTail(sb);
    return defs.toString() + sb.toString();
}
Example 5
Project: mywebio-sdk-master  File: MyCodeGenerator.java View source code
private void generateAssetsInfo(VelocityEngine ve, String sourceCodePath) {
    String currentProjectPath = substringBeforeLast(sourceCodePath, "/build/");
    final String mywebAssetDir = currentProjectPath + "/src/main/assets/myweb";
    FluentIterable<File> filesAndDirs = fileTreeTraverser().breadthFirstTraversal(new File(mywebAssetDir));
    FluentIterable<File> files = filesAndDirs.filter(isFile());
    FluentIterable<AssetFile> assetFiles = files.transform(new Function<File, AssetFile>() {

        @Override
        public AssetFile apply(File f) {
            String relativePath = substringAfter(f.getAbsolutePath(), mywebAssetDir);
            return new AssetFile(relativePath, f.length());
        }
    });
    generateAssetInfo(ve, assetFiles.toList());
}
Example 6
Project: jfunk-master  File: EmailModule.java View source code
@Provides
@Singleton
SetMultimap<String, MailAccount> provideEmailAddressPools(final Configuration config) {
    SetMultimap<String, MailAccount> result = HashMultimap.create();
    Set<String> accountIdCache = newHashSet();
    for (Entry<String, String> entry : config.entrySet()) {
        String key = entry.getKey();
        Matcher matcher = MAIL_ACCOUNT_START_PATTERN.matcher(key);
        if (matcher.matches()) {
            String pool = matcher.group(1);
            String suffix = substringAfterLast(key, pool + '.');
            matcher = MAIL_ACCOUNT_END_PATTERN.matcher(suffix);
            String accountId = matcher.find() ? substringBeforeLast(suffix, ".") : suffix;
            if (accountIdCache.contains(accountId)) {
                continue;
            }
            accountIdCache.add(accountId);
            String user = config.processPropertyValue(format(MAIL_USER_KEY_TEMPLATE, pool, accountId, accountId));
            String password = config.processPropertyValue(format(MAIL_PASSWORD_KEY_TEMPLATE, pool, accountId));
            String address = config.processPropertyValue(format(MAIL_ADDRESS_KEY_TEMPLATE, pool, accountId, accountId));
            result.put(pool, new MailAccount(accountId, address, user, password));
        }
    }
    return result;
}
Example 7
Project: arquillian-rusheye-master  File: CommandCrawl.java View source code
private void addMasks(File dir, Element base, MaskType maskType) {
    if (dir.exists() && dir.isDirectory()) {
        for (File file : dir.listFiles()) {
            String id = substringBeforeLast(file.getName(), ".");
            String source = getRelativePath(maskBase, file);
            String info = substringAfterLast(id, "--");
            String[] infoTokens = split(info, "-");
            Element mask = base.addElement(QName.get("mask", ns)).addAttribute("id", id).addAttribute("type", maskType.value()).addAttribute("source", source);
            for (String alignment : infoTokens) {
                String attribute = ArrayUtils.contains(new String[] { "top", "bottom" }, alignment) ? "vertical-align" : "horizontal-align";
                mask.addAttribute(attribute, alignment);
            }
        }
    }
}
Example 8
Project: recommenders-master  File: RecommendersCompletionContext.java View source code
@VisibleForTesting
public static Set<ITypeName> createTypeNamesFromSignatures(final char[][] sigs) {
    if (sigs == null) {
        return Collections.emptySet();
    }
    if (sigs.length < 1) {
        return Collections.emptySet();
    }
    Set<ITypeName> res = Sets.newHashSet();
    // JDT signatures contain '.' instead of '/' and may end with ';'
    for (char[] sig : sigs) {
        try {
            String descriptor = new String(sig).replace('.', '/');
            //$NON-NLS-1$
            descriptor = substringBeforeLast(descriptor, ";");
            res.add(VmTypeName.get(descriptor));
        } catch (Exception e) {
            log(ERROR_FAILED_TO_PARSE_TYPE_NAME, e, String.valueOf(sig));
        }
    }
    return res;
}
Example 9
Project: jazzautomation_source-master  File: FeatureParser.java View source code
public static Map<String, String> processMap(String text) throws IllegalCucumberFormatException {
    Map<String, String> keyValuePair = new LinkedHashMap<>();
    List<String> lines = scanIntoLines(text);
    // every line is a key value pair
    for (String line : lines) {
        line = filterLineNumber(line);
        if (isTableStructureValid(line)) {
            String innerString = substringBeforeLast(line, TABLE_COLUMN_SEPARATOR);
            String value = substringAfterLast(innerString, TABLE_COLUMN_SEPARATOR);
            String key = substringBeforeLast(innerString, TABLE_COLUMN_SEPARATOR);
            key = substringAfter(key, TABLE_COLUMN_SEPARATOR);
            keyValuePair.put(key.trim(), value.trim());
        } else {
            if (isBlank(line)) {
                continue;
            }
            if (line.trim().startsWith(COMMENT_MARKER)) {
                LOG.info("Skipping line [" + line.trim() + ']');
                continue;
            }
            throw new IllegalCucumberFormatException("The following line could not be processed; it was invalid. Line = [" + line + ']');
        }
    }
    return keyValuePair;
}
Example 10
Project: constellio-master  File: ClassifyConnectorRecordInTaxonomyExecutor.java View source code
private String getParentPath(String fullPath, String pathPart) {
    StringBuilder builder = new StringBuilder(fullPath);
    int lastSlash = fullPath.lastIndexOf(pathPart + "/");
    if (lastSlash == -1) {
        int indexOfSlash = fullPath.indexOf("/");
        int indexOfBackslash = fullPath.indexOf("\\");
        if (indexOfSlash > indexOfBackslash) {
            return fullPath.substring(indexOfSlash);
        } else {
            return fullPath.substring(indexOfBackslash);
        }
    } else {
        builder.replace(lastSlash, lastSlash + pathPart.length() + 1, "");
        return builder.toString();
    }
//
// if (fullPath.endsWith("/")) {
// fullPath = fullPath.substring(0, fullPath.length() - 1);
// }
//
// return org.apache.commons.lang3.StringUtils.substringBeforeLast(fullPath, "/");
}
Example 11
Project: springlab-master  File: WithoutTrailingImplBeanNameGenerator.java View source code
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
    String beanName = super.generateBeanName(definition, registry);
    return beanName.endsWith("Impl") ? substringBeforeLast(beanName, "Impl") : beanName;
}