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.eclipse.recommenders.utils.rcp.JdtUtils.java

public static Optional<ITypeName> resolveUnqualifiedJDTType(String qName, final IJavaElement parent) {
    try {//from  ww  w .j  a v  a  2  s  . com
        qName = Signature.getTypeErasure(qName);
        qName = StringUtils.removeEnd(qName, ";");
        final int dimensions = Signature.getArrayCount(qName);
        if (dimensions > 0) {
            qName = Signature.getElementType(qName);
        }

        if (isPrimitiveTypeSignature(qName)) {
            final ITypeName t = VmTypeName.get(StringUtils.repeat('[', dimensions) + qName);
            return of(t);
        }

        final IType type = findClosestTypeOrThis(parent);
        if (type == null) {
            return absent();
        }

        if (qName.charAt(0) == Signature.C_TYPE_VARIABLE) {
            String literal = StringUtils.repeat('[', dimensions) + VmTypeName.OBJECT.getIdentifier();
            ITypeName name = VmTypeName.get(literal);
            return of(name);
        }
        if (qName.charAt(0) == Signature.C_UNRESOLVED) {

            final String[][] resolvedNames = type.resolveType(qName.substring(1));
            if (resolvedNames == null || resolvedNames.length == 0) {
                return of((ITypeName) VmTypeName.OBJECT);
            }
            final String pkg = new String(resolvedNames[0][0]);
            final String name = new String(resolvedNames[0][1]).replace('.', '$');
            qName = StringUtils.repeat('[', dimensions) + "L" + pkg + "." + name;
        }
        qName = qName.replace('.', '/');
        final ITypeName typeName = VmTypeName.get(qName);
        return of(typeName);
    } catch (final Exception e) {
        log(e);
        return absent();
    }
}

From source file:org.eclipse.recommenders.utils.Zips.java

public static ITypeName type(ZipEntry entry, @Nullable String suffix) {
    String name = StringUtils.removeEnd(entry.getName(), suffix);
    return VmTypeName.get("L" + name);
}

From source file:org.efaps.cli.EQLHandler.java

/**
 * Gets the stmt./*from w  ww .  j av a  2s.com*/
 *
 * @return the stmt
 * @throws IOException Signals that an I/O exception has occurred.
 */
protected String getStmt() throws IOException {
    final StringBuilder eql = EQLObserver.get().getEql();
    while (!StringUtils.endsWithAny(eql, ";", "; ", ";  ", ";   ")) {
        eql.append(this.input.in().withPromt("\\").readLine());
    }
    return StringUtils.removeEnd(StringUtils.strip(eql.toString()), ";");
}

From source file:org.efaps.ui.wicket.models.objects.AbstractUIPageObject.java

/**
 * @param _field Field the Base select will be evaluated for
 * @return base select//w  ww  .j  av  a  2s. co m
 */
protected String getBaseSelect4MsgPhrase(final Field _field) {
    String ret = "";
    if (_field.getSelectAlternateOID() != null) {
        ret = StringUtils.removeEnd(_field.getSelectAlternateOID(), ".oid");
    }
    return ret;
}

From source file:org.exist.mongodb.xquery.gridfs.ListBuckets.java

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {/*from   www. j  a  va2 s .c om*/
        // Verify clientid and get client
        String mongodbClientId = args[0].itemAt(0).getStringValue();
        MongodbClientStore.getInstance().validate(mongodbClientId);
        MongoClient client = MongodbClientStore.getInstance().get(mongodbClientId);

        // Get parameters
        String dbname = args[1].itemAt(0).getStringValue();

        // Retrieve database          
        DB db = client.getDB(dbname);

        // Retrieve collection names
        Set<String> collectionNames = db.getCollectionNames();

        // Storage for results
        ValueSequence valueSequence = new ValueSequence();

        // Iterate over collection names ; only pairs of collections
        // with names ending .chunks and .files are buckets
        for (String collName : collectionNames) {
            if (collName.endsWith(".chunks")) {
                String bucketName = StringUtils.removeEnd(collName, ".chunks");
                if (collectionNames.contains(bucketName + ".files")) {
                    valueSequence.add(new StringValue(bucketName));
                }
            }
        }

        return valueSequence;

    } catch (XPathException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new XPathException(this, ex.getMessage(), ex);

    } catch (MongoException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new XPathException(this, GridfsModule.GRFS0002, ex.getMessage());

    } catch (Throwable ex) {
        LOG.error(ex.getMessage(), ex);
        throw new XPathException(this, GridfsModule.GRFS0003, ex.getMessage());
    }

    //return Sequence.EMPTY_SEQUENCE;
}

From source file:org.gbif.api.vocabulary.License.java

/**
 * FIXME returning Guava Optional will cause issues, Java 8 Optional should be returned.
 * Lookup a License by either its a) legal code URL or b) human readable summary URL.
 * For any parsing see LicenseParser in GBIF parsers project.
 *
 * @param licenseUrl the case insensitive URL for the license.
 *
 * @return instance of com.google.common.base.Optional, never null
 *//*from  w  w w.  jav a 2 s. com*/
public static Optional<License> fromLicenseUrl(String licenseUrl) {
    if (!Strings.isNullOrEmpty(licenseUrl)) {
        licenseUrl = licenseUrl.trim().toLowerCase();
        licenseUrl = StringUtils.removeEnd(licenseUrl, "/");

        // do lookup by legal code URL or human readable summary URL (excluding "/legalcode")
        for (License license : License.values()) {
            if (license.getLicenseUrl() != null && (licenseUrl.equals(license.getLicenseUrl())
                    || license.getLicenseUrl().startsWith(licenseUrl))) {
                return Optional.fromNullable(license);
            }
        }
    }
    return Optional.absent();
}

From source file:org.haiku.haikudepotserver.pkg.PkgServiceImpl.java

@Override
public Optional<Pkg> tryGetMainPkgForSubordinatePkg(ObjectContext objectContext,
        final String subordinatePkgName) {
    Preconditions.checkArgument(null != objectContext, "the object context must be provided");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(subordinatePkgName), "the pkg must be provided");

    return ImmutableList.of(SUFFIX_PKG_DEVELOPMENT, SUFFIX_PKG_X86).stream()
            .filter(subordinatePkgName::endsWith)
            .map(suffix -> StringUtils.removeEnd(subordinatePkgName, suffix)).findFirst()
            .map(mainPackageName -> Pkg.tryGetByName(objectContext, mainPackageName).orElse(null));
}

From source file:org.jszip.pseudo.io.PseudoFileSystem.java

public PseudoFile getPseudoFile(String filename) {
    filename = StringUtils.removeEnd(filename, getPathSeparator());
    if (filename.isEmpty()) {
        return root();
    }/* w  w w . j a va  2s.  c o m*/
    int index = filename.lastIndexOf(getPathSeparator());
    if (index != -1) {
        return getPseudoFile(getPseudoFile(filename.substring(0, index)), filename.substring(index + 1));
    }
    return getPseudoFile(root(), filename);
}

From source file:org.jszip.rhino.OptimizeContextAction.java

public Object run(Context context) {
    context.setErrorReporter(new MavenLogErrorReporter(log));
    PseudoFileSystem fileSystem = new PseudoFileSystem(layers);
    context.putThreadLocal(Log.class, log);
    fileSystem.installInContext();// ww  w.  jav a  2 s . co  m
    try {

        if (log.isDebugEnabled()) {
            log.debug("Virtual filesystem exposed to r.js:");
            Stack<Iterator<PseudoFile>> stack = new Stack<Iterator<PseudoFile>>();
            stack.push(Arrays.asList(fileSystem.root().listFiles()).iterator());
            while (!stack.isEmpty()) {
                Iterator<PseudoFile> iterator = stack.pop();
                while (iterator.hasNext()) {
                    PseudoFile f = iterator.next();
                    if (f.isFile()) {
                        log.debug("  " + f.getAbsolutePath() + " [file]");
                    } else {
                        log.debug("  " + f.getAbsolutePath() + " [dir]");
                        stack.push(iterator);
                        iterator = Arrays.asList(f.listFiles()).iterator();
                    }
                }
            }
        }

        List<String> argsList = new ArrayList<String>();
        argsList.add("-o");
        argsList.add("/build/" + profileJs.getName());
        String appDir = null;
        String baseUrl = "./";
        String dir = null;
        try {
            String profile = FileUtils.fileRead(profileJs, "UTF-8");
            Scriptable scope = context.newObject(global);
            scope.setPrototype(global);
            scope.setParentScope(null);
            Object parsedProfile = context.evaluateString(scope, profile, profileJs.getName(), 0, null);
            if (parsedProfile instanceof Scriptable) {
                final Scriptable scriptable = (Scriptable) parsedProfile;
                appDir = getStringWithDefault(scriptable, "appDir", null);
                baseUrl = getStringWithDefault(scriptable, "baseUrl", "./");
                dir = getStringWithDefault(scriptable, "dir", null);
            }
        } catch (IOException e) {
            log.debug("Cannot infer profile fixups", e);
        } catch (JavaScriptException e) {
            log.warn("JavaScript exception while parsing " + profileJs.getAbsolutePath() + ": " + e.details());
        } catch (Throwable e) {
            log.warn("Cannot infer if profile needs appDir and dir remapping to virtual directory structure",
                    e);
        }
        if (appDir == null) {
            argsList.add("appDir=/virtual/");
            argsList.add("baseUrl=" + baseUrl);
        } else if (!appDir.startsWith("/virtual/") && !appDir.equals("/virtual")) {
            argsList.add("appDir=/virtual/" + StringUtils.removeEnd(StringUtils.removeStart(appDir, "/"), "/")
                    + "/");
            argsList.add("baseUrl=" + baseUrl);
        }
        if (dir == null) {
            argsList.add("dir=/target/");
        } else if (!dir.startsWith("/target/") && !dir.equals("/target")) {
            argsList.add("dir=/target/" + StringUtils.removeEnd(StringUtils.removeStart(dir, "/"), "/") + "/");
        }

        global.defineFunctionProperties(new String[] { "print", "quit" }, GlobalFunctions.class,
                ScriptableObject.DONTENUM);

        Script script = context.compileString(source, "r.js", lineNo, null);
        script.getClass();

        Scriptable argsObj = context.newArray(global, argsList.toArray());
        global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);

        Scriptable scope = GlobalFunctions.createPseudoFileSystemScope(global, context);

        log.info("Applying r.js profile " + profileJs.getPath());
        log.debug("Executing r.js with arguments: " + StringUtils.join(argsList, " "));
        GlobalFunctions.setExitCode(0);
        script.exec(context, scope);
        return GlobalFunctions.getExitCode();
    } finally {
        fileSystem.removeFromContext();
        context.putThreadLocal(OptimizeContextAction.class, null);
    }
}

From source file:org.jtalks.poulpe.model.entity.Jcommune.java

/**
 * Returns the URL of JCommune, cuts the last symbol if it is '/', to provide link in correct format.
 *
 * @return URL of the component/*from  www  .ja  va2 s .  c o  m*/
 */
public String getUrl() {
    String url = getProperty(URL_PROPERTY);
    if (!StringUtils.isBlank(url) && !url.startsWith(URL_PROTOCOL)) {
        url = URL_PROTOCOL + url;
    }
    return StringUtils.removeEnd(url, URL_SUFFIX);
}