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

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

Introduction

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

Prototype

public static String substringBeforeLast(String str, String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:io.wcm.tooling.netbeans.sightly.completion.classLookup.MemberLookupResolver.java

/**
 * performs a nested lookup. E.g for foo.bar it will resolve the type of bar and then get it's methods
 *
 * @param variable e.g. foo.bar//from  ww  w.  ja  v  a  2  s  . c o m
 * @return set with matching results
 */
private Set<MemberLookupResult> performNestedLookup(String variable) {
    Set<MemberLookupResult> ret = new LinkedHashSet<>();
    // start with the first part
    String[] parts = StringUtils.split(variable, ".");
    if (parts.length > 2) {
        Set<MemberLookupResult> subResult = performNestedLookup(StringUtils.substringBeforeLast(variable, "."));
        for (MemberLookupResult result : subResult) {
            if (result.matches(parts[parts.length - 1])) {
                ret.addAll(getResultsForClass(result.getReturnType(), variable));
            }
        }
    } else {
        Set<MemberLookupResult> subResults = performMemberLookup(parts[0]);
        for (MemberLookupResult result : subResults) {
            if (result.matches(parts[1])) {
                // we found a method which has the correct name, now we can resolv this
                ret.addAll(getResultsForClass(result.getReturnType(), variable));
            }
        }
    }
    return ret;
}

From source file:com.evolveum.midpoint.notifications.impl.notifiers.SimpleFocalObjectNotifier.java

private String getFocusTypeName(Event event) {
    String simpleName = ((ModelEvent) event).getFocusContext().getObjectTypeClass().getSimpleName();
    return StringUtils.substringBeforeLast(simpleName, "Tip"); // should usually work ;)
}

From source file:com.sonicle.webtop.core.app.shiro.WTRealm.java

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    if (token instanceof UsernamePasswordToken) {
        UsernamePasswordToken upt = (UsernamePasswordToken) token;

        String domainId = null;//from www . j  a va 2  s .  c  o m
        if (token instanceof UsernamePasswordDomainToken) {
            domainId = ((UsernamePasswordDomainToken) token).getDomain();
        }
        //logger.debug("isRememberMe={}",upt.isRememberMe());

        String sprincipal = (String) upt.getPrincipal();
        String internetDomain = StringUtils.lowerCase(StringUtils.substringAfterLast(sprincipal, "@"));
        String username = StringUtils.substringBeforeLast(sprincipal, "@");
        logger.trace("doGetAuthenticationInfo [{}, {}, {}]", domainId, internetDomain, username);

        Principal principal = authenticateUser(domainId, internetDomain, username, upt.getPassword());

        // Update token with new values resulting from authentication
        if (token instanceof UsernamePasswordDomainToken) {
            ((UsernamePasswordDomainToken) token).setDomain(principal.getDomainId());
        }
        upt.setUsername(principal.getUserId());

        return new WTAuthenticationInfo(principal, upt.getPassword(), this.getName());

    } else {
        return null;
    }
}

From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.MovingFolder.java

protected boolean createFolderNode(String folderPath, ResourceResolver r)
        throws RepositoryException, PersistenceException {
    Session s = r.adaptTo(Session.class);
    if (s.nodeExists(folderPath)) {
        return false;
    }//from  ww  w.  j av a 2 s. c  o m

    String name = StringUtils.substringAfterLast(folderPath, "/");
    String parentPath = StringUtils.substringBeforeLast(folderPath, "/");
    createFolderNode(parentPath, r);

    s.getNode(parentPath).addNode(name, DEFAULT_FOLDER_TYPE);
    r.commit();
    r.refresh();
    return true;
}

From source file:edu.monash.merc.system.parser.gpm.GPMRSSReader.java

private GPMSyndEntry createGPMSyndEntry(String ftpLink, Date publishedDate) {
    if (publishedDate == null) {
        return null;
    }//from   www .j  a  v  a  2  s  .c  om

    if (StringUtils.isBlank(ftpLink)) {
        return null;
    }

    GPMSyndEntry gpmSyndEntry = new GPMSyndEntry();
    gpmSyndEntry.setReleasedTime(publishedDate);

    String tmpFtpDir = StringUtils.substringBeforeLast(ftpLink, PATH_SEPARATOR);
    String ftpPath = StringUtils.substringAfter(tmpFtpDir, FTP_PROTOCOL);
    String ftpServerName = StringUtils.substringBefore(ftpPath, PATH_SEPARATOR);
    String workdir = StringUtils.substringAfter(ftpPath, PATH_SEPARATOR);
    String fileName = StringUtils.substringAfterLast(ftpLink, PATH_SEPARATOR);
    gpmSyndEntry.setGmpFtpServer(ftpServerName);
    gpmSyndEntry.setTpbWorkDir(PATH_SEPARATOR + workdir);
    gpmSyndEntry.setReleasedTpbFileName(fileName);
    return gpmSyndEntry;
}

From source file:ch.algotrader.esper.SpringServiceResolver.java

@Override
public void resolve(final EPStatement statement, final String subscriberExpression) {

    if (StringUtils.isBlank(subscriberExpression)) {
        throw new IllegalArgumentException("Subscriber is empty");
    }//from   w w w  .j a  va  2s  . com

    PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("${", "}", ",", false);
    String s = placeholderHelper.replacePlaceholders(subscriberExpression, name -> {
        if (name.equalsIgnoreCase("strategyName")) {
            return this.strategyName;
        } else {
            return this.configParams.getString(name, "null");
        }
    });

    final Matcher matcher = SUBSCRIBER_NOTATION.matcher(s);
    if (matcher.matches()) {
        // New subscriber notation
        final String beanName = matcher.group(1);
        final String beanMethod = matcher.group(3);
        Object bean = this.applicationContext.getBean(beanName);
        try {
            statement.setSubscriber(bean, beanMethod);
        } catch (EPSubscriberException ex) {
            throw new SubscriberResolutionException("Subscriber expression '" + subscriberExpression
                    + "' could not be resolved to a service method", ex);
        }
    } else {
        // Assuming to be a fully qualified class name otherwise
        try {
            Class<?> cl = Class.forName(s);
            statement.setSubscriber(cl.newInstance());
        } catch (Exception e) {
            // Old notation for backward compatibility
            String serviceName = StringUtils.substringBeforeLast(s, ".");
            if (serviceName.contains(".")) {
                serviceName = StringUtils.remove(StringUtils.remove(
                        StringUtils.uncapitalize(StringUtils.substringAfterLast(serviceName, ".")), "Base"),
                        "Impl");
            }
            String beanMethod = StringUtils.substringAfterLast(s, ".");
            Object bean = this.applicationContext.getBean(serviceName);
            statement.setSubscriber(bean, beanMethod);
        }
    }
}

From source file:info.magnolia.importexport.PropertiesImportExport.java

/**
 * Transforms the keys to the following inner notation: <code>some/path/node.prop</code> or <code>some/path/node.@type</code>.
 *///from   w  ww. j  av a  2  s  . c  om
private Properties keysToInnerFormat(Properties properties) {
    Properties cleaned = new OrderedProperties();

    for (Object o : properties.keySet()) {
        String orgKey = (String) o;

        //if this is a node definition (no property)
        String newKey = orgKey;

        // make sure we have a dot as a property separator
        newKey = StringUtils.replace(newKey, "@", ".@");
        // avoid double dots
        newKey = StringUtils.replace(newKey, "..@", ".@");

        String propertyName = StringUtils.substringAfterLast(newKey, ".");
        String keySuffix = StringUtils.substringBeforeLast(newKey, ".");
        String path = StringUtils.replace(keySuffix, ".", "/");
        path = StringUtils.removeStart(path, "/");

        // if this is a path (no property)
        if (StringUtils.isEmpty(propertyName)) {
            // no value --> is a node
            if (StringUtils.isEmpty(properties.getProperty(orgKey))) {
                // make this the type property if not defined otherwise
                if (!properties.containsKey(orgKey + "@type")) {
                    cleaned.put(path + ".@type", ItemType.CONTENTNODE.getSystemName());
                }
                continue;
            }
            propertyName = StringUtils.substringAfterLast(path, "/");
            path = StringUtils.substringBeforeLast(path, "/");
        }
        cleaned.put(path + "." + propertyName, properties.get(orgKey));
    }
    return cleaned;
}

From source file:de.akquinet.innovation.play.maven.Play2PackageMojo.java

private void packageAdditionalFiles(List<String> additionalFiles, File distributionFile)
        throws MojoExecutionException {
    try {/*from www.j  a  va 2  s  . c o m*/
        ZipFile zipFile = new ZipFile(distributionFile);

        ArrayList<File> filesToAdd = new ArrayList<File>(additionalFiles.size());
        for (String file : additionalFiles) {
            File fileToAdd = new File(file);
            if (!fileToAdd.exists()) {
                throw new MojoExecutionException(
                        fileToAdd.getCanonicalPath() + " not found, can't add to package");
            }
            filesToAdd.add(fileToAdd);

            ZipParameters parameters = new ZipParameters();
            parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
            parameters.setIncludeRootFolder(true);
            // Let's safely assume that the zip filename is also the root directory all files are packaged in
            parameters.setRootFolderInZip(StringUtils.substringBeforeLast(distributionFile.getName(), ".zip"));
            parameters.setReadHiddenFiles(true);

            String message = String.format("Adding files to distribution zip [%s]: \n\t%s",
                    distributionFile.getCanonicalPath(), StringUtils.join(additionalFiles, "\n\t"));
            getLog().info(message);

            zipFile.addFiles(filesToAdd, parameters);
        }
    } catch (ZipException e) {
        throw new MojoExecutionException("Cannot add files to zipfile: " + distributionFile, e);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot add files to zipfile: " + distributionFile, e);
    }
}

From source file:adalid.util.i18n.Merger.java

private static String locale(String name) {
    String substringBeforeLast = StringUtils.substringBeforeLast(name, ".");
    String substringAfter = StringUtils.substringAfter(substringBeforeLast, "_");
    return StringUtils.trimToNull(substringAfter);
}

From source file:de.forsthaus.webui.logging.loginlog.model.SecLoginlogListModelItemRenderer.java

private String truncateIPForPrivacy(String remoteIp) {
    return StringUtils.substringBeforeLast(remoteIp, ".") + ".xxx";
}