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

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

Introduction

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

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:com.willwinder.universalgcodesender.connection.TCPConnection.java

@Override
public void setUri(String uri) {
    try {/*from w  w  w.java2  s .c  o  m*/
        host = StringUtils.substringBetween(uri, ConnectionDriver.TCP.getProtocol(), ":");
        port = Integer.valueOf(StringUtils.substringAfterLast(uri, ":"));
    } catch (Exception e) {
        throw new ConnectionException("Couldn't parse connection string " + uri, e);
    }

    if (StringUtils.isEmpty(host)) {
        throw new ConnectionException("Empty host in connection string.");
    }
    if ((port < 1) || (port > 65535)) {
        throw new ConnectionException("Please ensure port is a port number between 1 and 65535.");
    }
}

From source file:com.threewks.thundr.route.controller.Controller.java

static final String methodNameForAction(String actionName) {
    return StringUtils.substringAfterLast(actionName, ".");
}

From source file:de.jcup.egradle.sdk.builder.action.type.ImportTypesAction.java

@Override
public void execute(SDKBuilderContext context) throws IOException {

    TypeImportFilter filter = new TypeImportFilter();
    scanTypes(context.sourceParentDirectory, filter, context);

    if (context.originTypeNameToOriginFileMapping.isEmpty()) {
        throw new IllegalStateException("no types found!");
    }//from w w w  . j a va  2 s .c  o  m

    /* now types are scanned, so start importing all types */
    for (String typeName : context.originTypeNameToOriginFileMapping.keySet()) {
        /* simply call the provider, it will resolve the type */
        Type buildtype = context.originGradleFilesProvider.getType(typeName);
        if (!typeName.startsWith("org.gradle.tooling")) {
            String shortName = StringUtils.substringAfterLast(typeName, ".");
            context.alternativeApiMapping.put(shortName, typeName);
        }
        if (buildtype == null) {
            throw new IllegalArgumentException("Cannot build type:" + typeName);
        }
    }
}

From source file:com.adeptj.modules.oauth.http.OAuthAuthorizationRequestServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String providerName = StringUtils.substringAfterLast(req.getRequestURI(), "/");
    LOGGER.info("Authz request for provider: [{}]", providerName);
    OAuthProvider provider = this.providerFactory.getProvider(providerName);
    LOGGER.info("OAuthProvider: [{}]", provider);
    OAuth20Service oauth2Service = this.providerFactory.getOAuth2Service(providerName);
    if (oauth2Service == null) {
        oauth2Service = new ServiceBuilder(provider.getApiKey()).apiSecret(provider.getApiSecret())
                .callback(provider.getCallbackURL()).build(provider.getApi());
        this.providerFactory.addOAuth2Service(providerName, oauth2Service);
    }// w  ww.  j  a va 2s . co  m
    String authorizationUrl = oauth2Service.getAuthorizationUrl();
    LOGGER.info("Authz URL: [{}]", authorizationUrl);
    resp.sendRedirect(authorizationUrl);
}

From source file:com.dowdandassociates.gentoo.bootstrap.LatestImageProvider.java

@Override
public Optional<Image> get() {
    DescribeImagesResult result = ec2Client.describeImages(getRequest());

    Map<String, Image> imageMap = new HashMap<String, Image>();

    for (Image image : result.getImages()) {
        String imageLocation = StringUtils.substringAfterLast(image.getImageLocation(), "/");
        if (StringUtils.isBlank(imageLocation)) {
            imageLocation = image.getImageLocation();
        }//from  w w  w . j  a  v a  2 s  .c o  m
        log.info("imageLocation = " + imageLocation);
        imageMap.put(imageLocation, image);
    }

    if (imageMap.isEmpty()) {
        return Optional.absent();
    }

    SortedSet<String> sortedKeySet = new TreeSet<String>();
    sortedKeySet.addAll(imageMap.keySet());
    String[] keys = sortedKeySet.toArray(new String[0]);
    log.info("key = " + keys[keys.length - 1]);
    return Optional.fromNullable(imageMap.get(keys[keys.length - 1]));
}

From source file:kenh.xscript.elements.Accum.java

public void process(@Attribute(ATTRIBUTE_VARIABLE) String var, @Attribute(ATTRIBUTE_STEP) int step)
        throws UnsupportedScriptException {
    var = StringUtils.trimToEmpty(var);

    if (StringUtils.isBlank(var)) {
        UnsupportedScriptException ex = new UnsupportedScriptException(this, "Variable name is empty.");
        throw ex;
    }/*from   w w  w . j  a v a  2  s .  c om*/

    String thisVar = var;
    if (StringUtils.contains(var, " ")) {
        thisVar = StringUtils.substringAfterLast(var, " ");
    }

    int defaultValue = 0;
    if (this.getEnvironment().containsVariable(thisVar)) {
        Object obj = this.getEnvironment().getVariable(thisVar);
        if (obj instanceof Integer) {
            defaultValue = ((Integer) obj).intValue();
        } else if (obj instanceof String) {
            if (StringUtils.isNumeric((String) obj)) {
                defaultValue = Integer.parseInt((String) obj);
            }

        } else {
            UnsupportedScriptException ex = new UnsupportedScriptException(this,
                    "Only support integer variable.");
            throw ex;
        }
    }
    defaultValue += step;

    saveVariable(var, defaultValue, defaultValue);
}

From source file:gobblin.data.management.conversion.hive.provider.DatePatternUpdateProvider.java

private long parseDateForLocation(String location) throws UpdateNotFoundException {
    for (Patterns pattern : Patterns.values()) {
        String dateString = StringUtils.substringAfterLast(location, pattern.prefix);
        if (StringUtils.isNotBlank(dateString)) {
            try {
                return pattern.dateFormat.parseMillis(dateString);
            } catch (IllegalArgumentException | UnsupportedOperationException e) {
                throw new UpdateNotFoundException(String.format("Failed parsing date string %s", dateString));
            }//from   ww w. j a v  a 2 s.  c  o m

        }
    }
    throw new UpdateNotFoundException(String.format("Path %s does not match any date pattern %s", location,
            Arrays.toString(Patterns.values())));
}

From source file:egovframework.com.utl.wed.filter.DefaultFileSaveManager.java

@Override
public String saveFile(FileItem fileItem, String imageBaseDir, String imageDomain) {
    String originalFileName = FilenameUtils.getName(fileItem.getName());
    String relUrl;/*from  w  w w  .  j a  va 2  s. c om*/
    // filename
    String subDir = File.separator + DirectoryPathManager
            .getDirectoryPathByDateType(DirectoryPathManager.DIR_DATE_TYPE.DATE_POLICY_YYYY_MM);
    String fileName = RandomStringUtils.randomAlphanumeric(20) + "."
            + StringUtils.lowerCase(StringUtils.substringAfterLast(originalFileName, "."));

    File newFile = new File(imageBaseDir + subDir + fileName);
    File fileToSave = DirectoryPathManager.getUniqueFile(newFile.getAbsoluteFile());

    try {
        FileUtils.writeByteArrayToFile(fileToSave, fileItem.get());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String savedFileName = FilenameUtils.getName(fileToSave.getAbsolutePath());
    relUrl = StringUtils.replace(subDir, "\\", "/") + savedFileName;

    return imageDomain + relUrl;
}

From source file:info.magnolia.test.fixture.CommandEventListenerTestCommand.java

@Override
public boolean execute(Context context) throws Exception {
    Session session = MgnlContext.getInstance().getJCRSession(RepositoryConstants.WEBSITE);
    session.getNode(OBSERVATION_RESULTS)
            .setProperty(StringUtils.substringAfterLast(context.getAttribute("path").toString(), "/"), "end");
    session.save();/*from   ww w .  ja va 2  s . co  m*/
    return true;
}

From source file:com.adeptj.modules.oauth.http.OAuthCallbackServlet.java

@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String code = req.getParameter("code");
    LOGGER.info("OAuth2 code: [{}]", code);
    String provider = StringUtils.substringAfterLast(req.getRequestURI(), "/");
    LOGGER.info("Provider: [{}]", provider);
    OAuth20Service oAuth2Service = this.providerFactory.getOAuth2Service(provider);
    OAuth2AccessToken token = null;//from  w ww .j a v a  2  s .  c o m
    try {
        token = oAuth2Service.getAccessToken(code);
        LOGGER.info("OAuth2AccessToken: [{}]", token);
        OAuthRequest oReq = new OAuthRequest(Verb.GET, "https://api.linkedin.com/v1/people/~?format=json");
        oAuth2Service.signRequest(token, oReq);
        Response oResp = oAuth2Service.execute(oReq);
        LOGGER.info("Linkedin Profile: [{}]", oResp.getBody());
        resp.getOutputStream().write(oResp.getBody().getBytes(StandardCharsets.UTF_8));
    } catch (InterruptedException | ExecutionException ex) {
    }
}