Java Code Examples for org.apache.commons.lang.StringUtils#removeStartIgnoreCase()

The following examples show how to use org.apache.commons.lang.StringUtils#removeStartIgnoreCase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APIUtil.java    From rest-client with Apache License 2.0 5 votes vote down vote up
/**
* 
* @Title: getShortPath 
* @Description: Get URL short path 
* @param @param url
* @param @return 
* @return String
* @throws
 */
public static String getShortPath(String url)
{
    if (StringUtils.isEmpty(url))
    {
        return StringUtils.EMPTY;
    }

    url = StringUtils.removeStartIgnoreCase(url, RESTConst.HTTP_HEAD);
    url = StringUtils.removeStartIgnoreCase(url, RESTConst.HTTPS_HEAD);
    url = "/" + StringUtils.substringAfter(url, "/");
    String path = StringUtils.substringBefore(url, "?");
    return path;
}
 
Example 2
Source File: KeycloakOauthPolicy.java    From apiman-plugins with Apache License 2.0 5 votes vote down vote up
private String getRawAuthToken(ApiRequest request) {
    String rawToken = StringUtils.strip(request.getHeaders().get(AUTHORIZATION_KEY));

    if (rawToken != null && StringUtils.startsWithIgnoreCase(rawToken, BEARER)) {
        rawToken = StringUtils.removeStartIgnoreCase(rawToken, BEARER);
    } else {
        rawToken = request.getQueryParams().get(ACCESS_TOKEN_QUERY_KEY);
    }

    return rawToken;
}
 
Example 3
Source File: XmlUtils.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
/**
 * Relativize path
 * <p>
 * TODO replace all the workarounds (JENKINS-44088, JENKINS-46084, mac special folders...) by a unique call to
 * {@link File#getCanonicalPath()} on the workspace for the whole "MavenSpyLogProcessor#processMavenSpyLogs" code block.
 * We donb't want to pay an RPC call to {@link File#getCanonicalPath()} each time.
 *
 * @return relativized path
 * @throws IllegalArgumentException if {@code other} is not a {@code Path} that can be relativized
 *                                  against this path
 * @see java.nio.file.Path#relativize(Path)
 */
@Nonnull
public static String getPathInWorkspace(@Nonnull final String absoluteFilePath, @Nonnull FilePath workspace) {
    boolean windows = FileUtils.isWindows(workspace);

    final String workspaceRemote = workspace.getRemote();

    String sanitizedAbsoluteFilePath;
    String sanitizedWorkspaceRemote;
    if (windows) {
        // sanitize to workaround JENKINS-44088
        sanitizedWorkspaceRemote = workspaceRemote.replace('/', '\\');
        sanitizedAbsoluteFilePath = absoluteFilePath.replace('/', '\\');
    } else if (workspaceRemote.startsWith("/var/") && absoluteFilePath.startsWith("/private/var/")) {
        // workaround MacOSX special folders path
        // eg String workspace = "/var/folders/lq/50t8n2nx7l316pwm8gc_2rt40000gn/T/jenkinsTests.tmp/jenkins3845105900446934883test/workspace/build-on-master-with-tool-provided-maven";
        // eg String absolutePath = "/private/var/folders/lq/50t8n2nx7l316pwm8gc_2rt40000gn/T/jenkinsTests.tmp/jenkins3845105900446934883test/workspace/build-on-master-with-tool-provided-maven/pom.xml";
        sanitizedWorkspaceRemote = workspaceRemote;
        sanitizedAbsoluteFilePath = absoluteFilePath.substring("/private".length());
    } else {
        sanitizedAbsoluteFilePath = absoluteFilePath;
        sanitizedWorkspaceRemote = workspaceRemote;
    }

    if (StringUtils.startsWithIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote)) {
        // OK
    } else if (sanitizedWorkspaceRemote.contains("/workspace/") && sanitizedAbsoluteFilePath.contains("/workspace/")) {
        // workaround JENKINS-46084
        // sanitizedAbsoluteFilePath = '/app/Jenkins/home/workspace/testjob/pom.xml'
        // sanitizedWorkspaceRemote = '/var/lib/jenkins/workspace/testjob'
        sanitizedAbsoluteFilePath = "/workspace/" + StringUtils.substringAfter(sanitizedAbsoluteFilePath, "/workspace/");
        sanitizedWorkspaceRemote = "/workspace/" + StringUtils.substringAfter(sanitizedWorkspaceRemote, "/workspace/");
    } else if (sanitizedWorkspaceRemote.endsWith("/workspace") && sanitizedAbsoluteFilePath.contains("/workspace/")) {
        // workspace = "/var/lib/jenkins/jobs/Test-Pipeline/workspace";
        // absolutePath = "/storage/jenkins/jobs/Test-Pipeline/workspace/pom.xml";
        sanitizedAbsoluteFilePath = "workspace/" + StringUtils.substringAfter(sanitizedAbsoluteFilePath, "/workspace/");
        sanitizedWorkspaceRemote = "workspace/";
    } else {
        throw new IllegalArgumentException("Cannot relativize '" + absoluteFilePath + "' relatively to '" + workspace.getRemote() + "'");
    }

    String relativePath = StringUtils.removeStartIgnoreCase(sanitizedAbsoluteFilePath, sanitizedWorkspaceRemote);
    String fileSeparator = windows ? "\\" : "/";

    if (relativePath.startsWith(fileSeparator)) {
        relativePath = relativePath.substring(fileSeparator.length());
    }
    LOGGER.log(Level.FINEST, "getPathInWorkspace({0}, {1}: {2}", new Object[]{absoluteFilePath, workspaceRemote, relativePath});
    return relativePath;
}