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

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

Introduction

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

Prototype

public static String removeEnd(String str, String remove) 

Source Link

Document

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

Usage

From source file:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java

@SuppressWarnings("unchecked")
private String computeProviderKey(Dictionary<String, ?> dictionary) {
    String provideKey = (String) dictionary.get(LDAP_PROVIDER_KEY_PROP);
    if (provideKey != null) {
        return provideKey;
    }/* w w  w .j ava2 s .c om*/
    String filename = (String) dictionary.get("felix.fileinstall.filename");
    String factoryPid = (String) dictionary.get(ConfigurationAdmin.SERVICE_FACTORYPID);
    String confId;
    if (StringUtils.isBlank(filename)) {
        confId = (String) dictionary.get(Constants.SERVICE_PID);
        if (StringUtils.startsWith(confId, factoryPid + ".")) {
            confId = StringUtils.substringAfter(confId, factoryPid + ".");
        }
    } else {
        confId = StringUtils.removeEnd(StringUtils.substringAfter(filename, factoryPid + "-"), ".cfg");
    }
    return (StringUtils.isBlank(confId) || "config".equals(confId)) ? "ldap" : ("ldap." + confId);
}

From source file:org.jahia.services.usermanager.mongo.JahiaMongoConfig.java

/**
 *
 * @param dictionary//from w  w  w .  j a v a2s  . co m
 * @return
 */
private String computeProviderKey(final Dictionary<String, ?> dictionary) {
    final String provideKey = (String) dictionary.get(MONGO_PROVIDER_KEY);
    if (provideKey != null) {
        return provideKey;
    }
    final String filename = (String) dictionary.get("felix.fileinstall.filename");
    final String factoryPid = (String) dictionary.get(ConfigurationAdmin.SERVICE_FACTORYPID);
    String confId;
    if (StringUtils.isBlank(filename)) {
        confId = (String) dictionary.get(Constants.SERVICE_PID);
        if (StringUtils.startsWith(confId, factoryPid + ".")) {
            confId = StringUtils.substringAfter(confId, factoryPid + ".");
        }
    } else {
        confId = StringUtils.removeEnd(StringUtils.substringAfter(filename, factoryPid + "-"), ".cfg");
    }
    return (StringUtils.isBlank(confId) || "config".equals(confId)) ? "mongo" : ("mongo." + confId);
}

From source file:org.jboss.loom.utils.as7.AS7CliUtils.java

public static ModelNode parseCommand(String command, boolean needOp) {
    String[] parts = StringUtils.split(command, ':');
    if (needOp && parts.length < 2)
        throw new IllegalArgumentException("Missing CLI command operation: " + command);
    String addr = parts[0];/*from w w w. j a va2  s .c  o  m*/

    ModelNode query = new ModelNode();

    // Addr
    String[] partsAddr = StringUtils.split(addr, '/');
    for (String segment : partsAddr) {
        String[] partsSegment = StringUtils.split(segment, "=", 2);
        if (partsSegment.length != 2)
            throw new IllegalArgumentException("Wrong addr segment format - need '=': " + command);
        query.get(ClientConstants.OP_ADDR).add(partsSegment[0], partsSegment[1]);
    }

    // No op?
    if (parts.length < 2)
        return query;

    // Op
    String[] partsOp = StringUtils.split(parts[1], '(');
    String opName = partsOp[0];
    query.get(ClientConstants.OP).set(opName);

    // Op args
    if (partsOp.length > 1) {
        String args = StringUtils.removeEnd(partsOp[1], ")");
        for (String arg : args.split(",")) {
            String[] partsArg = arg.split("=", 2);
            query.get(partsArg[0]).set(unquote(partsArg[1]));
        }
    }
    return query;
}

From source file:org.jboss.loom.utils.as7.AS7CliUtils.java

/**
 *  Changes "foo\"bar" to foo"bar./*from ww  w. j  a  v a2s . c  o m*/
 *  Is tolerant - doesn't check if the quotes are really present.
 */
public static String unquote(String string) {
    string = StringUtils.removeStart(string, "\"");
    string = StringUtils.removeEnd(string, "\"");
    return StringEscapeUtils.unescapeJava(string);
}

From source file:org.jboss.tools.openshift.internal.ui.webhooks.WebHooksComponent.java

private SelectionAdapter onClickWebhook(final IBuildConfig buildConfig) {
    return new SelectionAdapter() {
        @Override/*from  www  .ja  va  2 s.c o m*/
        public void widgetSelected(SelectionEvent e) {
            String url = buildConfig.getBuildSource().getURI();
            url = StringUtils.removeEnd(url, ".git");
            if (isGitHub(url)) {
                //open https://github.com/<user>/<repo>/settings/hooks
                if (!url.endsWith("/")) {
                    url = url + "/";
                }
                url += "settings/hooks";
            }
            new BrowserUtility().checkedCreateExternalBrowser(url, OpenShiftUIActivator.PLUGIN_ID,
                    OpenShiftUIActivator.getDefault().getLog());
        }
    };
}

From source file:org.jboss.windup.decorator.archive.ClassesProvidedDecorator.java

protected String extractClassName(String entryName) {
    String className = StringUtils.replace(entryName, "\\", "/");
    className = StringUtils.removeStart(className, "/");
    className = StringUtils.replace(className, "/", ".");
    className = StringUtils.removeEnd(className, ".class");
    className = StringUtils.removeEnd(className, ".java");

    // account for WAR classes.
    if (StringUtils.contains(className, "WEB-INF.classes.")) {
        className = StringUtils.substringAfter(className, "WEB-INF.classes.");
    }/*from   w  ww .j a v  a 2s  . c o m*/
    return className;
}

From source file:org.jboss.windup.decorator.archive.ManifestDecorator.java

protected String cleanseValue(String value) {
    value = StringUtils.trim(value);/*from  w  w  w  .  j  a v a2  s  .  c o m*/
    value = StringUtils.removeStart(value, "'");
    value = StringUtils.removeStart(value, "\"");
    value = StringUtils.removeEnd(value, "\"");
    value = StringUtils.removeEnd(value, "'");
    value = StringUtils.trim(value);

    return value;
}

From source file:org.jboss.windup.decorator.java.JavaASTAnnotationVisitor.java

protected String extract(StringLiteral value) {
    String val = value.toString();
    val = StringUtils.removeStart(val, "\"");
    val = StringUtils.removeEnd(val, "\"");

    return val;
}

From source file:org.jboss.windup.decorator.java.JavaASTVariableResolvingVisitor.java

private String qualifyType(String objRef) {
    // temporarily remove to resolve arrays
    objRef = StringUtils.removeEnd(objRef, "[]");
    if (nameInstance.containsKey(objRef)) {
        objRef = nameInstance.get(objRef);
    }//from ww w.ja  v a  2 s .c  om

    if (classNameToFullyQualified.containsKey(objRef)) {
        objRef = classNameToFullyQualified.get(objRef);
    }

    return objRef;
}

From source file:org.jboss.windup.interrogator.impl.ClassInterrogator.java

private JavaMetadata extractJavaFile(String className, Set<String> clzImports, ZipEntryMetadata archiveEntry) {
    JavaMetadata javaMeta = new JavaMetadata();
    try {//from ww  w. ja v  a2s.  c o m
        File clzFile;
        File javaFile;

        //TODO: make this work for directorymeta too.
        ZipMetadata zipMeta = (ZipMetadata) archiveEntry.getArchiveMeta();
        ZipFile zipFile = zipMeta.getZipFile();
        ZipEntry entry = archiveEntry.getZipEntry();
        // check to see whether the Java version is packaged with the archive...
        String javaZipEntry = StringUtils.removeEnd(entry.getName(), ".class") + ".java";

        if (zipFile.getEntry(javaZipEntry) != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Found Java in archive: " + className);
            }
            ZipEntry javaEntry = zipFile.getEntry(javaZipEntry);
            archiveEntry.setZipEntry(javaEntry);
            javaFile = archiveEntry.getFilePointer();
        } else {
            clzFile = archiveEntry.getFilePointer();
            javaFile = new File(StringUtils.substringBeforeLast(clzFile.getAbsolutePath(), ".class") + ".java");
            File javaPathFile = new File(
                    StringUtils.substringBeforeLast(clzFile.getAbsolutePath(), File.separator));

            if (LOG.isDebugEnabled()) {
                LOG.debug("Did not find class in archive. Decompiling class: " + className);
            }
            decompiler.decompile(className, clzFile, javaPathFile);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Unzipped class: " + className);
            }
        }

        javaMeta.setFilePointer(javaFile);
        javaMeta.setArchiveMeta(archiveEntry.getArchiveMeta());
        javaMeta.setClassDependencies(clzImports);
        javaMeta.setQualifiedClassName(className);
        javaMeta.setBlackListedDependencies(blacklistPackageResolver.extractBlacklist(clzImports));

        return javaMeta;
    } catch (Exception e) {
        if (e instanceof FatalWindupException) {
            throw (FatalWindupException) e;
        }

        LOG.error(e);
        return null;
    }
}