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

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

Introduction

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

Prototype

public static String removeEnd(final String str, final String remove) 

Source Link

Document

Removes a substring only if it is at the end of a source string, otherwise returns the source string.

A null source string will return null .

Usage

From source file:org.sleuthkit.autopsy.imageanalyzer.datamodel.DrawableFile.java

public String getDrawablePath() {
    if (drawablePath != null) {
        return drawablePath;
    } else {/* ww w  .jav a2s.c  om*/
        try {
            drawablePath = StringUtils.removeEnd(getUniquePath(), getName());
            return drawablePath;
        } catch (TskCoreException ex) {
            Logger.getLogger(DrawableFile.class.getName()).log(Level.WARNING,
                    "failed to get drawablePath from {0}", getName());
            return "";
        }
    }
}

From source file:org.squashtest.tm.web.internal.context.ReloadableSquashTmMessageSource.java

private void addPluginBasenames(Set<String> consolidatedBasenames) throws IOException {
    Resource[] resources = resourcePatternResolver
            .getResources("classpath*:org/squashtest/tm/plugin/**/messages.properties");

    for (Resource resource : resources) {
        try {/* w w  w. j  a  v  a 2 s  .c o m*/
            if (resource.exists()) {
                // resource path is external-path/jar-name.jar!/internal-path/messages.properties
                String path = resource.getURL().getPath();
                int bang = path.lastIndexOf('!');
                String basename = "classpath:" + StringUtils.removeEnd(path.substring(bang + 2), ".properties");
                consolidatedBasenames.add(basename);

                LOGGER.info(
                        "Registering *discovered* plugin classpath path {} as a basename for application MessageSource",
                        basename);
            }

        } catch (IOException e) {
            LOGGER.info("An IO error occurred while looking up plugin language resources '{}': {}", resource,
                    e.getMessage());
            LOGGER.debug("Plugin language resources lookup error for resource {}", resource, e);
        }
    }
}

From source file:org.squashtest.tm.web.internal.context.ReloadableSquashTmMessageSource.java

private void addExternalBasenames(Set<String> consolidatedBasenames) {
    String locationPattern = squashPathProperties.getLanguagesPath() + "/**/messages.properties";
    if (!locationPattern.startsWith("file:")) {
        locationPattern = "file:" + locationPattern;
    }//from ww  w  .  j av  a2  s  .  c  o m

    try {
        Resource[] resources = resourcePatternResolver.getResources(locationPattern);

        for (Resource resource : resources) {
            if (resource.exists()) {
                String basename = StringUtils.removeEnd(resource.getURL().getPath(), ".properties");
                consolidatedBasenames.add(basename);

                LOGGER.info(
                        "Registering *discovered* external path {} as a basename for application MessageSource",
                        basename);
            }

        }
    } catch (IOException e) {
        LOGGER.info("An IO error occurred while looking up external language resources '{}' : {}",
                locationPattern, e.getMessage());
        LOGGER.debug("External language lookup error. Current path : {}", new File(".").toString(), e);
    }
}

From source file:org.structr.console.rest.RestCommand.java

protected String getBasePath() {
    return StringUtils.removeEnd(Settings.RestServletPath.getValue(), "/*");
}

From source file:org.structr.schema.SchemaHelper.java

/**
 * Tries to normalize (and singularize) the given string so that it
 * resolves to an existing entity type./*from   w ww . jav a 2 s .c o  m*/
 *
 * @param possibleEntityString
 * @return the normalized entity name in its singular form
 */
public static String normalizeEntityName(String possibleEntityString) {

    if (possibleEntityString == null) {

        return null;

    }

    if ("/".equals(possibleEntityString)) {

        return "/";

    }

    final StringBuilder result = new StringBuilder();

    if (possibleEntityString.contains("/")) {

        final String[] names = StringUtils.split(possibleEntityString, "/");

        for (String possibleEntityName : names) {

            // CAUTION: this cache might grow to a very large size, as it
            // contains all normalized mappings for every possible
            // property key / entity name that is ever called.
            String normalizedType = normalizedEntityNameCache.get(possibleEntityName);

            if (normalizedType == null) {

                normalizedType = StringUtils.capitalize(CaseHelper.toUpperCamelCase(stem(possibleEntityName)));

            }

            result.append(normalizedType).append("/");

        }

        return StringUtils.removeEnd(result.toString(), "/");

    } else {

        //                      CAUTION: this cache might grow to a very large size, as it
        // contains all normalized mappings for every possible
        // property key / entity name that is ever called.
        String normalizedType = normalizedEntityNameCache.get(possibleEntityString);

        if (normalizedType == null) {

            normalizedType = StringUtils.capitalize(CaseHelper.toUpperCamelCase(stem(possibleEntityString)));

        }

        return normalizedType;
    }
}

From source file:org.talend.updates.runtime.nexus.component.ComponentIndexManager.java

public ComponentIndexBean createIndexBean4Patch(File patchZipFile, Type type) {
    if (patchZipFile == null || !patchZipFile.exists() || patchZipFile.isDirectory()
            || !patchZipFile.getName().endsWith(FileExtensions.ZIP_FILE_SUFFIX) || type == null) {
        return null;
    }/*ww w. ja  va  2 s.  c  o  m*/
    String name = StringUtils.removeEnd(patchZipFile.getName(), FileExtensions.ZIP_FILE_SUFFIX);
    String bundleId = null;
    String bundleVersion = null;
    String mvnUri = null;
    if (type == Type.PLAIN_ZIP) {
        bundleId = "org.talend.studio.patch.plainzip"; //$NON-NLS-1$
        bundleVersion = name;
    } else if (type == Type.P2_PATCH) {
        bundleId = "org.talend.studio.patch.updatesite"; //$NON-NLS-1$
        bundleVersion = P2Manager.getInstance().getP2Version(patchZipFile);
    }
    String artifactId = StringUtils.substringBeforeLast(name, "-"); //$NON-NLS-1$
    String artifactVersion = StringUtils.substringAfterLast(name, "-"); //$NON-NLS-1$
    mvnUri = MavenUrlHelper.generateMvnUrl(bundleId, artifactId, artifactVersion, FileExtensions.ZIP_EXTENSION,
            null);
    if (name != null && bundleId != null && bundleVersion != null && mvnUri != null) {
        ComponentIndexBean indexBean = new ComponentIndexBean();
        boolean set = indexBean.setRequiredFieldsValue(name, bundleId, bundleVersion, mvnUri);
        indexBean.setValue(ComponentIndexNames.types, PathUtils.convert2StringTypes(Arrays.asList(type)));
        if (set) {
            return indexBean;
        }
    }
    return null;
}

From source file:org.thelq.pircbotx.commands.HelpCommand.java

protected static String getCommandName(BasicCommand command) {
    return StringUtils.removeEnd(command.getClass().getSimpleName(), "Command");
}

From source file:org.thelq.stackexchange.dbimport.Utils.java

public static String genTablePrefix(String containerName) {
    String name = containerName.trim().toLowerCase();
    if (StringUtils.isBlank(name))
        return "";
    //Hardcoded conversions
    name = StringUtils.removeEnd(name, ".7z");
    name = StringUtils.removeEnd(name, ".stackexchange.com");
    if (StringUtils.contains(name, "stackoverflow"))
        name = StringUtils.replace(name, "stackoverflow", "so");
    else if (StringUtils.contains(name, "serverfault"))
        name = StringUtils.replace(name, "serverfault", "sf");
    else if (StringUtils.containsIgnoreCase(name, "superuser"))
        name = StringUtils.replace(name, "superuser", "su");

    //Remove unnessesary extensions
    name = StringUtils.removeEnd(name, ".com");

    //Meta handling
    if (StringUtils.startsWith(name, "meta"))
        name = StringUtils.removeStart(name, "meta") + "_m";
    else if (StringUtils.startsWith(name, "meta."))
        name = StringUtils.removeStart(name, "meta.") + "_m";

    //Basic make valid for SQL
    //TODO: more validation?
    name = StringUtils.remove(name, " ");
    name = StringUtils.remove(name, ".");
    return name + "_";
}

From source file:org.trimou.dropwizard.views.TrimouViewRenderer.java

private String getLocalizedTemplateName(String templateName, String localePart) {
    return StringUtils.removeEnd(templateName, suffix) + "_" + localePart + suffix;
}

From source file:org.trimou.engine.locator.PathTemplateLocator.java

protected String stripSuffix(String filename) {
    return suffix != null ? StringUtils.removeEnd(filename, "." + suffix) : filename;
}